Skip to content

Commit

Permalink
feat: support SN 0.9.1 estimate_fee response
Browse files Browse the repository at this point in the history
support is backward compatible
  • Loading branch information
yoga-braavos committed Jul 15, 2022
1 parent 41eea22 commit 9302aab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/account/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ export class Account extends Provider implements AccountInterface {
signature: bigNumberishArrayToDecimalStringArray(signature),
}
);
const suggestedMaxFee = estimatedFeeToMaxFee(fetchedEstimate.amount);
const fee = fetchedEstimate.overall_fee ?? fetchedEstimate.amount;
if (fee === undefined) {
throw new Error('Expected either amount or overall_fee in estimate_fee response');
}
const suggestedMaxFee = estimatedFeeToMaxFee(fee);

return {
...fetchedEstimate,
amount: fee,
unit: fetchedEstimate.unit,
suggestedMaxFee,
};
}
Expand Down
5 changes: 3 additions & 2 deletions src/types/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import BN from 'bn.js';

import { BlockIdentifier } from '../provider/utils';
import { BigNumberish } from '../utils/number';
import { EstimateFeeResponse } from './api';

export interface EstimateFee extends EstimateFeeResponse {
export interface EstimateFee {
amount: BN;
unit: string;
suggestedMaxFee: BN;
}

Expand Down
6 changes: 5 additions & 1 deletion src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,13 @@ export type TransactionReceiptResponse =
| SuccessfulTransactionReceiptResponse
| FailedTransactionReceiptResponse;

// Support 0.9.1 changes in a backward-compatible way
export type EstimateFeeResponse = {
amount: BN;
overall_fee?: BN;
amount?: BN;
unit: string;
gas_price?: BN;
gas_usage?: BigNumberish;
};

export type RawArgs = {
Expand Down

0 comments on commit 9302aab

Please sign in to comment.