Skip to content

Commit

Permalink
Merge pull request #11193 from hassnian/issue-11192
Browse files Browse the repository at this point in the history
fix: Can't change chain from profile page
  • Loading branch information
vikiival authored Dec 10, 2024
2 parents b654924 + ce72171 commit 44bf46c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
8 changes: 6 additions & 2 deletions components/common/ConnectWallet/ConnectWalletModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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_CHANGE_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()
Expand All @@ -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_CHANGE_ROUTES_NAMES.includes(route.name?.toString() || '')) {
setUrlPrefix(prefix)
redirectAfterChainChange(urlPrefix.value)
}
Expand Down
13 changes: 1 addition & 12 deletions components/profile/ProfileDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -513,16 +513,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))
Expand Down Expand Up @@ -841,15 +839,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()
Expand Down
4 changes: 2 additions & 2 deletions composables/useAddress.ts
Original file line number Diff line number Diff line change
@@ -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<Prefix> = usePrefix().urlPrefix) {
const { isEvm, isSub } = useIsChain(urlPrefix)

const getPrefixByAddress = (address: string) => {
Expand Down
21 changes: 14 additions & 7 deletions composables/useChainRedirect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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'

const NO_REDIRECT_ROUTE_NAMES = [
Expand Down Expand Up @@ -39,10 +40,12 @@ function getRedirectPathForPrefix({
}: {
routeName: string
chain: Prefix
route
}): RawLocation {
route: RouteLocationNormalizedLoadedGeneric
}): RouteLocationRaw {
const vmChanged = !arePrefixesOfSameVm(route.params.prefix.toString() as Prefix, chain)

if (routeName.includes('prefix-swap-id')) {
const accountId = getss58AddressByPrefix(route.params.id, chain)
const accountId = getss58AddressByPrefix(route.params.id.toString(), chain)

return {
params: {
Expand All @@ -56,7 +59,11 @@ function getRedirectPathForPrefix({
}

if (routeName === 'prefix-u-id') {
const accountId = getss58AddressByPrefix(route.params.id, chain)
if (vmChanged) {
return { path: `/${chain}` }
}

const accountId = getss58AddressByPrefix(route.params.id.toString(), chain)

delete route.query.collections

Expand Down Expand Up @@ -111,15 +118,15 @@ 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
}

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

let redirectLocation: RawLocation = { path: `/${newChain}` }
let redirectLocation: RouteLocationRaw = { path: `/${newChain}` }

if (route.params.prefix) {
redirectLocation = getRedirectPathForPrefix({
Expand Down

0 comments on commit 44bf46c

Please sign in to comment.