Skip to content

Commit

Permalink
chore: regroup sent elements by collection when creataing vault
Browse files Browse the repository at this point in the history
  • Loading branch information
mishuagopian committed Jan 13, 2024
1 parent ec38b14 commit 2d268d5
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/contracts/UserVaultV5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,23 @@ export class UserVaultV5 extends Contract<typeof userVaultABIV5> {
const { id: vaultId } = await this.#mintVault();
const receipts = [];

for (let i = 0; i < nfts.length; i++) {
const { collection, tokenIds } = nfts[i];
// Regroup all elements in the same collection in case users send tokenIds as separate elements of the array
const groupedNfts = nfts.reduce(
(acc, curr) => {
const { collection, tokenIds } = curr;
const index = acc.findIndex((element) => element.collection === collection);
if (index === -1) {
acc.push({ collection, tokenIds });
} else {
acc[index].tokenIds = [...acc[index].tokenIds, ...tokenIds];
}
return acc;
},
[] as typeof nfts,
);

for (let i = 0; i < groupedNfts.length; i++) {
const { collection, tokenIds } = groupedNfts[i];
const deposit = await this.depositERC721s({ vaultId, collection, tokenIds });
const receipt = await deposit.waitTxInBlock();
receipts.push(receipt);
Expand Down

0 comments on commit 2d268d5

Please sign in to comment.