1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 17:33:23 +01:00

Revert "Allow sending up to 15 decimals on the send screen (#12707)" (#13823)

This reverts commit 8597cd1401.
This commit is contained in:
ryanml 2022-03-02 17:28:56 -07:00 committed by GitHub
parent 6e8f4a6a76
commit ce495d7a66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 8 additions and 48 deletions

View File

@ -1,5 +0,0 @@
/**
* MAX_DECIMAL represensts the maximum number of decimal values allow for the input,
* the limitation in javascript <input/> retstricts us to keep it as 15 and below.
*/
export const MAX_DECIMAL = 15;

View File

@ -14,7 +14,6 @@ import {
getNativeCurrency,
} from '../../../ducks/metamask/metamask';
import { getCurrentCurrency, getShouldShowFiat } from '../../../selectors';
import { MAX_DECIMAL } from '../../../../shared/constants/decimal';
/**
* Component that allows user to enter currency values as a number, and props receive a converted
@ -26,14 +25,12 @@ import { MAX_DECIMAL } from '../../../../shared/constants/decimal';
* @param options0.featureSecondary
* @param options0.onChange
* @param options0.onPreferenceToggle
* @param options0.primaryNumberOfDecimals
*/
export default function CurrencyInput({
hexValue,
featureSecondary,
onChange,
onPreferenceToggle,
primaryNumberOfDecimals = 8,
}) {
const t = useContext(I18nContext);
@ -67,10 +64,7 @@ export default function CurrencyInput({
: getValueFromWeiHex({
value: hexValue,
toCurrency: ETH,
numberOfDecimals:
primaryNumberOfDecimals <= MAX_DECIMAL
? primaryNumberOfDecimals
: MAX_DECIMAL,
numberOfDecimals: 8,
});
return Number(decimalValueString) || 0;
@ -133,10 +127,7 @@ export default function CurrencyInput({
if (shouldUseFiat()) {
// Display ETH
currency = preferredCurrency || ETH;
numberOfDecimals =
primaryNumberOfDecimals <= MAX_DECIMAL
? primaryNumberOfDecimals
: MAX_DECIMAL;
numberOfDecimals = 8;
} else {
// Display Fiat
currency = secondaryCurrency;
@ -152,6 +143,7 @@ export default function CurrencyInput({
/>
);
};
return (
<UnitInput
{...{
@ -181,5 +173,4 @@ CurrencyInput.propTypes = {
featureSecondary: PropTypes.bool,
onChange: PropTypes.func,
onPreferenceToggle: PropTypes.func,
primaryNumberOfDecimals: PropTypes.number,
};

View File

@ -6,7 +6,6 @@ import { Provider } from 'react-redux';
import configureMockStore from 'redux-mock-store';
import UnitInput from '../../ui/unit-input';
import CurrencyDisplay from '../../ui/currency-display';
import { MAX_DECIMAL } from '../../../../shared/constants/decimal';
import CurrencyInput from './currency-input';
describe('CurrencyInput Component', () => {
@ -146,11 +145,7 @@ describe('CurrencyInput Component', () => {
const wrapper = mount(
<Provider store={store}>
<CurrencyInput
hexValue="f602f2234d0ea"
featureSecondary
primaryNumberOfDecimals={MAX_DECIMAL}
/>
<CurrencyInput hexValue="f602f2234d0ea" featureSecondary />
</Provider>,
{
context: { t: (str) => `${str}_t` },
@ -162,7 +157,7 @@ describe('CurrencyInput Component', () => {
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.004327880204276,
0.00432788,
);
expect(
wrapper.find('.currency-input__conversion-component').text(),
@ -198,11 +193,7 @@ describe('CurrencyInput Component', () => {
const store = configureMockStore()(mockStore);
const wrapper = mount(
<Provider store={store}>
<CurrencyInput
onChange={handleChangeSpy}
hexValue="f602f2234d0ea"
primaryNumberOfDecimals={MAX_DECIMAL}
/>
<CurrencyInput onChange={handleChangeSpy} hexValue="f602f2234d0ea" />
</Provider>,
);
@ -211,7 +202,7 @@ describe('CurrencyInput Component', () => {
expect(handleBlurSpy.callCount).toStrictEqual(0);
const input = wrapper.find('input');
expect(input.props().value).toStrictEqual(0.004327880204276);
expect(input.props().value).toStrictEqual(0.00432788);
input.simulate('change', { target: { value: 1 } });
expect(handleChangeSpy.callCount).toStrictEqual(2);

View File

@ -11,7 +11,6 @@ import {
import { ETH } from '../../../helpers/constants/common';
import { addHexPrefix } from '../../../../app/scripts/lib/util';
import { MAX_DECIMAL } from '../../../../shared/constants/decimal';
/**
* Component that allows user to enter token values as a number, and props receive a converted
@ -35,7 +34,6 @@ export default class TokenInput extends PureComponent {
symbol: PropTypes.string,
}).isRequired,
tokenExchangeRates: PropTypes.object,
primaryNumberOfDecimals: PropTypes.number,
};
constructor(props) {
@ -110,7 +108,6 @@ export default class TokenInput extends PureComponent {
currentCurrency,
hideConversion,
token,
primaryNumberOfDecimals = 8,
} = this.props;
const { decimalValue } = this.state;
@ -132,10 +129,7 @@ export default class TokenInput extends PureComponent {
} else {
// Display ETH
currency = ETH;
numberOfDecimals =
primaryNumberOfDecimals <= MAX_DECIMAL
? primaryNumberOfDecimals
: MAX_DECIMAL;
numberOfDecimals = 6;
}
const decimalEthValue = decimalValue * tokenExchangeRate || 0;

View File

@ -1,9 +1,6 @@
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { MAX_DECIMAL } from '../../../../shared/constants/decimal';
const DECIMAL_REGEX = /\.(\d*)/u;
function removeLeadingZeroes(str) {
return str.replace(/^0*(?=\d)/u, '');
@ -65,11 +62,6 @@ export default class UnitInput extends PureComponent {
handleChange = (event) => {
const { value: userInput } = event.target;
const match = DECIMAL_REGEX.exec(userInput);
if (match?.[1]?.length > MAX_DECIMAL) {
return;
}
let value = userInput;
if (userInput.length && userInput.length > 1) {

View File

@ -4,7 +4,6 @@ import SendRowWrapper from '../send-row-wrapper';
import UserPreferencedCurrencyInput from '../../../../components/app/user-preferenced-currency-input';
import UserPreferencedTokenInput from '../../../../components/app/user-preferenced-token-input';
import { ASSET_TYPES } from '../../../../ducks/send';
import { MAX_DECIMAL } from '../../../../../shared/constants/decimal';
import AmountMaxButton from './amount-max-button';
export default class SendAmountRow extends Component {
@ -32,14 +31,12 @@ export default class SendAmountRow extends Component {
onChange={this.handleChange}
token={asset.details}
value={amount}
primaryNumberOfDecimals={asset.decimals}
/>
) : (
<UserPreferencedCurrencyInput
error={inError}
onChange={this.handleChange}
hexValue={amount}
primaryNumberOfDecimals={MAX_DECIMAL}
/>
);
}