Skip to content

Commit

Permalink
Merge pull request #10756 from Jarsen136/issue-10752
Browse files Browse the repository at this point in the history
fix: Confusing linking on Base
  • Loading branch information
vikiival authored Aug 12, 2024
2 parents df17a4e + 16084ff commit 5ccfe23
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 14 deletions.
2 changes: 1 addition & 1 deletion components/common/ChainDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const props = withDefaults(
},
)
const route = useRoute()
const route = useReactiveRoute()
const { setUrlPrefix, urlPrefix } = usePrefix()
const allChains = useAvailableChainsOptions()
const { redirectAfterChainChange } = useChainRedirect()
Expand Down
8 changes: 4 additions & 4 deletions components/common/ConnectWallet/WalletAssetIdentity.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<template>
<div class="flex items-center justify-between">
<NuxtLink
:to="`/${urlPrefix}/u/${account}`"
:to="`/${prefix}/u/${account}`"
class="w-full"
@click="closeModal"
>
<IdentityItem
:account="account"
:label="display || shortenedAddress"
:prefix="urlPrefix"
:prefix="prefix"
>
<template #default="{ label }">
<div class="pl-3">
Expand Down Expand Up @@ -42,14 +42,14 @@
import { NeoIcon } from '@kodadot1/brick'
import { useIdentityStore } from '@/stores/identity'
const { urlPrefix } = usePrefix()
const { toast } = useToast()
const { neoModal } = useProgrammatic()
const { getPrefixByAddress } = useAddress()
const identityStore = useIdentityStore()
const { logout } = useWallet()
const account = computed(() => identityStore.getAuthAddress)
const prefix = computed(() => getPrefixByAddress(account.value))
const { profile } = useFetchProfile(account.value)
const { display, shortenedAddress } = useIdentity({
Expand Down
13 changes: 12 additions & 1 deletion components/profile/ProfileDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,14 @@ const { $i18n } = useNuxtApp()
const { toast } = useToast()
const { replaceUrl } = useReplaceUrl()
const { accountId } = useAuth()
const { urlPrefix, client } = usePrefix()
const { urlPrefix, client, setUrlPrefix } = usePrefix()
const { shareOnX, shareOnFarcaster } = useSocialShare()
const { redirectAfterChainChange } = useChainRedirect()
const { isRemark, isSub } = useIsChain(urlPrefix)
const listingCartStore = useListingCartStore()
const { vm } = useChain()
const { getPrefixByAddress } = useAddress()
const { hasProfile, userProfile, isFetchingProfile }
= useProfile()
Expand Down Expand Up @@ -786,6 +788,15 @@ watch(collections, (value) => {
})
})
watch(() => getPrefixByAddress(route.params.id.toString()), (prefix) => {
if (prefix !== urlPrefix.value) {
setUrlPrefix(prefix)
redirectAfterChainChange(prefix)
}
}, {
immediate: true,
})
onMounted(() => {
if (!hasProfile.value && isOwner.value) {
openProfileCreateModal()
Expand Down
18 changes: 18 additions & 0 deletions composables/useAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { isEthereumAddress } from '@polkadot/util-crypto'

export default function () {
const { urlPrefix } = usePrefix()
const { isEvm, isSub } = useIsChain(urlPrefix)

const getPrefixByAddress = (address: string) => {
if (isEthereumAddress(address)) {
return isEvm.value ? urlPrefix.value : 'base'
}

return isSub.value ? urlPrefix.value : 'ahp'
}

return {
getPrefixByAddress,
}
}
10 changes: 2 additions & 8 deletions composables/useChainRedirect.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { Prefix } from '@kodadot1/static'
import { CHAINS } from '@kodadot1/static'
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto'
import type { RawLocation } from 'vue-router/types/router'
import { createVisible } from '@/utils/config/permission.config'
import { getss58AddressByPrefix } from '@/utils/account'

const NO_REDIRECT_ROUTE_NAMES = [
'hot',
Expand All @@ -19,11 +18,6 @@ function isNoRedirect(routeName: string): boolean {
return NO_REDIRECT_ROUTE_NAMES.includes(routeName)
}

const getAddress = (chain: string, accountId: string) => {
const publicKey = decodeAddress(accountId)
return encodeAddress(publicKey, CHAINS[chain].ss58Format)
}

const clearInstanceSortFromQuery = (query) => {
if (Array.isArray(query.sort)) {
query.sort = query.sort.filter(value => !value.startsWith('instance_'))
Expand All @@ -48,7 +42,7 @@ function getRedirectPathForPrefix({
route
}): RawLocation {
if (routeName === 'prefix-u-id') {
const accountId = getAddress(chain, route.params.id)
const accountId = getss58AddressByPrefix(route.params.id, chain)

delete route.query.collections

Expand Down
6 changes: 6 additions & 0 deletions composables/useReactiveRoute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useRoute as _useRoute } from 'vue-router'

// context: auto-import useRouter is not reactive after initially being set. ref: https://github.com/kodadot/nft-gallery/issues/10757
export default function () {
return _useRoute()
}

0 comments on commit 5ccfe23

Please sign in to comment.