From 3db1198fd4674a2924a90e011a5113ebe1a59a4d Mon Sep 17 00:00:00 2001 From: MickWang <1244134672@qq.com> Date: Sat, 13 Apr 2024 11:29:53 +0800 Subject: [PATCH] fix ui issues for withdraw;add merge token to token list for withdraw --- store/zksync/wallet.ts | 19 ++++++++++++++++- utils/constants.ts | 34 +++++++++++++++++++++++++++-- views/transactions/Withdraw.vue | 38 +++++++++++++++++++++++++++++---- 3 files changed, 84 insertions(+), 7 deletions(-) diff --git a/store/zksync/wallet.ts b/store/zksync/wallet.ts index 1516c96ce..8600ca862 100644 --- a/store/zksync/wallet.ts +++ b/store/zksync/wallet.ts @@ -1,3 +1,4 @@ +import { MERGE_TOKENS } from "./../../utils/constants"; import { getPublicClient } from "@wagmi/core"; import { BigNumber, ethers, VoidSigner } from "ethers"; import { $fetch } from "ofetch"; @@ -13,6 +14,7 @@ import { useOnboardStore } from "@/store/onboard"; import { useZkSyncProviderStore } from "@/store/zksync/provider"; import { useZkSyncTokensStore } from "@/store/zksync/tokens"; import { L1Signer, L1VoidSigner, Web3Provider } from "@/zksync-web3-nova/src"; + export const useZkSyncWalletStore = defineStore("zkSyncWallet", () => { const onboardStore = useOnboardStore(); const providerStore = useZkSyncProviderStore(); @@ -91,7 +93,7 @@ export const useZkSyncWalletStore = defineStore("zkSyncWallet", () => { await Promise.all([requestAccountState({ force: true }), tokensStore.requestTokens()]); if (!accountState.value) throw new Error("Account state is not available"); if (!tokens.value) throw new Error("Tokens are not available"); - return Object.entries(accountState.value.balances) + const accountBalances = Object.entries(accountState.value.balances) .filter(([, { token }]) => token) .map(([, { balance, token }]) => { return { @@ -103,6 +105,21 @@ export const useZkSyncWalletStore = defineStore("zkSyncWallet", () => { amount: balance, }; }); + //add merge tokens + for (const token of MERGE_TOKENS) { + const find = accountBalances.find((item) => item.address.toLowerCase() === token.address.toLowerCase()); + if (!find) { + accountBalances.push({ + address: token.address, + l1Address: undefined, + name: token!.symbol || undefined, + symbol: token!.symbol!, + decimals: token!.decimals, + amount: "0", + }); + } + } + return accountBalances; }; const getBalancesFromRPC = async (): Promise => { await tokensStore.requestTokens(); diff --git a/utils/constants.ts b/utils/constants.ts index bcaeb8bfe..851f705f1 100644 --- a/utils/constants.ts +++ b/utils/constants.ts @@ -1,4 +1,3 @@ -import { WITHDRAWAL_DELAY } from './../store/zksync/transactionStatus'; import type { Token } from "@/types"; export const ETH_TOKEN: Token = { @@ -10,4 +9,35 @@ export const ETH_TOKEN: Token = { iconUrl: "/img/eth.svg", }; -export const WITHDRAWAL_DELAY_DAYS = 12 \ No newline at end of file +export const WITHDRAWAL_DELAY_DAYS = 12; + +export const MERGE_TOKENS = [ + { + symbol: "USDT", + address: "0x2F8A25ac62179B31D62D7F80884AE57464699059", + targetNetworkKeys: ["ethereum", "arbitrum", "zksync", "linea", "manta", "mantle", "optimism"], + decimals: 6, + }, + { + symbol: "WBTC", + address: "0xDa4AaEd3A53962c83B35697Cd138cc6df43aF71f", + targetNetworkKeys: ["ethereum", "arbitrum", "zksync", "linea", "manta", "mantle", "optimism"], + decimals: 18, + }, + { + symbol: "USDC", + address: "0x1a1A3b2ff016332e866787B311fcB63928464509", + targetNetworkKeys: ["ethereum", "arbitrum", "zksync", "linea", "manta", "mantle", "optimism", "base"], + decimals: 6, + }, + { + symbol: "DAI", + address: "0xF573fA04A73d5AC442F3DEa8741317fEaA3cDeab", + targetNetworkKeys: ["ethereum", "arbitrum", "zksync", "linea", "optimism", "base"], + decimals: 18, + }, +]; + +export const isMergeToken = (address: string) => { + return address && MERGE_TOKENS.some((token) => token.address.toLowerCase() === address.toLowerCase()); +}; diff --git a/views/transactions/Withdraw.vue b/views/transactions/Withdraw.vue index 9a211a261..3af360a88 100644 --- a/views/transactions/Withdraw.vue +++ b/views/transactions/Withdraw.vue @@ -267,7 +267,16 @@ class="w-full" @click="buttonContinue()" > - Continue + {{ isMergeTokenSelected ? "Redeem" : "Continue" }} + + + Processing...