Skip to content

Commit

Permalink
fix: use users balance to calculate fee
Browse files Browse the repository at this point in the history
  • Loading branch information
JackHamer09 committed Mar 4, 2024
1 parent 1511bdf commit e81a8d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
12 changes: 6 additions & 6 deletions composables/zksync/useFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ export default (
if (!params) throw new Error("Params are not available");

const provider = getProvider();
const tokenBalance = balances.value.find((e) => e.address === params!.tokenAddress)?.amount || "1";
const [price, limit] = await Promise.all([
retry(() => provider.getGasPrice()),
retry(() => {
if (!params) throw new Error("Params are not available");
return provider[params.type === "transfer" ? "estimateGasTransfer" : "estimateGasWithdraw"]({
from: params.from,
to: params.to,
token: params.tokenAddress === ETH_TOKEN.address ? ETH_TOKEN.l1Address! : params.tokenAddress,
amount: "1",
return provider[params!.type === "transfer" ? "estimateGasTransfer" : "estimateGasWithdraw"]({
from: params!.from,
to: params!.to,
token: params!.tokenAddress === ETH_TOKEN.address ? ETH_TOKEN.l1Address! : params!.tokenAddress,
amount: tokenBalance,
});
}),
]);
Expand Down
11 changes: 2 additions & 9 deletions views/transactions/Transfer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,6 @@ const amountInputTokenAddress = computed({
const tokenBalance = computed<BigNumberish | undefined>(() => {
return balance.value.find((e) => e.address === selectedToken.value?.address)?.amount;
});
const selectedTokenZeroBalance = computed(() => {
if (!tokenBalance.value) {
return true;
}
return BigNumber.from(tokenBalance.value).isZero();
});

const unsubscribe = onboardStore.subscribeOnAccountChange(() => {
step.value = "form";
Expand Down Expand Up @@ -548,8 +542,7 @@ const estimate = async () => {
!transaction.value?.from.address ||
!transaction.value?.to.address ||
!selectedToken.value ||
!tokenBalance.value ||
selectedTokenZeroBalance.value
!tokenBalance.value
) {
return;
}
Expand All @@ -561,7 +554,7 @@ const estimate = async () => {
});
};
watch(
[() => selectedToken.value?.address, () => selectedTokenZeroBalance.value],
[() => selectedToken.value?.address, () => tokenBalance.value?.toString()],
() => {
resetFee();
estimate();
Expand Down

0 comments on commit e81a8d3

Please sign in to comment.