diff --git a/src/ncw-api-client.ts b/src/ncw-api-client.ts index ec6b76d3..a45755a4 100644 --- a/src/ncw-api-client.ts +++ b/src/ncw-api-client.ts @@ -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 { return await this.apiClient.issuePutRequest( - `/v1/wallets/${walletId}/enable`, + `${this.NCW_BASE_PATH}/${walletId}/enable`, { enabled }); } public async getWalletDevices(walletId: string): Promise { 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 { 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 }); } @@ -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`, {}); } @@ -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 { 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> { @@ -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 { 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 { 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> { @@ -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 { 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 { return await this.apiClient.issuePutRequest( - `/v1/wallets/${walletId}/accounts/${accountId}/assets/${assetId}/balance`, + `${this.NCW_BASE_PATH}/${walletId}/accounts/${accountId}/assets/${assetId}/balance`, {}); } }