From 65984291b6a4c3d44b73844994c8a214116c1d81 Mon Sep 17 00:00:00 2001 From: VSaric <92527393+VSaric@users.noreply.github.com> Date: Fri, 5 Nov 2021 15:52:03 +0100 Subject: [PATCH] Changed ETH decimal values to have 8 places for sending (#12437) * Changed ETH decimal values to have 8 places for sending * Fixing unit tests * Fixing test-lint --- .../transaction-breakdown.test.js | 4 ++-- .../ui/currency-input/currency-input.component.js | 4 ++-- .../currency-input/currency-input.component.test.js | 12 +++++++----- ui/hooks/useUserPreferencedCurrency.js | 2 +- ui/hooks/useUserPreferencedCurrency.test.js | 4 ++-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/ui/components/app/transaction-breakdown/transaction-breakdown.test.js b/ui/components/app/transaction-breakdown/transaction-breakdown.test.js index 6fec2e3ca..f1f9645eb 100644 --- a/ui/components/app/transaction-breakdown/transaction-breakdown.test.js +++ b/ui/components/app/transaction-breakdown/transaction-breakdown.test.js @@ -51,7 +51,7 @@ describe('TransactionBreakdown', () => { ['Amount', '-0.01 ETH'], ['Gas Limit (units)', '46890'], ['Gas price', '2.467043803'], - ['Total', '0.010116ETH'], + ['Total', '0.01011568ETH'], ]); }); }); @@ -90,7 +90,7 @@ describe('TransactionBreakdown', () => { ['Priority Fee (GWEI)', '2.467043796'], ['Total Gas Fee', '0.000077ETH'], ['Max Fee Per Gas', '0.000000003ETH'], - ['Total', '0.010077ETH'], + ['Total', '0.01007712ETH'], ]); }); }); diff --git a/ui/components/ui/currency-input/currency-input.component.js b/ui/components/ui/currency-input/currency-input.component.js index e953d3090..8c6276f34 100644 --- a/ui/components/ui/currency-input/currency-input.component.js +++ b/ui/components/ui/currency-input/currency-input.component.js @@ -69,7 +69,7 @@ export default class CurrencyInput extends PureComponent { : getValueFromWeiHex({ value: hexValue, toCurrency: ETH, - numberOfDecimals: 6, + numberOfDecimals: 8, }); return Number(decimalValueString) || 0; @@ -134,7 +134,7 @@ export default class CurrencyInput extends PureComponent { if (this.shouldUseFiat()) { // Display ETH currency = nativeCurrency || ETH; - numberOfDecimals = 6; + numberOfDecimals = 8; } else { // Display Fiat currency = currentCurrency; diff --git a/ui/components/ui/currency-input/currency-input.component.test.js b/ui/components/ui/currency-input/currency-input.component.test.js index 7092b73dd..840871cb3 100644 --- a/ui/components/ui/currency-input/currency-input.component.test.js +++ b/ui/components/ui/currency-input/currency-input.component.test.js @@ -120,7 +120,7 @@ describe('CurrencyInput Component', () => { expect(wrapper.find('.unit-input__suffix').text()).toStrictEqual('USD'); expect(wrapper.find('.unit-input__input').props().value).toStrictEqual(1); expect(wrapper.find('.currency-display-component').text()).toStrictEqual( - '0.004328ETH', + '0.00432788ETH', ); }); @@ -159,14 +159,16 @@ describe('CurrencyInput Component', () => { .find(CurrencyInput) .at(0) .instance(); - expect(currencyInputInstance.state.decimalValue).toStrictEqual(0.004328); + expect(currencyInputInstance.state.decimalValue).toStrictEqual( + 0.00432788, + ); expect(currencyInputInstance.state.hexValue).toStrictEqual( 'f602f2234d0ea', ); expect(wrapper.find('.unit-input__suffix')).toHaveLength(1); expect(wrapper.find('.unit-input__suffix').text()).toStrictEqual('ETH'); expect(wrapper.find('.unit-input__input').props().value).toStrictEqual( - 0.004328, + 0.00432788, ); expect( wrapper.find('.currency-input__conversion-component').text(), @@ -274,7 +276,7 @@ describe('CurrencyInput Component', () => { expect(handleChangeSpy.callCount).toStrictEqual(1); expect(handleChangeSpy.calledWith('f602f2234d0ea')).toStrictEqual(true); expect(wrapper.find('.currency-display-component').text()).toStrictEqual( - '0.004328ETH', + '0.00432788ETH', ); expect(currencyInputInstance.state.decimalValue).toStrictEqual(1); expect(currencyInputInstance.state.hexValue).toStrictEqual( @@ -375,7 +377,7 @@ describe('CurrencyInput Component', () => { const swap = wrapper.find('.currency-input__swap-component'); swap.simulate('click'); expect(wrapper.find('.currency-display-component').text()).toStrictEqual( - '0.004328ETH', + '0.00432788ETH', ); }); }); diff --git a/ui/hooks/useUserPreferencedCurrency.js b/ui/hooks/useUserPreferencedCurrency.js index c41195345..a4716e43f 100644 --- a/ui/hooks/useUserPreferencedCurrency.js +++ b/ui/hooks/useUserPreferencedCurrency.js @@ -49,7 +49,7 @@ export function useUserPreferencedCurrency(type, opts = {}) { ) { // Display ETH currency = nativeCurrency || ETH; - numberOfDecimals = opts.numberOfDecimals || opts.ethNumberOfDecimals || 6; + numberOfDecimals = opts.numberOfDecimals || opts.ethNumberOfDecimals || 8; } else if ( (type === SECONDARY && useNativeCurrencyAsPrimaryCurrency) || (type === PRIMARY && !useNativeCurrencyAsPrimaryCurrency) diff --git a/ui/hooks/useUserPreferencedCurrency.test.js b/ui/hooks/useUserPreferencedCurrency.test.js index 62030b7e3..32f987340 100644 --- a/ui/hooks/useUserPreferencedCurrency.test.js +++ b/ui/hooks/useUserPreferencedCurrency.test.js @@ -20,7 +20,7 @@ const tests = [ }, result: { currency: 'ETH', - numberOfDecimals: 6, + numberOfDecimals: 8, }, }, { @@ -82,7 +82,7 @@ const tests = [ }, result: { currency: 'ETH', - numberOfDecimals: 6, + numberOfDecimals: 8, }, }, {