const Component = require('react').Component const h = require('react-hyperscript') const inherits = require('util').inherits const { conversionUtil, multiplyCurrencies } = require('../../../conversion-util') const { removeLeadingZeroes } = require('../send.utils') const currencyFormatter = require('currency-formatter') const currencies = require('currency-formatter/currencies') const ethUtil = require('ethereumjs-util') const PropTypes = require('prop-types') CurrencyDisplay.contextTypes = { t: PropTypes.func, } module.exports = CurrencyDisplay inherits(CurrencyDisplay, Component) function CurrencyDisplay () { Component.call(this) } function toHexWei (value) { return conversionUtil(value, { fromNumericBase: 'dec', toNumericBase: 'hex', toDenomination: 'WEI', }) } CurrencyDisplay.prototype.componentWillMount = function () { this.setState({ valueToRender: this.getValueToRender(this.props), }) } CurrencyDisplay.prototype.componentWillReceiveProps = function (nextProps) { const currentValueToRender = this.getValueToRender(this.props) const newValueToRender = this.getValueToRender(nextProps) if (currentValueToRender !== newValueToRender) { this.setState({ valueToRender: newValueToRender, }) } } CurrencyDisplay.prototype.getAmount = function (value) { const { selectedToken } = this.props const { decimals } = selectedToken || {} const multiplier = Math.pow(10, Number(decimals || 0)) const sendAmount = multiplyCurrencies(value || '0', multiplier, {toNumericBase: 'hex'}) return selectedToken ? sendAmount : toHexWei(value) } CurrencyDisplay.prototype.getValueToRender = function ({ selectedToken, conversionRate, value, readOnly }) { if (value === '0x0') return readOnly ? '0' : '' const { decimals, symbol } = selectedToken || {} const multiplier = Math.pow(10, Number(decimals || 0)) return selectedToken ? conversionUtil(ethUtil.addHexPrefix(value), { fromNumericBase: 'hex', toNumericBase: 'dec', toCurrency: symbol, conversionRate: multiplier, invertConversionRate: true, }) : conversionUtil(ethUtil.addHexPrefix(value), { fromNumericBase: 'hex', toNumericBase: 'dec', fromDenomination: 'WEI', numberOfDecimals: 9, conversionRate, }) } CurrencyDisplay.prototype.getConvertedValueToRender = function (nonFormattedValue) { const { primaryCurrency, convertedCurrency, conversionRate } = this.props if (conversionRate === 0 || conversionRate === null || conversionRate === undefined) { if (nonFormattedValue !== 0) { return null } } let convertedValue = conversionUtil(nonFormattedValue, { fromNumericBase: 'dec', fromCurrency: primaryCurrency, toCurrency: convertedCurrency, numberOfDecimals: 2, conversionRate, }) convertedValue = Number(convertedValue).toFixed(2) const upperCaseCurrencyCode = convertedCurrency.toUpperCase() return currencies.find(currency => currency.code === upperCaseCurrencyCode) ? currencyFormatter.format(Number(convertedValue), { code: upperCaseCurrencyCode, }) : convertedValue } CurrencyDisplay.prototype.handleChange = function (newVal) { this.setState({ valueToRender: removeLeadingZeroes(newVal) }) this.props.onChange(this.getAmount(newVal)) } CurrencyDisplay.prototype.getInputWidth = function (valueToRender, readOnly) { const valueString = String(valueToRender) const valueLength = valueString.length || 1 const decimalPointDeficit = valueString.match(/\./) ? -0.5 : 0 return (valueLength + decimalPointDeficit + 0.75) + 'ch' } CurrencyDisplay.prototype.onlyRenderConversions = function (convertedValueToRender) { const { convertedBalanceClassName = 'currency-display__converted-value', convertedCurrency, } = this.props return h('div', { className: convertedBalanceClassName, }, convertedValueToRender == null ? this.context.t('noConversionRateAvailable') : `${convertedValueToRender} ${convertedCurrency.toUpperCase()}` ) } CurrencyDisplay.prototype.render = function () { const { className = 'currency-display', primaryBalanceClassName = 'currency-display__input', primaryCurrency, readOnly = false, inError = false, onBlur, step, } = this.props const { valueToRender } = this.state const convertedValueToRender = this.getConvertedValueToRender(valueToRender) return h('div', { className, style: { borderColor: inError ? 'red' : null, }, onClick: () => { this.currencyInput && this.currencyInput.focus() }, }, [ h('div.currency-display__primary-row', [ h('div.currency-display__input-wrapper', [ h('input', { className: primaryBalanceClassName, value: `${valueToRender}`, placeholder: '0', type: 'number', readOnly, ...(!readOnly ? { onChange: e => this.handleChange(e.target.value), onBlur: () => onBlur(this.getAmount(valueToRender)), } : {}), ref: input => { this.currencyInput = input }, style: { width: this.getInputWidth(valueToRender, readOnly), }, min: 0, step, }), h('span.currency-display__currency-symbol', primaryCurrency), ]), ]), this.onlyRenderConversions(convertedValueToRender), ]) } '>dependabot/npm_and_yarn/devel/electron4/files/lodash.merge-4.6.2 FreeBSD Ports (https://github.com/freebsd/freebsd-ports)
aboutsummaryrefslogtreecommitdiffstats
path: root/net-im/farsight2
Commit message (Expand)AuthorAgeFilesLines
* Add NO_STAGE all over the place in preparation for the staging support (cat: ...Baptiste Daroussin2013-09-211-0/+1
* - Convert USE_GETTEXT to USES (part 1)Alex Kozlov2013-04-241-2/+1
* Finish converting the whole ports tree to USES=pkgconfigBaptiste Daroussin2013-04-231-1/+1
* fix build with glib 2.34: wv2, gimp-focusblur-plugin, gtk-murrine-engineKoop Mast2013-04-021-2/+2
* * Update the glib to 2.34.3 and gtk20 to 2.24.17 and gtk30 to 3.6.4 whichKoop Mast2013-03-084-31/+30
* - update png to 1.5.10Dirk Meyer2012-06-011-0/+1
* - Add LDFLAGS to CONFIGURE_ENV and MAKE_ENV (as it was done with LDFLAGS)Dmitry Marakasov2011-09-241-2/+2
* Remove USE_GNOME=gnometarget from ports. It has been a empty keyword sinceKoop Mast2011-08-121-1/+1
* - Mark BROKEN on <7.2Pav Lucistnik2011-01-281-1/+7
* Sync to new bsd.autotools.mkAde Lovett2010-12-041-1/+1
* Update to 0.0.22.Joe Marcus Clarke2010-11-275-15/+18
* Update to 0.0.21.Joe Marcus Clarke2010-07-253-6/+5
* Bump PORTREVISION and add USE_GETTEXT where missing.Joe Marcus Clarke2010-06-011-0/+2
* Update to 0.0.19.Joe Marcus Clarke2010-05-224-22/+24
* - update to 1.4.1Dirk Meyer2010-03-281-1/+1
* Fix the build with the new libnice.Joe Marcus Clarke2010-03-211-0/+11
* - update to jpeg-8Dirk Meyer2010-02-051-0/+1
* Update to 0.0.17.Joe Marcus Clarke2010-01-102-4/+4
* Update to 0.0.16.Joe Marcus Clarke2009-10-102-4/+4
* This patch is no longer required.Joe Marcus Clarke2009-09-081-11/+0
* Update to 0.0.15.Joe Marcus Clarke2009-09-082-4/+4
* Fix the build on 6.X.Joe Marcus Clarke2009-08-102-5/+7
* Update to 0.0.18.Joe Marcus Clarke2009-08-096-54/+14
* -Repocopy devel/libtool15 -> libtool22 and libltdl15 -> libltdl22.Jeremy Messenger2009-08-031-1/+1
* Fix farsight2 update. Bump PORTVERSION to correct version noted in distfiles.Koop Mast2009-08-021-2/+1
* Update to 0.0.13.Joe Marcus Clarke2009-08-024-3/+48
* - bump all port that indirectly depends on libjpeg and have not yet been bump...Dirk Meyer2009-07-311-1/+1
* Remove a file from the plist.Joe Marcus Clarke2009-06-032-1/+1
* Update to 0.0.12.Joe Marcus Clarke2009-06-032-4/+4
* Update to 0.0.10.Joe Marcus Clarke2009-05-263-4/+5
* Update to 0.0.9.Joe Marcus Clarke2009-04-074-16/+11
* Update to 0.0.8.Joe Marcus Clarke2009-03-213-4/+7