|
@ -21,6 +21,7 @@ import { getCurrentDevice } from 'reducers/devices' |
|
|
import { sendEvent } from 'renderer/events' |
|
|
import { sendEvent } from 'renderer/events' |
|
|
|
|
|
|
|
|
import { addAccount, updateAccount } from 'actions/accounts' |
|
|
import { addAccount, updateAccount } from 'actions/accounts' |
|
|
|
|
|
import { fetchCounterValues } from 'actions/counterValues' |
|
|
|
|
|
|
|
|
import Box from 'components/base/Box' |
|
|
import Box from 'components/base/Box' |
|
|
import Button from 'components/base/Button' |
|
|
import Button from 'components/base/Button' |
|
@ -55,9 +56,13 @@ const Steps = { |
|
|
/> |
|
|
/> |
|
|
</Box> |
|
|
</Box> |
|
|
<Box horizontal justifyContent="flex-end"> |
|
|
<Box horizontal justifyContent="flex-end"> |
|
|
|
|
|
{props.fetchingCounterValues ? ( |
|
|
|
|
|
'Fetching counterValues...' |
|
|
|
|
|
) : ( |
|
|
<Button primary type="submit"> |
|
|
<Button primary type="submit"> |
|
|
{props.t('addAccount:title')} |
|
|
{props.t('addAccount:title')} |
|
|
</Button> |
|
|
</Button> |
|
|
|
|
|
)} |
|
|
</Box> |
|
|
</Box> |
|
|
</Box> |
|
|
</Box> |
|
|
</form> |
|
|
</form> |
|
@ -113,41 +118,47 @@ const Steps = { |
|
|
type Step = 'chooseCurrency' | 'connectDevice' | 'inProgress' | 'listAccounts' |
|
|
type Step = 'chooseCurrency' | 'connectDevice' | 'inProgress' | 'listAccounts' |
|
|
|
|
|
|
|
|
type Props = { |
|
|
type Props = { |
|
|
t: T, |
|
|
|
|
|
accounts: Accounts, |
|
|
accounts: Accounts, |
|
|
archivedAccounts: Accounts, |
|
|
|
|
|
addAccount: Function, |
|
|
addAccount: Function, |
|
|
updateAccount: Function, |
|
|
archivedAccounts: Accounts, |
|
|
canCreateAccount: boolean, |
|
|
canCreateAccount: boolean, |
|
|
closeModal: Function, |
|
|
closeModal: Function, |
|
|
|
|
|
counterValues: Object, |
|
|
currentDevice: Device | null, |
|
|
currentDevice: Device | null, |
|
|
|
|
|
fetchCounterValues: Function, |
|
|
|
|
|
t: T, |
|
|
|
|
|
updateAccount: Function, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type State = { |
|
|
type State = { |
|
|
step: Step, |
|
|
|
|
|
currency: Currency | null, |
|
|
|
|
|
accounts: Accounts, |
|
|
accounts: Accounts, |
|
|
|
|
|
currency: Currency | null, |
|
|
|
|
|
fetchingCounterValues: boolean, |
|
|
progress: null | Object, |
|
|
progress: null | Object, |
|
|
|
|
|
step: Step, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const mapStateToProps: MapStateToProps<*, *, *> = state => ({ |
|
|
const mapStateToProps: MapStateToProps<*, *, *> = state => ({ |
|
|
accounts: getAccounts(state), |
|
|
accounts: getAccounts(state), |
|
|
archivedAccounts: getArchivedAccounts(state), |
|
|
archivedAccounts: getArchivedAccounts(state), |
|
|
canCreateAccount: canCreateAccount(state), |
|
|
canCreateAccount: canCreateAccount(state), |
|
|
|
|
|
counterValues: state.counterValues, |
|
|
currentDevice: getCurrentDevice(state), |
|
|
currentDevice: getCurrentDevice(state), |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
const mapDispatchToProps = { |
|
|
const mapDispatchToProps = { |
|
|
addAccount, |
|
|
addAccount, |
|
|
updateAccount, |
|
|
|
|
|
closeModal, |
|
|
closeModal, |
|
|
|
|
|
fetchCounterValues, |
|
|
|
|
|
updateAccount, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const defaultState = { |
|
|
const defaultState = { |
|
|
|
|
|
step: 'chooseCurrency', |
|
|
|
|
|
progress: null, |
|
|
|
|
|
fetchingCounterValues: false, |
|
|
currency: null, |
|
|
currency: null, |
|
|
accounts: [], |
|
|
accounts: [], |
|
|
progress: null, |
|
|
|
|
|
step: 'chooseCurrency', |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
class AddAccountModal extends PureComponent<Props, State> { |
|
|
class AddAccountModal extends PureComponent<Props, State> { |
|
@ -200,16 +211,17 @@ class AddAccountModal extends PureComponent<Props, State> { |
|
|
|
|
|
|
|
|
getStepProps() { |
|
|
getStepProps() { |
|
|
const { currentDevice, archivedAccounts, canCreateAccount, updateAccount, t } = this.props |
|
|
const { currentDevice, archivedAccounts, canCreateAccount, updateAccount, t } = this.props |
|
|
const { currency, step, progress, accounts } = this.state |
|
|
const { currency, step, progress, accounts, fetchingCounterValues } = this.state |
|
|
|
|
|
|
|
|
const props = (predicate, props) => (predicate ? props : {}) |
|
|
const props = (predicate, props) => (predicate ? props : {}) |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
...props(step === 'chooseCurrency', { |
|
|
...props(step === 'chooseCurrency', { |
|
|
t, |
|
|
|
|
|
currency, |
|
|
currency, |
|
|
|
|
|
fetchingCounterValues, |
|
|
onChangeCurrency: this.handleChangeCurrency, |
|
|
onChangeCurrency: this.handleChangeCurrency, |
|
|
onSubmit: this.handleSubmit, |
|
|
onSubmit: this.handleSubmit, |
|
|
|
|
|
t, |
|
|
}), |
|
|
}), |
|
|
...props(step === 'connectDevice', { |
|
|
...props(step === 'connectDevice', { |
|
|
t, |
|
|
t, |
|
@ -271,13 +283,25 @@ class AddAccountModal extends PureComponent<Props, State> { |
|
|
|
|
|
|
|
|
handleChangeCurrency = (currency: Currency) => this.setState({ currency }) |
|
|
handleChangeCurrency = (currency: Currency) => this.setState({ currency }) |
|
|
|
|
|
|
|
|
handleSubmit = (e: SyntheticEvent<HTMLFormElement>) => { |
|
|
handleSubmit = async (e: SyntheticEvent<HTMLFormElement>) => { |
|
|
e.preventDefault() |
|
|
e.preventDefault() |
|
|
|
|
|
|
|
|
|
|
|
const { fetchCounterValues } = this.props |
|
|
|
|
|
const { currency } = this.state |
|
|
|
|
|
|
|
|
|
|
|
if (currency !== null) { |
|
|
|
|
|
this.setState({ |
|
|
|
|
|
fetchingCounterValues: true, |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
await fetchCounterValues(currency.coinType) |
|
|
|
|
|
|
|
|
this.setState({ |
|
|
this.setState({ |
|
|
|
|
|
fetchingCounterValues: false, |
|
|
step: 'connectDevice', |
|
|
step: 'connectDevice', |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
handleClose = () => { |
|
|
handleClose = () => { |
|
|
sendEvent('msg', 'kill.process', { |
|
|
sendEvent('msg', 'kill.process', { |
|
|