Skip to content

Commit

Permalink
Allow custom network fiat values (#2863)
Browse files Browse the repository at this point in the history
  • Loading branch information
wachunei authored Jul 26, 2021
1 parent 89e2d41 commit 72d6904
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 39 deletions.
3 changes: 1 addition & 2 deletions app/components/UI/AccountOverview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import Device from '../../../util/Device';
import { ANALYTICS_EVENT_OPTS } from '../../../util/analytics';
import { renderFiat } from '../../../util/number';
import { renderAccountName } from '../../../util/address';
import { isMainNet } from '../../../util/networks';
import { getEther } from '../../../util/transactions';
import { isSwapsAllowed } from '../Swaps/utils';

Expand Down Expand Up @@ -336,7 +335,7 @@ class AccountOverview extends PureComponent {
</TouchableOpacity>
)}
</View>
{isMainNet(chainId) && <Text style={styles.amountFiat}>{fiatBalance}</Text>}
<Text style={styles.amountFiat}>{fiatBalance}</Text>
<TouchableOpacity style={styles.addressWrapper} onPress={this.copyAccountToClipboard}>
<EthereumAddress address={address} style={styles.address} type={'short'} />
</TouchableOpacity>
Expand Down
9 changes: 2 additions & 7 deletions app/components/UI/AssetOverview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { toggleReceiveModal } from '../../../actions/modals';
import { connect } from 'react-redux';
import { renderFromTokenMinimalUnit, balanceToFiat, renderFromWei, weiToFiat, hexToBN } from '../../../util/number';
import { safeToChecksumAddress } from '../../../util/address';
import { isMainNet } from '../../../util/networks';
import { getEther } from '../../../util/transactions';
import { newAssetTransaction } from '../../../actions/transaction';
import { isSwapsAllowed } from '../Swaps/utils';
Expand Down Expand Up @@ -256,16 +255,12 @@ class AssetOverview extends PureComponent {
let balance, balanceFiat;
if (isETH) {
balance = renderFromWei(accounts[selectedAddress] && accounts[selectedAddress].balance);
balanceFiat = isMainNet(chainId)
? weiToFiat(hexToBN(accounts[selectedAddress].balance), conversionRate, currentCurrency)
: null;
balanceFiat = weiToFiat(hexToBN(accounts[selectedAddress].balance), conversionRate, currentCurrency);
} else {
const exchangeRate = itemAddress in tokenExchangeRates ? tokenExchangeRates[itemAddress] : undefined;
balance =
itemAddress in tokenBalances ? renderFromTokenMinimalUnit(tokenBalances[itemAddress], decimals) : 0;
balanceFiat = isMainNet(chainId)
? balanceToFiat(balance, conversionRate, exchangeRate, currentCurrency)
: null;
balanceFiat = balanceToFiat(balance, conversionRate, exchangeRate, currentCurrency);
}
// choose balances depending on 'primaryCurrency'
if (primaryCurrency === 'ETH') {
Expand Down
10 changes: 2 additions & 8 deletions app/components/UI/DrawerView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Icon from 'react-native-vector-icons/FontAwesome';
import FeatherIcon from 'react-native-vector-icons/Feather';
import MaterialIcon from 'react-native-vector-icons/MaterialCommunityIcons';
import { colors, fontStyles } from '../../../styles/common';
import { hasBlockExplorer, findBlockExplorerForRpc, getBlockExplorerName, isMainNet } from '../../../util/networks';
import { hasBlockExplorer, findBlockExplorerForRpc, getBlockExplorerName } from '../../../util/networks';
import Identicon from '../Identicon';
import StyledButton from '../StyledButton';
import AccountList from '../AccountList';
Expand Down Expand Up @@ -337,10 +337,6 @@ class DrawerView extends PureComponent {
* Wizard onboarding state
*/
wizard: PropTypes.object,
/**
* Chain Id
*/
chainId: PropTypes.string,
/**
* Current provider ticker
*/
Expand Down Expand Up @@ -849,7 +845,6 @@ class DrawerView extends PureComponent {
selectedAddress,
keyrings,
currentCurrency,
chainId,
ticker,
seedphraseBackedUp
} = this.props;
Expand Down Expand Up @@ -896,7 +891,7 @@ class DrawerView extends PureComponent {
</Text>
<Icon name="caret-down" size={24} style={styles.caretDown} />
</View>
{isMainNet(chainId) && <Text style={styles.accountBalance}>{fiatBalanceStr}</Text>}
<Text style={styles.accountBalance}>{fiatBalanceStr}</Text>
<EthereumAddress
address={account.address}
style={styles.accountAddress}
Expand Down Expand Up @@ -1087,7 +1082,6 @@ const mapStateToProps = state => ({
receiveModalVisible: state.modals.receiveModalVisible,
passwordSet: state.user.passwordSet,
wizard: state.wizard,
chainId: state.engine.backgroundState.NetworkController.provider.chainId,
ticker: state.engine.backgroundState.NetworkController.provider.ticker,
tokens: state.engine.backgroundState.TokensController.tokens,
tokenBalances: state.engine.backgroundState.TokenBalancesController.contractBalances,
Expand Down
14 changes: 2 additions & 12 deletions app/components/UI/Tokens/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { ANALYTICS_EVENT_OPTS } from '../../../util/analytics';
import StyledButton from '../StyledButton';
import { allowedToBuy } from '../FiatOrders';
import NetworkMainAssetLogo from '../NetworkMainAssetLogo';
import { isMainNet } from '../../../util/networks';

const styles = StyleSheet.create({
wrapper: {
Expand Down Expand Up @@ -167,23 +166,14 @@ class Tokens extends PureComponent {
);

renderItem = asset => {
const {
chainId,
conversionRate,
currentCurrency,
tokenBalances,
tokenExchangeRates,
primaryCurrency
} = this.props;
const { conversionRate, currentCurrency, tokenBalances, tokenExchangeRates, primaryCurrency } = this.props;
const itemAddress = safeToChecksumAddress(asset.address);
const logo = asset.logo || ((contractMap[itemAddress] && contractMap[itemAddress].logo) || undefined);
const exchangeRate = itemAddress in tokenExchangeRates ? tokenExchangeRates[itemAddress] : undefined;
const balance =
asset.balance ||
(itemAddress in tokenBalances ? renderFromTokenMinimalUnit(tokenBalances[itemAddress], asset.decimals) : 0);
const balanceFiat = isMainNet(chainId)
? asset.balanceFiat || balanceToFiat(balance, conversionRate, exchangeRate, currentCurrency)
: null;
const balanceFiat = asset.balanceFiat || balanceToFiat(balance, conversionRate, exchangeRate, currentCurrency);
const balanceValue = `${balance} ${asset.symbol}`;

// render balances according to primary currency
Expand Down
9 changes: 2 additions & 7 deletions app/components/Views/SendFlow/Amount/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,6 @@ class Amount extends PureComponent {
renderToken = (token, index) => {
const {
accounts,
chainId,
selectedAddress,
conversionRate,
currentCurrency,
Expand All @@ -794,15 +793,11 @@ class Amount extends PureComponent {
const { address, decimals, symbol } = token;
if (token.isETH) {
balance = renderFromWei(accounts[selectedAddress].balance);
balanceFiat = isMainNet(chainId)
? weiToFiat(hexToBN(accounts[selectedAddress].balance), conversionRate, currentCurrency)
: null;
balanceFiat = weiToFiat(hexToBN(accounts[selectedAddress].balance), conversionRate, currentCurrency);
} else {
balance = renderFromTokenMinimalUnit(contractBalances[address], decimals);
const exchangeRate = contractExchangeRates[address];
balanceFiat = isMainNet(chainId)
? balanceToFiat(balance, conversionRate, exchangeRate, currentCurrency)
: null;
balanceFiat = balanceToFiat(balance, conversionRate, exchangeRate, currentCurrency);
}
return (
<TouchableOpacity
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5810,7 +5810,7 @@ eth-json-rpc-middleware@^6.0.0:
pify "^3.0.0"
safe-event-emitter "^1.0.1"

eth-keyring-controller@^6.1.0, eth-keyring-controller@^6.2.1:
eth-keyring-controller@^6.2.1:
version "6.2.1"
resolved "https://registry.yarnpkg.com/eth-keyring-controller/-/eth-keyring-controller-6.2.1.tgz#61901071fc74059ed37cb5ae93870fdcae6e3781"
integrity sha512-x2gTM1iHp2Kbvdtd9Eslysw0qzVZiqOzpVB3AU/ni2Xiit+rlcv2H80zYKjrEwlfWFDj4YILD3bOqlnEMmRJOA==
Expand All @@ -5832,7 +5832,7 @@ eth-method-registry@1.1.0:
dependencies:
ethjs "^0.3.0"

eth-phishing-detect@^1.1.13, eth-phishing-detect@^1.1.14:
eth-phishing-detect@^1.1.14:
version "1.1.15"
resolved "https://registry.yarnpkg.com/eth-phishing-detect/-/eth-phishing-detect-1.1.15.tgz#c42e1aad6cd1c5eeee41c6bf932dcfd0e523d499"
integrity sha512-RVNSGMVIuO6VZ1Uv4v8dljjj0ephW+APVAU5QL5mBu3VEqfBluPMNb6jw66kxYrIFrSNalnb/pMeDpAA+W3cvg==
Expand Down Expand Up @@ -6034,7 +6034,7 @@ ethereumjs-util@^5.0.0, ethereumjs-util@^5.1.1, ethereumjs-util@^5.1.2, ethereum
rlp "^2.0.0"
safe-buffer "^5.1.1"

ethereumjs-util@^6.0.0, ethereumjs-util@^6.1.0:
ethereumjs-util@^6.0.0:
version "6.2.1"
resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-6.2.1.tgz#fcb4e4dd5ceacb9d2305426ab1a5cd93e3163b69"
integrity sha512-W2Ktez4L01Vexijrm5EB6w7dg4n/TgpoYU4avuT5T3Vmnw/eCRtiBrJfQYS/DCSvDIOLn2k57GcHdeBcgVxAqw==
Expand Down

0 comments on commit 72d6904

Please sign in to comment.