Skip to content

Commit 6090c75

Browse files
committed
Update
1 parent 2fdb69d commit 6090c75

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

packages/thirdweb/src/extensions/erc721/drops/write/claimToBatch.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
WithOverrides,
66
} from "../../../../transaction/types.js";
77
import { getClaimParams } from "../../../../utils/extensions/drops/get-claim-params.js";
8+
import { resolvePromisedValue } from "../../../../utils/promise/resolve-promised-value.js";
89
import { encodeClaim } from "../../__generated__/IDrop/write/claim.js";
910

1011
/**
@@ -49,7 +50,10 @@ export function claimToBatch(
4950
return multicall({
5051
contract: options.contract,
5152
asyncParams: () => getClaimToBatchParams(options),
52-
overrides: options.overrides,
53+
overrides: {
54+
erc20Value: getERC20Value(options),
55+
...options.overrides,
56+
},
5357
});
5458
}
5559

@@ -96,6 +100,53 @@ async function getClaimToBatchParams(
96100
return { data };
97101
}
98102

103+
/**
104+
* @internal
105+
*/
106+
async function getERC20Value(
107+
options: BaseTransactionOptions<ClaimToBatchParams>,
108+
): Promise<
109+
| {
110+
amountWei: bigint;
111+
tokenAddress: string;
112+
}
113+
| undefined
114+
> {
115+
const data = await Promise.all(
116+
options.content.map(async (item) => {
117+
const claimParams = await getClaimParams({
118+
type: "erc721",
119+
contract: options.contract,
120+
to: item.to,
121+
from: options.from,
122+
quantity: item.quantity,
123+
});
124+
const erc20Value = await resolvePromisedValue(
125+
claimParams.overrides.erc20Value,
126+
);
127+
return erc20Value;
128+
}),
129+
);
130+
131+
const filteredData = data.filter((item) => item !== undefined);
132+
133+
if (!filteredData.length || !filteredData[0]) {
134+
return undefined;
135+
}
136+
137+
const totalAmountWei = filteredData
138+
.filter((item) => item !== undefined)
139+
.reduce(
140+
(accumulator, currentValue) => accumulator + currentValue.amountWei,
141+
BigInt(0),
142+
);
143+
144+
return {
145+
amountWei: totalAmountWei,
146+
tokenAddress: filteredData[0].tokenAddress,
147+
};
148+
}
149+
99150
/**
100151
* Optimization
101152
* For identical addresses that stays next to each other in the array,

packages/thirdweb/src/transaction/prepare-transaction.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,20 @@ export type StaticPrepareTransactionOptions = {
2525
client: ThirdwebClient;
2626
// extras
2727
extraCallData?: Hex;
28-
erc20Value?: {
29-
amountWei: bigint;
30-
tokenAddress: Address;
31-
};
28+
erc20Value?:
29+
| {
30+
amountWei: bigint;
31+
tokenAddress: Address;
32+
}
33+
| Promise<
34+
Readonly<
35+
| {
36+
amountWei: bigint;
37+
tokenAddress: Address;
38+
}
39+
| undefined
40+
>
41+
>;
3242
};
3343

3444
export type EIP712TransactionOptions = {

0 commit comments

Comments
 (0)