Skip to content

Commit 8c26d78

Browse files
feat(sendEmailCampaign): add allowDeposit parameter to enable automatic deposit
1 parent 2ae31e3 commit 8c26d78

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/web3mail/sendEmail.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ export const sendEmail = async ({
331331
workerpoolorder: workerpoolorder,
332332
requestorder: requestorder,
333333
},
334+
// TODO: Remove @ts-ignore once iexec SDK is updated to a version that includes allowDeposit in matchOrders types
335+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
336+
// @ts-ignore - allowDeposit is supported at runtime but not yet in TypeScript types
334337
{ useVoucher: vUseVoucher, allowDeposit: vAllowDeposit }
335338
);
336339

src/web3mail/sendEmailCampaign.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
addressOrEnsSchema,
66
campaignRequestSchema,
77
throwIfMissing,
8+
booleanSchema,
89
} from '../utils/validators.js';
910
import {
1011
CampaignRequest,
@@ -19,6 +20,7 @@ export const sendEmailCampaign = async ({
1920
dataProtector = throwIfMissing(),
2021
workerpoolAddressOrEns = throwIfMissing(),
2122
campaignRequest,
23+
allowDeposit = false,
2224
}: DataProtectorConsumer &
2325
SendEmailCampaignParams): Promise<SendEmailCampaignResponse> => {
2426
const vCampaignRequest = campaignRequestSchema()
@@ -31,6 +33,10 @@ export const sendEmailCampaign = async ({
3133
.label('workerpoolAddressOrEns')
3234
.validateSync(workerpoolAddressOrEns);
3335

36+
const vAllowDeposit = booleanSchema()
37+
.label('allowDeposit')
38+
.validateSync(allowDeposit);
39+
3440
if (
3541
vCampaignRequest.workerpool !== NULL_ADDRESS &&
3642
vCampaignRequest.workerpool.toLowerCase() !==
@@ -43,10 +49,14 @@ export const sendEmailCampaign = async ({
4349

4450
try {
4551
// Process the prepared bulk request
52+
// TODO: Remove @ts-ignore once @iexec/dataprotector is updated to a version that includes allowDeposit in ProcessBulkRequestParams types
53+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
54+
// @ts-ignore - allowDeposit is supported at runtime but not yet in TypeScript types
4655
const processBulkRequestResponse = await dataProtector.processBulkRequest({
4756
bulkRequest: vCampaignRequest,
4857
workerpool: vWorkerpoolAddressOrEns,
4958
waitForResult: false,
59+
allowDeposit: vAllowDeposit,
5060
});
5161

5262
return processBulkRequestResponse;

src/web3mail/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ export type SendEmailCampaignParams = {
181181
* Workerpool address or ENS to use for processing
182182
*/
183183
workerpoolAddressOrEns?: AddressOrENS;
184+
/**
185+
* If true, allows automatic deposit of funds when balance is insufficient
186+
* @default false
187+
*/
188+
allowDeposit?: boolean;
184189
};
185190

186191
export type SendEmailCampaignResponse = {

0 commit comments

Comments
 (0)