From 1368aad6741411a8425c5f2221309b061d812c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Wed, 21 Mar 2018 10:07:45 +0100 Subject: [PATCH] Add Unit selector in InputCurrency --- package.json | 6 +- src/components/SelectAccount/stories.js | 8 +- src/components/base/DropDown/index.js | 4 +- src/components/base/InputCurrency/index.js | 48 ++++++++++- src/components/base/InputCurrency/stories.js | 43 ++++++++-- src/components/base/Select/index.js | 32 +++++--- src/components/modals/Send/01-step-amount.js | 85 ++++++++++++-------- src/components/modals/Send/index.js | 11 ++- src/styles/theme.js | 11 +-- yarn.lock | 33 ++++---- 10 files changed, 197 insertions(+), 84 deletions(-) diff --git a/package.json b/package.json index 0972f0bc..e15c7742 100644 --- a/package.json +++ b/package.json @@ -57,12 +57,12 @@ "cross-env": "^5.1.4", "d3": "^4.13.0", "debug": "^3.1.0", - "downshift": "^1.30.1", + "downshift": "^1.31.1", "electron-store": "^1.3.0", "electron-updater": "^2.21.1", "fuse.js": "^3.2.0", "history": "^4.7.2", - "i18next": "^10.5.1", + "i18next": "^10.6.0", "i18next-node-fs-backend": "^1.0.0", "ledger-test-library": "KhalilBellakrid/ledger-test-library-nodejs#7d37482", "lodash": "^4.17.5", @@ -91,7 +91,7 @@ "source-map-support": "^0.5.4", "styled-components": "^3.2.3", "styled-system": "^2.2.1", - "tippy.js": "^2.3.0", + "tippy.js": "^2.4.0", "victory": "^0.25.6" }, "devDependencies": { diff --git a/src/components/SelectAccount/stories.js b/src/components/SelectAccount/stories.js index 845216b9..c2d9c573 100644 --- a/src/components/SelectAccount/stories.js +++ b/src/components/SelectAccount/stories.js @@ -1,6 +1,6 @@ // @flow -import React, { PureComponent } from 'react' +import React, { Component } from 'react' import { storiesOf } from '@storybook/react' import Chance from 'chance' import { getCurrencyByCoinType, getDefaultUnitByCoinType } from '@ledgerhq/currencies' @@ -29,11 +29,7 @@ export const accounts = [...Array(20)].map(() => ({ }, })) -type State = { - value: any, -} - -class Wrapper extends PureComponent { +class Wrapper extends Component { state = { value: '', } diff --git a/src/components/base/DropDown/index.js b/src/components/base/DropDown/index.js index 3f8f0b84..3d8a076b 100644 --- a/src/components/base/DropDown/index.js +++ b/src/components/base/DropDown/index.js @@ -145,7 +145,7 @@ class DropDown extends PureComponent { itemToString={itemToString} selectedItem={value} render={({ - getButtonProps, + getToggleButtonProps, getRootProps, isOpen, openMenu, @@ -153,7 +153,7 @@ class DropDown extends PureComponent { ...downshiftProps }) => ( - + {children} {isOpen && this.renderItems(items, selectedItem, downshiftProps)} diff --git a/src/components/base/InputCurrency/index.js b/src/components/base/InputCurrency/index.js index cb1f941d..69354e6c 100644 --- a/src/components/base/InputCurrency/index.js +++ b/src/components/base/InputCurrency/index.js @@ -1,13 +1,15 @@ // @flow import React, { PureComponent } from 'react' - +import styled from 'styled-components' import { parseCurrencyUnit, formatCurrencyUnit } from '@ledgerhq/currencies' import noop from 'lodash/noop' import isNaN from 'lodash/isNaN' +import Box from 'components/base/Box' import Input from 'components/base/Input' +import Select from 'components/base/Select' import type { Unit } from '@ledgerhq/currencies' @@ -35,12 +37,20 @@ function unformat(unit, value) { return v } +const Currencies = styled(Box)` + position: relative; + top: -1px; + right: -1px; +` + type Value = string | number type Props = { onChange: Function, - value: Value, + renderRight: any, unit: Unit, + units: Array, + value: Value, } type State = { @@ -51,6 +61,8 @@ type State = { class InputCurrency extends PureComponent { static defaultProps = { onChange: noop, + renderRight: null, + units: [], value: 0, } @@ -105,15 +117,42 @@ class InputCurrency extends PureComponent { } emitOnChange = (v: Value) => { - const { onChange } = this.props + const { onChange, unit } = this.props const { value } = this.state if (value.toString() !== v.toString()) { - onChange(v.toString()) + onChange(v.toString(), unit) } } + renderListUnits = () => { + const { unit, units, onChange } = this.props + const { value } = this.state + + if (units.length <= 1) { + return null + } + + const renderItem = item => item.code + + return ( + e.stopPropagation()}> + item.name} - onChange={onChange('fees')} + onChange('fees')({ value, unit })} /> - - {/* */} - {/* ADVANCED OPTIONS */} - {/* */} + {/* ADVANCED OPTIONS */} - {/* */} {/* RBF transaction */} - {/* */} - {/* */} {/* Message */} - {/* */}