Skip to content

fix: remove useRoute warning #11250

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

Merged
merged 2 commits into from
Dec 16, 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
4 changes: 2 additions & 2 deletions components/common/ChainDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class="chain-dropdown-text"
:variant="variant"
:label="
isMobile || !showNetworkLabel
isMobileDevice || !showNetworkLabel
? label || selected?.text
: `Network: ${selected?.text}`
"
Expand All @@ -31,6 +31,7 @@
<script setup lang="ts">
import { NeoButton, NeoDropdown, NeoDropdownItem, type NeoButtonVariant } from '@kodadot1/brick'
import { type Prefix } from '@kodadot1/static'
import { isMobileDevice } from '@/utils/extension'

const props = withDefaults(
defineProps<{
Expand All @@ -57,7 +58,6 @@ const route = useReactiveRoute()
const { setUrlPrefix, urlPrefix } = usePrefix()
const { availableChains: allChains, availableChainsByVm: allChainInVm } = useChain()
const { redirectAfterChainChange } = useChainRedirect()
const { isMobile } = useViewport()

const prefix = computed(() => route.params.prefix || urlPrefix.value)

Expand Down
12 changes: 1 addition & 11 deletions composables/usePrefix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,16 @@ import { DEFAULT_PREFIX } from '@kodadot1/static'
import type { Prefix } from '@kodadot1/static'
import { useWalletStore } from '@/stores/wallet'
import { useAssetsStore } from '@/stores/assets'
import { getAvailablePrefix } from '@/utils/chain'

const sharedPrefix = ref<Prefix>()

export default function () {
const route = useRoute()
const storage = useLocalStorage('urlPrefix', { selected: DEFAULT_PREFIX })
const initialPrefixFromPath = getAvailablePrefix(route.path.split('/')[1])
const walletStore = useWalletStore()

const validPrefixFromRoute = computed(() =>
getAvailablePrefix(route.params.prefix),
)

const prefix = computed<Prefix>(
() =>
(sharedPrefix.value
|| validPrefixFromRoute.value
|| storage.value.selected
|| initialPrefixFromPath) as Prefix,
(sharedPrefix.value || storage.value.selected) as Prefix,
)

const handlePrefixChange = (value: Prefix) => {
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/redirect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ test('Redirections', async ({ page }) => {
// Collection
await test.step('Expect collection url to be properly redirected', async () => {
await page.goto('/ahk/explore/gallery')
await expect(page).toHaveURL('/ahk/explore/items')
await expect(page).toHaveURL('/ahk/explore/items?listed=true')
})

// Statemine
await test.step('Expect url with stmn to be properly redirected', async () => {
await page.goto('/stmn/explore/items')
await expect(page).toHaveURL('/ahk/explore/items')
await expect(page).toHaveURL('/ahk/explore/items?listed=true')
})

// Transfer
Expand Down
6 changes: 0 additions & 6 deletions utils/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ export const isPrefixVmOf = (prefix: Prefix, vm: ChainVM) =>
.map(({ value }) => value)
.includes(prefix)

export const getAvailablePrefix = (prefix: string): string => {
return availablePrefixes().some(chain => chain.value === prefix)
? prefix
: ''
}

export const chainIcons = {
ahk: '/token/kusama_asset_hub.svg',
ahp: '/token/polkadot_asset_hub.svg',
Expand Down
Loading