From 44462f68872fdc459838fe6327f01bb6b4e257eb Mon Sep 17 00:00:00 2001 From: AricRedemption Date: Fri, 19 Apr 2024 10:24:53 +0800 Subject: [PATCH] chore: change opening method for welcome page --- src/lib/utils.ts | 8 +++++++ src/lib/wallet.ts | 44 +++++++++++++++++++++++++++++++++++--- src/pages/manage/Index.vue | 4 ++-- src/pages/wallet/Asset.vue | 6 +++--- src/router.ts | 8 +++---- src/stores/WalletStore.ts | 44 ++++++++++++++++---------------------- 6 files changed, 77 insertions(+), 37 deletions(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index cd73d64f..b676eadd 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -21,6 +21,14 @@ export const goToPage = (path: string, created = false) => { } } +export const goToTab = (path: string, created = false) => { + if (IS_DEV || !created) { + router.push(path) + } else { + window.open(`${window.location.href.split('#')[0]}#${path}`, '_blank') + } +} + export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)) } diff --git a/src/lib/wallet.ts b/src/lib/wallet.ts index 63d9bc8a..20b8b3a0 100644 --- a/src/lib/wallet.ts +++ b/src/lib/wallet.ts @@ -1,8 +1,8 @@ import { goToPage } from './utils' -import { V3Wallet } from './types' import useStorage from '@/lib/storage' -import { getCurrentAccountId } from './account' +import { type V3Wallet } from './types' import { toast } from '@/components/ui/toast' +import { getCurrentAccountId } from './account' const CURRENT_WALLET_ID = 'currentWalletId' const V3_WALLETS_STORAGE_KEY = 'wallets_v3' @@ -61,7 +61,7 @@ export async function getV3CurrentWallet() { return wallet } -export async function getActiveWalletAccount() { +export async function getActiveWalletOnlyAccount() { const walletId = await getCurrentWalletId() if (!walletId) { throw new Error('current wallet id not found') @@ -91,6 +91,44 @@ export async function getActiveWalletAccount() { return wallet } +export async function getInactiveWallets() { + const currentWalletId = await getCurrentWalletId() + if (!currentWalletId) { + throw new Error('Current wallet id not found.') + } + const wallets = await getV3Wallets() + if (!wallets.length) { + throw new Error('No wallets found. Please create a wallet first.') + } + return wallets.filter((wallet) => wallet.id !== currentWalletId) +} + +export async function getActiveWalletOtherAccounts() { + const walletId = await getCurrentWalletId() + if (!walletId) { + throw new Error('current wallet id not found') + } + const wallets = await getV3Wallets() + if (!wallets.length) { + throw new Error('wallets not found') + } + const wallet = wallets.find((wallet) => wallet.id === walletId) + if (!wallet) { + throw new Error('wallet not found') + } + + const { accounts } = wallet + if (!accounts || !accounts.length) { + throw new Error('wallet does not have any accounts') + } + const currentAccountId = await getCurrentAccountId() + if (!currentAccountId) { + throw new Error('current account id not found') + } + wallet.accounts = accounts.filter((account) => account.id !== currentAccountId) + return wallet +} + export async function getV3CurrentAccount() { const walletId = await getCurrentWalletId() const wallets = await getV3Wallets() diff --git a/src/pages/manage/Index.vue b/src/pages/manage/Index.vue index 7724ad38..b801bd87 100644 --- a/src/pages/manage/Index.vue +++ b/src/pages/manage/Index.vue @@ -1,12 +1,12 @@