Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add patch dapp method #113

Merged
merged 3 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "[email protected]: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
Loading