Skip to content

Commit

Permalink
fix: redirectAfterChainChange on route with prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
hassnian committed Nov 28, 2024
1 parent dc4b34e commit ea494ae
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions composables/useChainRedirect.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ea494ae

Please sign in to comment.