Skip to content

Commit

Permalink
Merge branch 'ncw_ns_squash' into ncw_ns
Browse files Browse the repository at this point in the history
  • Loading branch information
amper-fb committed Aug 20, 2023
2 parents 8189dab + 58a4375 commit 2d23469
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
10 changes: 4 additions & 6 deletions src/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,15 @@ export class ApiClient {

public async issuePostRequest<T>(path: string, body: any, requestOptions?: RequestOptions): Promise<T> {
const token = this.authProvider.signJwt(path, body);
const headers: any = {"Authorization": `Bearer ${token}`};
const headers: Record<string, string> = {
"Authorization": `Bearer ${token}`,
...requestOptions?.headers
};
const idempotencyKey = requestOptions?.idempotencyKey;
if (idempotencyKey) {
headers["Idempotency-Key"] = idempotencyKey;
}

const ncwWalletId = requestOptions?.NCW?.walletId;
if (ncwWalletId) {
headers["X-End-User-Wallet-Id"] = ncwWalletId;
}

const response = await this.axiosInstance.post<T>(path, body, {headers});
return response.data;
}
Expand Down
21 changes: 16 additions & 5 deletions src/fireblocks-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ import {
SmartTransfersTicketTermPayload,
SmartTransfersTicketTermFundPayload,
SmartTransfersTicketTermResponse,
UsersGroup, PendingTokenLinkDto,
UsersGroup, PendingTokenLinkDto, NCW,
} from "./types";
import { AxiosProxyConfig, AxiosResponse } from "axios";
import { PIIEncryption } from "./pii-client";
Expand All @@ -101,6 +101,7 @@ import { NcwSdk } from "./ncw-sdk";

export * from "./types";


export interface SDKOptions {
/** HTTP request timeout */
timeoutInMs?: number;
Expand Down Expand Up @@ -630,8 +631,15 @@ export class FireblocksSDK {
* @param txId The transaction id to cancel
* @param requestOptions
*/
public async cancelTransactionById(txId: string, requestOptions?: RequestOptions): Promise<CancelTransactionResponse> {
return await this.apiClient.issuePostRequest(`/v1/transactions/${txId}/cancel`, {}, requestOptions);
public async cancelTransactionById(txId: string, requestOptions?: RequestOptions, ncwWalletId?: string): Promise<CancelTransactionResponse> {
const opts = {
...requestOptions,
headers: {
[NCW.WalletIdHeader]: ncwWalletId,
...requestOptions?.headers,
},
};
return await this.apiClient.issuePostRequest(`/v1/transactions/${txId}/cancel`, {}, opts);
}

/**
Expand Down Expand Up @@ -821,9 +829,12 @@ export class FireblocksSDK {
transactionArguments = await this.piiClient.hybridEncode(transactionArguments, travelRuleEncryptionOptions);
}

if (transactionArguments.source?.type === PeerType.END_USER_WALLET && !opts.NCW?.walletId) {
if (transactionArguments.source?.type === PeerType.END_USER_WALLET && !opts.headers?.[NCW.WalletIdHeader]) {
const { walletId } = transactionArguments.source;
opts.NCW = { ...opts.NCW, walletId };
opts.headers = {
...opts.headers,
[NCW.WalletIdHeader]: walletId
};
}

return await this.apiClient.issuePostRequest("/v1/transactions", transactionArguments, opts);
Expand Down
2 changes: 1 addition & 1 deletion src/ncw-api-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiClient } from "./api-client";
import {
AssetResponse, DepositAddressResponse, Web3PagedResponse, NCW
AssetResponse, Web3PagedResponse, NCW
} from "./types";
import { NcwSdk } from "./ncw-sdk";

Expand Down
4 changes: 3 additions & 1 deletion src/ncw-sdk.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {
AssetResponse, DepositAddressResponse, Web3PagedResponse, NCW,
AssetResponse, Web3PagedResponse, NCW,
} from "./types";

export const NcwWalletIdHeader = "X-End-User-Wallet-Id";

export interface NcwSdk {
/**
* Create a new NCW wallet
Expand Down
24 changes: 12 additions & 12 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1080,9 +1080,7 @@ export interface VaultBalancesFilter {

export interface RequestOptions {
idempotencyKey?: string;
NCW?: {
walletId?: string;
}
headers?: Record<string, string>;
}

export interface ValidateAddressResponse {
Expand Down Expand Up @@ -1547,6 +1545,8 @@ export interface SmartTransfersTicketTermFundPayload {
}

export namespace NCW {
export const WalletIdHeader = "X-End-User-Wallet-Id";

export interface WalletInfo {
walletId: string;
enabled: boolean;
Expand Down Expand Up @@ -1601,14 +1601,14 @@ export namespace NCW {
blockchainId?: string;
}
export interface WalletAssetAddress {
accountName: string,
accountId: string,
asset: string,
address: string,
addressType: string,
addressDescription?: string,
tag?: string,
addressIndex?: number,
legacyAddress?: string,
accountName: string;
accountId: string;
asset: string;
address: string;
addressType: string;
addressDescription?: string;
tag?: string;
addressIndex?: number;
legacyAddress?: string;
}
}

0 comments on commit 2d23469

Please sign in to comment.