Skip to content

Commit

Permalink
Merge pull request #198 from fireblocks/rename-ncw-endpoint
Browse files Browse the repository at this point in the history
Rename NCW base path
  • Loading branch information
tomervil authored Aug 23, 2023
2 parents eb7dc74 + e105d26 commit a68d733
Showing 1 changed file with 22 additions and 19 deletions.
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`,
{});
}
}

0 comments on commit a68d733

Please sign in to comment.