Browse Source

Update wallet-common & currencies. Simplify again InputCurrency.

master
meriadec 7 years ago
parent
commit
b1e68fe647
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 4
      package.json
  2. 4
      src/actions/counterValues.js
  3. 35
      src/components/base/InputCurrency/index.js
  4. 2
      src/components/base/InputCurrency/stories.js
  5. 25
      yarn.lock

4
package.json

@ -44,12 +44,12 @@
"webpack-sources": "1.0.1"
},
"dependencies": {
"@ledgerhq/currencies": "^4.7.5",
"@ledgerhq/currencies": "^4.10.0",
"@ledgerhq/hw-app-btc": "^4.7.3",
"@ledgerhq/hw-app-eth": "^4.7.3",
"@ledgerhq/hw-transport": "^4.7.3",
"@ledgerhq/hw-transport-node-hid": "^4.7.6",
"@ledgerhq/wallet-common": "^0.10.1",
"@ledgerhq/wallet-common": "^0.11.0",
"axios": "^0.18.0",
"bcryptjs": "^2.4.3",
"bitcoinjs-lib": "^3.3.2",

4
src/actions/counterValues.js

@ -1,7 +1,7 @@
// @flow
import { getFiatUnit } from '@ledgerhq/currencies'
import { fetchHistodayCounterValuesMultiple } from '@ledgerhq/wallet-common/lib/api/countervalue'
import { fetchHistodayRates } from '@ledgerhq/wallet-common/lib/api/countervalue'
import type { Currency } from '@ledgerhq/currencies'
import type { Dispatch } from 'redux'
@ -32,6 +32,6 @@ export const fetchCounterValues: FetchCounterValues = (currencies: ?(Currency[])
const { counterValue } = settings
const fiatUnit = getFiatUnit(counterValue)
const counterValues = await fetchHistodayCounterValuesMultiple(currencies, fiatUnit)
const counterValues = await fetchHistodayRates(currencies, fiatUnit)
dispatch(updateCounterValues(counterValues))
}

35
src/components/base/InputCurrency/index.js

@ -2,7 +2,7 @@
import React, { PureComponent } from 'react'
import styled from 'styled-components'
import { parseCurrencyUnit, formatCurrencyUnit } from '@ledgerhq/currencies'
import { formatCurrencyUnit } from '@ledgerhq/currencies'
import noop from 'lodash/noop'
import isNaN from 'lodash/isNaN'
@ -17,24 +17,14 @@ function parseValue(value) {
return value.toString().replace(/,/g, '.')
}
function format(unit: Unit, value: number) {
function format(unit: Unit, value: number, useGrouping = false) {
return formatCurrencyUnit(unit, value, {
useGrouping,
disableRounding: true,
showAllDigits: false,
})
}
function unformat(unit, value) {
if (value === 0 || value === '') {
return '0'
}
let v = parseCurrencyUnit(unit, value.toString())
v /= 10 ** unit.magnitude
return v.toString()
}
const Currencies = styled(Box)`
position: relative;
top: -1px;
@ -79,7 +69,7 @@ class InputCurrency extends PureComponent<Props, State> {
componentWillMount() {
const { value } = this.props
const { unit } = this.state
const displayValue = format(unit, value)
const displayValue = format(unit, value, true)
this.setState({ displayValue })
}
@ -89,15 +79,15 @@ class InputCurrency extends PureComponent<Props, State> {
const { isFocus } = this.state
const displayValue = isFocus
? (nextProps.value / 10 ** unit.magnitude).toString()
: format(unit, nextProps.value)
: format(unit, nextProps.value, true)
this.setState({ displayValue })
}
}
handleChange = (v: string) => {
// const { displayValue } = this.state
v = parseValue(v)
// forbid multiple 0 at start
if (v.startsWith('00')) {
return
}
@ -114,17 +104,13 @@ class InputCurrency extends PureComponent<Props, State> {
handleBlur = () => {
const { value } = this.props
const { unit } = this.state
const v = format(unit, value)
this.setState({ isFocus: false, displayValue: v })
this.setState({ isFocus: false, displayValue: format(unit, value, true) })
}
handleFocus = () => {
const { value } = this.props
const { unit } = this.state
this.setState(prev => ({
isFocus: true,
displayValue: unformat(unit, prev.displayValue),
}))
this.setState({ isFocus: true, displayValue: format(unit, value) })
}
emitOnChange = (v: string) => {
@ -152,8 +138,7 @@ class InputCurrency extends PureComponent<Props, State> {
keyProp="code"
flatLeft
onChange={item => {
this.setState({ unit: item, displayValue: format(item, value) })
// onChange(unformat(item, value), item)
this.setState({ unit: item, displayValue: format(item, value, true) })
}}
items={units}
value={unit}

2
src/components/base/InputCurrency/stories.js

@ -14,7 +14,7 @@ const { units } = getCurrencyByCoinType(1)
class Wrapper extends Component<any, any> {
state = {
value: 1e8,
value: 1000e8,
unit: units[0],
}

25
yarn.lock

@ -913,17 +913,17 @@
lodash "^4.2.0"
to-fast-properties "^2.0.0"
"@ledgerhq/currencies@^4.7.1":
version "4.7.3"
resolved "https://registry.yarnpkg.com/@ledgerhq/currencies/-/currencies-4.7.3.tgz#0e28c0f1c74cf00b990be6865fbec374f808b71f"
"@ledgerhq/currencies@^4.10.0":
version "4.10.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/currencies/-/currencies-4.10.0.tgz#8cc25a232ca62fa5f4e17140df0678cdb48123e0"
dependencies:
lodash "^4.17.5"
numeral "^2.0.6"
querystring "^0.2.0"
"@ledgerhq/currencies@^4.7.5":
version "4.7.5"
resolved "https://registry.yarnpkg.com/@ledgerhq/currencies/-/currencies-4.7.5.tgz#e852b58359254fbb2087de328df84343b586f4ab"
"@ledgerhq/currencies@^4.7.1":
version "4.7.3"
resolved "https://registry.yarnpkg.com/@ledgerhq/currencies/-/currencies-4.7.3.tgz#0e28c0f1c74cf00b990be6865fbec374f808b71f"
dependencies:
lodash "^4.17.5"
numeral "^2.0.6"
@ -955,9 +955,9 @@
dependencies:
events "^2.0.0"
"@ledgerhq/wallet-common@^0.10.1":
version "0.10.1"
resolved "https://registry.yarnpkg.com/@ledgerhq/wallet-common/-/wallet-common-0.10.1.tgz#72e17329de02bebb5ed54bf797113266824e4af8"
"@ledgerhq/wallet-common@^0.11.0":
version "0.11.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/wallet-common/-/wallet-common-0.11.0.tgz#3b6bbc4f93ff766ff5f1c570322fe73260fe4835"
dependencies:
"@ledgerhq/currencies" "^4.7.1"
axios "^0.18.0"
@ -4817,7 +4817,7 @@ electron-builder-lib@~20.6.2:
semver "^5.5.0"
temp-file "^3.1.1"
electron-builder@^20.0.4, electron-builder@^20.8.1:
electron-builder@^20.8.1:
version "20.8.1"
resolved "https://registry.yarnpkg.com/electron-builder/-/electron-builder-20.8.1.tgz#3d19607a7f7d3ee7f3e110a6fc66c720ed1d2cc0"
dependencies:
@ -4997,7 +4997,7 @@ electron-webpack@^2.0.1:
webpack-merge "^4.1.2"
yargs "^11.1.0"
electron@1.8.4, electron@^1.8.2:
electron@1.8.4:
version "1.8.4"
resolved "https://registry.yarnpkg.com/electron/-/electron-1.8.4.tgz#cca8d0e6889f238f55b414ad224f03e03b226a38"
dependencies:
@ -8028,9 +8028,6 @@ ledger-test-library@KhalilBellakrid/ledger-test-library-nodejs#7d37482:
dependencies:
axios "^0.17.1"
bindings "^1.3.0"
electron "^1.8.2"
electron-builder "^20.0.4"
electron-rebuild "^1.7.3"
nan "^2.6.2"
prebuild-install "^2.2.2"

Loading…
Cancel
Save