From cc5d7a9b662ee7c0cabe6ae8a665e23aa5b5108d Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Tue, 8 Jan 2019 10:40:21 +0100 Subject: [PATCH 1/4] use faster toFixed() --- src/actions/ethereum/SendFormValidationActions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/ethereum/SendFormValidationActions.js b/src/actions/ethereum/SendFormValidationActions.js index 46451fb5..9407c5ce 100644 --- a/src/actions/ethereum/SendFormValidationActions.js +++ b/src/actions/ethereum/SendFormValidationActions.js @@ -347,7 +347,7 @@ export const calculateFee = (gasPrice: string, gasLimit: string): string => { export const calculateTotal = (amount: string, gasPrice: string, gasLimit: string): string => { try { - return new BigNumber(amount).plus(calculateFee(gasPrice, gasLimit)).toString(10); + return new BigNumber(amount).plus(calculateFee(gasPrice, gasLimit)).toFixed(); } catch (error) { return '0'; } From 83abbd9ac3742e3326d81d5a25984164d9a900ed Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Tue, 8 Jan 2019 11:50:30 +0100 Subject: [PATCH 2/4] faster conversion to string for ripple --- src/actions/ripple/SendFormValidationActions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/actions/ripple/SendFormValidationActions.js b/src/actions/ripple/SendFormValidationActions.js index db5131fa..1e529763 100644 --- a/src/actions/ripple/SendFormValidationActions.js +++ b/src/actions/ripple/SendFormValidationActions.js @@ -237,7 +237,7 @@ export const feeValidation = ($state: State): PayloadAction => (dispatch: const calculateTotal = (amount: string, fee: string): string => { try { - return new BigNumber(amount).plus(fee).toString(10); + return new BigNumber(amount).plus(fee).toFixed(); } catch (error) { return '0'; } @@ -248,7 +248,7 @@ const calculateMaxAmount = (balance: BigNumber, fee: string): string => { // TODO - minus pendings const max = balance.minus(fee); if (max.lessThan(0)) return '0'; - return max.toString(10); + return max.toFixed(); } catch (error) { return '0'; } From 8970f90d4573f6247c70d19ee6d58be608e93eca Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Tue, 8 Jan 2019 13:23:46 +0100 Subject: [PATCH 3/4] use toFixed for fees on eth --- src/actions/ethereum/SendFormValidationActions.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/actions/ethereum/SendFormValidationActions.js b/src/actions/ethereum/SendFormValidationActions.js index 9407c5ce..f5283ff6 100644 --- a/src/actions/ethereum/SendFormValidationActions.js +++ b/src/actions/ethereum/SendFormValidationActions.js @@ -115,7 +115,7 @@ export const recalculateTotalAmount = ($state: State): PayloadAction => ( if (isToken) { const token = findToken(tokens, account.descriptor, state.currency, account.deviceState); if (token) { - state.amount = new BigNumber(token.balance).minus(pendingAmount).toString(10); + state.amount = new BigNumber(token.balance).minus(pendingAmount).toFixed(); } } else { const b = new BigNumber(account.balance).minus(pendingAmount); @@ -359,7 +359,7 @@ export const calculateMaxAmount = (balance: BigNumber, gasPrice: string, gasLimi const fee = calculateFee(gasPrice, gasLimit); const max = balance.minus(fee); if (max.lessThan(0)) return '0'; - return max.toString(10); + return max.toFixed(); } catch (error) { return '0'; } @@ -368,8 +368,8 @@ export const calculateMaxAmount = (balance: BigNumber, gasPrice: string, gasLimi export const getFeeLevels = (symbol: string, gasPrice: BigNumber | string, gasLimit: string, selected?: FeeLevel): Array => { const price: BigNumber = typeof gasPrice === 'string' ? new BigNumber(gasPrice) : gasPrice; const quarter: BigNumber = price.dividedBy(4); - const high: string = price.plus(quarter.times(2)).toString(10); - const low: string = price.minus(quarter.times(2)).toString(10); + const high: string = price.plus(quarter.times(2)).toFixed(); + const low: string = price.minus(quarter.times(2)).toFixed(); const customLevel: FeeLevel = selected && selected.value === 'Custom' ? { value: 'Custom', @@ -391,7 +391,7 @@ export const getFeeLevels = (symbol: string, gasPrice: BigNumber | string, gasLi { value: 'Normal', gasPrice: gasPrice.toString(), - label: `${calculateFee(price.toString(10), gasLimit)} ${symbol}`, + label: `${calculateFee(price.toFixed(), gasLimit)} ${symbol}`, }, { value: 'Low', From bbfd3cafce88b10a12f80c65d715956c0bde4f17 Mon Sep 17 00:00:00 2001 From: slowbackspace Date: Tue, 8 Jan 2019 14:04:42 +0100 Subject: [PATCH 4/4] convert normal notation, converting exp notation will fail --- src/actions/ethereum/SendFormValidationActions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/ethereum/SendFormValidationActions.js b/src/actions/ethereum/SendFormValidationActions.js index f5283ff6..16a30c7f 100644 --- a/src/actions/ethereum/SendFormValidationActions.js +++ b/src/actions/ethereum/SendFormValidationActions.js @@ -339,7 +339,7 @@ export const dataValidation = ($state: State): PayloadAction => (): State export const calculateFee = (gasPrice: string, gasLimit: string): string => { try { - return EthereumjsUnits.convert(new BigNumber(gasPrice).times(gasLimit), 'gwei', 'ether'); + return EthereumjsUnits.convert(new BigNumber(gasPrice).times(gasLimit).toFixed(), 'gwei', 'ether'); } catch (error) { return '0'; }