Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Use snakecase on the other TransferProvider function arguments (#83)
Browse files Browse the repository at this point in the history
This keeps it consistent with the deposit / withdraw functions, and also submits the correct `asset_code` var to the /fee endpoint (where previously it was incorrectly sending `assetCode`.)
  • Loading branch information
Morley Zhi authored Jul 17, 2019
1 parent 2b815b7 commit 78dba6a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stellar/wallet-sdk",
"version": "0.0.3-rc.13",
"version": "0.0.3-rc.14",
"description": "Libraries to help you write Stellar-enabled wallets in Javascript",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
8 changes: 4 additions & 4 deletions src/transfers/DepositProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ describe("fetchFinalFee", () => {

expect(
await provider.fetchFinalFee({
supportedAssets: info,
assetCode: info.USD.assetCode,
supported_assets: info,
asset_code: info.USD.assetCode,
amount: "15",
type: "",
}),
Expand Down Expand Up @@ -55,8 +55,8 @@ describe("fetchFinalFee", () => {

expect(
await provider.fetchFinalFee({
supportedAssets: info,
assetCode: info.EUR.assetCode,
supported_assets: info,
asset_code: info.EUR.assetCode,
amount: "10",
type: "",
}),
Expand Down
14 changes: 8 additions & 6 deletions src/transfers/TransferProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,26 @@ export abstract class TransferProvider {
| Promise<DepositInfo>;

protected async fetchFinalFee(args: FeeArgs): Promise<number> {
const { supportedAssets, assetCode, amount } = args;
const { supported_assets, ...rest } = args;

if (!supportedAssets[assetCode]) {
throw new Error(`Can't get fee for an unsupported asset, '${assetCode}`);
if (!supported_assets[args.asset_code]) {
throw new Error(
`Can't get fee for an unsupported asset, '${args.asset_code}`,
);
}
const { fee } = supportedAssets[assetCode];
const { fee } = supported_assets[args.asset_code];
switch (fee.type) {
case "none":
return 0;
case "simple":
const simpleFee = fee as SimpleFee;
return (
((simpleFee.percent || 0) / 100) * Number(amount) +
((simpleFee.percent || 0) / 100) * Number(args.amount) +
(simpleFee.fixed || 0)
);
case "complex":
const response = await fetch(
`${this.transferServer}/fee?${queryString.stringify(args)}`,
`${this.transferServer}/fee?${queryString.stringify(rest)}`,
);
const { fee: feeResponse } = await response.json();
return feeResponse as number;
Expand Down
4 changes: 2 additions & 2 deletions src/types/transfers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export interface GetKycArgs {
}

export interface FeeArgs {
supportedAssets: WithdrawInfo | DepositInfo;
assetCode: string;
supported_assets: WithdrawInfo | DepositInfo;
asset_code: string;
amount: string;
operation: "withdraw" | "deposit";
type: string;
Expand Down

0 comments on commit 78dba6a

Please sign in to comment.