feat: 更新钱包存储,添加USDT余额同步功能并移除初始化钱包调用

This commit is contained in:
2026-01-11 17:42:28 +07:00
parent 3f846a2a04
commit 9f0f0a076c
3 changed files with 19 additions and 4 deletions

View File

@@ -17,7 +17,6 @@ onMounted(() => {
if (!isAuthenticated.value)
return;
updateProfile();
initializeWallet();
CapacitorApp.addListener("appStateChange", ({ isActive }) => {
if (isActive) {
userStore.updateProfile();

View File

@@ -13,9 +13,9 @@ const emit = defineEmits<{
const { t } = useI18n();
const walletStore = useWalletStore();
await walletStore.syncFundingBalances();
const { fundingBalances } = storeToRefs(walletStore);
const currentUSDTBalance = computed(() => fundingBalances.value[0]?.available || 0);
await walletStore.syncUSDTBalance();
const { USDTBalance } = storeToRefs(walletStore);
const currentUSDTBalance = computed(() => USDTBalance.value?.available || 0);
const num = ref<number | null>(null);

View File

@@ -2,6 +2,12 @@ import type { BalancesData, BankAccountsData, SupportBanksData, TotalAssetValue
import { defineStore } from "pinia";
import { client, safeClient } from "@/api";
interface USDTBalance {
available: string;
frozen: string;
total: string;
}
interface State {
totalAssetValue: TotalAssetValue;
balances: BalancesData;
@@ -9,6 +15,7 @@ interface State {
tradingBalances: BalancesData;
bankAccounts: BankAccountsData[];
supportBanks: SupportBanksData["data"];
USDTBalance: USDTBalance | null;
}
export const useWalletStore = defineStore("wallet", () => {
@@ -23,6 +30,7 @@ export const useWalletStore = defineStore("wallet", () => {
tradingBalances: [],
bankAccounts: [],
supportBanks: [],
USDTBalance: null,
});
async function initializeWallet() {
@@ -71,6 +79,13 @@ export const useWalletStore = defineStore("wallet", () => {
state.supportBanks = banks.value?.data || [];
}
async function syncUSDTBalance() {
const { data } = await safeClient(client.api.wallet.balance({ assetCode: "USDT" }).get({
query: { accountType: "funding" },
}), { silent: true });
state.USDTBalance = data.value || null;
}
return {
...toRefs(state),
initializeWallet,
@@ -79,5 +94,6 @@ export const useWalletStore = defineStore("wallet", () => {
syncTradingBalances,
syncBankAccounts,
syncSupportBanks,
syncUSDTBalance,
};
});