1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00

use native currency in asset row (#10413)

* use native currency in asset row

* set native currency on startup
This commit is contained in:
Brad Decker 2021-02-11 12:20:08 -06:00 committed by GitHub
parent ba9a67fe5a
commit bd1683402a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 8 deletions

View File

@ -335,6 +335,9 @@ export default class MetamaskController extends EventEmitter {
); );
}); });
const { ticker } = this.networkController.getProviderConfig();
this.currencyRateController.update({ nativeCurrency: ticker ?? 'ETH' });
this.networkController.lookupNetwork(); this.networkController.lookupNetwork();
this.messageManager = new MessageManager(); this.messageManager = new MessageManager();
this.personalMessageManager = new PersonalMessageManager(); this.personalMessageManager = new PersonalMessageManager();

View File

@ -5,6 +5,8 @@ export const WEI = 'WEI';
export const PRIMARY = 'PRIMARY'; export const PRIMARY = 'PRIMARY';
export const SECONDARY = 'SECONDARY'; export const SECONDARY = 'SECONDARY';
export const ERC20 = 'ERC20';
export const GAS_ESTIMATE_TYPES = { export const GAS_ESTIMATE_TYPES = {
SLOW: 'SLOW', SLOW: 'SLOW',
AVERAGE: 'AVERAGE', AVERAGE: 'AVERAGE',

View File

@ -4,7 +4,7 @@ import SendRowWrapper from '../send-row-wrapper';
import Identicon from '../../../../components/ui/identicon/identicon.component'; import Identicon from '../../../../components/ui/identicon/identicon.component';
import TokenBalance from '../../../../components/ui/token-balance'; import TokenBalance from '../../../../components/ui/token-balance';
import UserPreferencedCurrencyDisplay from '../../../../components/app/user-preferenced-currency-display'; import UserPreferencedCurrencyDisplay from '../../../../components/app/user-preferenced-currency-display';
import { PRIMARY } from '../../../../helpers/constants/common'; import { ERC20, ETH, PRIMARY } from '../../../../helpers/constants/common';
export default class SendAssetRow extends Component { export default class SendAssetRow extends Component {
static propTypes = { static propTypes = {
@ -19,6 +19,7 @@ export default class SendAssetRow extends Component {
selectedAddress: PropTypes.string.isRequired, selectedAddress: PropTypes.string.isRequired,
sendTokenAddress: PropTypes.string, sendTokenAddress: PropTypes.string,
setSendToken: PropTypes.func.isRequired, setSendToken: PropTypes.func.isRequired,
nativeCurrency: PropTypes.string,
}; };
static contextTypes = { static contextTypes = {
@ -47,7 +48,7 @@ export default class SendAssetRow extends Component {
name: 'User clicks "Assets" dropdown', name: 'User clicks "Assets" dropdown',
}, },
customVariables: { customVariables: {
assetSelected: token ? 'ERC20' : 'ETH', assetSelected: token ? ERC20 : this.props.nativeCurrency,
}, },
}); });
this.props.setSendToken(token); this.props.setSendToken(token);
@ -78,7 +79,7 @@ export default class SendAssetRow extends Component {
className="send-v2__asset-dropdown__input-wrapper" className="send-v2__asset-dropdown__input-wrapper"
onClick={this.openDropdown} onClick={this.openDropdown}
> >
{token ? this.renderAsset(token) : this.renderEth()} {token ? this.renderAsset(token) : this.renderNativeCurrency()}
</div> </div>
); );
} }
@ -92,7 +93,7 @@ export default class SendAssetRow extends Component {
onClick={this.closeDropdown} onClick={this.closeDropdown}
/> />
<div className="send-v2__asset-dropdown__list"> <div className="send-v2__asset-dropdown__list">
{this.renderEth(true)} {this.renderNativeCurrency(true)}
{this.props.tokens.map((token) => this.renderAsset(token, true))} {this.props.tokens.map((token) => this.renderAsset(token, true))}
</div> </div>
</div> </div>
@ -100,9 +101,9 @@ export default class SendAssetRow extends Component {
); );
} }
renderEth(insideDropdown = false) { renderNativeCurrency(insideDropdown = false) {
const { t } = this.context; const { t } = this.context;
const { accounts, selectedAddress } = this.props; const { accounts, selectedAddress, nativeCurrency } = this.props;
const balanceValue = accounts[selectedAddress] const balanceValue = accounts[selectedAddress]
? accounts[selectedAddress].balance ? accounts[selectedAddress].balance
@ -118,10 +119,15 @@ export default class SendAssetRow extends Component {
onClick={() => this.selectToken()} onClick={() => this.selectToken()}
> >
<div className="send-v2__asset-dropdown__asset-icon"> <div className="send-v2__asset-dropdown__asset-icon">
<Identicon diameter={36} /> <Identicon
diameter={36}
address={nativeCurrency === ETH ? undefined : nativeCurrency}
/>
</div> </div>
<div className="send-v2__asset-dropdown__asset-data"> <div className="send-v2__asset-dropdown__asset-data">
<div className="send-v2__asset-dropdown__symbol">ETH</div> <div className="send-v2__asset-dropdown__symbol">
{nativeCurrency}
</div>
<div className="send-v2__asset-dropdown__name"> <div className="send-v2__asset-dropdown__name">
<span className="send-v2__asset-dropdown__name__label"> <span className="send-v2__asset-dropdown__name__label">
{`${t('balance')}:`} {`${t('balance')}:`}

View File

@ -1,6 +1,7 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { import {
getMetaMaskAccounts, getMetaMaskAccounts,
getNativeCurrency,
getSendTokenAddress, getSendTokenAddress,
} from '../../../../selectors'; } from '../../../../selectors';
import { updateSendToken } from '../../../../store/actions'; import { updateSendToken } from '../../../../store/actions';
@ -12,6 +13,7 @@ function mapStateToProps(state) {
selectedAddress: state.metamask.selectedAddress, selectedAddress: state.metamask.selectedAddress,
sendTokenAddress: getSendTokenAddress(state), sendTokenAddress: getSendTokenAddress(state),
accounts: getMetaMaskAccounts(state), accounts: getMetaMaskAccounts(state),
nativeCurrency: getNativeCurrency(state),
}; };
} }