From d75cea16b3ecc65221339bafefd90fdc719e17a4 Mon Sep 17 00:00:00 2001 From: esaminu Date: Tue, 4 Jan 2022 18:53:38 +0400 Subject: [PATCH] fix: compute liquid amount locally instead of fetching --- packages/frontend/src/utils/account-with-lockup.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/frontend/src/utils/account-with-lockup.js b/packages/frontend/src/utils/account-with-lockup.js index a310526bf8..943d7d4245 100644 --- a/packages/frontend/src/utils/account-with-lockup.js +++ b/packages/frontend/src/utils/account-with-lockup.js @@ -206,6 +206,7 @@ async function getAccountBalance(limitedAccountData = false) { const { transfer_poll_account_id, transfers_timestamp } = transferInformation; let transfersTimestamp = transfer_poll_account_id ? await this.viewFunction(transfer_poll_account_id, 'get_result') : transfers_timestamp; + let areTransfersEnabled = !!transfersTimestamp; transfersTimestamp = transfersTimestamp || (Date.now() * 1000000).toString(); const { code_hash: lockupContractCodeHash } = await lockupAccount.state(); @@ -268,14 +269,10 @@ async function getAccountBalance(limitedAccountData = false) { // if acc is deletable (nothing locked && nothing stake) you can transfer the whole amount ohterwise get_liquid_owners_balance const isAccDeletable = lockedAmount.isZero() && stakedBalanceLockup.isZero(); - const liquidOwnersBalance = isAccDeletable + const liquidOwnersBalanceTransfersEnabled = isAccDeletable ? new BN(lockupBalance.total) - : new BN( - await this.wrappedAccount.viewFunction( - lockupAccountId, - "get_liquid_owners_balance" - ) - ); + : BN.min(ownersBalance, new BN(lockupBalance.total).sub(new BN(MIN_BALANCE_FOR_GAS))) + const liquidOwnersBalance = areTransfersEnabled ? liquidOwnersBalanceTransfersEnabled : new BN(0); const available = BN.max(new BN(0), new BN(balance.available).add(new BN(liquidOwnersBalance)).sub(new BN(MIN_BALANCE_FOR_GAS)));