2017-08-29 15:55:11 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
2017-09-12 07:14:09 +02:00
|
|
|
const classnames = require('classnames')
|
|
|
|
|
2017-08-29 15:55:11 +02:00
|
|
|
module.exports = CurrencyToggle
|
|
|
|
|
|
|
|
inherits(CurrencyToggle, Component)
|
|
|
|
function CurrencyToggle () {
|
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
2017-09-12 07:14:09 +02:00
|
|
|
const defaultCurrencies = [ 'ETH', 'USD' ]
|
|
|
|
|
2017-09-13 10:25:39 +02:00
|
|
|
CurrencyToggle.prototype.renderToggles = function () {
|
2017-09-13 19:57:15 +02:00
|
|
|
const { onClick, activeCurrency } = this.props
|
2017-09-12 07:14:09 +02:00
|
|
|
const [currencyA, currencyB] = this.props.currencies || defaultCurrencies
|
2017-08-29 15:55:11 +02:00
|
|
|
|
2017-09-13 10:25:39 +02:00
|
|
|
return [
|
2017-08-29 15:55:11 +02:00
|
|
|
h('span', {
|
2017-09-12 07:14:09 +02:00
|
|
|
className: classnames('currency-toggle__item', {
|
2017-09-13 19:57:15 +02:00
|
|
|
'currency-toggle__item--selected': currencyA === activeCurrency,
|
2017-09-12 07:14:09 +02:00
|
|
|
}),
|
|
|
|
onClick: () => onClick(currencyA),
|
2017-09-12 08:18:54 +02:00
|
|
|
}, [ currencyA ]),
|
2017-08-29 15:55:11 +02:00
|
|
|
'<>',
|
|
|
|
h('span', {
|
2017-09-12 07:14:09 +02:00
|
|
|
className: classnames('currency-toggle__item', {
|
2017-09-13 19:57:15 +02:00
|
|
|
'currency-toggle__item--selected': currencyB === activeCurrency,
|
2017-09-12 07:14:09 +02:00
|
|
|
}),
|
|
|
|
onClick: () => onClick(currencyB),
|
2017-09-12 08:18:54 +02:00
|
|
|
}, [ currencyB ]),
|
2017-09-13 10:25:39 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
CurrencyToggle.prototype.render = function () {
|
|
|
|
const currencies = this.props.currencies || defaultCurrencies
|
|
|
|
|
|
|
|
return h('span.currency-toggle', currencies.length
|
|
|
|
? this.renderToggles()
|
|
|
|
: []
|
|
|
|
)
|
2017-08-29 15:55:11 +02:00
|
|
|
}
|
|
|
|
|