Skip to content

Commit

Permalink
fix multitransfer with 1 address
Browse files Browse the repository at this point in the history
  • Loading branch information
maxaleks committed Nov 21, 2022
1 parent 474044c commit 9c84912
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/components/TransactionModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ const titles = {
const descriptions = {
[TX_STATUSES.DEPOSITED]: amount => (
<span>
Your <b>{formatNumber(amount)} {tokenSymbol()}</b> deposit to the zero knowledge pool is in process.<br /><br />
Your <b>{formatNumber(amount, 18)} {tokenSymbol()}</b> deposit to the zero knowledge pool is in process.<br /><br />
To increase the level of privacy, consider keeping the tokens in the zero knowledge pool for some time before withdrawal.
</span>
),
[TX_STATUSES.TRANSFERRED]: amount => (
<span>
Your <b>{formatNumber(amount)} {tokenSymbol()}</b> transfer within the zero knowledge pool is in process.
Your <b>{formatNumber(amount, 18)} {tokenSymbol()}</b> transfer within the zero knowledge pool is in process.
</span>
),
[TX_STATUSES.TRANSFERRED_MULTI]: () => (
[TX_STATUSES.TRANSFERRED_MULTI]: amount => (
<span>
Your multitransfer within the zero knowledge pool is in process.
Your <b>{formatNumber(amount, 18)} {tokenSymbol()}</b> multitransfer within the zero knowledge pool is in process.
</span>
),
[TX_STATUSES.WITHDRAWN]: amount => (
<span>
Your <b>{formatNumber(amount)} {tokenSymbol()}</b> withdrawal from the zero knowledge pool is in process.
Your <b>{formatNumber(amount, 18)} {tokenSymbol()}</b> withdrawal from the zero knowledge pool is in process.
</span>
),
[TX_STATUSES.SIGNATURE_EXPIRED]: () => (
Expand Down
7 changes: 4 additions & 3 deletions src/contexts/ZkAccountContext/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -210,21 +210,22 @@ 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);
setTxStatus(TX_STATUSES.REJECTED);
}
}, [
zkAccount, updatePoolData, openTxModal,
setTxStatus, toShieldedAmount,
setTxStatus, toShieldedAmount, setTxAmount,
]);

const withdraw = useCallback(async (to, amount) => {
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/ZkAccountContext/zp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 9c84912

Please sign in to comment.