Skip to content

Commit

Permalink
fix: Welcome page can not open
Browse files Browse the repository at this point in the history
  • Loading branch information
AricRedemption committed Mar 14, 2024
1 parent 689a6f9 commit 9cc3a2e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { FEEB } from './data/config'
import useStorage from '@/lib/storage'
import { gotoWelcome } from '@/lib/utils'
import { getNetwork } from './lib/network'
import { computed, Ref, inject } from 'vue'
import { useRoute, useRouter } from 'vue-router'
Expand All @@ -12,6 +13,7 @@ import TheHeader from './components/headers/TheHeader.vue'
import { API_NET, API_TARGET, Wallet } from 'meta-contract'
import { getCurrentAccount, getPrivateKey } from './lib/account'
import SecondaryHeader from './components/headers/SecondaryHeader.vue'
import {
migrateV2,
migrationSync,
Expand Down Expand Up @@ -57,7 +59,7 @@ checkMigrate().then(async () => {
const wif = await getPrivateKey()
wallet.value = new Wallet(wif, network as API_NET, FEEB, API_TARGET.MVC)
} else {
router.push('/welcome')
gotoWelcome('/welcome')
}
})
</script>
Expand Down
13 changes: 12 additions & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { type ClassValue, clsx } from 'clsx'
import router from '@/router'
import { IS_DEV } from '@/data/config'
import { twMerge } from 'tailwind-merge'
import { type ClassValue, clsx } from 'clsx'
import { camelize, getCurrentInstance, toHandlerKey } from 'vue'

export const gotoWelcome = (path: string) => {
if (IS_DEV) {
router.push('/welcome')
} else {
const { origin, pathname } = window.location
window.open(`${origin}${pathname}/#${path}`, '_blank')
}
}

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
3 changes: 2 additions & 1 deletion src/pages/migrateV2/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useRouter } from 'vue-router'
import { getCurrentAccount } from '@/lib/account'
import { migrateV2, needMigrationV2 } from '@/lib/migrate'
import MetaletLogoImg from '@/assets/images/metalet-logo.png?url'
import { gotoWelcome } from '@/lib/utils'
const router = useRouter()
needMigrationV2().then(async (needsMigration: boolean) => {
Expand All @@ -15,7 +16,7 @@ needMigrationV2().then(async (needsMigration: boolean) => {
if (await getCurrentAccount()) {
router.push('/wallet')
} else {
router.push('/welcome')
gotoWelcome('/welcome')
}
})
</script>
Expand Down
4 changes: 0 additions & 4 deletions src/pages/wallet/components/AssetList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ onMounted(async () => {
mvcAddress.value = await getAddress('mvc')
btcAddress.value = await getAddress('btc')
if (!btcAddress.value || !mvcAddress.value) {
router.push('/welcome')
}
getServiceNetwork().then((_serviceNetwork) => {
serviceNetwork.value = _serviceNetwork
})
Expand Down
2 changes: 2 additions & 0 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import useStorage from './lib/storage'
import { IS_DEV } from '@/data/config'
import * as VueRouter from 'vue-router'
import { assetList } from '@/lib/balance'
import { gotoWelcome } from '@/lib/utils'
import Wallet from './pages/wallet/Index.vue'
import { getCurrentAccount } from './lib/account'

Expand Down Expand Up @@ -419,6 +420,7 @@ router.beforeEach(async (to, _, next) => {
if (to.fullPath !== '/lock' && (await storage.get('locked'))) {
next('/lock')
} else if (!authPages.includes(to.path) && !(await getCurrentAccount())) {
gotoWelcome('/welcome')
next('/welcome')
} else {
if (['asset', 'token'].includes(to.name as string)) {
Expand Down

0 comments on commit 9cc3a2e

Please sign in to comment.