Fix Conversions bugs; Fiat value bugs

feature/default_network_editable
Chi Kei Chan 7 years ago
parent 5eb3cf43bf
commit 8f3b762461
  1. 4
      ui/app/components/pending-tx/confirm-deploy-contract.js
  2. 2
      ui/app/components/pending-tx/confirm-send-ether.js
  3. 12
      ui/app/components/send/currency-display.js
  4. 8
      ui/app/components/token-cell.js
  5. 7
      ui/app/send-v2.js

@ -195,14 +195,16 @@ ConfirmDeployContract.prototype.getGasFee = function () {
eth: Number(ETH), eth: Number(ETH),
} }
} }
ConfirmDeployContract.prototype.renderGasFee = function () { ConfirmDeployContract.prototype.renderGasFee = function () {
const { currentCurrency } = this.props
const { fiat: fiatGas, eth: ethGas } = this.getGasFee() const { fiat: fiatGas, eth: ethGas } = this.getGasFee()
return ( return (
h('section.flex-row.flex-center.confirm-screen-row', [ h('section.flex-row.flex-center.confirm-screen-row', [
h('span.confirm-screen-label.confirm-screen-section-column', [ 'Gas Fee' ]), h('span.confirm-screen-label.confirm-screen-section-column', [ 'Gas Fee' ]),
h('div.confirm-screen-section-column', [ h('div.confirm-screen-section-column', [
h('div.confirm-screen-row-info', `${fiatGas} FIAT`), h('div.confirm-screen-row-info', `${fiatGas} ${currentCurrency.toUpperCase()}`),
h( h(
'div.confirm-screen-row-detail', 'div.confirm-screen-row-detail',

@ -241,7 +241,7 @@ ConfirmSendEther.prototype.render = function () {
// `You're sending to Recipient ...${toAddress.slice(toAddress.length - 4)}`, // `You're sending to Recipient ...${toAddress.slice(toAddress.length - 4)}`,
// ]), // ]),
h('h3.flex-center.confirm-screen-send-amount', [`$${amountInFIAT}`]), h('h3.flex-center.confirm-screen-send-amount', [`${amountInFIAT}`]),
h('h3.flex-center.confirm-screen-send-amount-currency', [ currentCurrency.toUpperCase() ]), h('h3.flex-center.confirm-screen-send-amount-currency', [ currentCurrency.toUpperCase() ]),
h('div.flex-center.confirm-memo-wrapper', [ h('div.flex-center.confirm-memo-wrapper', [
h('h3.confirm-screen-send-memo', [ memo ? `"${memo}"` : '' ]), h('h3.confirm-screen-send-memo', [ memo ? `"${memo}"` : '' ]),

@ -36,6 +36,16 @@ function toHexWei (value) {
}) })
} }
CurrencyDisplay.prototype.getAmount = function (value) {
const { selectedToken } = this.props
const { decimals } = selectedToken || {}
const multiplier = Math.pow(10, Number(decimals || 0))
const sendAmount = '0x' + Number(value * multiplier).toString(16)
return selectedToken
? sendAmount
: toHexWei(value)
}
CurrencyDisplay.prototype.render = function () { CurrencyDisplay.prototype.render = function () {
const { const {
className = 'currency-display', className = 'currency-display',
@ -102,7 +112,7 @@ CurrencyDisplay.prototype.render = function () {
this.setState({ value: newValue }) this.setState({ value: newValue })
} }
}, },
onBlur: event => !readOnly && handleChange(toHexWei(event.target.value.split(' ')[0])), onBlur: event => !readOnly && handleChange(this.getAmount(event.target.value.split(' ')[0])),
onKeyUp: event => { onKeyUp: event => {
if (!readOnly) { if (!readOnly) {
validate(toHexWei(value || initValueToRender)) validate(toHexWei(value || initValueToRender))

@ -13,6 +13,7 @@ const TokenMenuDropdown = require('./dropdowns/token-menu-dropdown.js')
function mapStateToProps (state) { function mapStateToProps (state) {
return { return {
network: state.metamask.network, network: state.metamask.network,
currentCurrency: state.metamask.currentCurrency,
selectedTokenAddress: state.metamask.selectedTokenAddress, selectedTokenAddress: state.metamask.selectedTokenAddress,
userAddress: selectors.getSelectedAddress(state), userAddress: selectors.getSelectedAddress(state),
tokenExchangeRates: state.metamask.tokenExchangeRates, tokenExchangeRates: state.metamask.tokenExchangeRates,
@ -63,18 +64,19 @@ TokenCell.prototype.render = function () {
ethToUSDRate, ethToUSDRate,
hideSidebar, hideSidebar,
sidebarOpen, sidebarOpen,
currentCurrency,
// userAddress, // userAddress,
} = props } = props
const pair = `${symbol.toLowerCase()}_eth`; const pair = `${symbol.toLowerCase()}_eth`;
let currentTokenToEthRate; let currentTokenToEthRate;
let currentTokenInUSD; let currentTokenInFiat;
let formattedUSD = '' let formattedUSD = ''
if (tokenExchangeRates[pair]) { if (tokenExchangeRates[pair]) {
currentTokenToEthRate = tokenExchangeRates[pair].rate; currentTokenToEthRate = tokenExchangeRates[pair].rate;
currentTokenInUSD = conversionUtil(string, { currentTokenInFiat = conversionUtil(string, {
fromNumericBase: 'dec', fromNumericBase: 'dec',
fromCurrency: symbol, fromCurrency: symbol,
toCurrency: 'USD', toCurrency: 'USD',
@ -82,7 +84,7 @@ TokenCell.prototype.render = function () {
conversionRate: currentTokenToEthRate, conversionRate: currentTokenToEthRate,
ethToUSDRate, ethToUSDRate,
}) })
formattedUSD = `$${currentTokenInUSD} USD`; formattedUSD = `${currentTokenInFiat} ${currentCurrency.toUpperCase()}`;
} }
return ( return (

@ -296,6 +296,7 @@ SendTransactionScreen.prototype.renderAmountRow = function () {
inError: Boolean(errors.amount), inError: Boolean(errors.amount),
primaryCurrency, primaryCurrency,
convertedCurrency, convertedCurrency,
selectedToken,
value: amount, value: amount,
conversionRate: amountConversionRate, conversionRate: amountConversionRate,
handleChange: this.handleAmountChange, handleChange: this.handleAmountChange,
@ -326,14 +327,14 @@ SendTransactionScreen.prototype.renderGasRow = function () {
convertedCurrency, convertedCurrency,
onClick: showCustomizeGasModal, onClick: showCustomizeGasModal,
}), }),
h('div.send-v2__sliders-icon-container', { h('div.send-v2__sliders-icon-container', {
onClick: showCustomizeGasModal, onClick: showCustomizeGasModal,
}, [ }, [
h('i.fa.fa-sliders.send-v2__sliders-icon'), h('i.fa.fa-sliders.send-v2__sliders-icon'),
]), ]),
]), ]),
]) ])
} }
@ -350,7 +351,7 @@ SendTransactionScreen.prototype.renderMemoRow = function () {
h(MemoTextArea, { h(MemoTextArea, {
memo, memo,
onChange: (event) => updateSendMemo(event.target.value), onChange: (event) => updateSendMemo(event.target.value),
}) }),
]), ]),
]) ])

Loading…
Cancel
Save