Skip to content

Commit 8c1d0b1

Browse files
authored
add patch dapp method (#113)
1 parent 7ab1445 commit 8c1d0b1

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
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": "1.9.3",
3+
"version": "1.9.4",
44
"type": "module",
55
"repository": "[email protected]:dialectlabs/sdk.git",
66
"author": "dialectlabs",

packages/sdk/src/dapp/dapp.interface.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import type { AddressType, DappAddress } from '../address/addresses.interface';
2-
import type { NotificationConfig, NotificationSubscription, NotificationType } from '../wallet/wallet.interface';
2+
import type {
3+
NotificationConfig,
4+
NotificationSubscription,
5+
NotificationType,
6+
} from '../wallet/wallet.interface';
37
import type { AccountAddress } from '../auth/auth.interface';
48

59
export interface Dapps {
610
create(command: CreateDappCommand): Promise<Dapp>;
711

12+
patch(command: PatchDappCommand): Promise<Dapp>;
13+
814
find(query?: FindOneDappQuery): Promise<Dapp | null>;
915

1016
findAll(query?: FindDappQuery): Promise<ReadOnlyDapp[]>;
@@ -59,6 +65,14 @@ export interface CreateDappCommand {
5965
blockchainType: BlockchainType;
6066
}
6167

68+
export interface PatchDappCommand {
69+
name?: string;
70+
description?: string | null;
71+
websiteUrl?: string | null;
72+
avatarUrl?: string | null;
73+
heroUrl?: string | null;
74+
}
75+
6276
export interface DappTelegramBotConfiguration {
6377
token: string;
6478
}
@@ -81,7 +95,7 @@ interface DappMessageActionBase {
8195
type: DappMessageActionType;
8296
}
8397

84-
export interface DappMessageLinksAction extends DappMessageActionBase {
98+
export interface DappMessageLinksAction extends DappMessageActionBase {
8599
type: DappMessageActionType.LINK;
86100
links: [DappMessageLinkAction];
87101
}
@@ -103,7 +117,6 @@ export interface SmartMessage {
103117
// eslint-disable-next-line @typescript-eslint/no-empty-interface
104118
export interface SmartMessageParams {}
105119

106-
107120
export interface SendDappMessageCommandBase {
108121
message: string;
109122
title?: string;
@@ -113,7 +126,8 @@ export interface SendDappMessageCommandBase {
113126
// tags?: string[];
114127
}
115128

116-
export interface BroadcastDappMessageCommand extends SendDappMessageCommandBase {
129+
export interface BroadcastDappMessageCommand
130+
extends SendDappMessageCommandBase {
117131
actionsV2?: DappMessageLinksAction;
118132
}
119133

@@ -174,4 +188,3 @@ export class DappNotificationSubscription {
174188
notificationType!: NotificationType;
175189
subscriptions!: NotificationSubscription[];
176190
}
177-

packages/sdk/src/dialect-cloud-api/data-service-dapps-api.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import type { BlockchainType } from '../dapp/dapp.interface';
99
export interface DataServiceDappsApi {
1010
create(command: Omit<CreateDappCommandDto, 'publicKey'>): Promise<DappDto>;
1111

12+
patch(command: PatchDappCommandDto): Promise<DappDto>;
13+
1214
findAll(query?: FindDappQueryDto): Promise<DappDto[]>;
1315

1416
find(dappAddress?: string): Promise<DappDto>;
@@ -45,6 +47,21 @@ export class DataServiceDappsApiClient implements DataServiceDappsApi {
4547
);
4648
}
4749

50+
async patch(command: PatchDappCommandDto): Promise<DappDto> {
51+
const token = await this.tokenProvider.get();
52+
return withReThrowingDataServiceError(
53+
axios
54+
.patch<DappDto>(
55+
`${this.baseUrl}/api/v1/dapps/${token.body.sub}`,
56+
command,
57+
{
58+
headers: createHeaders(token),
59+
},
60+
)
61+
.then((it) => it.data),
62+
);
63+
}
64+
4865
async findAllDappAddresses(): Promise<DappAddressDto[]> {
4966
const token = await this.tokenProvider.get();
5067
return withReThrowingDataServiceError(
@@ -153,6 +170,14 @@ export class CreateDappCommandDto {
153170
readonly blockchainType?: string;
154171
}
155172

173+
export class PatchDappCommandDto {
174+
readonly name?: string;
175+
readonly description?: string | null;
176+
readonly websiteUrl?: string | null;
177+
readonly avatarUrl?: string | null;
178+
readonly heroUrl?: string | null;
179+
}
180+
156181
export class DappTelegramBotConfigurationDto {
157182
readonly token!: string;
158183
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
Dapps,
1616
FindDappQuery,
1717
FindOneDappQuery,
18+
PatchDappCommand,
1819
ReadOnlyDapp,
1920
} from '../../dapp/dapp.interface';
2021
import type { DataServiceDappNotificationTypes } from './data-service-dapp-notification-types';
@@ -93,6 +94,19 @@ export class DappsImpl implements Dapps {
9394
);
9495
return this.toDapp(dappDto);
9596
}
97+
98+
async patch(command: PatchDappCommand): Promise<Dapp> {
99+
const dappDto = await withErrorParsing(
100+
this.dappsApi.patch({
101+
name: command.name,
102+
description: command.description,
103+
websiteUrl: command.websiteUrl,
104+
avatarUrl: command.avatarUrl,
105+
heroUrl: command.heroUrl,
106+
}),
107+
);
108+
return this.toDapp(dappDto);
109+
}
96110
}
97111

98112
export class DappImpl implements Dapp {

0 commit comments

Comments
 (0)