From 5909f730c033f54c314c06ebe249f537c769a719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Fri, 26 Jan 2018 17:17:31 +0100 Subject: [PATCH] Add ImportAccounts component --- package.json | 2 +- src/components/SelectAccount.js | 26 ++--- src/components/base/Select/index.js | 5 +- .../modals/AddAccount/ImportAccounts.js | 73 ++++++++++++++ .../{AddAccount.js => AddAccount/index.js} | 97 ++++++++++++------- src/components/modals/Send.js | 41 ++------ src/main/app.js | 1 + yarn.lock | 6 +- 8 files changed, 159 insertions(+), 92 deletions(-) create mode 100644 src/components/modals/AddAccount/ImportAccounts.js rename src/components/modals/{AddAccount.js => AddAccount/index.js} (75%) diff --git a/package.json b/package.json index 92c60ab9..deec998d 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "raven-js": "^3.22.1", "react": "^16.2.0", "react-dom": "^16.2.0", - "react-i18next": "^7.3.2", + "react-i18next": "^7.3.4", "react-mortal": "^3.0.1", "react-motion": "^0.5.2", "react-redux": "^5.0.6", diff --git a/src/components/SelectAccount.js b/src/components/SelectAccount.js index 40e9a6c9..08957cb5 100644 --- a/src/components/SelectAccount.js +++ b/src/components/SelectAccount.js @@ -2,22 +2,16 @@ import React from 'react' import { connect } from 'react-redux' -import values from 'lodash/values' import type { MapStateToProps } from 'react-redux' import { getAccounts } from 'reducers/accounts' import Select from 'components/base/Select' -import Text from 'components/base/Text' import type { Account } from 'types/common' -function renderItem(accounts) { - return item => {(accounts.find(a => a.id === item) || {}).name} -} - const mapStateToProps: MapStateToProps<*, *, *> = state => ({ - accounts: values(getAccounts(state)), + accounts: Object.entries(getAccounts(state)).map(([, account]: [string, any]) => account), }) type Props = { @@ -28,18 +22,18 @@ type Props = { const SelectAccount = ({ accounts, value, onChange }: Props) => ( props.onChangeInput('account')(item.key)} - renderSelected={item => item.name} - items={Object.entries(props.accounts).map(([id, account]: [string, any]) => ({ - key: id, - name: account.name, - }))} - /> +
@@ -64,59 +51,49 @@ const Steps = {
summary
{props.value.amount}
to {props.value.address}
-
from {props.account.name}
+
from {props.value.account.name}
), } type InputValue = { - account: string, + account: any, address: string, amount: string, } type Step = 'amount' | 'summary' -type Props = { - accounts: Accounts, -} type State = { inputValue: InputValue, step: Step, } -const mapStateToProps: MapStateToProps<*, *, *> = state => ({ - accounts: getAccounts(state), -}) - const defaultState = { inputValue: { - account: '', + account: undefined, address: '', amount: '', }, step: 'amount', } -class Send extends PureComponent { +class Send extends PureComponent<{}, State> { state = { ...defaultState, } getStepProps() { - const { accounts } = this.props const { inputValue, step } = this.state const props = (predicate, props) => (predicate ? props : {}) return { ...props(step === 'amount', { - accounts, onChangeInput: this.handleChangeInput, value: inputValue, }), ...props(step === 'summary', { - account: accounts[inputValue.account], value: inputValue, }), onChangeStep: this.handleChangeStep, @@ -131,7 +108,7 @@ class Send extends PureComponent { }, })) - handleChangeStep = step => + handleChangeStep = (step: Step) => this.setState({ step, }) @@ -163,4 +140,4 @@ class Send extends PureComponent { } } -export default connect(mapStateToProps)(Send) +export default Send diff --git a/src/main/app.js b/src/main/app.js index f182d09c..c98d98ae 100644 --- a/src/main/app.js +++ b/src/main/app.js @@ -17,6 +17,7 @@ function createMainWindow() { vibrancy: 'ultra-dark', // https://github.com/electron/electron/issues/10521 } : {}), + center: true, show: true, height: MIN_HEIGHT, width: MIN_WIDTH, diff --git a/yarn.lock b/yarn.lock index af50b281..2db86db9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7322,9 +7322,9 @@ react-html-attributes@^1.3.0: dependencies: html-element-attributes "^1.0.0" -react-i18next@^7.3.2: - version "7.3.2" - resolved "https://registry.yarnpkg.com/react-i18next/-/react-i18next-7.3.2.tgz#5036dc0371808bd8afe0c9a4a738ebd39721e33b" +react-i18next@^7.3.4: + version "7.3.4" + resolved "https://registry.yarnpkg.com/react-i18next/-/react-i18next-7.3.4.tgz#d5932d47ac7f0d723eecef492ea97b7232673706" dependencies: hoist-non-react-statics "2.3.1" html-parse-stringify2 "2.0.1"