Skip to content

Commit 46bb6b8

Browse files
refactor: clean types
1 parent 86a1bc0 commit 46bb6b8

File tree

3 files changed

+20
-67
lines changed

3 files changed

+20
-67
lines changed

src/web3telegram/IExecWeb3telegram.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ export class IExecWeb3telegram {
116116
});
117117
}
118118

119-
async sendTelegram(
120-
args: SendTelegramParams & { protectedData: string }
121-
): Promise<SendTelegramResponse> {
119+
async sendTelegram(args: SendTelegramParams): Promise<SendTelegramResponse> {
122120
await this.init();
123121
await isValidProvider(this.iexec);
124122
return sendTelegram({

src/web3telegram/sendTelegram.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
senderNameSchema,
1919
booleanSchema,
2020
} from '../utils/validators.js';
21-
import { SendTelegramResponse } from './types.js';
21+
import { SendTelegramParams, SendTelegramResponse } from './types.js';
2222
import {
2323
checkUserVoucher,
2424
filterWorkerpoolOrders,
@@ -34,18 +34,6 @@ import {
3434

3535
export type SendTelegram = typeof sendTelegram;
3636

37-
type SendTelegramSingleParams = {
38-
senderName?: string;
39-
telegramContent: string;
40-
label?: string;
41-
workerpoolAddressOrEns?: string;
42-
dataMaxPrice?: number;
43-
appMaxPrice?: number;
44-
workerpoolMaxPrice?: number;
45-
protectedData: string;
46-
useVoucher?: boolean;
47-
};
48-
4937
export const sendTelegram = async ({
5038
graphQLClient = throwIfMissing(),
5139
iexec = throwIfMissing(),
@@ -68,7 +56,7 @@ export const sendTelegram = async ({
6856
DappWhitelistAddressConsumer &
6957
IpfsNodeConfigConsumer &
7058
IpfsGatewayConfigConsumer &
71-
SendTelegramSingleParams): Promise<SendTelegramResponse> => {
59+
SendTelegramParams): Promise<SendTelegramResponse> => {
7260
try {
7361
const vDatasetAddress = addressOrEnsSchema()
7462
.required()

src/web3telegram/types.ts

Lines changed: 17 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,6 @@ export type Contact = {
3636
grantedAccess: GrantedAccess;
3737
};
3838

39-
type SendTelegramCommonParams = {
40-
senderName?: string;
41-
telegramContent: string;
42-
label?: string;
43-
workerpoolAddressOrEns?: AddressOrENS;
44-
dataMaxPrice?: number;
45-
appMaxPrice?: number;
46-
workerpoolMaxPrice?: number;
47-
useVoucher?: boolean;
48-
};
49-
50-
export type SendTelegramParams =
51-
| ({
52-
/**
53-
* protected data to process.
54-
*/
55-
protectedData: Address;
56-
} & SendTelegramCommonParams)
57-
| ({
58-
/**
59-
* Granted access to process in bulk.
60-
* use `fetchMyContacts({ bulkOnly: true })` to get granted accesses.
61-
* if not provided, the single message will be processed.
62-
*/
63-
grantedAccess: GrantedAccess[];
64-
maxProtectedDataPerTask?: number;
65-
} & SendTelegramCommonParams);
66-
6739
export type FetchMyContactsParams = {
6840
/**
6941
* Get contacts for this specific user only
@@ -79,27 +51,22 @@ export type FetchUserContactsParams = {
7951
userAddress: Address;
8052
} & FetchMyContactsParams;
8153

82-
type SendTelegramSingleResponse = {
83-
taskId: string;
54+
export type SendTelegramParams = {
55+
senderName?: string;
56+
telegramContent: string;
57+
protectedData: Address;
58+
label?: string;
59+
workerpoolAddressOrEns?: AddressOrENS;
60+
dataMaxPrice?: number;
61+
appMaxPrice?: number;
62+
workerpoolMaxPrice?: number;
63+
useVoucher?: boolean;
8464
};
8565

86-
type SendTelegramBulkResponse = {
87-
tasks: {
88-
bulkIndex: number;
89-
taskId: string;
90-
dealId: string;
91-
}[];
66+
export type SendTelegramResponse = {
67+
taskId: string;
9268
};
9369

94-
export type SendTelegramResponse<Params = { protectedData: Address }> =
95-
Params extends {
96-
grantedAccess: GrantedAccess[];
97-
}
98-
? SendTelegramBulkResponse
99-
: never & Params extends { protectedData: Address }
100-
? SendTelegramSingleResponse
101-
: never;
102-
10370
export type PrepareTelegramCampaignParams = {
10471
/**
10572
* Granted access to process in bulk.
@@ -121,6 +88,11 @@ export type PrepareTelegramCampaignResponse = {
12188
campaignRequest: BulkRequest;
12289
};
12390

91+
export type SendTelegramCampaignParams = {
92+
campaignRequest: BulkRequest;
93+
workerpoolAddressOrEns?: string;
94+
};
95+
12496
export type SendTelegramCampaignResponse = {
12597
tasks: {
12698
bulkIndex: number;
@@ -129,11 +101,6 @@ export type SendTelegramCampaignResponse = {
129101
}[];
130102
};
131103

132-
export type SendTelegramCampaignParams = {
133-
campaignRequest: BulkRequest;
134-
workerpoolAddressOrEns?: string;
135-
};
136-
137104
/**
138105
* Configuration options for web3telegram.
139106
*/

0 commit comments

Comments
 (0)