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

Merge remote-tracking branch 'origin/master' into Version-v10.7.0-updated

This commit is contained in:
Dan Miller 2021-11-26 15:15:41 -03:30
commit 0631403c46
8 changed files with 118 additions and 27 deletions

View File

@ -20,6 +20,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#12727](https://github.com/MetaMask/metamask-extension/pull/12727): Make toggle buttons keyboard accessible - [#12727](https://github.com/MetaMask/metamask-extension/pull/12727): Make toggle buttons keyboard accessible
- [#12729](https://github.com/MetaMask/metamask-extension/pull/12729): Swaps: Fix issue with wrapping and unwrapping when an address contains uppercase characters - [#12729](https://github.com/MetaMask/metamask-extension/pull/12729): Swaps: Fix issue with wrapping and unwrapping when an address contains uppercase characters
- [#12631](https://github.com/MetaMask/metamask-extension/pull/12631): Fix bug preventing sending high precision decimal amounts of tokens in the send flow - [#12631](https://github.com/MetaMask/metamask-extension/pull/12631): Fix bug preventing sending high precision decimal amounts of tokens in the send flow
## [10.6.4]
### Changed
- [#12752](https://github.com/MetaMask/metamask-extension/pull/12752): Update link, in the add network flow, to the article with information about network security risks
## [10.6.3]
### Fixed
- [##12822](https://github.com/MetaMask/metamask-extension/pull/#12822): Fix `replaceChildren` and `function.prototype.apply` errors that could make the app unusable on older browsers due to a bug in our logo component.
- [#61e0526d5](https://github.com/MetaMask/metamask-extension/pull/61e0526d5): Fix requesting of swaps quotes for token pairs that have highly precise exchange rates.
- [##12773](https://github.com/MetaMask/metamask-extension/pull/#12773): Prevent token input in send flow from adding arbitary trailing decimal values to input
## [10.6.2] ## [10.6.2]
### Fixed ### Fixed
@ -2620,6 +2629,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v10.7.0...HEAD [Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v10.7.0...HEAD
[10.7.0]: https://github.com/MetaMask/metamask-extension/compare/v10.6.2...v10.7.0 [10.7.0]: https://github.com/MetaMask/metamask-extension/compare/v10.6.2...v10.7.0
[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v10.6.4...HEAD
[10.6.4]: https://github.com/MetaMask/metamask-extension/compare/v10.6.3...v10.6.4
[10.6.3]: https://github.com/MetaMask/metamask-extension/compare/v10.6.2...v10.6.3
[10.6.2]: https://github.com/MetaMask/metamask-extension/compare/v10.6.1...v10.6.2 [10.6.2]: https://github.com/MetaMask/metamask-extension/compare/v10.6.1...v10.6.2
[10.6.1]: https://github.com/MetaMask/metamask-extension/compare/v10.6.0...v10.6.1 [10.6.1]: https://github.com/MetaMask/metamask-extension/compare/v10.6.0...v10.6.1
[10.6.0]: https://github.com/MetaMask/metamask-extension/compare/v10.5.2...v10.6.0 [10.6.0]: https://github.com/MetaMask/metamask-extension/compare/v10.5.2...v10.6.0

View File

@ -746,7 +746,7 @@ export default class SwapsController {
const conversionRateForSorting = tokenConversionRate || 1; const conversionRateForSorting = tokenConversionRate || 1;
const ethValueOfTokens = decimalAdjustedDestinationAmount.times( const ethValueOfTokens = decimalAdjustedDestinationAmount.times(
conversionRateForSorting, conversionRateForSorting.toString(10),
10, 10,
); );
@ -768,7 +768,7 @@ export default class SwapsController {
quote.ethValueOfTokens = ethValueOfTokens.toString(10); quote.ethValueOfTokens = ethValueOfTokens.toString(10);
quote.overallValueOfQuote = overallValueOfQuoteForSorting.toString(10); quote.overallValueOfQuote = overallValueOfQuoteForSorting.toString(10);
quote.metaMaskFeeInEth = metaMaskFeeInTokens quote.metaMaskFeeInEth = metaMaskFeeInTokens
.times(conversionRateForCalculations) .times(conversionRateForCalculations.toString(10))
.toString(10); .toString(10);
} }

View File

@ -113,7 +113,7 @@
"@metamask/eth-token-tracker": "^3.0.1", "@metamask/eth-token-tracker": "^3.0.1",
"@metamask/etherscan-link": "^2.1.0", "@metamask/etherscan-link": "^2.1.0",
"@metamask/jazzicon": "^2.0.0", "@metamask/jazzicon": "^2.0.0",
"@metamask/logo": "^3.1.0", "@metamask/logo": "^3.1.1",
"@metamask/obs-store": "^5.0.0", "@metamask/obs-store": "^5.0.0",
"@metamask/post-message-stream": "^4.0.0", "@metamask/post-message-stream": "^4.0.0",
"@metamask/providers": "^8.1.1", "@metamask/providers": "^8.1.1",

View File

@ -359,6 +359,8 @@ class Driver {
const ignoredErrorMessages = [ const ignoredErrorMessages = [
// Third-party Favicon 404s show up as errors // Third-party Favicon 404s show up as errors
'favicon.ico - Failed to load resource: the server responded with a status of 404 (Not Found)', 'favicon.ico - Failed to load resource: the server responded with a status of 404 (Not Found)',
// Sentry rate limiting
'Failed to load resource: the server responded with a status of 429',
]; ];
const browserLogs = await this.driver.manage().logs().get('browser'); const browserLogs = await this.driver.manage().logs().get('browser');
const errorEntries = browserLogs.filter( const errorEntries = browserLogs.filter(

View File

@ -1,5 +1,6 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import BigNumber from 'bignumber.js';
import UnitInput from '../unit-input'; import UnitInput from '../unit-input';
import CurrencyDisplay from '../currency-display'; import CurrencyDisplay from '../currency-display';
import { getWeiHexFromDecimalValue } from '../../../helpers/utils/conversions.util'; import { getWeiHexFromDecimalValue } from '../../../helpers/utils/conversions.util';
@ -7,6 +8,7 @@ import {
conversionUtil, conversionUtil,
multiplyCurrencies, multiplyCurrencies,
} from '../../../../shared/modules/conversion.utils'; } from '../../../../shared/modules/conversion.utils';
import { ETH } from '../../../helpers/constants/common'; import { ETH } from '../../../helpers/constants/common';
import { addHexPrefix } from '../../../../app/scripts/lib/util'; import { addHexPrefix } from '../../../../app/scripts/lib/util';
@ -80,8 +82,8 @@ export default class TokenInput extends PureComponent {
let newDecimalValue = decimalValue; let newDecimalValue = decimalValue;
if (decimals && applyDecimals) { if (decimals && decimalValue && applyDecimals) {
newDecimalValue = parseFloat(decimalValue).toFixed(decimals); newDecimalValue = new BigNumber(decimalValue, 10).toFixed(decimals);
} }
const multiplier = Math.pow(10, Number(decimals || 0)); const multiplier = Math.pow(10, Number(decimals || 0));

View File

@ -1,7 +1,6 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { shallow, mount } from 'enzyme'; import { shallow, mount } from 'enzyme';
import sinon from 'sinon';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import configureMockStore from 'redux-mock-store'; import configureMockStore from 'redux-mock-store';
import UnitInput from '../unit-input'; import UnitInput from '../unit-input';
@ -207,12 +206,10 @@ describe('TokenInput Component', () => {
}); });
describe('handling actions', () => { describe('handling actions', () => {
const handleChangeSpy = sinon.spy(); const handleChangeSpy = jest.fn();
const handleBlurSpy = sinon.spy();
afterEach(() => { afterEach(() => {
handleChangeSpy.resetHistory(); handleChangeSpy.mockClear();
handleBlurSpy.resetHistory();
}); });
it('should call onChange on input changes with the hex value for ETH', () => { it('should call onChange on input changes with the hex value for ETH', () => {
@ -238,8 +235,7 @@ describe('TokenInput Component', () => {
); );
expect(wrapper).toHaveLength(1); expect(wrapper).toHaveLength(1);
expect(handleChangeSpy.callCount).toStrictEqual(0); expect(handleChangeSpy.mock.calls).toHaveLength(0);
expect(handleBlurSpy.callCount).toStrictEqual(0);
const tokenInputInstance = wrapper.find(TokenInput).at(0).instance(); const tokenInputInstance = wrapper.find(TokenInput).at(0).instance();
expect(tokenInputInstance.state.decimalValue).toStrictEqual(0); expect(tokenInputInstance.state.decimalValue).toStrictEqual(0);
@ -250,13 +246,13 @@ describe('TokenInput Component', () => {
const input = wrapper.find('input'); const input = wrapper.find('input');
expect(input.props().value).toStrictEqual(0); expect(input.props().value).toStrictEqual(0);
input.simulate('change', { target: { value: 1 } }); input.simulate('change', { target: { value: '1' } });
expect(handleChangeSpy.callCount).toStrictEqual(1); expect(handleChangeSpy.mock.calls).toHaveLength(1);
expect(handleChangeSpy.calledWith('2710')).toStrictEqual(true); expect(handleChangeSpy.mock.calls[0][0]).toStrictEqual('2710');
expect(wrapper.find('.currency-display-component').text()).toStrictEqual( expect(wrapper.find('.currency-display-component').text()).toStrictEqual(
'2ETH', '2ETH',
); );
expect(tokenInputInstance.state.decimalValue).toStrictEqual(1); expect(tokenInputInstance.state.decimalValue).toStrictEqual('1');
expect(tokenInputInstance.state.hexValue).toStrictEqual('2710'); expect(tokenInputInstance.state.hexValue).toStrictEqual('2710');
}); });
@ -285,8 +281,7 @@ describe('TokenInput Component', () => {
); );
expect(wrapper).toHaveLength(1); expect(wrapper).toHaveLength(1);
expect(handleChangeSpy.callCount).toStrictEqual(0); expect(handleChangeSpy.mock.calls).toHaveLength(0);
expect(handleBlurSpy.callCount).toStrictEqual(0);
const tokenInputInstance = wrapper.find(TokenInput).at(0).instance(); const tokenInputInstance = wrapper.find(TokenInput).at(0).instance();
expect(tokenInputInstance.state.decimalValue).toStrictEqual(0); expect(tokenInputInstance.state.decimalValue).toStrictEqual(0);
@ -297,13 +292,13 @@ describe('TokenInput Component', () => {
const input = wrapper.find('input'); const input = wrapper.find('input');
expect(input.props().value).toStrictEqual(0); expect(input.props().value).toStrictEqual(0);
input.simulate('change', { target: { value: 1 } }); input.simulate('change', { target: { value: '1' } });
expect(handleChangeSpy.callCount).toStrictEqual(1); expect(handleChangeSpy.mock.calls).toHaveLength(1);
expect(handleChangeSpy.calledWith('2710')).toStrictEqual(true); expect(handleChangeSpy.mock.calls[0][0]).toStrictEqual('2710');
expect(wrapper.find('.currency-display-component').text()).toStrictEqual( expect(wrapper.find('.currency-display-component').text()).toStrictEqual(
'$462.12USD', '$462.12USD',
); );
expect(tokenInputInstance.state.decimalValue).toStrictEqual(1); expect(tokenInputInstance.state.decimalValue).toStrictEqual('1');
expect(tokenInputInstance.state.hexValue).toStrictEqual('2710'); expect(tokenInputInstance.state.hexValue).toStrictEqual('2710');
}); });
@ -345,4 +340,84 @@ describe('TokenInput Component', () => {
); );
}); });
}); });
describe('Token Input Decimals Check', () => {
const handleChangeSpy = jest.fn();
afterEach(() => {
handleChangeSpy.mockClear();
});
it('should render incorrect hex onChange when input decimals is more than token decimals', () => {
const mockStore = {
metamask: {
currentCurrency: 'usd',
conversionRate: 231.06,
},
};
const store = configureMockStore()(mockStore);
const wrapper = mount(
<Provider store={store}>
<TokenInput
onChange={handleChangeSpy}
token={{
address: '0x1',
decimals: 4,
symbol: 'ABC',
}}
tokenExchangeRates={{ '0x1': 2 }}
showFiat
currentCurrency="usd"
/>
</Provider>,
);
expect(wrapper).toHaveLength(1);
expect(handleChangeSpy.mock.calls).toHaveLength(0);
const input = wrapper.find('input');
expect(input.props().value).toStrictEqual(0);
input.simulate('change', { target: { value: '1.11111' } });
expect(handleChangeSpy.mock.calls).toHaveLength(1);
expect(handleChangeSpy.mock.calls[0][0]).toStrictEqual(
'2b67.1999999999999999999a',
);
});
it('should render correct hex onChange when input decimals is more than token decimals by omitting excess fractional part on blur', () => {
const mockStore = {
metamask: {
currentCurrency: 'usd',
conversionRate: 231.06,
},
};
const store = configureMockStore()(mockStore);
const wrapper = mount(
<Provider store={store}>
<TokenInput
onChange={handleChangeSpy}
token={{
address: '0x1',
decimals: 4,
symbol: 'ABC',
}}
tokenExchangeRates={{ '0x1': 2 }}
showFiat
currentCurrency="usd"
/>
</Provider>,
);
expect(wrapper).toHaveLength(1);
const input = wrapper.find('input');
input.simulate('blur', { target: { value: '1.11111' } });
expect(handleChangeSpy.mock.calls).toHaveLength(1);
expect(handleChangeSpy.mock.calls[0][0]).toStrictEqual('2b67');
});
});
}); });

View File

@ -153,7 +153,7 @@ function getValues(pendingApproval, t, actions) {
key: 'addEthereumChainConfirmationRisksLearnMoreLink', key: 'addEthereumChainConfirmationRisksLearnMoreLink',
props: { props: {
href: href:
'https://metamask.zendesk.com/hc/en-us/articles/360056196151', 'https://metamask.zendesk.com/hc/en-us/articles/4404424659995',
target: '__blank', target: '__blank',
}, },
}, },

View File

@ -4314,10 +4314,10 @@
color "^0.11.3" color "^0.11.3"
mersenne-twister "^1.1.0" mersenne-twister "^1.1.0"
"@metamask/logo@^3.1.0": "@metamask/logo@^3.1.1":
version "3.1.0" version "3.1.1"
resolved "https://registry.yarnpkg.com/@metamask/logo/-/logo-3.1.0.tgz#6b7b9b90b6d846583558de855511d34796735855" resolved "https://registry.yarnpkg.com/@metamask/logo/-/logo-3.1.1.tgz#0a40bcfc462a70aa2110efc737767ca7ba188fa3"
integrity sha512-W0FBwIaG1pC4Vk/ZdUJYv7PDjnAbQJro3yhEXN7WXEdz8kyVcxFb6dj0Dpe6ytaveYiqIL6+iDDWMevzU2MpVw== integrity sha512-8/ObOWyBtwbe3/r9QbXMs+aKK2EgcYp2NiF4fm1xIO/c3aBMN5wBc2zUnl1lpHU71l70/OH5cxHbyDYoEgdMoA==
dependencies: dependencies:
gl-mat4 "1.1.4" gl-mat4 "1.1.4"
gl-vec3 "1.0.3" gl-vec3 "1.0.3"