Skip to content

Commit

Permalink
add patch dapp method (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
prsvic authored Jun 9, 2024
1 parent 7ab1445 commit 8c1d0b1
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dialectlabs/sdk",
"version": "1.9.3",
"version": "1.9.4",
"type": "module",
"repository": "git@github.com:dialectlabs/sdk.git",
"author": "dialectlabs",
Expand Down
23 changes: 18 additions & 5 deletions packages/sdk/src/dapp/dapp.interface.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import type { AddressType, DappAddress } from '../address/addresses.interface';
import type { NotificationConfig, NotificationSubscription, NotificationType } from '../wallet/wallet.interface';
import type {
NotificationConfig,
NotificationSubscription,
NotificationType,
} from '../wallet/wallet.interface';
import type { AccountAddress } from '../auth/auth.interface';

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

patch(command: PatchDappCommand): Promise<Dapp>;

find(query?: FindOneDappQuery): Promise<Dapp | null>;

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

export interface PatchDappCommand {
name?: string;
description?: string | null;
websiteUrl?: string | null;
avatarUrl?: string | null;
heroUrl?: string | null;
}

export interface DappTelegramBotConfiguration {
token: string;
}
Expand All @@ -81,7 +95,7 @@ interface DappMessageActionBase {
type: DappMessageActionType;
}

export interface DappMessageLinksAction extends DappMessageActionBase {
export interface DappMessageLinksAction extends DappMessageActionBase {
type: DappMessageActionType.LINK;
links: [DappMessageLinkAction];
}
Expand All @@ -103,7 +117,6 @@ export interface SmartMessage {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface SmartMessageParams {}


export interface SendDappMessageCommandBase {
message: string;
title?: string;
Expand All @@ -113,7 +126,8 @@ export interface SendDappMessageCommandBase {
// tags?: string[];
}

export interface BroadcastDappMessageCommand extends SendDappMessageCommandBase {
export interface BroadcastDappMessageCommand
extends SendDappMessageCommandBase {
actionsV2?: DappMessageLinksAction;
}

Expand Down Expand Up @@ -174,4 +188,3 @@ export class DappNotificationSubscription {
notificationType!: NotificationType;
subscriptions!: NotificationSubscription[];
}

25 changes: 25 additions & 0 deletions packages/sdk/src/dialect-cloud-api/data-service-dapps-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type { BlockchainType } from '../dapp/dapp.interface';
export interface DataServiceDappsApi {
create(command: Omit<CreateDappCommandDto, 'publicKey'>): Promise<DappDto>;

patch(command: PatchDappCommandDto): Promise<DappDto>;

findAll(query?: FindDappQueryDto): Promise<DappDto[]>;

find(dappAddress?: string): Promise<DappDto>;
Expand Down Expand Up @@ -45,6 +47,21 @@ export class DataServiceDappsApiClient implements DataServiceDappsApi {
);
}

async patch(command: PatchDappCommandDto): Promise<DappDto> {
const token = await this.tokenProvider.get();
return withReThrowingDataServiceError(
axios
.patch<DappDto>(
`${this.baseUrl}/api/v1/dapps/${token.body.sub}`,
command,
{
headers: createHeaders(token),
},
)
.then((it) => it.data),
);
}

async findAllDappAddresses(): Promise<DappAddressDto[]> {
const token = await this.tokenProvider.get();
return withReThrowingDataServiceError(
Expand Down Expand Up @@ -153,6 +170,14 @@ export class CreateDappCommandDto {
readonly blockchainType?: string;
}

export class PatchDappCommandDto {
readonly name?: string;
readonly description?: string | null;
readonly websiteUrl?: string | null;
readonly avatarUrl?: string | null;
readonly heroUrl?: string | null;
}

export class DappTelegramBotConfigurationDto {
readonly token!: string;
}
Expand Down
14 changes: 14 additions & 0 deletions packages/sdk/src/internal/dapp/dapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
Dapps,
FindDappQuery,
FindOneDappQuery,
PatchDappCommand,
ReadOnlyDapp,
} from '../../dapp/dapp.interface';
import type { DataServiceDappNotificationTypes } from './data-service-dapp-notification-types';
Expand Down Expand Up @@ -93,6 +94,19 @@ export class DappsImpl implements Dapps {
);
return this.toDapp(dappDto);
}

async patch(command: PatchDappCommand): Promise<Dapp> {
const dappDto = await withErrorParsing(
this.dappsApi.patch({
name: command.name,
description: command.description,
websiteUrl: command.websiteUrl,
avatarUrl: command.avatarUrl,
heroUrl: command.heroUrl,
}),
);
return this.toDapp(dappDto);
}
}

export class DappImpl implements Dapp {
Expand Down

0 comments on commit 8c1d0b1

Please sign in to comment.