1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00

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
This commit is contained in:
VSaric 2021-11-05 15:52:03 +01:00 committed by GitHub
parent 6d786a7bbf
commit 65984291b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 12 deletions

View File

@ -51,7 +51,7 @@ describe('TransactionBreakdown', () => {
['Amount', '-0.01 ETH'], ['Amount', '-0.01 ETH'],
['Gas Limit (units)', '46890'], ['Gas Limit (units)', '46890'],
['Gas price', '2.467043803'], ['Gas price', '2.467043803'],
['Total', '0.010116ETH'], ['Total', '0.01011568ETH'],
]); ]);
}); });
}); });
@ -90,7 +90,7 @@ describe('TransactionBreakdown', () => {
['Priority Fee (GWEI)', '2.467043796'], ['Priority Fee (GWEI)', '2.467043796'],
['Total Gas Fee', '0.000077ETH'], ['Total Gas Fee', '0.000077ETH'],
['Max Fee Per Gas', '0.000000003ETH'], ['Max Fee Per Gas', '0.000000003ETH'],
['Total', '0.010077ETH'], ['Total', '0.01007712ETH'],
]); ]);
}); });
}); });

View File

@ -69,7 +69,7 @@ export default class CurrencyInput extends PureComponent {
: getValueFromWeiHex({ : getValueFromWeiHex({
value: hexValue, value: hexValue,
toCurrency: ETH, toCurrency: ETH,
numberOfDecimals: 6, numberOfDecimals: 8,
}); });
return Number(decimalValueString) || 0; return Number(decimalValueString) || 0;
@ -134,7 +134,7 @@ export default class CurrencyInput extends PureComponent {
if (this.shouldUseFiat()) { if (this.shouldUseFiat()) {
// Display ETH // Display ETH
currency = nativeCurrency || ETH; currency = nativeCurrency || ETH;
numberOfDecimals = 6; numberOfDecimals = 8;
} else { } else {
// Display Fiat // Display Fiat
currency = currentCurrency; currency = currentCurrency;

View File

@ -120,7 +120,7 @@ describe('CurrencyInput Component', () => {
expect(wrapper.find('.unit-input__suffix').text()).toStrictEqual('USD'); expect(wrapper.find('.unit-input__suffix').text()).toStrictEqual('USD');
expect(wrapper.find('.unit-input__input').props().value).toStrictEqual(1); expect(wrapper.find('.unit-input__input').props().value).toStrictEqual(1);
expect(wrapper.find('.currency-display-component').text()).toStrictEqual( expect(wrapper.find('.currency-display-component').text()).toStrictEqual(
'0.004328ETH', '0.00432788ETH',
); );
}); });
@ -159,14 +159,16 @@ describe('CurrencyInput Component', () => {
.find(CurrencyInput) .find(CurrencyInput)
.at(0) .at(0)
.instance(); .instance();
expect(currencyInputInstance.state.decimalValue).toStrictEqual(0.004328); expect(currencyInputInstance.state.decimalValue).toStrictEqual(
0.00432788,
);
expect(currencyInputInstance.state.hexValue).toStrictEqual( expect(currencyInputInstance.state.hexValue).toStrictEqual(
'f602f2234d0ea', 'f602f2234d0ea',
); );
expect(wrapper.find('.unit-input__suffix')).toHaveLength(1); expect(wrapper.find('.unit-input__suffix')).toHaveLength(1);
expect(wrapper.find('.unit-input__suffix').text()).toStrictEqual('ETH'); expect(wrapper.find('.unit-input__suffix').text()).toStrictEqual('ETH');
expect(wrapper.find('.unit-input__input').props().value).toStrictEqual( expect(wrapper.find('.unit-input__input').props().value).toStrictEqual(
0.004328, 0.00432788,
); );
expect( expect(
wrapper.find('.currency-input__conversion-component').text(), wrapper.find('.currency-input__conversion-component').text(),
@ -274,7 +276,7 @@ describe('CurrencyInput Component', () => {
expect(handleChangeSpy.callCount).toStrictEqual(1); expect(handleChangeSpy.callCount).toStrictEqual(1);
expect(handleChangeSpy.calledWith('f602f2234d0ea')).toStrictEqual(true); expect(handleChangeSpy.calledWith('f602f2234d0ea')).toStrictEqual(true);
expect(wrapper.find('.currency-display-component').text()).toStrictEqual( expect(wrapper.find('.currency-display-component').text()).toStrictEqual(
'0.004328ETH', '0.00432788ETH',
); );
expect(currencyInputInstance.state.decimalValue).toStrictEqual(1); expect(currencyInputInstance.state.decimalValue).toStrictEqual(1);
expect(currencyInputInstance.state.hexValue).toStrictEqual( expect(currencyInputInstance.state.hexValue).toStrictEqual(
@ -375,7 +377,7 @@ describe('CurrencyInput Component', () => {
const swap = wrapper.find('.currency-input__swap-component'); const swap = wrapper.find('.currency-input__swap-component');
swap.simulate('click'); swap.simulate('click');
expect(wrapper.find('.currency-display-component').text()).toStrictEqual( expect(wrapper.find('.currency-display-component').text()).toStrictEqual(
'0.004328ETH', '0.00432788ETH',
); );
}); });
}); });

View File

@ -49,7 +49,7 @@ export function useUserPreferencedCurrency(type, opts = {}) {
) { ) {
// Display ETH // Display ETH
currency = nativeCurrency || ETH; currency = nativeCurrency || ETH;
numberOfDecimals = opts.numberOfDecimals || opts.ethNumberOfDecimals || 6; numberOfDecimals = opts.numberOfDecimals || opts.ethNumberOfDecimals || 8;
} else if ( } else if (
(type === SECONDARY && useNativeCurrencyAsPrimaryCurrency) || (type === SECONDARY && useNativeCurrencyAsPrimaryCurrency) ||
(type === PRIMARY && !useNativeCurrencyAsPrimaryCurrency) (type === PRIMARY && !useNativeCurrencyAsPrimaryCurrency)

View File

@ -20,7 +20,7 @@ const tests = [
}, },
result: { result: {
currency: 'ETH', currency: 'ETH',
numberOfDecimals: 6, numberOfDecimals: 8,
}, },
}, },
{ {
@ -82,7 +82,7 @@ const tests = [
}, },
result: { result: {
currency: 'ETH', currency: 'ETH',
numberOfDecimals: 6, numberOfDecimals: 8,
}, },
}, },
{ {