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

Feat/withdraw estimate time #165

Merged
merged 25 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a10f642
fix: Adjustment of transfer status judgment
haymond-ZK Apr 18, 2024
6f6d9a8
Merge pull request #141 from zkLinkProtocol/feature-withdraw
MickWang Apr 18, 2024
6465e2d
add detect for binance web3 app
MickWang Apr 18, 2024
20df07d
Merge pull request #143 from zkLinkProtocol/feat/binance_wallet_detect
leochw Apr 18, 2024
7911345
add injected in supported wallet list
MickWang Apr 19, 2024
9c9d2f0
Merge pull request #146 from zkLinkProtocol/fix/support_injected
haymond-ZK Apr 19, 2024
5406046
Merge pull request #151 from zkLinkProtocol/preview
haymond-ZK Apr 19, 2024
9558725
fix change network ui issue for claim withdrawal
MickWang Apr 19, 2024
a3aef17
Merge pull request #152 from zkLinkProtocol/fix/fix_change_network_issue
leochw Apr 20, 2024
344289b
update injected binance wallet
MickWang Apr 20, 2024
8c240a9
Merge pull request #154 from zkLinkProtocol/feat/binance_wallet_detect
leochw Apr 20, 2024
b030fd3
show thrid party bridge
MickWang Apr 20, 2024
6d6eaeb
show thrid party bridge
MickWang Apr 20, 2024
220f300
fix hide blast ui issue
MickWang Apr 21, 2024
61536f7
Merge pull request #156 from zkLinkProtocol/fix/hide_blast_issue
leochw Apr 21, 2024
53bfa1c
Merge pull request #155 from zkLinkProtocol/feat/show_thrid_party_bridge
leochw Apr 21, 2024
ed2c917
fix blast ui issue
MickWang Apr 21, 2024
ab65cea
fix blast ui issue
MickWang Apr 21, 2024
a44c00b
fix blast ui issue
MickWang Apr 21, 2024
a8ae15e
Merge pull request #157 from zkLinkProtocol/fix/hide_blast_issue
leochw Apr 21, 2024
8c8e7c8
handle for url params
MickWang Apr 22, 2024
6fc4ea2
Merge pull request #159 from zkLinkProtocol/fix/hide_blast_issue
leochw Apr 22, 2024
187b22b
Merge pull request #161 from zkLinkProtocol/feature-change-getNetwork
haymond-ZK Apr 22, 2024
9889827
update for estimate withdray delay time
MickWang Apr 22, 2024
54c2960
update for estimate withdray delay time
MickWang Apr 22, 2024
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
2 changes: 1 addition & 1 deletion components/network/NetworkSelectModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
variant="light"
size="sm"
@click="
buttonClicked(zkSyncNetwork[groupIndex]);
buttonClicked(zkSyncNetwork.find(item => item.key === group.key)!);
selectedNetworkKey = group.key!;
"
/>
Expand Down
3 changes: 2 additions & 1 deletion data/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ type WalletEntry = { walletName: string; type: "injected" | "metaMask" | "wallet
export const confirmedSupportedWallets: WalletEntry[] = [
{ walletName: "MetaMask", type: "metaMask" },

{ walletName: "OKX", type: "injected" },
{ walletName: "Injected", type: "injected" },
{ walletName: "OKX", type: "injected" },
{ walletName: "GateWallet", type: "injected" },
{ walletName: "MetaMask", type: "injected" },
{ walletName: "BitKeep", type: "injected" },
Expand Down
Binary file added public/img-binance-web3-wallet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion store/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ export const useNetworkStore = defineStore("network", () => {
const identifyNetworkByQueryParam = () => {
const windowLocation = window.location;
const networkFromQueryParam = new URLSearchParams(windowLocation.search).get("network");
if (networkFromQueryParam && zkSyncNetworks.some((e) => e.key === networkFromQueryParam)) {
if (windowLocation.pathname === "/" && networkFromQueryParam === "blast") {
// hide blast for deposit
const url = new URL(windowLocation.href);
url.searchParams.set("network", zkSyncNetworks[0].key);
window.location.replace(url.toString());
} else if (networkFromQueryParam && zkSyncNetworks.some((e) => e.key === networkFromQueryParam)) {
selectedNetworkKey.value = networkFromQueryParam;
resetNetworkChangeWarning();
}
Expand Down
27 changes: 17 additions & 10 deletions store/onboard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { injected, safe, walletConnect } from "@wagmi/connectors";
import {
createConfig,
getAccount,
getConnections,
getConnectors,
Expand All @@ -26,7 +27,7 @@ import { confirmedSupportedWallets, disabledWallets } from "@/data/wallets";
import { useNetworkStore } from "@/store/network";

const isMobile = () => window.innerWidth < 800; // simple way to detect mobile device

const isBinanceWeb3App = () => window.ethereum?.isBinance;
export const useOnboardStore = defineStore("onboard", () => {
const { zkSyncNetworks } = useNetworks();
const runtimeConfig = useRuntimeConfig();
Expand Down Expand Up @@ -83,12 +84,23 @@ export const useOnboardStore = defineStore("onboard", () => {
};
console.log("extendedChains", extendedChains);
console.log("selectedNetwork", selectedNetwork.value);
const wagmiConfig = defaultWagmiConfig({
const wagmiConfig = createConfig({
chains: extendedChains,
projectId: env.walletConnectProjectID,
metadata,
connectors: [
injected(),
isBinanceWeb3App()
? injected({
target() {
return {
id: "Binance Web3 Wallet",
name: "Binance Web3 Wallet",
provider: window.ethereum,
icon: "/img-binance-web3-wallet.png",
};
},
})
: injected(),
safe({
allowedDomains: [/app.safe.global$/],
debug: true,
Expand Down Expand Up @@ -169,7 +181,7 @@ export const useOnboardStore = defineStore("onboard", () => {

const BinanceWalletId = "8a0ee50d1f22f6651afcae7eb4253e52a3310b90af5daef78a8c4929a9bb99d4";
const excludeWalletIds = ["bc949c5d968ae81310268bf9193f9c9fb7bb4e1283e1284af8f2bd4992535fd6"];
if (isMobile()) {
if (isMobile() && isBinanceWeb3App()) {
excludeWalletIds.push(BinanceWalletId);
}
const featuredWalletIds = [
Expand All @@ -181,18 +193,13 @@ export const useOnboardStore = defineStore("onboard", () => {
// "aba1f652e61fd536e8a7a5cd5e0319c9047c435ef8f7e907717361ff33bb3588",
// "38f5d18bd8522c244bdd70cb4a68e0e718865155811c043f052fb9f1c51de662",//bitget
];
if (!isMobile()) {
if (!isBinanceWeb3App()) {
featuredWalletIds.unshift(BinanceWalletId);
}

const web3modal = createWeb3Modal({
wagmiConfig,
projectId: env.walletConnectProjectID,
connectorImages: isMobile()
? {
injected: "/img-browser-wallet.png",
}
: undefined,
excludeWalletIds,
featuredWalletIds,
// termsConditionsUrl: "https://zksync.io/terms",
Expand Down
2 changes: 1 addition & 1 deletion store/zksync/transactionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const getEstmatdDepositDelay = (networkKey: string): number => {
return ESTIMATED_DEPOSIT_DELAY_SECONDARY;
}
};
export const WITHDRAWAL_DELAY = 14 * 24 * 60 * 60 * 1000; // 7 * 24 hours
export const WITHDRAWAL_DELAY = 7 * 24 * 60 * 60 * 1000; // 7 * 24 hours
export type Address = Hash;
export type ForwardL2Request = {
gateway: Address;
Expand Down
7 changes: 4 additions & 3 deletions store/zksync/withdrawals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ 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,getNetworkInfo } = useNetworks();
const { primaryNetwork, zkSyncNetworks, getNetworkInfo } = useNetworks();

const { selectedNetwork } = storeToRefs(useNetworkStore());
let provider: Provider | undefined;
Expand Down Expand Up @@ -82,7 +82,7 @@ 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,getNetworkInfo } = useNetworks();
const { primaryNetwork, zkSyncNetworks, getNetworkInfo } = useNetworks();

const transactionFromStorage = transactionStatusStore.getTransaction(withdrawal.transactionHash);
if (transactionFromStorage) {
Expand Down Expand Up @@ -156,7 +156,8 @@ export const useZkSyncWithdrawalsStore = defineStore("zkSyncWithdrawals", () =>
},
info: {
expectedCompleteTimestamp: new Date(
new Date(withdrawalTransfer.timestamp).getTime() + WITHDRAWAL_DELAY
new Date(withdrawalTransfer.timestamp).getTime() +
getEstimateWithdrawalDelayDays(withdrawalTransfer.timestamp) * 24 * 3600 * 1000
).toISOString(),
completed: withdrawal.status === "Finalized",
withdrawalFinalizationAvailable: transactionDetails.status === "verified",
Expand Down
8 changes: 7 additions & 1 deletion utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ export const ETH_TOKEN: Token = {
iconUrl: "/img/eth.svg",
};

export const WITHDRAWAL_DELAY_DAYS = 14;
export const WITHDRAWAL_DELAY_DAYS = 7;

// Last syncL2Requests tx on blast: Apr-20-2024 09:45:31 AM +UTC;
// deposit before this time , estimate withdraw time is 14 days;
// deposit after this time, estimate withdraw time is :
// ( 14 days - (deposit time - this time)) < 7days ? 7days : ( 14 days - (deposit time - this time));
export const LAST_BLAST_SYNCL2_TIME = 1713606331000;

export const MERGE_TOKENS = [
{
Expand Down
10 changes: 10 additions & 0 deletions utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,13 @@ export async function retry<T>(func: () => Promise<T>, options: RetryOptions = {
}
}
}

export const getEstimateWithdrawalDelayDays = (txTime: string | number) => {
const transactionTime = new Date(txTime).getTime();
if (transactionTime < LAST_BLAST_SYNCL2_TIME) {
return 14;
} else {
const gap = Math.ceil(14 - (transactionTime - LAST_BLAST_SYNCL2_TIME) / (24 * 3600 * 1000));
return gap >= 8 ? gap : 8;
}
};
12 changes: 10 additions & 2 deletions views/transactions/Deposit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@
</template>

<script lang="ts" setup>
import { computed, onBeforeUnmount, ref, watch } from "vue";
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";

import { Switch } from "@headlessui/vue";
import {
Expand All @@ -449,6 +449,7 @@ import EthereumTransactionFooter from "@/components/transaction/EthereumTransact
import useAllowance from "@/composables/transaction/useAllowance";
import useMergeToken from "@/composables/transaction/useMergeToken";
import useInterval from "@/composables/useInterval";
import useNetworks from "@/composables/useNetworks";
import useEcosystemBanner from "@/composables/zksync/deposit/useEcosystemBanner";
import useFee from "@/composables/zksync/deposit/useFee";
import useMntAndWeth from "@/composables/zksync/deposit/useMntAndWeth";
Expand Down Expand Up @@ -482,6 +483,7 @@ import { ETH_ADDRESS, WMNT_CONTRACT } from "@/zksync-web3-nova/src/utils";

// const okxIcon = "/img/okx-cryptopedia.svg";
const launchIcon = "/img/launch.svg";
const { zkSyncNetworks } = useNetworks();

const route = useRoute();
const router = useRouter();
Expand All @@ -494,7 +496,7 @@ const eraWalletStore = useZkSyncWalletStore();
const { account, isConnected } = storeToRefs(onboardStore);
const { eraNetwork } = storeToRefs(providerStore);
const { destinations } = storeToRefs(useDestinationsStore());
const { l1BlockExplorerUrl, selectedNetwork } = storeToRefs(useNetworkStore());
const { l1BlockExplorerUrl, selectedNetwork, selectedNetworkKey } = storeToRefs(useNetworkStore());
const { l1Tokens, tokensRequestInProgress, tokensRequestError } = storeToRefs(tokensStore);
const { balance, balanceInProgress, balanceError } = storeToRefs(zkSyncEthereumBalance);

Expand Down Expand Up @@ -957,6 +959,12 @@ onboardStore.subscribeOnNetworkChange((newchainId) => {
if (!newchainId) return;
resetFeeImmediately();
});

onMounted(() => {
if (selectedNetworkKey.value === "blast") {
selectedNetworkKey.value = zkSyncNetworks[0].key;
}
})
</script>

<style lang="scss" scoped>
Expand Down
57 changes: 37 additions & 20 deletions views/transactions/Withdraw.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
</PageTitle>

<div class="warnBox flex" v-if="!route.query.s || route.query.s !== 'okx'">
<div>Note: All LRT points will continue to be calculated after you request a withdrawal. They will appear in the next few days in dashboard due to the data synchronization process.</div>
<div>
Note: All LRT points will continue to be calculated after you request a withdrawal. They will appear in the next
few days in dashboard due to the data synchronization process.
</div>
</div>

<div v-if="showBridge">
Expand Down Expand Up @@ -181,11 +184,12 @@
class="mb-block-padding-1/2 sm:mb-block-gap"
>
<p v-if="withdrawalManualFinalizationRequired">
You will be able to claim your withdrawal only after a {{ WITHDRAWAL_DELAY_DAYS }}-day withdrawal delay.
You will be able to claim your withdrawal only after a {{ displayEstimateWithdrawalDelayDays }}-day
withdrawal delay.
<!-- <a class="underline underline-offset-2" :href="ZKSYNC_WITHDRAWAL_DELAY" target="_blank">Learn more</a> -->
</p>
<p v-else>
You will receive funds only after a {{ WITHDRAWAL_DELAY_DAYS }}-day withdrawal delay.
You will receive funds only after a {{ displayEstimateWithdrawalDelayDays }}-day withdrawal delay.
<!-- <a class="underline underline-offset-2" :href="ZKSYNC_WITHDRAWAL_DELAY" target="_blank">Learn more</a> -->
</p>
</CommonAlert>
Expand Down Expand Up @@ -227,7 +231,7 @@
class="mt-2"
@try-again="isMergeTokenSelected ? estiamteForMergeToken : estimate"
>
Fee estimation error: {{ feeError.message }}
Fee estimation error: {{ feeError.message }}
</CommonErrorBlock>
<div class="mt-4 flex items-center gap-4">
<transition v-bind="TransitionOpacity()">
Expand Down Expand Up @@ -292,7 +296,7 @@

<CommonHeightTransition
v-if="isMergeTokenSelected && step === 'form'"
:opened="( !enoughAllowance && !continueButtonDisabled) || !!setAllowanceReceipt"
:opened="(!enoughAllowance && !continueButtonDisabled) || !!setAllowanceReceipt"
>
<CommonCardWithLineButtons class="mt-4">
<DestinationItem
Expand Down Expand Up @@ -429,7 +433,7 @@
</template>
</form>
</div>
<div class="flex flex-col gap-block-gap" v-else>
<div class="mt-6 flex flex-col gap-block-gap">
<CommonCardWithLineButtons v-for="(item, index) in thirdChainMethods" :key="index" class="relative">
<DestinationItem v-bind="item.props">
<template #image v-if="item.icon">
Expand Down Expand Up @@ -484,31 +488,40 @@ import { useOnboardStore } from "@/store/onboard";
import { usePreferencesStore } from "@/store/preferences";
import { useZkSyncProviderStore } from "@/store/zksync/provider";
import { useZkSyncTokensStore } from "@/store/zksync/tokens";
import { WITHDRAWAL_DELAY } from "@/store/zksync/transactionStatus";
import { useZkSyncTransactionStatusStore } from "@/store/zksync/transactionStatus";
import { useZkSyncTransfersHistoryStore } from "@/store/zksync/transfersHistory";
import { useZkSyncWalletStore } from "@/store/zksync/wallet";
import { ETH_TOKEN, isMergeToken, isSupportedMergeToken, MergeTokenContractUrl, WITHDRAWAL_DELAY_DAYS } from "@/utils/constants";
import { ETH_TOKEN, isMergeToken, isSupportedMergeToken } from "@/utils/constants";
import { ZKSYNC_WITHDRAWAL_DELAY } from "@/utils/doc-links";
import { checksumAddress, decimalToBigNumber, formatRawTokenPrice, parseTokenAmount } from "@/utils/formatters";
import { calculateFee } from "@/utils/helpers";
import { calculateFee, getEstimateWithdrawalDelayDays } from "@/utils/helpers";
import { silentRouterChange } from "@/utils/helpers";
import { TransitionAlertScaleInOutTransition, TransitionOpacity } from "@/utils/transitions";
import TransferSubmitted from "@/views/transactions/TransferSubmitted.vue";
import WithdrawalSubmitted from "@/views/transactions/WithdrawalSubmitted.vue";
import { ETH_ADDRESS } from "~/zksync-web3-nova/src/utils";
const showBridge = true;
const chainList = [
// {
// "name": "Symbiosis",
// "description": "https://symbiosis.finance/",
// "logo": "Symbiosys.svg",
// "bannerImg": "Symbiosys.jpg",
// "type": "Defi",
// "url": "https://symbiosis.finance/",
// "tiwwerUrl": "https://twitter.com/symbiosis_fi",
// "discordUrl": "https://discord.com/invite/YHgDSJ42eG"
// },
{
name: "Meson Finance",
description: "https://meson.fi/",
logo: "Meson.svg",
bannerImg: "Meson.jpg",
type: "Infra",
url: "https://meson.fi/",
tiwwerUrl: "https://twitter.com/mesonfi",
discordUrl: "https://discord.com/invite/meson",
},
{
name: "Symbiosis",
description: "https://symbiosis.finance/",
logo: "Symbiosys.svg",
bannerImg: "Symbiosys.jpg",
type: "Defi",
url: "https://symbiosis.finance/",
tiwwerUrl: "https://twitter.com/symbiosis_fi",
discordUrl: "https://discord.com/invite/YHgDSJ42eG",
},
{
name: "Owlto Finance",
description: "https://owlto.finance/",
Expand Down Expand Up @@ -576,6 +589,8 @@ const fromNetworkSelected = (networkKey?: string) => {
const step = ref<"form" | "withdrawal-finalization-warning" | "confirm" | "submitted">("form");
const destination = computed(() => (props.type === "transfer" ? destinations.value.nova : destinations.value.arbitrum));

const displayEstimateWithdrawalDelayDays = getEstimateWithdrawalDelayDays(Date.now());

const availableTokens = computed(() => {
if (!tokens.value) return [];
if (props.type === "withdrawal") {
Expand Down Expand Up @@ -1048,7 +1063,9 @@ const makeTransaction = async () => {
info: {
expectedCompleteTimestamp:
transaction.value?.type === "withdrawal"
? new Date(new Date().getTime() + WITHDRAWAL_DELAY).toISOString()
? new Date(
new Date().getTime() + getEstimateWithdrawalDelayDays(Date.now()) * 24 * 60 * 60 * 1000
).toISOString()
: undefined,
completed: false,
},
Expand Down
Loading
Loading