mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Use network provider state, instead of CurrencyRateController state, to select 'nativeCurrency' (#17450)
* Use network provider state, instead of CurrencyRateController state, select 'nativeCurrency' * Fix unit tests * Lint fix * Only use the network provider ticket for the native currency when useCurrencyRateCheck is false * Fix unit test * Fix tests for real
This commit is contained in:
parent
abb2532a3b
commit
7a77c82514
@ -74,7 +74,8 @@
|
|||||||
"network": "5",
|
"network": "5",
|
||||||
"provider": {
|
"provider": {
|
||||||
"type": "rpc",
|
"type": "rpc",
|
||||||
"chainId": "0x5"
|
"chainId": "0x5",
|
||||||
|
"ticker": "ETH"
|
||||||
},
|
},
|
||||||
"keyrings": [
|
"keyrings": [
|
||||||
{
|
{
|
||||||
|
@ -18,6 +18,9 @@ describe('TransactionActivityLog container', () => {
|
|||||||
conversionRate: 280.45,
|
conversionRate: 280.45,
|
||||||
nativeCurrency: 'ETH',
|
nativeCurrency: 'ETH',
|
||||||
frequentRpcListDetail: [],
|
frequentRpcListDetail: [],
|
||||||
|
provider: {
|
||||||
|
ticker: 'ETH',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -43,6 +46,7 @@ describe('TransactionActivityLog container', () => {
|
|||||||
],
|
],
|
||||||
provider: {
|
provider: {
|
||||||
rpcUrl: 'https://customnetwork.com/',
|
rpcUrl: 'https://customnetwork.com/',
|
||||||
|
ticker: 'ETH',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -290,6 +290,9 @@ describe('Confirm Transaction Duck', () => {
|
|||||||
metamask: {
|
metamask: {
|
||||||
conversionRate: 468.58,
|
conversionRate: 468.58,
|
||||||
currentCurrency: 'usd',
|
currentCurrency: 'usd',
|
||||||
|
provider: {
|
||||||
|
ticker: 'ETH',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
confirmTransaction: {
|
confirmTransaction: {
|
||||||
ethTransactionAmount: '1',
|
ethTransactionAmount: '1',
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
accountsWithSendEtherInfoSelector,
|
accountsWithSendEtherInfoSelector,
|
||||||
checkNetworkAndAccountSupports1559,
|
checkNetworkAndAccountSupports1559,
|
||||||
getAddressBook,
|
getAddressBook,
|
||||||
|
getUseCurrencyRateCheck,
|
||||||
} from '../../selectors';
|
} from '../../selectors';
|
||||||
import { updateTransactionGasFees } from '../../store/actions';
|
import { updateTransactionGasFees } from '../../store/actions';
|
||||||
import { setCustomGasLimit, setCustomGasPrice } from '../gas/gas.duck';
|
import { setCustomGasLimit, setCustomGasPrice } from '../gas/gas.duck';
|
||||||
@ -307,7 +308,10 @@ export function getConversionRate(state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getNativeCurrency(state) {
|
export function getNativeCurrency(state) {
|
||||||
return state.metamask.nativeCurrency;
|
const useCurrencyRateCheck = getUseCurrencyRateCheck(state);
|
||||||
|
return useCurrencyRateCheck
|
||||||
|
? state.metamask.nativeCurrency
|
||||||
|
: state.metamask.provider.ticker;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSendHexDataFeatureFlagState(state) {
|
export function getSendHexDataFeatureFlagState(state) {
|
||||||
|
@ -40,10 +40,12 @@ describe('MetaMask Reducers', () => {
|
|||||||
currentBlockGasLimit: '0x4c1878',
|
currentBlockGasLimit: '0x4c1878',
|
||||||
conversionRate: 1200.88200327,
|
conversionRate: 1200.88200327,
|
||||||
nativeCurrency: 'ETH',
|
nativeCurrency: 'ETH',
|
||||||
|
useCurrencyRateCheck: true,
|
||||||
network: '5',
|
network: '5',
|
||||||
provider: {
|
provider: {
|
||||||
type: 'testnet',
|
type: 'testnet',
|
||||||
chainId: '0x5',
|
chainId: '0x5',
|
||||||
|
ticker: 'TestETH',
|
||||||
},
|
},
|
||||||
accounts: {
|
accounts: {
|
||||||
'0xfdea65c8e26263f6d9a1b5de9555d2931a33b825': {
|
'0xfdea65c8e26263f6d9a1b5de9555d2931a33b825': {
|
||||||
@ -308,9 +310,21 @@ describe('MetaMask Reducers', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('getNativeCurrency()', () => {
|
describe('getNativeCurrency()', () => {
|
||||||
it('should return the ticker symbol of the selected network', () => {
|
it('should return nativeCurrency when useCurrencyRateCheck is true', () => {
|
||||||
expect(getNativeCurrency(mockState)).toStrictEqual('ETH');
|
expect(getNativeCurrency(mockState)).toStrictEqual('ETH');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return the ticker symbol of the selected network when useCurrencyRateCheck is false', () => {
|
||||||
|
expect(
|
||||||
|
getNativeCurrency({
|
||||||
|
...mockState,
|
||||||
|
metamask: {
|
||||||
|
...mockState.metamask,
|
||||||
|
useCurrencyRateCheck: false,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).toStrictEqual('TestETH');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getSendHexDataFeatureFlagState()', () => {
|
describe('getSendHexDataFeatureFlagState()', () => {
|
||||||
|
@ -60,9 +60,8 @@ export default function GasDisplay({ gasError }) {
|
|||||||
const useCurrencyRateCheck = useSelector(getUseCurrencyRateCheck);
|
const useCurrencyRateCheck = useSelector(getUseCurrencyRateCheck);
|
||||||
const { showFiatInTestnets, useNativeCurrencyAsPrimaryCurrency } =
|
const { showFiatInTestnets, useNativeCurrencyAsPrimaryCurrency } =
|
||||||
useSelector(getPreferences);
|
useSelector(getPreferences);
|
||||||
const { nativeCurrency, provider, unapprovedTxs } = useSelector(
|
const { provider, unapprovedTxs } = useSelector((state) => state.metamask);
|
||||||
(state) => state.metamask,
|
const nativeCurrency = provider.ticker;
|
||||||
);
|
|
||||||
const { chainId } = provider;
|
const { chainId } = provider;
|
||||||
const networkName = NETWORK_TO_NAME_MAP[chainId];
|
const networkName = NETWORK_TO_NAME_MAP[chainId];
|
||||||
const isInsufficientTokenError =
|
const isInsufficientTokenError =
|
||||||
|
@ -31,10 +31,8 @@ exports[`SendContent Component render should match snapshot 1`] = `
|
|||||||
<div
|
<div
|
||||||
class="send-v2__asset-dropdown__asset-icon"
|
class="send-v2__asset-dropdown__asset-icon"
|
||||||
>
|
>
|
||||||
<img
|
<div
|
||||||
alt=""
|
class="identicon__image-border"
|
||||||
class="identicon"
|
|
||||||
src="./images/eth_logo.svg"
|
|
||||||
style="height: 36px; width: 36px; border-radius: 18px;"
|
style="height: 36px; width: 36px; border-radius: 18px;"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -43,9 +41,7 @@ exports[`SendContent Component render should match snapshot 1`] = `
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
class="send-v2__asset-dropdown__symbol"
|
class="send-v2__asset-dropdown__symbol"
|
||||||
>
|
/>
|
||||||
ETH
|
|
||||||
</div>
|
|
||||||
<div
|
<div
|
||||||
class="send-v2__asset-dropdown__name"
|
class="send-v2__asset-dropdown__name"
|
||||||
>
|
>
|
||||||
|
Loading…
Reference in New Issue
Block a user