From ec86ad9465087fd310d6de9f19310c85dc614c73 Mon Sep 17 00:00:00 2001 From: Emmanuel Date: Fri, 25 Feb 2022 10:16:17 -0300 Subject: [PATCH] move extra field parsers to the correct file --- src/families/filecoin/account.ts | 44 ++++++++++++++++++++++++++++ src/families/filecoin/transaction.ts | 36 ----------------------- src/generated/account.ts | 3 ++ 3 files changed, 47 insertions(+), 36 deletions(-) create mode 100644 src/families/filecoin/account.ts diff --git a/src/families/filecoin/account.ts b/src/families/filecoin/account.ts new file mode 100644 index 0000000000..4397d7c064 --- /dev/null +++ b/src/families/filecoin/account.ts @@ -0,0 +1,44 @@ +import BigNumber from "bignumber.js"; + +export function fromOperationExtraRaw( + extra: Record | null | undefined +): Record | 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 | null | undefined +): Record | 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, +}; diff --git a/src/families/filecoin/transaction.ts b/src/families/filecoin/transaction.ts index 3c4f578f6c..e0d81b2b85 100644 --- a/src/families/filecoin/transaction.ts +++ b/src/families/filecoin/transaction.ts @@ -56,44 +56,8 @@ const toTransactionRaw = (t: Transaction): TransactionRaw => { }; }; -export function fromOperationExtraRaw( - extra: Record | null | undefined -): Record | 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 | null | undefined -): Record | 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, }; diff --git a/src/generated/account.ts b/src/generated/account.ts index ece6073d38..e4f6314b1a 100644 --- a/src/generated/account.ts +++ b/src/generated/account.ts @@ -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"; @@ -17,5 +19,6 @@ export default { cosmos, crypto_org, elrond, + filecoin, polkadot, };