mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix currency conversion rate (#14713)
This commit is contained in:
parent
f6576801d4
commit
623fd91d65
@ -11,6 +11,7 @@ import {
|
|||||||
|
|
||||||
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';
|
||||||
|
import { isEqualCaseInsensitive } from '../../../../shared/modules/string-utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component that allows user to enter token values as a number, and props receive a converted
|
* Component that allows user to enter token values as a number, and props receive a converted
|
||||||
@ -34,6 +35,7 @@ export default class TokenInput extends PureComponent {
|
|||||||
symbol: PropTypes.string,
|
symbol: PropTypes.string,
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
tokenExchangeRates: PropTypes.object,
|
tokenExchangeRates: PropTypes.object,
|
||||||
|
tokens: PropTypes.array.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -108,10 +110,15 @@ export default class TokenInput extends PureComponent {
|
|||||||
currentCurrency,
|
currentCurrency,
|
||||||
hideConversion,
|
hideConversion,
|
||||||
token,
|
token,
|
||||||
|
tokens,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const { decimalValue } = this.state;
|
const { decimalValue } = this.state;
|
||||||
|
|
||||||
const tokenExchangeRate = tokenExchangeRates?.[token.address] || 0;
|
const existingToken = tokens.find(({ address }) =>
|
||||||
|
isEqualCaseInsensitive(address, token.address),
|
||||||
|
);
|
||||||
|
|
||||||
|
const tokenExchangeRate = tokenExchangeRates?.[existingToken.address] || 0;
|
||||||
let currency, numberOfDecimals;
|
let currency, numberOfDecimals;
|
||||||
|
|
||||||
if (hideConversion) {
|
if (hideConversion) {
|
||||||
|
@ -28,6 +28,15 @@ describe('TokenInput Component', () => {
|
|||||||
decimals: 4,
|
decimals: 4,
|
||||||
symbol: 'ABC',
|
symbol: 'ABC',
|
||||||
}}
|
}}
|
||||||
|
tokens={[
|
||||||
|
{
|
||||||
|
address: '0x1',
|
||||||
|
decimals: 4,
|
||||||
|
symbol: 'ABC',
|
||||||
|
image: null,
|
||||||
|
isERC721: false,
|
||||||
|
},
|
||||||
|
]}
|
||||||
/>
|
/>
|
||||||
</Provider>,
|
</Provider>,
|
||||||
{
|
{
|
||||||
@ -66,6 +75,15 @@ describe('TokenInput Component', () => {
|
|||||||
decimals: 4,
|
decimals: 4,
|
||||||
symbol: 'ABC',
|
symbol: 'ABC',
|
||||||
}}
|
}}
|
||||||
|
tokens={[
|
||||||
|
{
|
||||||
|
address: '0x1',
|
||||||
|
decimals: 4,
|
||||||
|
symbol: 'ABC',
|
||||||
|
image: null,
|
||||||
|
isERC721: false,
|
||||||
|
},
|
||||||
|
]}
|
||||||
tokenExchangeRates={{ '0x1': 2 }}
|
tokenExchangeRates={{ '0x1': 2 }}
|
||||||
/>
|
/>
|
||||||
</Provider>,
|
</Provider>,
|
||||||
@ -101,6 +119,15 @@ describe('TokenInput Component', () => {
|
|||||||
decimals: 4,
|
decimals: 4,
|
||||||
symbol: 'ABC',
|
symbol: 'ABC',
|
||||||
}}
|
}}
|
||||||
|
tokens={[
|
||||||
|
{
|
||||||
|
address: '0x1',
|
||||||
|
decimals: 4,
|
||||||
|
symbol: 'ABC',
|
||||||
|
image: null,
|
||||||
|
isERC721: false,
|
||||||
|
},
|
||||||
|
]}
|
||||||
tokenExchangeRates={{ '0x1': 2 }}
|
tokenExchangeRates={{ '0x1': 2 }}
|
||||||
/>
|
/>
|
||||||
</Provider>,
|
</Provider>,
|
||||||
@ -138,6 +165,15 @@ describe('TokenInput Component', () => {
|
|||||||
decimals: 4,
|
decimals: 4,
|
||||||
symbol: 'ABC',
|
symbol: 'ABC',
|
||||||
}}
|
}}
|
||||||
|
tokens={[
|
||||||
|
{
|
||||||
|
address: '0x1',
|
||||||
|
decimals: 4,
|
||||||
|
symbol: 'ABC',
|
||||||
|
image: null,
|
||||||
|
isERC721: false,
|
||||||
|
},
|
||||||
|
]}
|
||||||
tokenExchangeRates={{ '0x1': 2 }}
|
tokenExchangeRates={{ '0x1': 2 }}
|
||||||
showFiat
|
showFiat
|
||||||
currentCurrency="usd"
|
currentCurrency="usd"
|
||||||
@ -177,6 +213,15 @@ describe('TokenInput Component', () => {
|
|||||||
decimals: 4,
|
decimals: 4,
|
||||||
symbol: 'ABC',
|
symbol: 'ABC',
|
||||||
}}
|
}}
|
||||||
|
tokens={[
|
||||||
|
{
|
||||||
|
address: '0x1',
|
||||||
|
decimals: 4,
|
||||||
|
symbol: 'ABC',
|
||||||
|
image: null,
|
||||||
|
isERC721: false,
|
||||||
|
},
|
||||||
|
]}
|
||||||
tokenExchangeRates={{ '0x1': 2 }}
|
tokenExchangeRates={{ '0x1': 2 }}
|
||||||
showFiat
|
showFiat
|
||||||
hideConversion
|
hideConversion
|
||||||
@ -229,6 +274,15 @@ describe('TokenInput Component', () => {
|
|||||||
decimals: 4,
|
decimals: 4,
|
||||||
symbol: 'ABC',
|
symbol: 'ABC',
|
||||||
}}
|
}}
|
||||||
|
tokens={[
|
||||||
|
{
|
||||||
|
address: '0x1',
|
||||||
|
decimals: 4,
|
||||||
|
symbol: 'ABC',
|
||||||
|
image: null,
|
||||||
|
isERC721: false,
|
||||||
|
},
|
||||||
|
]}
|
||||||
tokenExchangeRates={{ '0x1': 2 }}
|
tokenExchangeRates={{ '0x1': 2 }}
|
||||||
/>
|
/>
|
||||||
</Provider>,
|
</Provider>,
|
||||||
@ -273,6 +327,15 @@ describe('TokenInput Component', () => {
|
|||||||
decimals: 4,
|
decimals: 4,
|
||||||
symbol: 'ABC',
|
symbol: 'ABC',
|
||||||
}}
|
}}
|
||||||
|
tokens={[
|
||||||
|
{
|
||||||
|
address: '0x1',
|
||||||
|
decimals: 4,
|
||||||
|
symbol: 'ABC',
|
||||||
|
image: null,
|
||||||
|
isERC721: false,
|
||||||
|
},
|
||||||
|
]}
|
||||||
tokenExchangeRates={{ '0x1': 2 }}
|
tokenExchangeRates={{ '0x1': 2 }}
|
||||||
showFiat
|
showFiat
|
||||||
currentCurrency="usd"
|
currentCurrency="usd"
|
||||||
@ -319,6 +382,15 @@ describe('TokenInput Component', () => {
|
|||||||
decimals: 4,
|
decimals: 4,
|
||||||
symbol: 'ABC',
|
symbol: 'ABC',
|
||||||
}}
|
}}
|
||||||
|
tokens={[
|
||||||
|
{
|
||||||
|
address: '0x1',
|
||||||
|
decimals: 4,
|
||||||
|
symbol: 'ABC',
|
||||||
|
image: null,
|
||||||
|
isERC721: false,
|
||||||
|
},
|
||||||
|
]}
|
||||||
tokenExchangeRates={{ '0x1': 2 }}
|
tokenExchangeRates={{ '0x1': 2 }}
|
||||||
showFiat
|
showFiat
|
||||||
/>
|
/>
|
||||||
@ -365,6 +437,15 @@ describe('TokenInput Component', () => {
|
|||||||
decimals: 4,
|
decimals: 4,
|
||||||
symbol: 'ABC',
|
symbol: 'ABC',
|
||||||
}}
|
}}
|
||||||
|
tokens={[
|
||||||
|
{
|
||||||
|
address: '0x1',
|
||||||
|
decimals: 4,
|
||||||
|
symbol: 'ABC',
|
||||||
|
image: null,
|
||||||
|
isERC721: false,
|
||||||
|
},
|
||||||
|
]}
|
||||||
tokenExchangeRates={{ '0x1': 2 }}
|
tokenExchangeRates={{ '0x1': 2 }}
|
||||||
showFiat
|
showFiat
|
||||||
currentCurrency="usd"
|
currentCurrency="usd"
|
||||||
@ -404,6 +485,15 @@ describe('TokenInput Component', () => {
|
|||||||
decimals: 4,
|
decimals: 4,
|
||||||
symbol: 'ABC',
|
symbol: 'ABC',
|
||||||
}}
|
}}
|
||||||
|
tokens={[
|
||||||
|
{
|
||||||
|
address: '0x1',
|
||||||
|
decimals: 4,
|
||||||
|
symbol: 'ABC',
|
||||||
|
image: null,
|
||||||
|
isERC721: false,
|
||||||
|
},
|
||||||
|
]}
|
||||||
tokenExchangeRates={{ '0x1': 2 }}
|
tokenExchangeRates={{ '0x1': 2 }}
|
||||||
showFiat
|
showFiat
|
||||||
currentCurrency="usd"
|
currentCurrency="usd"
|
||||||
|
@ -5,13 +5,14 @@ import TokenInput from './token-input.component';
|
|||||||
|
|
||||||
const mapStateToProps = (state) => {
|
const mapStateToProps = (state) => {
|
||||||
const {
|
const {
|
||||||
metamask: { currentCurrency },
|
metamask: { currentCurrency, tokens },
|
||||||
} = state;
|
} = state;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
currentCurrency,
|
currentCurrency,
|
||||||
tokenExchangeRates: getTokenExchangeRates(state),
|
tokenExchangeRates: getTokenExchangeRates(state),
|
||||||
hideConversion: !getShouldShowFiat(state),
|
hideConversion: !getShouldShowFiat(state),
|
||||||
|
tokens,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user