From 572d4c15da92e1f228465f4e9e775e45fc10ef22 Mon Sep 17 00:00:00 2001 From: Yuval Niezni Date: Tue, 22 Aug 2023 13:14:59 +0300 Subject: [PATCH 1/2] rename base url --- src/ncw-api-client.ts | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/ncw-api-client.ts b/src/ncw-api-client.ts index ec6b76d3..0722ce6e 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 BASE_URL = "/v1/ncw/wallets"; + + constructor(private readonly apiClient: ApiClient) { } public async createWallet(): Promise<{ walletId: string; enabled: boolean; }> { return await this.apiClient.issuePostRequest( - `/v1/wallets`, + `${this.BASE_URL}`, {}); } public async getWallet(walletId: string): Promise<{ walletId: string; enabled: boolean; }> { return await this.apiClient.issueGetRequest( - `/v1/wallets/${walletId}`); + `${this.BASE_URL}/${walletId}`); } public async enableWallet(walletId: string, enabled: boolean): Promise { return await this.apiClient.issuePutRequest( - `/v1/wallets/${walletId}/enable`, + `${this.BASE_URL}/${walletId}/enable`, { enabled }); } public async getWalletDevices(walletId: string): Promise { return await this.apiClient.issueGetRequest( - `/v1/wallets/${walletId}/devices/`); + `${this.BASE_URL}/${walletId}/devices/`); } public async enableWalletDevice(walletId: string, deviceId: string, enabled: boolean): Promise { return await this.apiClient.issuePutRequest( - `/v1/wallets/${walletId}/devices/${deviceId}/enable`, + `${this.BASE_URL}/${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.BASE_URL}/${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.BASE_URL}/${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.BASE_URL}?${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.BASE_URL}/${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.BASE_URL}/${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.BASE_URL}/${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.BASE_URL}/${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.BASE_URL}/${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.BASE_URL}/${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.BASE_URL}/${walletId}/accounts/${accountId}/assets/${assetId}/balance`, {}); } } From e105d26d5b904241017763dfb4064c9d1e9375c4 Mon Sep 17 00:00:00 2001 From: Yuval Niezni Date: Tue, 22 Aug 2023 17:39:47 +0300 Subject: [PATCH 2/2] rename var --- src/ncw-api-client.ts | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/ncw-api-client.ts b/src/ncw-api-client.ts index 0722ce6e..a45755a4 100644 --- a/src/ncw-api-client.ts +++ b/src/ncw-api-client.ts @@ -7,41 +7,41 @@ import { import { NcwSdk } from "./ncw-sdk"; export class NcwApiClient implements NcwSdk { - private readonly BASE_URL = "/v1/ncw/wallets"; + 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( - `${this.BASE_URL}`, + `${this.NCW_BASE_PATH}`, {}); } public async getWallet(walletId: string): Promise<{ walletId: string; enabled: boolean; }> { return await this.apiClient.issueGetRequest( - `${this.BASE_URL}/${walletId}`); + `${this.NCW_BASE_PATH}/${walletId}`); } public async enableWallet(walletId: string, enabled: boolean): Promise { return await this.apiClient.issuePutRequest( - `${this.BASE_URL}/${walletId}/enable`, + `${this.NCW_BASE_PATH}/${walletId}/enable`, { enabled }); } public async getWalletDevices(walletId: string): Promise { return await this.apiClient.issueGetRequest( - `${this.BASE_URL}/${walletId}/devices/`); + `${this.NCW_BASE_PATH}/${walletId}/devices/`); } public async enableWalletDevice(walletId: string, deviceId: string, enabled: boolean): Promise { return await this.apiClient.issuePutRequest( - `${this.BASE_URL}/${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( - `${this.BASE_URL}/${walletId}/devices/${deviceId}/invoke`, + `${this.NCW_BASE_PATH}/${walletId}/devices/${deviceId}/invoke`, { payload }); } @@ -50,7 +50,7 @@ export class NcwApiClient implements NcwSdk { accountId: number; }> { return await this.apiClient.issuePostRequest( - `${this.BASE_URL}/${walletId}/accounts`, + `${this.NCW_BASE_PATH}/${walletId}/accounts`, {}); } @@ -62,7 +62,7 @@ export class NcwApiClient implements NcwSdk { ...(order && { order }), }); - return await this.apiClient.issueGetRequest(`${this.BASE_URL}?${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( - `${this.BASE_URL}/${walletId}/accounts/${accountId}`); + `${this.NCW_BASE_PATH}/${walletId}/accounts/${accountId}`); } public async getWalletAssets(walletId: string, accountId: number, { pageCursor, pageSize, sort, order }: NCW.GetWalletAssetsPayload = {}): Promise> { @@ -97,17 +97,17 @@ export class NcwApiClient implements NcwSdk { }); return await this.apiClient.issueGetRequest( - `${this.BASE_URL}/${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( - `${this.BASE_URL}/${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( - `${this.BASE_URL}/${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> { @@ -119,17 +119,17 @@ export class NcwApiClient implements NcwSdk { }); return await this.apiClient.issueGetRequest( - `${this.BASE_URL}/${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( - `${this.BASE_URL}/${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( - `${this.BASE_URL}/${walletId}/accounts/${accountId}/assets/${assetId}/balance`, + `${this.NCW_BASE_PATH}/${walletId}/accounts/${accountId}/assets/${assetId}/balance`, {}); } }