Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: edit Business logic of function getNetworkInfo #161

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions components/transaction/EthereumTransactionFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
16 changes: 5 additions & 11 deletions components/transaction/TransferLineItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,20 @@ 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
if (gateway) {
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: "",
};
}
Expand All @@ -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,
};
}
}
Expand Down
14 changes: 4 additions & 10 deletions components/transaction/TransferWithdrawalLineItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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: "",
};
}
Expand Down
17 changes: 2 additions & 15 deletions components/transaction/WithdrawalsAvailableForClaimAlert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
})
</script>
14 changes: 14 additions & 0 deletions composables/useNetworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,26 @@ 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,
zkSyncNetworks,
defaultNetwork,
primaryNetwork,
isMainnet,
getNetworkInfo,
};
};
17 changes: 5 additions & 12 deletions composables/zksync/useWithdrawalFinalization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,12 @@ export default (transactionInfo: ComputedRef<TransactionInfo>) => {
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);
}
Expand Down Expand Up @@ -163,10 +156,10 @@ export default (transactionInfo: ComputedRef<TransactionInfo>) => {
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({
Expand Down
19 changes: 6 additions & 13 deletions store/zksync/transactionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
23 changes: 5 additions & 18 deletions store/zksync/withdrawals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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"
);
Expand All @@ -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) {
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 2 additions & 8 deletions views/transactions/DepositSubmitted.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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<TransactionInfo>,
Expand All @@ -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());
</script>
18 changes: 13 additions & 5 deletions views/transactions/WithdrawalSubmitted.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading