diff --git a/components/transaction/EthereumTransactionFooter.vue b/components/transaction/EthereumTransactionFooter.vue index 637758ab0..687e276f8 100644 --- a/components/transaction/EthereumTransactionFooter.vue +++ b/components/transaction/EthereumTransactionFooter.vue @@ -117,13 +117,20 @@ const { } = storeToRefs(onboardStore); const { selectedNetwork, l1Network } = storeToRefs(useNetworkStore()); const { primaryNetwork, zkSyncNetworks } = useNetworks(); -console.log("l1Netowrk: ", l1Network.value); const getNetworkInfo = () => { - const newNetwork = zkSyncNetworks.find( - (item) => item.l1Gateway && item.l1Gateway.toLowerCase() === props.transaction?.gateway?.toLowerCase() - ); - const obj = { l1Network: { id: l1Network.value?.id } }; - return props.transaction ? newNetwork ?? primaryNetwork : obj; + if (props.transaction?.gateway) { + const newNetwork = zkSyncNetworks.find( + (item) => item.l1Gateway && item.l1Gateway.toLowerCase() === props.transaction?.gateway?.toLowerCase() + ); + const obj = { l1Network: { id: l1Network.value?.id } }; + return props.transaction ? newNetwork ?? primaryNetwork : obj; + } else { + let obj = zkSyncNetworks.find( + (item) => item.key && item.key.toLowerCase() === (props.transaction?.token?.networkKey || 'primary').toLowerCase() + ) + const objs = { l1Network: { id: l1Network.value?.id } }; + return props.transaction ? obj ?? primaryNetwork : objs; + } }; const isGateWalletUnsupportedChain = computed(() => { diff --git a/components/transaction/TransferLineItem.vue b/components/transaction/TransferLineItem.vue index 34f6d92c4..7d6a65584 100644 --- a/components/transaction/TransferLineItem.vue +++ b/components/transaction/TransferLineItem.vue @@ -134,14 +134,8 @@ const label = computed(() => { return props.transfer.type || "Unknown"; }); -const { primaryNetwork, zkSyncNetworks } = useNetworks(); +const { primaryNetwork, zkSyncNetworks,getNetworkInfo } = useNetworks(); -const getNetworkInfo = () => { - const newNetwork = zkSyncNetworks.find( - (item) => item.l1Gateway && item.l1Gateway.toLowerCase() === props.transfer.gateway?.toLowerCase() - ); - return newNetwork ?? primaryNetwork; -}; const getl1NetworkName = () => { const { type, gateway } = props.transfer; // other chain @@ -149,11 +143,11 @@ const getl1NetworkName = () => { if (type === "withdrawal") { return { from: "", - to: getNetworkInfo().l1Network?.name, + to: getNetworkInfo(props.transfer).l1Network?.name, }; } else if (type === "deposit") { return { - from: getNetworkInfo().l1Network?.name, + from: getNetworkInfo(props.transfer).l1Network?.name, to: "", }; } @@ -174,8 +168,8 @@ const getl1NetworkName = () => { }; } else { return { - from: getNetworkInfo().l1Network?.name, - to: getNetworkInfo().l1Network?.name, + from: getNetworkInfo(props.transfer).l1Network?.name, + to: getNetworkInfo(props.transfer).l1Network?.name, }; } } diff --git a/components/transaction/TransferWithdrawalLineItem.vue b/components/transaction/TransferWithdrawalLineItem.vue index 7645b70ca..3272f8e25 100644 --- a/components/transaction/TransferWithdrawalLineItem.vue +++ b/components/transaction/TransferWithdrawalLineItem.vue @@ -94,15 +94,9 @@ const props = defineProps({ }, }); -const { primaryNetwork, zkSyncNetworks } = useNetworks(); -const getNetworkInfo = () => { - const newNetwork = zkSyncNetworks.find( - (item) => item.l1Gateway && item.l1Gateway.toLowerCase() === props.transfer.gateway?.toLowerCase() - ); - return newNetwork ?? primaryNetwork; -}; +const { primaryNetwork, zkSyncNetworks,getNetworkInfo } = useNetworks(); const { account } = storeToRefs(useOnboardStore()); -const eraNetwork = getNetworkInfo(); +const eraNetwork = getNetworkInfo(props.transfer); const label = computed(() => { const article = "Withdraw"; if (props.transfer.to === account.value.address) { @@ -125,11 +119,11 @@ const getl1NetworkName = () => { if (type === "withdrawal") { return { from: "", - to: getNetworkInfo().l1Network?.name, + to: getNetworkInfo(props.transfer).l1Network?.name, }; } else if (type === "deposit") { return { - from: getNetworkInfo().l1Network?.name, + from: getNetworkInfo(props.transfer).l1Network?.name, to: "", }; } diff --git a/components/transaction/WithdrawalsAvailableForClaimAlert.vue b/components/transaction/WithdrawalsAvailableForClaimAlert.vue index 2b25a0a3b..4932d9d9e 100644 --- a/components/transaction/WithdrawalsAvailableForClaimAlert.vue +++ b/components/transaction/WithdrawalsAvailableForClaimAlert.vue @@ -19,23 +19,10 @@ import useNetworks from "@/composables/useNetworks"; const { eraNetwork } = storeToRefs(useZkSyncProviderStore()); const { withdrawalsAvailableForClaiming } = storeToRefs(useZkSyncWithdrawalsStore()); -const { primaryNetwork, zkSyncNetworks } = useNetworks(); -const getNetworkInfo = () => { - const newNetwork = zkSyncNetworks.find( - (item) => item.l1Gateway && item.l1Gateway.toLowerCase() === withdrawalsAvailableForClaiming.value[0].gateway?.toLowerCase() - ); - return newNetwork ?? primaryNetwork; -}; +const { primaryNetwork, zkSyncNetworks,getNetworkInfo } = useNetworks(); const newNetwork = computed(() => { if (withdrawalsAvailableForClaiming.value.length> 0) { - if (withdrawalsAvailableForClaiming.value[0].gateway) { - getNetworkInfo() - } else { - let obj = zkSyncNetworks.find( - (item) => item.key && item.key.toLowerCase() === (withdrawalsAvailableForClaiming.value[0].token?.networkKey || 'primary').toLowerCase() - ) - return obj ?? primaryNetwork; - } + return getNetworkInfo(withdrawalsAvailableForClaiming.value[0]) } }) diff --git a/composables/useNetworks.ts b/composables/useNetworks.ts index aa00b866d..fe53fcb9b 100644 --- a/composables/useNetworks.ts +++ b/composables/useNetworks.ts @@ -40,6 +40,19 @@ export default () => { nexusNetworks[element.key] = element; } const isMainnet = runtimeConfig.public.nodeType === "nexus"; + const getNetworkInfo = (transactionInfo:any) => { + if (transactionInfo.gateway) { + const newNetwork = zkSyncNetworks.find( + (item) => item.l1Gateway && item.l1Gateway.toLowerCase() === transactionInfo.gateway?.toLowerCase() + ); + return newNetwork ?? primaryNetwork; + } else { + let obj = zkSyncNetworks.find( + (item) => item.key && item.key.toLowerCase() === (transactionInfo.token?.networkKey || 'primary').toLowerCase() + ) + return obj ?? primaryNetwork; + } + }; return { isCustomNode, nexusNetworks, @@ -47,5 +60,6 @@ export default () => { defaultNetwork, primaryNetwork, isMainnet, + getNetworkInfo, }; }; diff --git a/composables/zksync/useWithdrawalFinalization.ts b/composables/zksync/useWithdrawalFinalization.ts index 1a3d84052..df3d4ccaf 100644 --- a/composables/zksync/useWithdrawalFinalization.ts +++ b/composables/zksync/useWithdrawalFinalization.ts @@ -24,19 +24,12 @@ export default (transactionInfo: ComputedRef) => { const tokensStore = useZkSyncTokensStore(); const { network } = storeToRefs(onboardStore); const { tokens } = storeToRefs(tokensStore); - const { primaryNetwork, zkSyncNetworks } = useNetworks(); - - const getNetworkInfo = () => { - const newNetwork = zkSyncNetworks.find( - (item) => item.l1Gateway && item.l1Gateway.toLowerCase() === transactionInfo.value.gateway?.toLowerCase() - ); - return newNetwork ?? primaryNetwork; - }; + const { primaryNetwork, zkSyncNetworks,getNetworkInfo } = useNetworks(); const { selectedNetwork } = storeToRefs(useNetworkStore()); let provider: Provider | undefined; const request = () => { - const eraNetwork = getNetworkInfo() || selectedNetwork.value; + const eraNetwork = getNetworkInfo(transactionInfo.value) || selectedNetwork.value; if (!provider) { provider = new Provider(eraNetwork.rpcUrl); } @@ -163,10 +156,10 @@ export default (transactionInfo: ComputedRef) => { error.value = undefined; status.value = "processing"; - if (!(network.value.chain?.id === getNetworkInfo().l1Network?.id)) { - await onboardStore.setCorrectNetwork(getNetworkInfo().l1Network?.id); + if (!(network.value.chain?.id === getNetworkInfo(transactionInfo.value).l1Network?.id)) { + await onboardStore.setCorrectNetwork(getNetworkInfo(transactionInfo.value).l1Network?.id); } - const wallet = await onboardStore.getWallet(getNetworkInfo().l1Network?.id); + const wallet = await onboardStore.getWallet(getNetworkInfo(transactionInfo.value).l1Network?.id); const { transactionParams, gasLimit, gasPrice } = (await estimateFee())!; status.value = "waiting-for-signature"; transactionHash.value = await wallet.writeContract({ diff --git a/store/zksync/transactionStatus.ts b/store/zksync/transactionStatus.ts index 97a25a6d6..bf36dd6b8 100644 --- a/store/zksync/transactionStatus.ts +++ b/store/zksync/transactionStatus.ts @@ -177,24 +177,17 @@ export const useZkSyncTransactionStatusStore = defineStore("zkSyncTransactionSta transactionHash = await getDepositL2TransactionHash(transaction.transactionHash); } - const transactionReceipt = await request(transaction.gateway).getTransactionReceipt(transactionHash); + const transactionReceipt = await request(transaction).getTransactionReceipt(transactionHash); if (!transactionReceipt) return transaction; transaction.info.toTransactionHash = transactionHash; transaction.info.completed = true; return transaction; }; - const { primaryNetwork, zkSyncNetworks } = useNetworks(); - const getNetworkInfo = (gateway: string) => { - const newNetwork = zkSyncNetworks.find( - (item) => item.l1Gateway && item.l1Gateway.toLowerCase() === gateway?.toLowerCase() - ); - return newNetwork ?? primaryNetwork; - }; - + const { primaryNetwork, zkSyncNetworks,getNetworkInfo } = useNetworks(); const { selectedNetwork } = storeToRefs(useNetworkStore()); let provider: Provider | undefined; - const request = (gateway: string) => { - const eraNetwork = getNetworkInfo(gateway) || selectedNetwork.value; + const request = (transaction: any) => { + const eraNetwork = getNetworkInfo(transaction) || selectedNetwork.value; if (!provider) { provider = new Provider(eraNetwork.rpcUrl); } @@ -212,7 +205,7 @@ export const useZkSyncTransactionStatusStore = defineStore("zkSyncTransactionSta }; const getWithdrawalStatus = async (transaction: TransactionInfo) => { if (!transaction.info.withdrawalFinalizationAvailable) { - const transactionDetails = await request(transaction.gateway).getTransactionDetails(transaction.transactionHash); + const transactionDetails = await request(transaction).getTransactionDetails(transaction.transactionHash); if (transactionDetails.status !== "verified") { return transaction; } @@ -226,7 +219,7 @@ export const useZkSyncTransactionStatusStore = defineStore("zkSyncTransactionSta return transaction; }; const getTransferStatus = async (transaction: TransactionInfo) => { - const transactionReceipt = await request(transaction.gateway).getTransactionReceipt(transaction.transactionHash); + const transactionReceipt = await request(transaction).getTransactionReceipt(transaction.transactionHash); if (!transactionReceipt) return transaction; transaction.info.completed = true; return transaction; diff --git a/store/zksync/withdrawals.ts b/store/zksync/withdrawals.ts index 60534c192..e2cd29d25 100644 --- a/store/zksync/withdrawals.ts +++ b/store/zksync/withdrawals.ts @@ -33,19 +33,12 @@ export const useZkSyncWithdrawalsStore = defineStore("zkSyncWithdrawals", () => return new Promise((resolve) => setTimeout(resolve, ms)); } const setStatus = async (obj: { transactionHash: ethers.utils.BytesLike; status: string; gateway: string }) => { - const { primaryNetwork, zkSyncNetworks } = useNetworks(); - - const getNetworkInfo = () => { - const newNetwork = zkSyncNetworks.find( - (item) => item.l1Gateway && item.l1Gateway.toLowerCase() === obj.gateway?.toLowerCase() - ); - return newNetwork ?? primaryNetwork; - }; + const { primaryNetwork, zkSyncNetworks,getNetworkInfo } = useNetworks(); const { selectedNetwork } = storeToRefs(useNetworkStore()); let provider: Provider | undefined; const request = () => { - const eraNetwork = getNetworkInfo() || selectedNetwork.value; + const eraNetwork = getNetworkInfo(obj) || selectedNetwork.value; if (!provider) { provider = new Provider(eraNetwork.rpcUrl); } @@ -62,7 +55,7 @@ export const useZkSyncWithdrawalsStore = defineStore("zkSyncWithdrawals", () => const web3Provider = new ethers.providers.Web3Provider( getPublicClient(onboardStore.wagmiConfig as Config, { - chainId: getNetworkInfo().l1Network?.id, + chainId: getNetworkInfo(obj).l1Network?.id, }) as ethers.providers.ExternalProvider, "any" ); @@ -89,14 +82,8 @@ export const useZkSyncWithdrawalsStore = defineStore("zkSyncWithdrawals", () => ); const withdrawals = transfers.items.filter((e) => e.type === "withdrawal" && e.token && e.amount); for (const withdrawal of withdrawals) { - const { primaryNetwork, zkSyncNetworks } = useNetworks(); + const { primaryNetwork, zkSyncNetworks,getNetworkInfo } = useNetworks(); - const getNetworkInfo = () => { - const newNetwork = zkSyncNetworks.find( - (item) => item.l1Gateway && item.l1Gateway.toLowerCase() === withdrawal.gateway?.toLowerCase() - ); - return newNetwork ?? primaryNetwork; - }; const transactionFromStorage = transactionStatusStore.getTransaction(withdrawal.transactionHash); if (transactionFromStorage) { if (!transactionFromStorage.info.completed) { @@ -128,7 +115,7 @@ export const useZkSyncWithdrawalsStore = defineStore("zkSyncWithdrawals", () => let eraNetworks: ZkSyncNetwork; let obj = {}; const request = () => { - eraNetworks = getNetworkInfo() || selectedNetwork.value; + eraNetworks = getNetworkInfo(withdrawal) || selectedNetwork.value; obj = { iconUrl: eraNetworks.logoUrl, key: "nova", diff --git a/views/transactions/DepositSubmitted.vue b/views/transactions/DepositSubmitted.vue index bf5bc77e4..ac280f1af 100644 --- a/views/transactions/DepositSubmitted.vue +++ b/views/transactions/DepositSubmitted.vue @@ -48,7 +48,7 @@ import type { PropType } from "vue"; import { useZkSyncProviderStore } from "@/store/zksync/provider"; -const { primaryNetwork, zkSyncNetworks } = useNetworks(); +const { primaryNetwork, zkSyncNetworks,getNetworkInfo } = useNetworks(); let prop = defineProps({ transaction: { type: Object as PropType, @@ -60,12 +60,6 @@ let prop = defineProps({ }, }); -const getNetworkInfo = () => { - const newNetwork = zkSyncNetworks.find( - (item) => item.l1Gateway && item.l1Gateway.toLowerCase() === prop.transaction.gateway?.toLowerCase() - ); - return newNetwork ?? primaryNetwork; -}; -const l1BlockExplorerUrl = getNetworkInfo()?.l1Network?.blockExplorers?.default.url; +const l1BlockExplorerUrl = getNetworkInfo(prop.transaction)?.l1Network?.blockExplorers?.default.url; const { eraNetwork, blockExplorerUrl } = storeToRefs(useZkSyncProviderStore()); diff --git a/views/transactions/WithdrawalSubmitted.vue b/views/transactions/WithdrawalSubmitted.vue index 9e9526cc9..3e4b26f29 100644 --- a/views/transactions/WithdrawalSubmitted.vue +++ b/views/transactions/WithdrawalSubmitted.vue @@ -181,11 +181,19 @@ const { primaryNetwork, zkSyncNetworks } = useNetworks(); const { l1Network, l1BlockExplorerUrl } = storeToRefs(useNetworkStore()); const getNetworkInfo = () => { - const newNetwork = zkSyncNetworks.find( - (item) => item.l1Gateway && item.l1Gateway.toLowerCase() === props.transaction?.gateway?.toLowerCase() - ); - const obj = { l1Network: { id: l1Network.value?.id, blockExplorers: { default: { url: l1BlockExplorerUrl } } } }; - return props.transaction ? newNetwork ?? primaryNetwork : obj; + if (props.transaction?.gateway) { + const newNetwork = zkSyncNetworks.find( + (item) => item.l1Gateway && item.l1Gateway.toLowerCase() === props.transaction?.gateway?.toLowerCase() + ); + const obj = { l1Network: { id: l1Network.value?.id, blockExplorers: { default: { url: l1BlockExplorerUrl } } } }; + return props.transaction ? newNetwork ?? primaryNetwork : obj; + } else { + let objs = zkSyncNetworks.find( + (item) => item.key && item.key.toLowerCase() === (props.transaction?.token?.networkKey || 'primary').toLowerCase() + ) + const obj = { l1Network: { id: l1Network.value?.id, blockExplorers: { default: { url: l1BlockExplorerUrl } } } }; + return props.transaction ? objs ?? primaryNetwork : obj; + } }; const l1BlockExplorerUrls = getNetworkInfo().l1Network?.blockExplorers?.default.url; const onboardStore = useOnboardStore();