Skip to content

Commit e8df98d

Browse files
refactor: extract bulk processing to sendTelegramCampaign function
1 parent 10592b2 commit e8df98d

File tree

8 files changed

+1299
-764
lines changed

8 files changed

+1299
-764
lines changed

src/utils/validators.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isAddress } from 'ethers';
22
import { IExec } from 'iexec';
3-
import { ValidationError, boolean, number, string } from 'yup';
3+
import { ValidationError, boolean, number, object, string } from 'yup';
44

55
export const isValidProvider = async (iexec: IExec) => {
66
const client = await iexec.config.resolveContractsClient();
@@ -53,3 +53,6 @@ export const positiveNumberSchema = () =>
5353

5454
export const booleanSchema = () =>
5555
boolean().strict().typeError('${path} should be a boolean');
56+
57+
export const campaignRequestSchema = () =>
58+
object().required().typeError('${path} should be a BulkRequest object');

src/web3telegram/IExecWeb3telegram.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import { GraphQLClient } from 'graphql-request';
55
import { fetchUserContacts } from './fetchUserContacts.js';
66
import { fetchMyContacts } from './fetchMyContacts.js';
77
import { sendTelegram } from './sendTelegram.js';
8+
import {
9+
sendTelegramCampaign,
10+
SendTelegramCampaignParams,
11+
SendTelegramCampaignResponse,
12+
} from './sendTelegramCampaign.js';
813
import {
914
Contact,
1015
FetchUserContactsParams,
@@ -115,23 +120,35 @@ export class IExecWeb3telegram {
115120
});
116121
}
117122

118-
async sendTelegram<Params extends SendTelegramParams>(
119-
args: Params
120-
): Promise<SendTelegramResponse<Params>> {
123+
async sendTelegram(
124+
args: SendTelegramParams & { protectedData: string }
125+
): Promise<SendTelegramResponse> {
121126
await this.init();
122127
await isValidProvider(this.iexec);
123128
return sendTelegram({
124129
...args,
125130
workerpoolAddressOrEns:
126131
args.workerpoolAddressOrEns || this.defaultWorkerpool,
127132
iexec: this.iexec,
128-
dataProtector: this.dataProtector,
129133
ipfsNode: this.ipfsNode,
130134
ipfsGateway: this.ipfsGateway,
131135
dappAddressOrENS: this.dappAddressOrENS,
132136
dappWhitelistAddress: this.dappWhitelistAddress,
133137
graphQLClient: this.graphQLClient,
134-
} as any) as Promise<SendTelegramResponse<Params>>;
138+
});
139+
}
140+
141+
async sendTelegramCampaign(
142+
args: SendTelegramCampaignParams
143+
): Promise<SendTelegramCampaignResponse> {
144+
await this.init();
145+
await isValidProvider(this.iexec);
146+
return sendTelegramCampaign({
147+
...args,
148+
workerpoolAddressOrEns:
149+
args.workerpoolAddressOrEns || this.defaultWorkerpool,
150+
dataProtector: this.dataProtector,
151+
});
135152
}
136153

137154
async prepareTelegramCampaign(

0 commit comments

Comments
 (0)