From 9c84912514cceecfb2cc538c68552e55ec621fe6 Mon Sep 17 00:00:00 2001 From: Max Alekseenko Date: Mon, 21 Nov 2022 13:23:28 +0100 Subject: [PATCH] fix multitransfer with 1 address --- src/components/TransactionModal/index.js | 10 +++++----- src/contexts/ZkAccountContext/index.js | 7 ++++--- src/contexts/ZkAccountContext/zp.js | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/components/TransactionModal/index.js b/src/components/TransactionModal/index.js index 548343ff..1b7e83dc 100644 --- a/src/components/TransactionModal/index.js +++ b/src/components/TransactionModal/index.js @@ -30,23 +30,23 @@ const titles = { const descriptions = { [TX_STATUSES.DEPOSITED]: amount => ( - Your {formatNumber(amount)} {tokenSymbol()} deposit to the zero knowledge pool is in process.

+ Your {formatNumber(amount, 18)} {tokenSymbol()} deposit to the zero knowledge pool is in process.

To increase the level of privacy, consider keeping the tokens in the zero knowledge pool for some time before withdrawal.
), [TX_STATUSES.TRANSFERRED]: amount => ( - Your {formatNumber(amount)} {tokenSymbol()} transfer within the zero knowledge pool is in process. + Your {formatNumber(amount, 18)} {tokenSymbol()} transfer within the zero knowledge pool is in process. ), - [TX_STATUSES.TRANSFERRED_MULTI]: () => ( + [TX_STATUSES.TRANSFERRED_MULTI]: amount => ( - Your multitransfer within the zero knowledge pool is in process. + Your {formatNumber(amount, 18)} {tokenSymbol()} multitransfer within the zero knowledge pool is in process. ), [TX_STATUSES.WITHDRAWN]: amount => ( - Your {formatNumber(amount)} {tokenSymbol()} withdrawal from the zero knowledge pool is in process. + Your {formatNumber(amount, 18)} {tokenSymbol()} withdrawal from the zero knowledge pool is in process. ), [TX_STATUSES.SIGNATURE_EXPIRED]: () => ( diff --git a/src/contexts/ZkAccountContext/index.js b/src/contexts/ZkAccountContext/index.js index 75f765ee..e1ed2cb1 100644 --- a/src/contexts/ZkAccountContext/index.js +++ b/src/contexts/ZkAccountContext/index.js @@ -192,8 +192,8 @@ export const ZkAccountContextProvider = ({ children }) => { const transfer = useCallback(async (to, amount) => { openTxModal(); - setTxAmount(amount); try { + setTxAmount(amount); const shieldedAmount = toShieldedAmount(amount); const { totalPerTx: fee } = await zkAccount.feeEstimate(TOKEN_ADDRESS, [shieldedAmount], TxType.Transfer, false); await zp.transfer(zkAccount, [{ destination: to, amountGwei: shieldedAmount }], fee, setTxStatus); @@ -210,13 +210,14 @@ export const ZkAccountContextProvider = ({ children }) => { const transferMulti = useCallback(async data => { openTxModal(); try { + setTxAmount(data.reduce((acc, curr) => acc.add(curr.amount), ethers.constants.Zero)); const transfers = data.map(({ address, amount }) => ({ destination: address, amountGwei: toShieldedAmount(amount) })); const shieldedAmounts = transfers.map(tr => tr.amountGwei); const { totalPerTx: fee } = await zkAccount.feeEstimate(TOKEN_ADDRESS, shieldedAmounts, TxType.Transfer, false); - await zp.transfer(zkAccount, transfers, fee, setTxStatus); + await zp.transfer(zkAccount, transfers, fee, setTxStatus, true); updatePoolData(); } catch (error) { console.log(error); @@ -224,7 +225,7 @@ export const ZkAccountContextProvider = ({ children }) => { } }, [ zkAccount, updatePoolData, openTxModal, - setTxStatus, toShieldedAmount, + setTxStatus, toShieldedAmount, setTxAmount, ]); const withdraw = useCallback(async (to, amount) => { diff --git a/src/contexts/ZkAccountContext/zp.js b/src/contexts/ZkAccountContext/zp.js index 3531ebc9..2210cd48 100644 --- a/src/contexts/ZkAccountContext/zp.js +++ b/src/contexts/ZkAccountContext/zp.js @@ -60,12 +60,12 @@ const deposit = async (signer, account, amount, fee, setTxStatus) => { setTxStatus(TX_STATUSES.DEPOSITED); }; -const transfer = async (account, transfers, fee, setTxStatus) => { +const transfer = async (account, transfers, fee, setTxStatus, isMulti) => { setTxStatus(TX_STATUSES.GENERATING_PROOF); const jobIds = await account.transferMulti(TOKEN_ADDRESS, transfers, fee); setTxStatus(TX_STATUSES.WAITING_FOR_RELAYER); await account.waitJobsTxHashes(TOKEN_ADDRESS, jobIds); - setTxStatus(TX_STATUSES[transfers.length > 1 ? 'TRANSFERRED_MULTI' : 'TRANSFERRED']); + setTxStatus(TX_STATUSES[isMulti ? 'TRANSFERRED_MULTI' : 'TRANSFERRED']); }; const withdraw = async (account, to, amount, fee, setTxStatus) => {