Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Transfer page showing wrong tokens #10809

Merged
merged 4 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions components/common/ConnectWallet/WalletAssetMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,29 +80,29 @@

<script setup lang="ts">
import { NeoDropdown, NeoDropdownItem, NeoIcon } from '@kodadot1/brick'
import type { ChainVM } from '@kodadot1/static'
import type { Prefix } from '@kodadot1/static'
import { langsFlags, setUserLocale } from '@/utils/config/i18n'
import { transferVisible, teleportVisible, migrateVisible } from '@/utils/config/permission.config'
const { urlPrefix } = usePrefix()
const { vm } = useChain()
// const { isAssetHub } = useIsChain(urlPrefix)
const { neoModal } = useProgrammatic()
const menus = ref<{ label: string, to: string, vm: ChainVM[] }[]>([
const menus = ref<{ label: string, to: string, check: (v: Prefix) => boolean }[]>([
{
label: 'Transfer',
to: `/${urlPrefix.value}/transfer`,
vm: ['SUB'],
check: transferVisible,
},
{
label: 'Teleport Bridge',
to: `/${urlPrefix.value}/teleport`,
vm: ['SUB'],
check: teleportVisible,
},
{
label: 'Migrate',
to: '/migrate',
vm: ['SUB'],
check: migrateVisible,
},
])
Expand All @@ -122,7 +122,7 @@ const menus = ref<{ label: string, to: string, vm: ChainVM[] }[]>([
// })
const filteredMenus = computed(() =>
menus.value.filter(menu => menu.vm.includes(vm.value)),
menus.value.filter(menu => menu.check(urlPrefix.value)),
)
const closeModal = () => {
Expand Down
5 changes: 2 additions & 3 deletions composables/useToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ const getUniqueArrayItems = (items: string[]) => [...new Set(items)]
export default function useToken() {
const { getCurrentTokenValue } = useFiatStore()
const { getTokenIconBySymbol } = useIcon()
const { multiBalanceAssets } = useIdentityStore()
const { getVmAssets } = storeToRefs(useIdentityStore())

const availableAssets = computed(() => multiBalanceAssets)
const availableTokensAcrossAllChains = computed(() =>
getUniqueArrayItems(
Object.values(availableAssets.value).map(getAssetToken),
Object.values(getVmAssets.value).map(getAssetToken),
),
)

Expand Down
32 changes: 20 additions & 12 deletions middleware/redirects.global.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import { createVisible } from '@/utils/config/permission.config'
import { type Prefix } from '@kodadot1/static'
import { createVisible, transferVisible, teleportVisible, migrateVisible } from '@/utils/config/permission.config'

export default defineNuxtRouteMiddleware((route) => {
const { urlPrefix } = usePrefix()

const getPermissionRouteCondition = (cond: (value: string) => boolean, routeVisible: (value: Prefix) => boolean) => {
return {
cond,
replaceValue: () => {
if (!routeVisible(urlPrefix.value)) {
return '/'
}
},
}
}

let redirectValue

const paths = [
Expand All @@ -28,22 +40,18 @@ export default defineNuxtRouteMiddleware((route) => {
cond: val => val.includes('/rmrk2/'),
replaceValue: () => window.location.href.replace('/rmrk2/', '/ksm/'),
},
getPermissionRouteCondition((val: string) => val === `/${urlPrefix.value}/teleport`, teleportVisible),
getPermissionRouteCondition((val: string) => val === `/${urlPrefix.value}/transfer`, transferVisible),
getPermissionRouteCondition((val: string) => val === '/migrate', migrateVisible),
{
cond: val => val.startsWith('/transfer'),
replaceValue: () =>
window.location.href.replace('/transfer', '/ksm/transfer'),
},
{
cond: val =>
val === `/${urlPrefix.value}/create`
|| val === `/${urlPrefix.value}/massmint`
|| val.startsWith('/create'),
replaceValue: () => {
if (!createVisible(urlPrefix.value)) {
return '/'
}
},
},
getPermissionRouteCondition((val: string) =>
val === `/${urlPrefix.value}/create`
|| val === `/${urlPrefix.value}/massmint`
|| val.startsWith('/create'), createVisible),
]

for (const path of paths) {
Expand Down
17 changes: 14 additions & 3 deletions utils/config/permission.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { chainPropListOf } from './chain.config'
import type { PartialConfig, Prefix } from './types'

const hasCreate: PartialConfig = {
Expand Down Expand Up @@ -32,7 +31,19 @@ export const createVisible = (prefix: Prefix | string): boolean => {
}

export const listVisible = (prefix: Prefix | string): boolean => {
return !isEvm(prefix as Prefix)
return isSub(prefix as Prefix)
}

export const transferVisible = (prefix: Prefix | string): boolean => {
return isSub(prefix as Prefix)
}

export const teleportVisible = (prefix: Prefix | string): boolean => {
return isSub(prefix as Prefix)
}

export const migrateVisible = (prefix: Prefix | string): boolean => {
return isSub(prefix as Prefix)
}

export const seriesInsightVisible = (prefix: Prefix | string) => {
Expand All @@ -48,7 +59,7 @@ export const salesVisible = (prefix: Prefix | string) => {
}

export const dropsVisible = (prefix: Prefix | string) => {
return prefix === 'ahk' || prefix === 'ahp' || chainPropListOf(prefix as Prefix).vm === 'EVM'
return prefix === 'ahk' || prefix === 'ahp' || isEvm(prefix)
}

export const explorerVisible = (prefix: Prefix | string): boolean => {
Expand Down
Loading