Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
move extra field parsers to the correct file
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelm41 committed Feb 25, 2022
1 parent e21a278 commit ec86ad9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 36 deletions.
44 changes: 44 additions & 0 deletions src/families/filecoin/account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import BigNumber from "bignumber.js";

export function fromOperationExtraRaw(
extra: Record<string, any> | null | undefined
): Record<string, any> | null | undefined {
if (!extra) return extra;

const { gasLimit, gasPremium, gasFeeCap } = extra;

if (gasLimit !== undefined)
extra = { ...extra, gasLimit: new BigNumber(gasLimit) };

if (gasPremium !== undefined)
extra = { ...extra, gasPremium: new BigNumber(gasPremium) };

if (gasFeeCap !== undefined)
extra = { ...extra, gasFeeCap: new BigNumber(gasFeeCap) };

return extra;
}

export function toOperationExtraRaw(
extra: Record<string, any> | null | undefined
): Record<string, any> | null | undefined {
if (!extra) return extra;

const { gasLimit, gasPremium, gasFeeCap } = extra;

if (gasLimit !== undefined)
extra = { ...extra, gasLimit: gasLimit.toNumber() };

if (gasPremium !== undefined)
extra = { ...extra, gasPremium: gasPremium.toFixed() };

if (gasFeeCap !== undefined)
extra = { ...extra, gasFeeCap: gasFeeCap.toFixed() };

return extra;
}

export default {
fromOperationExtraRaw,
toOperationExtraRaw,
};
36 changes: 0 additions & 36 deletions src/families/filecoin/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,44 +56,8 @@ const toTransactionRaw = (t: Transaction): TransactionRaw => {
};
};

export function fromOperationExtraRaw(
extra: Record<string, any> | null | undefined
): Record<string, any> | null | undefined {
if (extra) {
const newExtra = { ...extra };
const { gasLimit, gasPremium, gasFeeCap } = extra;

if (gasLimit !== undefined) newExtra.gasLimit = new BigNumber(gasLimit);
if (gasPremium !== undefined)
newExtra.gasPremium = new BigNumber(gasPremium);
if (gasFeeCap !== undefined) newExtra.gasFeeCap = new BigNumber(gasFeeCap);

return newExtra;
}

return extra;
}
export function toOperationExtraRaw(
extra: Record<string, any> | null | undefined
): Record<string, any> | null | undefined {
if (extra) {
const newExtra = { ...extra };
const { gasLimit, gasPremium, gasFeeCap } = extra;

if (gasLimit !== undefined) newExtra.gasLimit = gasLimit.toNumber();
if (gasPremium !== undefined) newExtra.gasPremium = gasPremium.toFixed();
if (gasFeeCap !== undefined) newExtra.gasFeeCap = gasFeeCap.toFixed();

return newExtra;
}

return extra;
}

export default {
formatTransaction,
fromTransactionRaw,
toTransactionRaw,
fromOperationExtraRaw,
toOperationExtraRaw,
};
3 changes: 3 additions & 0 deletions src/generated/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import crypto_org from "../families/crypto_org/account";

import elrond from "../families/elrond/account";

import filecoin from "../families/filecoin/account";

import polkadot from "../families/polkadot/account";


Expand All @@ -17,5 +19,6 @@ export default {
cosmos,
crypto_org,
elrond,
filecoin,
polkadot,
};

0 comments on commit ec86ad9

Please sign in to comment.