mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Stop setting 'currentCurrency' and use local state for active currency in send.js
This commit is contained in:
parent
a5ab91e572
commit
ca46bd200b
@ -13,20 +13,20 @@ function CurrencyToggle () {
|
|||||||
const defaultCurrencies = [ 'ETH', 'USD' ]
|
const defaultCurrencies = [ 'ETH', 'USD' ]
|
||||||
|
|
||||||
CurrencyToggle.prototype.renderToggles = function () {
|
CurrencyToggle.prototype.renderToggles = function () {
|
||||||
const { onClick, currentCurrency } = this.props
|
const { onClick, activeCurrency } = this.props
|
||||||
const [currencyA, currencyB] = this.props.currencies || defaultCurrencies
|
const [currencyA, currencyB] = this.props.currencies || defaultCurrencies
|
||||||
|
|
||||||
return [
|
return [
|
||||||
h('span', {
|
h('span', {
|
||||||
className: classnames('currency-toggle__item', {
|
className: classnames('currency-toggle__item', {
|
||||||
'currency-toggle__item--selected': currencyA === currentCurrency,
|
'currency-toggle__item--selected': currencyA === activeCurrency,
|
||||||
}),
|
}),
|
||||||
onClick: () => onClick(currencyA),
|
onClick: () => onClick(currencyA),
|
||||||
}, [ currencyA ]),
|
}, [ currencyA ]),
|
||||||
'<>',
|
'<>',
|
||||||
h('span', {
|
h('span', {
|
||||||
className: classnames('currency-toggle__item', {
|
className: classnames('currency-toggle__item', {
|
||||||
'currency-toggle__item--selected': currencyB === currentCurrency,
|
'currency-toggle__item--selected': currencyB === activeCurrency,
|
||||||
}),
|
}),
|
||||||
onClick: () => onClick(currencyB),
|
onClick: () => onClick(currencyB),
|
||||||
}, [ currencyB ]),
|
}, [ currencyB ]),
|
||||||
|
@ -13,7 +13,7 @@ function EthFeeDisplay () {
|
|||||||
|
|
||||||
EthFeeDisplay.prototype.render = function () {
|
EthFeeDisplay.prototype.render = function () {
|
||||||
const {
|
const {
|
||||||
currentCurrency,
|
activeCurrency,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
gas,
|
gas,
|
||||||
gasPrice,
|
gasPrice,
|
||||||
@ -22,7 +22,7 @@ EthFeeDisplay.prototype.render = function () {
|
|||||||
|
|
||||||
return h(EthBalance, {
|
return h(EthBalance, {
|
||||||
value: getTxFeeBn(gas, gasPrice, blockGasLimit),
|
value: getTxFeeBn(gas, gasPrice, blockGasLimit),
|
||||||
currentCurrency,
|
currentCurrency: activeCurrency,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
showFiat: false,
|
showFiat: false,
|
||||||
hideTooltip: true,
|
hideTooltip: true,
|
||||||
|
@ -28,17 +28,17 @@ GasFeeDisplay.prototype.getTokenValue = function () {
|
|||||||
|
|
||||||
GasFeeDisplay.prototype.render = function () {
|
GasFeeDisplay.prototype.render = function () {
|
||||||
const {
|
const {
|
||||||
currentCurrency,
|
activeCurrency,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
gas,
|
gas,
|
||||||
gasPrice,
|
gasPrice,
|
||||||
blockGasLimit,
|
blockGasLimit,
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
switch (currentCurrency) {
|
switch (activeCurrency) {
|
||||||
case 'USD':
|
case 'USD':
|
||||||
return h(USDFeeDisplay, {
|
return h(USDFeeDisplay, {
|
||||||
currentCurrency,
|
activeCurrency,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
gas,
|
gas,
|
||||||
gasPrice,
|
gasPrice,
|
||||||
@ -46,7 +46,7 @@ GasFeeDisplay.prototype.render = function () {
|
|||||||
})
|
})
|
||||||
case 'ETH':
|
case 'ETH':
|
||||||
return h(EthFeeDisplay, {
|
return h(EthFeeDisplay, {
|
||||||
currentCurrency,
|
activeCurrency,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
gas,
|
gas,
|
||||||
gasPrice,
|
gasPrice,
|
||||||
@ -55,7 +55,7 @@ GasFeeDisplay.prototype.render = function () {
|
|||||||
default:
|
default:
|
||||||
return h('div.token-gas', [
|
return h('div.token-gas', [
|
||||||
h('div.token-gas__amount', this.getTokenValue()),
|
h('div.token-gas__amount', this.getTokenValue()),
|
||||||
h('div.token-gas__symbol', currentCurrency),
|
h('div.token-gas__symbol', activeCurrency),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ function USDFeeDisplay () {
|
|||||||
|
|
||||||
USDFeeDisplay.prototype.render = function () {
|
USDFeeDisplay.prototype.render = function () {
|
||||||
const {
|
const {
|
||||||
currentCurrency,
|
activeCurrency,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
gas,
|
gas,
|
||||||
gasPrice,
|
gasPrice,
|
||||||
@ -23,7 +23,7 @@ USDFeeDisplay.prototype.render = function () {
|
|||||||
return h(FiatValue, {
|
return h(FiatValue, {
|
||||||
value: getTxFeeBn(gas, gasPrice, blockGasLimit),
|
value: getTxFeeBn(gas, gasPrice, blockGasLimit),
|
||||||
conversionRate,
|
conversionRate,
|
||||||
currentCurrency,
|
currentCurrency: activeCurrency,
|
||||||
style: {
|
style: {
|
||||||
color: '#5d5d5d',
|
color: '#5d5d5d',
|
||||||
fontSize: '16px',
|
fontSize: '16px',
|
||||||
|
@ -10,7 +10,6 @@ const GasFeeDisplay = require('./components/send/gas-fee-display')
|
|||||||
const { getSelectedIdentity } = require('./selectors')
|
const { getSelectedIdentity } = require('./selectors')
|
||||||
|
|
||||||
const {
|
const {
|
||||||
setCurrentCurrency,
|
|
||||||
showAccountsPage,
|
showAccountsPage,
|
||||||
backToAccountDetail,
|
backToAccountDetail,
|
||||||
displayWarning,
|
displayWarning,
|
||||||
@ -35,7 +34,6 @@ function mapStateToProps (state) {
|
|||||||
network,
|
network,
|
||||||
addressBook,
|
addressBook,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
currentCurrency,
|
|
||||||
currentBlockGasLimit: blockGasLimit,
|
currentBlockGasLimit: blockGasLimit,
|
||||||
} = state.metamask
|
} = state.metamask
|
||||||
const { warning } = state.appState
|
const { warning } = state.appState
|
||||||
@ -49,7 +47,6 @@ function mapStateToProps (state) {
|
|||||||
network,
|
network,
|
||||||
addressBook,
|
addressBook,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
currentCurrency,
|
|
||||||
blockGasLimit,
|
blockGasLimit,
|
||||||
warning,
|
warning,
|
||||||
selectedIdentity,
|
selectedIdentity,
|
||||||
@ -77,6 +74,7 @@ function SendTransactionScreen () {
|
|||||||
txData: null,
|
txData: null,
|
||||||
memo: '',
|
memo: '',
|
||||||
},
|
},
|
||||||
|
activeCurrency: 'USD',
|
||||||
tooltipIsOpen: false,
|
tooltipIsOpen: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +82,7 @@ function SendTransactionScreen () {
|
|||||||
this.closeTooltip = this.closeTooltip.bind(this)
|
this.closeTooltip = this.closeTooltip.bind(this)
|
||||||
this.onSubmit = this.onSubmit.bind(this)
|
this.onSubmit = this.onSubmit.bind(this)
|
||||||
this.recipientDidChange = this.recipientDidChange.bind(this)
|
this.recipientDidChange = this.recipientDidChange.bind(this)
|
||||||
this.setCurrentCurrency = this.setCurrentCurrency.bind(this)
|
this.setActiveCurrency = this.setActiveCurrency.bind(this)
|
||||||
this.toggleTooltip = this.toggleTooltip.bind(this)
|
this.toggleTooltip = this.toggleTooltip.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,12 +96,11 @@ SendTransactionScreen.prototype.render = function () {
|
|||||||
identities,
|
identities,
|
||||||
addressBook,
|
addressBook,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
currentCurrency,
|
|
||||||
} = props
|
} = props
|
||||||
|
|
||||||
const { blockGasLimit, newTx } = this.state
|
const { blockGasLimit, newTx, activeCurrency } = this.state
|
||||||
const { gas, gasPrice } = newTx
|
const { gas, gasPrice } = newTx
|
||||||
|
console.log(`activeCurrency`, activeCurrency);
|
||||||
console.log({ selectedIdentity, identities })
|
console.log({ selectedIdentity, identities })
|
||||||
console.log('SendTransactionScreen state:', this.state)
|
console.log('SendTransactionScreen state:', this.state)
|
||||||
|
|
||||||
@ -238,8 +235,8 @@ SendTransactionScreen.prototype.render = function () {
|
|||||||
h('div.send-screen-amount-labels', {}, [
|
h('div.send-screen-amount-labels', {}, [
|
||||||
h('span', {}, ['Amount']),
|
h('span', {}, ['Amount']),
|
||||||
h(CurrencyToggle, {
|
h(CurrencyToggle, {
|
||||||
currentCurrency,
|
activeCurrency,
|
||||||
onClick: (newCurrency) => this.setCurrentCurrency(newCurrency),
|
onClick: (newCurrency) => this.setActiveCurrency(newCurrency),
|
||||||
}), // holding on icon from design
|
}), // holding on icon from design
|
||||||
]),
|
]),
|
||||||
|
|
||||||
@ -296,7 +293,7 @@ SendTransactionScreen.prototype.render = function () {
|
|||||||
// TODO: handle loading time when switching to USD
|
// TODO: handle loading time when switching to USD
|
||||||
h('div.large-input.send-screen-gas-input', {}, [
|
h('div.large-input.send-screen-gas-input', {}, [
|
||||||
h(GasFeeDisplay, {
|
h(GasFeeDisplay, {
|
||||||
currentCurrency,
|
activeCurrency,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
gas,
|
gas,
|
||||||
gasPrice,
|
gasPrice,
|
||||||
@ -356,8 +353,8 @@ SendTransactionScreen.prototype.render = function () {
|
|||||||
// Buttons underneath card
|
// Buttons underneath card
|
||||||
h('section.flex-column.flex-center', [
|
h('section.flex-column.flex-center', [
|
||||||
|
|
||||||
h('button.btn-light', {
|
h('div.btn-light.send-screen-send-button', {
|
||||||
onClick: this.onSubmit,
|
onClick: (event) => this.onSubmit(event),
|
||||||
style: {
|
style: {
|
||||||
marginTop: '8px',
|
marginTop: '8px',
|
||||||
width: '8em',
|
width: '8em',
|
||||||
@ -603,8 +600,8 @@ SendTransactionScreen.prototype.closeTooltip = function () {
|
|||||||
this.setState({ tooltipIsOpen: false })
|
this.setState({ tooltipIsOpen: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
SendTransactionScreen.prototype.setCurrentCurrency = function (newCurrency) {
|
SendTransactionScreen.prototype.setActiveCurrency = function (newCurrency) {
|
||||||
this.props.dispatch(setCurrentCurrency(newCurrency))
|
this.setState({ activeCurrency: newCurrency })
|
||||||
}
|
}
|
||||||
|
|
||||||
SendTransactionScreen.prototype.navigateToAccounts = function (event) {
|
SendTransactionScreen.prototype.navigateToAccounts = function (event) {
|
||||||
@ -624,7 +621,8 @@ SendTransactionScreen.prototype.recipientDidChange = function (recipient, nickna
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
SendTransactionScreen.prototype.onSubmit = function () {
|
SendTransactionScreen.prototype.onSubmit = function (event) {
|
||||||
|
event.preventDefault()
|
||||||
const state = this.state || {}
|
const state = this.state || {}
|
||||||
|
|
||||||
// const recipient = state.recipient || document.querySelector('input[name="address"]').value.replace(/^[.\s]+|[.\s]+$/g, '')
|
// const recipient = state.recipient || document.querySelector('input[name="address"]').value.replace(/^[.\s]+|[.\s]+$/g, '')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user