Skip to content

Commit b41b377

Browse files
committed
remove redundant dapp fetching during notif send
1 parent e6c1861 commit b41b377

File tree

4 files changed

+23
-27
lines changed

4 files changed

+23
-27
lines changed

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dialectlabs/sdk",
3-
"version": "2.0.0-beta.1",
3+
"version": "2.0.0-beta.2",
44
"type": "module",
55
"repository": "[email protected]:dialectlabs/sdk.git",
66
"author": "dialectlabs",

packages/sdk/src/internal/dapp/alerts-v2-dapp-messages.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import {
1515
Channel,
1616
type SendAlertRequest,
1717
} from '../../dialect-cloud-api/v2/application-api';
18-
import { IllegalStateError } from '../../sdk/errors';
19-
import type { DataServiceDappsApi } from '../../dialect-cloud-api/data-service-dapps-api';
2018
import { withErrorParsing } from '../../dialect-cloud-api/data-service-errors';
2119

2220
export const AddressTypeToChannel = {
@@ -28,23 +26,21 @@ export const AddressTypeToChannel = {
2826

2927
export class AlertsV2DappMessages implements DappMessages {
3028
constructor(
31-
private readonly dapps: DataServiceDappsApi,
29+
private readonly dappId: string,
3230
private readonly api: AppV2Api,
3331
) {}
3432

3533
async send(command: SendDappMessageCommand): Promise<void> {
36-
const dapp = await withErrorParsing(this.dapps.find()); // TODO: cache
37-
3834
if (command.addressTypes?.length === 0) {
3935
return;
4036
}
4137
if ('recipient' in command) {
42-
return this.unicast(command, dapp.id);
38+
return this.unicast(command);
4339
}
4440
if ('recipients' in command) {
45-
return this.multicast(command, dapp.id);
41+
return this.multicast(command);
4642
}
47-
return this.broadcast(command, dapp.id);
43+
return this.broadcast(command);
4844
}
4945

5046
static mapChannels(addressTypes?: AddressType[]) {
@@ -76,9 +72,9 @@ export class AlertsV2DappMessages implements DappMessages {
7672
}
7773
}
7874

79-
private async unicast(command: UnicastDappMessageCommand, appId: string) {
75+
private async unicast(command: UnicastDappMessageCommand) {
8076
await withErrorParsing(
81-
this.api.sendAlert(appId, {
77+
this.api.sendAlert(this.dappId, {
8278
recipient: {
8379
type: 'subscriber',
8480
walletAddress: command.recipient.toString(),
@@ -95,7 +91,7 @@ export class AlertsV2DappMessages implements DappMessages {
9591
);
9692
}
9793

98-
private async multicast(command: MulticastDappMessageCommand, appId: string) {
94+
private async multicast(command: MulticastDappMessageCommand) {
9995
if (command.recipients.length === 0) {
10096
return;
10197
}
@@ -117,15 +113,15 @@ export class AlertsV2DappMessages implements DappMessages {
117113
} satisfies SendAlertRequest),
118114
);
119115
await withErrorParsing(
120-
this.api.sendBatch(appId, {
116+
this.api.sendBatch(this.dappId, {
121117
alerts: commands,
122118
}),
123119
);
124120
}
125121

126-
private async broadcast(command: BroadcastDappMessageCommand, appId: string) {
122+
private async broadcast(command: BroadcastDappMessageCommand) {
127123
await withErrorParsing(
128-
this.api.sendAlert(appId, {
124+
this.api.sendAlert(this.dappId, {
129125
recipient: {
130126
type: 'all-subscribers',
131127
},

packages/sdk/src/internal/dapp/dapp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import type { ApiClientError } from '../../dialect-cloud-api/utils';
2626
export class DappsImpl implements Dapps {
2727
constructor(
2828
private readonly dappAddresses: DappAddresses,
29-
private readonly dappMessages: DappMessages,
29+
private readonly dappMessagesFactory: (dappId: string) => DappMessages,
3030
private readonly notificationTypes: DataServiceDappNotificationTypes,
3131
private readonly notificationSubscriptions: DataServiceDappNotificationSubscriptions,
3232
private readonly dappsApi: DataServiceDappsApi,
@@ -54,7 +54,7 @@ export class DappsImpl implements Dapps {
5454
dappDto.telegramBotUserName,
5555
dappDto.blockchainType,
5656
this.dappAddresses,
57-
this.dappMessages,
57+
this.dappMessagesFactory(dappDto.id),
5858
this.notificationTypes,
5959
this.notificationSubscriptions,
6060
dappDto.description,

packages/sdk/src/internal/sdk/sdk-factory.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,16 @@ export class DialectSdkFactory<ChainSdk extends BlockchainSdk> {
195195
dataServiceApi.dappNotificationSubscriptions,
196196
);
197197

198-
const dappMessages = this.createDappMessages(
199-
dataServiceApi,
200-
appV2Api,
201-
blockchainSdk,
202-
dataServiceApi.dapps,
203-
config,
204-
);
205198
return new DappsImpl(
206199
dappAddresses,
207-
dappMessages,
200+
(dappId) =>
201+
this.createDappMessages(
202+
dappId,
203+
dataServiceApi,
204+
appV2Api,
205+
blockchainSdk,
206+
config,
207+
),
208208
dappNotificationTypes,
209209
dappNotificationSubscriptions,
210210
dataServiceApi.dapps,
@@ -227,10 +227,10 @@ export class DialectSdkFactory<ChainSdk extends BlockchainSdk> {
227227
}
228228

229229
private createDappMessages(
230+
dappId: string,
230231
dataServiceApi: DataServiceApi,
231232
appV2Api: AppV2Api,
232233
blockchainSdk: BlockchainSdk,
233-
dapps: DataServiceDappsApi,
234234
config: Config,
235235
): DappMessages {
236236
const dappMessages: DappMessages[] = [];
@@ -243,7 +243,7 @@ export class DialectSdkFactory<ChainSdk extends BlockchainSdk> {
243243
}
244244

245245
if (config.dialectCloud.apiVersion === 2) {
246-
const alertsV2DappMessages = new AlertsV2DappMessages(dapps, appV2Api);
246+
const alertsV2DappMessages = new AlertsV2DappMessages(dappId, appV2Api);
247247
dappMessages.push(alertsV2DappMessages);
248248
}
249249

0 commit comments

Comments
 (0)