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

Rename NCW base path #198

Merged
merged 2 commits into from
Aug 23, 2023
Merged
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
41 changes: 22 additions & 19 deletions src/ncw-api-client.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,47 @@
import { ApiClient } from "./api-client";
import {
AssetResponse, DepositAddressResponse, Web3PagedResponse, NCW
AssetResponse,
Web3PagedResponse,
NCW,
} from "./types";
import { NcwSdk } from "./ncw-sdk";

export class NcwApiClient implements NcwSdk {
constructor(private readonly apiClient: ApiClient) {
}
private readonly NCW_BASE_PATH = "/v1/ncw/wallets";

constructor(private readonly apiClient: ApiClient) { }

public async createWallet(): Promise<{ walletId: string; enabled: boolean; }> {
return await this.apiClient.issuePostRequest(
`/v1/wallets`,
`${this.NCW_BASE_PATH}`,
{});
}

public async getWallet(walletId: string): Promise<{ walletId: string; enabled: boolean; }> {
return await this.apiClient.issueGetRequest(
`/v1/wallets/${walletId}`);
`${this.NCW_BASE_PATH}/${walletId}`);
}

public async enableWallet(walletId: string, enabled: boolean): Promise<void> {
return await this.apiClient.issuePutRequest(
`/v1/wallets/${walletId}/enable`,
`${this.NCW_BASE_PATH}/${walletId}/enable`,
{ enabled });
}

public async getWalletDevices(walletId: string): Promise<NCW.Device> {
return await this.apiClient.issueGetRequest(
`/v1/wallets/${walletId}/devices/`);
`${this.NCW_BASE_PATH}/${walletId}/devices/`);
}

public async enableWalletDevice(walletId: string, deviceId: string, enabled: boolean): Promise<void> {
return await this.apiClient.issuePutRequest(
`/v1/wallets/${walletId}/devices/${deviceId}/enable`,
`${this.NCW_BASE_PATH}/${walletId}/devices/${deviceId}/enable`,
{ enabled });
}

public async invokeWalletRpc(walletId: string, deviceId: string, payload: string): Promise<{ result: string; } | { error: { message: string; code?: number; }; }> {
return await this.apiClient.issuePostRequest(
`/v1/wallets/${walletId}/devices/${deviceId}/invoke`,
`${this.NCW_BASE_PATH}/${walletId}/devices/${deviceId}/invoke`,
{ payload });
}

Expand All @@ -47,7 +50,7 @@ export class NcwApiClient implements NcwSdk {
accountId: number;
}> {
return await this.apiClient.issuePostRequest(
`/v1/wallets/${walletId}/accounts`,
`${this.NCW_BASE_PATH}/${walletId}/accounts`,
{});
}

Expand All @@ -59,7 +62,7 @@ export class NcwApiClient implements NcwSdk {
...(order && { order }),
});

return await this.apiClient.issueGetRequest(`/v1/wallets?${params.toString()}`);
return await this.apiClient.issueGetRequest(`${this.NCW_BASE_PATH}?${params.toString()}`);
}

public async getWalletAccounts(walletId: string, { pageCursor, pageSize, sort, order }: NCW.GetWalletsPayload = {}): Promise<Web3PagedResponse<{
Expand All @@ -74,15 +77,15 @@ export class NcwApiClient implements NcwSdk {
});

return await this.apiClient.issueGetRequest(
`/v1/wallets/${walletId}/accounts?${params.toString()}`);
`${this.NCW_BASE_PATH}/${walletId}/accounts?${params.toString()}`);
}

public async getWalletAccount(walletId: string, accountId: number): Promise<{
walletId: string;
accountId: number;
}> {
return await this.apiClient.issueGetRequest(
`/v1/wallets/${walletId}/accounts/${accountId}`);
`${this.NCW_BASE_PATH}/${walletId}/accounts/${accountId}`);
}

public async getWalletAssets(walletId: string, accountId: number, { pageCursor, pageSize, sort, order }: NCW.GetWalletAssetsPayload = {}): Promise<Web3PagedResponse<NCW.WalletAssetResponse>> {
Expand All @@ -94,17 +97,17 @@ export class NcwApiClient implements NcwSdk {
});

return await this.apiClient.issueGetRequest(
`/v1/wallets/${walletId}/accounts/${accountId}/assets?${params.toString()}`);
`${this.NCW_BASE_PATH}/${walletId}/accounts/${accountId}/assets?${params.toString()}`);
}

public async getWalletAsset(walletId: string, accountId: number, assetId: string): Promise<NCW.WalletAssetResponse> {
return await this.apiClient.issueGetRequest(
`/v1/wallets/${walletId}/accounts/${accountId}/assets/${assetId}`);
`${this.NCW_BASE_PATH}/${walletId}/accounts/${accountId}/assets/${assetId}`);
}

public async activateWalletAsset(walletId: string, accountId: number, assetId: string): Promise<NCW.WalletAssetAddress> {
return await this.apiClient.issuePostRequest(
`/v1/wallets/${walletId}/accounts/${accountId}/assets/${assetId}`, {});
`${this.NCW_BASE_PATH}/${walletId}/accounts/${accountId}/assets/${assetId}`, {});
}

public async getWalletAssetAddresses(walletId: string, accountId: number, assetId: string, { pageCursor, pageSize, sort, order }: NCW.GetWalletAddressesPayload = {}): Promise<Web3PagedResponse<NCW.WalletAssetAddress>> {
Expand All @@ -116,17 +119,17 @@ export class NcwApiClient implements NcwSdk {
});

return await this.apiClient.issueGetRequest(
`/v1/wallets/${walletId}/accounts/${accountId}/assets/${assetId}/addresses?${params.toString()}`);
`${this.NCW_BASE_PATH}/${walletId}/accounts/${accountId}/assets/${assetId}/addresses?${params.toString()}`);
}

public async getWalletAssetBalance(walletId: string, accountId: number, assetId: string): Promise<AssetResponse> {
return await this.apiClient.issueGetRequest(
`/v1/wallets/${walletId}/accounts/${accountId}/assets/${assetId}/balance`);
`${this.NCW_BASE_PATH}/${walletId}/accounts/${accountId}/assets/${assetId}/balance`);
}

public async refreshWalletAssetBalance(walletId: string, accountId: number, assetId: string): Promise<AssetResponse> {
return await this.apiClient.issuePutRequest(
`/v1/wallets/${walletId}/accounts/${accountId}/assets/${assetId}/balance`,
`${this.NCW_BASE_PATH}/${walletId}/accounts/${accountId}/assets/${assetId}/balance`,
{});
}
}