Skip to content

Commit

Permalink
feat: use BigNumber for estimate fee amount
Browse files Browse the repository at this point in the history
  • Loading branch information
janek26 committed May 4, 2022
1 parent 806eb7d commit 751c2ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/provider/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
CompiledContract,
DeployContractPayload,
Endpoints,
EstimateFeeResponse,
GetBlockResponse,
GetCodeResponse,
GetContractAddressesResponse,
Expand Down Expand Up @@ -153,6 +154,17 @@ export class Provider implements ProviderInterface {
try {
const { data } = await axios.request<Endpoints[T]['RESPONSE']>({
method,
transformResponse:
endpoint === 'estimate_fee'
? (res): EstimateFeeResponse => {
return parse(res, (_, v) => {
if (v && typeof v === 'bigint') {
return toBN(v.toString());
}
return v;
});
}
: axios.defaults.transformResponse,
url: urljoin(baseUrl, endpoint, queryString),
data: stringify(request),
headers,
Expand Down
4 changes: 3 additions & 1 deletion src/types/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import BN from 'bn.js';

import { BlockIdentifier } from '../provider/utils';
import { BigNumberish } from '../utils/number';
import {
Expand Down Expand Up @@ -235,7 +237,7 @@ export type TransactionReceiptResponse = {
};

export type EstimateFeeResponse = {
amount: number;
amount: BN;
unit: string;
};

Expand Down

0 comments on commit 751c2ed

Please sign in to comment.