From dc4b34e87bfe1b2721de0c27b41e4226434c6b08 Mon Sep 17 00:00:00 2001 From: hassnian <44554284+hassnian@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:00:40 +0500 Subject: [PATCH 1/5] fix(useChainRedirect.ts): can't change chain on profile page --- composables/useChainRedirect.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/composables/useChainRedirect.ts b/composables/useChainRedirect.ts index 91d1dd9d1b..54a3db51b5 100644 --- a/composables/useChainRedirect.ts +++ b/composables/useChainRedirect.ts @@ -1,6 +1,7 @@ import type { Prefix } from '@kodadot1/static' import type { RawLocation } from 'vue-router/types/router' import { createVisible } from '@/utils/config/permission.config' +import { arePrefixesOfSameVm } from '@/utils/config/chain.config' import { getss58AddressByPrefix } from '@/utils/account' const NO_REDIRECT_ROUTE_NAMES = [ @@ -14,6 +15,10 @@ const NO_REDIRECT_ROUTE_NAMES = [ 'create-collection', ] +const REDIRECT_HOME_ON_VM_CHANGE_ROUTE_NAMES = [ + 'prefix-u-id', +] + function isNoRedirect(routeName: string): boolean { return NO_REDIRECT_ROUTE_NAMES.includes(routeName) } @@ -103,10 +108,15 @@ export default function () { return } - const isSimpleCreate = routeName.includes('-create') - let redirectLocation: RawLocation = { path: `/${newChain}` } + if (!arePrefixesOfSameVm(route.params.prefix as Prefix, newChain) && REDIRECT_HOME_ON_VM_CHANGE_ROUTE_NAMES.includes(routeName)) { + router.push(redirectLocation) + return + } + + const isSimpleCreate = routeName.includes('-create') + if (route.params.prefix) { redirectLocation = getRedirectPathForPrefix({ routeName, From ea494ae898fe1e9a8b640664f1263dd7501a3365 Mon Sep 17 00:00:00 2001 From: hassnian <44554284+hassnian@users.noreply.github.com> Date: Thu, 28 Nov 2024 14:02:22 +0500 Subject: [PATCH 2/5] fix: `redirectAfterChainChange` on route with `prefix` --- composables/useChainRedirect.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/composables/useChainRedirect.ts b/composables/useChainRedirect.ts index 54a3db51b5..95940981b7 100644 --- a/composables/useChainRedirect.ts +++ b/composables/useChainRedirect.ts @@ -1,5 +1,5 @@ import type { Prefix } from '@kodadot1/static' -import type { RawLocation } from 'vue-router/types/router' +import type { RouteLocationRaw, RouteLocationNormalizedLoadedGeneric } from 'vue-router' import { createVisible } from '@/utils/config/permission.config' import { arePrefixesOfSameVm } from '@/utils/config/chain.config' import { getss58AddressByPrefix } from '@/utils/account' @@ -44,10 +44,14 @@ function getRedirectPathForPrefix({ }: { routeName: string chain: Prefix - route -}): RawLocation { + route: RouteLocationNormalizedLoadedGeneric +}): RouteLocationRaw { + if (!arePrefixesOfSameVm(route.params.prefix.toString() as Prefix, chain) && REDIRECT_HOME_ON_VM_CHANGE_ROUTE_NAMES.includes(routeName)) { + return { path: `/${chain}` } + } + if (routeName === 'prefix-u-id') { - const accountId = getss58AddressByPrefix(route.params.id, chain) + const accountId = getss58AddressByPrefix(route.params.id.toString(), chain) delete route.query.collections @@ -108,15 +112,10 @@ export default function () { return } - let redirectLocation: RawLocation = { path: `/${newChain}` } - - if (!arePrefixesOfSameVm(route.params.prefix as Prefix, newChain) && REDIRECT_HOME_ON_VM_CHANGE_ROUTE_NAMES.includes(routeName)) { - router.push(redirectLocation) - return - } - const isSimpleCreate = routeName.includes('-create') + let redirectLocation: RouteLocationRaw = { path: `/${newChain}` } + if (route.params.prefix) { redirectLocation = getRedirectPathForPrefix({ routeName, From 6842ba7e7aa7759dfd63a0376e662ae3d3152d60 Mon Sep 17 00:00:00 2001 From: hassnian <44554284+hassnian@users.noreply.github.com> Date: Fri, 6 Dec 2024 11:13:47 +0500 Subject: [PATCH 3/5] remove: watch `getPrefixByAddress` --- components/profile/ProfileDetail.vue | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/components/profile/ProfileDetail.vue b/components/profile/ProfileDetail.vue index e71059b6e6..1e11a35df1 100644 --- a/components/profile/ProfileDetail.vue +++ b/components/profile/ProfileDetail.vue @@ -504,16 +504,14 @@ const { $i18n } = useNuxtApp() const { toast } = useToast() const { replaceUrl } = useReplaceUrl() const { accountId, isCurrentOwner } = useAuth() -const { urlPrefix, client, setUrlPrefix } = usePrefix() +const { urlPrefix, client } = usePrefix() const { shareOnX, shareOnFarcaster } = useSocialShare() -const { redirectAfterChainChange } = useChainRedirect() const profileOnboardingStore = useProfileOnboardingStore() const { getIsOnboardingShown } = storeToRefs(profileOnboardingStore) const { isSub } = useIsChain(urlPrefix) const listingCartStore = useListingCartStore() const { vm } = useChain() -const { getPrefixByAddress } = useAddress() const { params } = useRoute() const { hasProfile, userProfile, isFetchingProfile } = useProfile(computed(() => params?.id as string)) @@ -826,15 +824,6 @@ watch(collections, (value) => { }) }) -watch(() => getPrefixByAddress(route.params.id.toString()), (prefix) => { - if (prefix !== urlPrefix.value) { - setUrlPrefix(prefix) - redirectAfterChainChange(prefix) - } -}, { - immediate: true, -}) - watchEffect(() => { if (!hasProfile.value && !isFetchingProfile.value && isOwner.value && !getIsOnboardingShown.value) { profileOnboardingStore.setOnboardingShown() From 574e4ee676da2c24143b013e62bae79abaf0b00f Mon Sep 17 00:00:00 2001 From: hassnian <44554284+hassnian@users.noreply.github.com> Date: Fri, 6 Dec 2024 12:29:45 +0500 Subject: [PATCH 4/5] fix(profile): route redirect on wallet connect --- .../common/ConnectWallet/ConnectWalletModal.vue | 8 ++++++-- composables/useAddress.ts | 4 ++-- composables/useChainRedirect.ts | 14 ++++++-------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/components/common/ConnectWallet/ConnectWalletModal.vue b/components/common/ConnectWallet/ConnectWalletModal.vue index bb9cd9665f..0abd36c1af 100644 --- a/components/common/ConnectWallet/ConnectWalletModal.vue +++ b/components/common/ConnectWallet/ConnectWalletModal.vue @@ -56,10 +56,14 @@ import WalletAsset from '@/components/common/ConnectWallet/WalletAsset.vue' import { ModalCloseType } from '@/components/navbar/types' import { arePrefixesOfSameVm } from '@/utils/config/chain.config' +const NO_PREFIX_CHNAGE_ROUTES_NAMES = [ + 'prefix-u-id', +] + const emit = defineEmits(['close', 'connect']) const props = defineProps<{ preselected?: ChainVM }>() const { isWalletModalOpen } = useWallet() - +const route = useRoute() const { urlPrefix, setUrlPrefix } = usePrefix() const { redirectAfterChainChange } = useChainRedirect() const walletStore = useWalletStore() @@ -76,7 +80,7 @@ const setAccount = ({ account, prefix }: { account: WalletAccount, prefix?: Pref walletStore.setWallet(account) identityStore.setAuth({ address: account.address }) - if (!arePrefixesOfSameVm(prefix, urlPrefix.value)) { + if (!arePrefixesOfSameVm(prefix, urlPrefix.value) && !NO_PREFIX_CHNAGE_ROUTES_NAMES.includes(route.name?.toString() || '')) { setUrlPrefix(prefix) redirectAfterChainChange(urlPrefix.value) } diff --git a/composables/useAddress.ts b/composables/useAddress.ts index 1103046ceb..44040cb73f 100644 --- a/composables/useAddress.ts +++ b/composables/useAddress.ts @@ -1,7 +1,7 @@ import { isEthereumAddress } from '@polkadot/util-crypto' +import { type Prefix } from '@kodadot1/static' -export default function () { - const { urlPrefix } = usePrefix() +export default function (urlPrefix: ComputedRef = usePrefix().urlPrefix) { const { isEvm, isSub } = useIsChain(urlPrefix) const getPrefixByAddress = (address: string) => { diff --git a/composables/useChainRedirect.ts b/composables/useChainRedirect.ts index 95940981b7..e4a694fd73 100644 --- a/composables/useChainRedirect.ts +++ b/composables/useChainRedirect.ts @@ -15,10 +15,6 @@ const NO_REDIRECT_ROUTE_NAMES = [ 'create-collection', ] -const REDIRECT_HOME_ON_VM_CHANGE_ROUTE_NAMES = [ - 'prefix-u-id', -] - function isNoRedirect(routeName: string): boolean { return NO_REDIRECT_ROUTE_NAMES.includes(routeName) } @@ -46,11 +42,13 @@ function getRedirectPathForPrefix({ chain: Prefix route: RouteLocationNormalizedLoadedGeneric }): RouteLocationRaw { - if (!arePrefixesOfSameVm(route.params.prefix.toString() as Prefix, chain) && REDIRECT_HOME_ON_VM_CHANGE_ROUTE_NAMES.includes(routeName)) { - return { path: `/${chain}` } - } + const vmChanged = !arePrefixesOfSameVm(route.params.prefix.toString() as Prefix, chain) if (routeName === 'prefix-u-id') { + if (vmChanged) { + return { path: `/${chain}` } + } + const accountId = getss58AddressByPrefix(route.params.id.toString(), chain) delete route.query.collections @@ -106,7 +104,7 @@ export default function () { const router = useRouter() const redirectAfterChainChange = (newChain: Prefix): void => { - const routeName = route.name as string + const routeName = route.name?.toString() || '' if (isNoRedirect(routeName)) { return From ce7217124b982494aae452a68318777c2061f0f0 Mon Sep 17 00:00:00 2001 From: hassnian <44554284+hassnian@users.noreply.github.com> Date: Tue, 10 Dec 2024 14:14:33 +0500 Subject: [PATCH 5/5] fix(ConnectWalletModal.vue): constant typo --- components/common/ConnectWallet/ConnectWalletModal.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/common/ConnectWallet/ConnectWalletModal.vue b/components/common/ConnectWallet/ConnectWalletModal.vue index 0abd36c1af..09bb3907d0 100644 --- a/components/common/ConnectWallet/ConnectWalletModal.vue +++ b/components/common/ConnectWallet/ConnectWalletModal.vue @@ -56,7 +56,7 @@ import WalletAsset from '@/components/common/ConnectWallet/WalletAsset.vue' import { ModalCloseType } from '@/components/navbar/types' import { arePrefixesOfSameVm } from '@/utils/config/chain.config' -const NO_PREFIX_CHNAGE_ROUTES_NAMES = [ +const NO_PREFIX_CHANGE_ROUTES_NAMES = [ 'prefix-u-id', ] @@ -80,7 +80,7 @@ const setAccount = ({ account, prefix }: { account: WalletAccount, prefix?: Pref walletStore.setWallet(account) identityStore.setAuth({ address: account.address }) - if (!arePrefixesOfSameVm(prefix, urlPrefix.value) && !NO_PREFIX_CHNAGE_ROUTES_NAMES.includes(route.name?.toString() || '')) { + if (!arePrefixesOfSameVm(prefix, urlPrefix.value) && !NO_PREFIX_CHANGE_ROUTES_NAMES.includes(route.name?.toString() || '')) { setUrlPrefix(prefix) redirectAfterChainChange(urlPrefix.value) }