Skip to content

Commit 44bf46c

Browse files
authored
Merge pull request #11193 from hassnian/issue-11192
fix: Can't change chain from profile page
2 parents b654924 + ce72171 commit 44bf46c

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

components/common/ConnectWallet/ConnectWalletModal.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ import WalletAsset from '@/components/common/ConnectWallet/WalletAsset.vue'
5656
import { ModalCloseType } from '@/components/navbar/types'
5757
import { arePrefixesOfSameVm } from '@/utils/config/chain.config'
5858
59+
const NO_PREFIX_CHANGE_ROUTES_NAMES = [
60+
'prefix-u-id',
61+
]
62+
5963
const emit = defineEmits(['close', 'connect'])
6064
const props = defineProps<{ preselected?: ChainVM }>()
6165
const { isWalletModalOpen } = useWallet()
62-
66+
const route = useRoute()
6367
const { urlPrefix, setUrlPrefix } = usePrefix()
6468
const { redirectAfterChainChange } = useChainRedirect()
6569
const walletStore = useWalletStore()
@@ -76,7 +80,7 @@ const setAccount = ({ account, prefix }: { account: WalletAccount, prefix?: Pref
7680
walletStore.setWallet(account)
7781
identityStore.setAuth({ address: account.address })
7882
79-
if (!arePrefixesOfSameVm(prefix, urlPrefix.value)) {
83+
if (!arePrefixesOfSameVm(prefix, urlPrefix.value) && !NO_PREFIX_CHANGE_ROUTES_NAMES.includes(route.name?.toString() || '')) {
8084
setUrlPrefix(prefix)
8185
redirectAfterChainChange(urlPrefix.value)
8286
}

components/profile/ProfileDetail.vue

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -513,16 +513,14 @@ const { $i18n } = useNuxtApp()
513513
const { toast } = useToast()
514514
const { replaceUrl } = useReplaceUrl()
515515
const { accountId, isCurrentOwner } = useAuth()
516-
const { urlPrefix, client, setUrlPrefix } = usePrefix()
516+
const { urlPrefix, client } = usePrefix()
517517
const { shareOnX, shareOnFarcaster } = useSocialShare()
518-
const { redirectAfterChainChange } = useChainRedirect()
519518
const profileOnboardingStore = useProfileOnboardingStore()
520519
const { getIsOnboardingShown } = storeToRefs(profileOnboardingStore)
521520
522521
const { isSub } = useIsChain(urlPrefix)
523522
const listingCartStore = useListingCartStore()
524523
const { vm } = useChain()
525-
const { getPrefixByAddress } = useAddress()
526524
const { params } = useRoute()
527525
528526
const { hasProfile, userProfile, isFetchingProfile } = useProfile(computed(() => params?.id as string))
@@ -841,15 +839,6 @@ watch(collections, (value) => {
841839
})
842840
})
843841
844-
watch(() => getPrefixByAddress(route.params.id.toString()), (prefix) => {
845-
if (prefix !== urlPrefix.value) {
846-
setUrlPrefix(prefix)
847-
redirectAfterChainChange(prefix)
848-
}
849-
}, {
850-
immediate: true,
851-
})
852-
853842
watchEffect(() => {
854843
if (!hasProfile.value && !isFetchingProfile.value && isOwner.value && !getIsOnboardingShown.value) {
855844
profileOnboardingStore.setOnboardingShown()

composables/useAddress.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isEthereumAddress } from '@polkadot/util-crypto'
2+
import { type Prefix } from '@kodadot1/static'
23

3-
export default function () {
4-
const { urlPrefix } = usePrefix()
4+
export default function (urlPrefix: ComputedRef<Prefix> = usePrefix().urlPrefix) {
55
const { isEvm, isSub } = useIsChain(urlPrefix)
66

77
const getPrefixByAddress = (address: string) => {

composables/useChainRedirect.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Prefix } from '@kodadot1/static'
2-
import type { RawLocation } from 'vue-router/types/router'
2+
import type { RouteLocationRaw, RouteLocationNormalizedLoadedGeneric } from 'vue-router'
33
import { createVisible } from '@/utils/config/permission.config'
4+
import { arePrefixesOfSameVm } from '@/utils/config/chain.config'
45
import { getss58AddressByPrefix } from '@/utils/account'
56

67
const NO_REDIRECT_ROUTE_NAMES = [
@@ -39,10 +40,12 @@ function getRedirectPathForPrefix({
3940
}: {
4041
routeName: string
4142
chain: Prefix
42-
route
43-
}): RawLocation {
43+
route: RouteLocationNormalizedLoadedGeneric
44+
}): RouteLocationRaw {
45+
const vmChanged = !arePrefixesOfSameVm(route.params.prefix.toString() as Prefix, chain)
46+
4447
if (routeName.includes('prefix-swap-id')) {
45-
const accountId = getss58AddressByPrefix(route.params.id, chain)
48+
const accountId = getss58AddressByPrefix(route.params.id.toString(), chain)
4649

4750
return {
4851
params: {
@@ -56,7 +59,11 @@ function getRedirectPathForPrefix({
5659
}
5760

5861
if (routeName === 'prefix-u-id') {
59-
const accountId = getss58AddressByPrefix(route.params.id, chain)
62+
if (vmChanged) {
63+
return { path: `/${chain}` }
64+
}
65+
66+
const accountId = getss58AddressByPrefix(route.params.id.toString(), chain)
6067

6168
delete route.query.collections
6269

@@ -111,15 +118,15 @@ export default function () {
111118
const router = useRouter()
112119

113120
const redirectAfterChainChange = (newChain: Prefix): void => {
114-
const routeName = route.name as string
121+
const routeName = route.name?.toString() || ''
115122

116123
if (isNoRedirect(routeName)) {
117124
return
118125
}
119126

120127
const isSimpleCreate = routeName.includes('-create')
121128

122-
let redirectLocation: RawLocation = { path: `/${newChain}` }
129+
let redirectLocation: RouteLocationRaw = { path: `/${newChain}` }
123130

124131
if (route.params.prefix) {
125132
redirectLocation = getRedirectPathForPrefix({

0 commit comments

Comments
 (0)