Skip to content

Commit

Permalink
add wait receipt for withdraw tx
Browse files Browse the repository at this point in the history
  • Loading branch information
MickWang committed Apr 24, 2024
1 parent 6981f82 commit 60d1189
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
10 changes: 5 additions & 5 deletions components/transaction/WithdrawalsAvailableForClaimAlert.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<CommonHeightTransition :opened="!!withdrawalsAvailableForClaiming.length">
<CommonAlert variant="warning" :icon="ExclamationTriangleIcon" class="mb-block-gap">
<p>You have withdrawals available for claiming on {{ newNetwork?.l1Network?.name }} network</p>
<p class="mr-4">You have withdrawals available for claiming on {{ newNetwork?.l1Network?.name }} network</p>
<CommonButton as="RouterLink" :to="{ name: 'transfers' }" variant="primary">
<span class="whitespace-nowrap">See withdrawals</span>
</CommonButton>
Expand All @@ -19,10 +19,10 @@ import useNetworks from "@/composables/useNetworks";

const { eraNetwork } = storeToRefs(useZkSyncProviderStore());
const { withdrawalsAvailableForClaiming } = storeToRefs(useZkSyncWithdrawalsStore());
const { primaryNetwork, zkSyncNetworks,getNetworkInfo } = useNetworks();
const { primaryNetwork, zkSyncNetworks, getNetworkInfo } = useNetworks();
const newNetwork = computed(() => {
if (withdrawalsAvailableForClaiming.value.length> 0) {
return getNetworkInfo(withdrawalsAvailableForClaiming.value[0])
if (withdrawalsAvailableForClaiming.value.length > 0) {
return getNetworkInfo(withdrawalsAvailableForClaiming.value[0]);
}
})
});
</script>
7 changes: 7 additions & 0 deletions composables/zksync/useTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { useMemoize } from "@vueuse/core";
import { type BigNumberish } from "ethers";

Expand All @@ -6,8 +7,10 @@ import useScreening from "@/composables/useScreening";
import type { TokenAmount } from "@/types";
import type { Provider, Signer } from "@/zksync-web3-nova/src";

import { useOnboardStore } from "@/store/onboard";
import { useZkSyncWalletStore } from "@/store/zksync/wallet";
import { formatError } from "@/utils/formatters";
import { sleep } from "@/utils/helpers";

type TransactionParams = {
type: "transfer" | "withdrawal";
Expand All @@ -29,6 +32,8 @@ export default (getSigner: () => Promise<Signer | undefined>, getProvider: () =>
const error = ref<Error | undefined>();
const transactionHash = ref<string | undefined>();
const eraWalletStore = useZkSyncWalletStore();
const onboardStore = useOnboardStore();
const publicClient = onboardStore.getPublicClient(onboardStore.network.chainId);

const retrieveBridgeAddresses = useMemoize(() => getProvider().getDefaultBridgeAddresses());
const { validateAddress } = useScreening();
Expand Down Expand Up @@ -68,6 +73,8 @@ export default (getSigner: () => Promise<Signer | undefined>, getProvider: () =>
});

transactionHash.value = tx.hash;
await sleep(1500);
await publicClient?.getTransactionReceipt({ hash: tx.hash as `0x${string}` });
status.value = "done";

return tx;
Expand Down
2 changes: 1 addition & 1 deletion store/zksync/withdrawals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const useZkSyncWithdrawalsStore = defineStore("zkSyncWithdrawals", () =>

const TRANSACTIONS_FETCH_LIMIT = 100; // may miss claimable tx when user address has many txs;

const DELAY_DAYS = process.env.NODE_TYPE === "nexus-sepolia" ? 1 : 7;
const DELAY_DAYS = process.env.NODE_TYPE === "nexus-sepolia" ? 0.5 : 7;

const isWithinDelayDays = (timestamp: number | string) => {
return Date.now() - new Date(timestamp).getTime() < DELAY_DAYS * 24 * 60 * 60 * 1000;
Expand Down
4 changes: 4 additions & 0 deletions utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ export async function retry<T>(func: () => Promise<T>, options: RetryOptions = {
}
}
}

export async function sleep(time: number) {
return new Promise((resolve) => setTimeout(resolve, time));
}

0 comments on commit 60d1189

Please sign in to comment.