+
+
Login using the Ledger Nano S:
+
-
-
{hardwareDeviceInfo}
-
{hardwarePublicKeyInfo}
+ {this.renderDeviceInfo()}
+ {this.renderStatus()}
+ {this.renderError()}
)
}
+
+ renderDeviceInfo () {
+ const { deviceInfo } = this.props
+
+ if (deviceInfo) {
+ return
Found USB ${deviceInfo.manufacturer} ${deviceInfo.product}
+ } else {
+ return
Looking for USB Devices. Please plugin your device and login.
+ }
+ }
+
+ renderStatus () {
+ const { publicKey } = this.props
+
+ if (publicKey) {
+ return
Success. NEO app found on hardware device. Click button above to login.
+ }
+ }
+
+ renderError () {
+ const { error } = this.props
+
+ if (error) {
+ return
{error}
+ }
+ }
+
+ canLogin () {
+ return !!this.props.publicKey
+ }
}
diff --git a/app/containers/LoginLedgerNanoS/index.js b/app/containers/LoginLedgerNanoS/index.js
index 20633572c..93efeb9a5 100644
--- a/app/containers/LoginLedgerNanoS/index.js
+++ b/app/containers/LoginLedgerNanoS/index.js
@@ -1,29 +1,29 @@
// @flow
-import { connect } from 'react-redux'
-import { bindActionCreators } from 'redux'
-
-import {
- ledgerNanoSGetLogin,
- ledgerNanoSGetInfoAsync,
- getPublicKey,
- getHardwareDeviceInfo,
- getHardwarePublicKeyInfo
-} from '../../modules/account'
+import { compose } from 'recompose'
import LoginLedgerNanoS from './LoginLedgerNanoS'
+import withData from '../../hocs/api/withData'
+import withError from '../../hocs/api/withError'
+import withFetch from '../../hocs/api/withFetch'
+import withActions from '../../hocs/api/withActions'
+import ledgerActions from '../../actions/ledgerActions'
+import { ledgerLoginActions } from '../../actions/accountActions'
-const mapStateToProps = (state: Object) => ({
- publicKey: getPublicKey(state),
- hardwareDeviceInfo: getHardwareDeviceInfo(state),
- hardwarePublicKeyInfo: getHardwarePublicKeyInfo(state)
+const mapLedgerActionsToProps = (actions) => ({
+ connect: () => ledgerActions.request()
})
-const actionCreators = {
- ledgerNanoSGetInfoAsync,
- ledgerNanoSGetLogin
-}
+const mapAccountActionsToProps = (actions) => ({
+ login: (publicKey, signingFunction) => ledgerLoginActions.request({ publicKey, signingFunction })
+})
-const mapDispatchToProps = dispatch =>
- bindActionCreators(actionCreators, dispatch)
+const mapLedgerDataToProps = ({ deviceInfo, publicKey }) => ({ deviceInfo, publicKey })
+const mapLedgerErrorToProps = ({ deviceInfo, publicKey }) => ({ error: deviceInfo || publicKey })
-export default connect(mapStateToProps, mapDispatchToProps)(LoginLedgerNanoS)
+export default compose(
+ withFetch(ledgerActions),
+ withActions(ledgerActions, mapLedgerActionsToProps),
+ withActions(ledgerLoginActions, mapAccountActionsToProps),
+ withData(ledgerActions, mapLedgerDataToProps),
+ withError(ledgerActions, mapLedgerErrorToProps)
+)(LoginLedgerNanoS)
diff --git a/app/containers/LoginLocalStorage/LoginLocalStorage.jsx b/app/containers/LoginLocalStorage/LoginLocalStorage.jsx
index c401789c6..4e4a19d3d 100644
--- a/app/containers/LoginLocalStorage/LoginLocalStorage.jsx
+++ b/app/containers/LoginLocalStorage/LoginLocalStorage.jsx
@@ -1,6 +1,5 @@
// @flow
import React, { Component } from 'react'
-import storage from 'electron-json-storage'
import { map } from 'lodash'
import PasswordField from '../../components/PasswordField'
@@ -11,9 +10,7 @@ import styles from './LoginLocalStorage.scss'
import loginStyles from '../../styles/login.scss'
type Props = {
- setAccounts: Function,
loginNep2: Function,
- history: Object,
accounts: Object
}
@@ -28,30 +25,23 @@ export default class LoginLocalStorage extends Component
{
encryptedWIF: ''
}
- componentDidMount () {
- const { setAccounts } = this.props
- // eslint-disable-next-line
- storage.get('userWallet', (error, data) => {
- setAccounts(data.accounts)
- })
- }
-
render () {
- const { accounts, history, loginNep2 } = this.props
+ const { accounts } = this.props
const { passphrase, encryptedWIF } = this.state
- const loginButtonDisabled = Object.keys(accounts).length === 0 || encryptedWIF === '' || passphrase === ''
return (
Login using a saved wallet:
-
)
}
+
+ handleSubmit = (event: Object) => {
+ const { loginNep2 } = this.props
+ const { passphrase, encryptedWIF } = this.state
+
+ event.preventDefault()
+ loginNep2(passphrase, encryptedWIF)
+ }
+
+ isValid = () => {
+ return this.state.encryptedWIF !== '' && this.state.passphrase !== ''
+ }
}
diff --git a/app/containers/LoginLocalStorage/index.js b/app/containers/LoginLocalStorage/index.js
index f910fa04c..869421f92 100644
--- a/app/containers/LoginLocalStorage/index.js
+++ b/app/containers/LoginLocalStorage/index.js
@@ -1,20 +1,24 @@
// @flow
-import { connect } from 'react-redux'
-import { bindActionCreators } from 'redux'
+import { compose } from 'recompose'
-import { setAccounts, getAccounts, loginNep2 } from '../../modules/account'
+import withData from '../../hocs/api/withData'
+import withActions from '../../hocs/api/withActions'
+import withFailureNotification from '../../hocs/withFailureNotification'
+import accountsActions from '../../actions/accountsActions'
+import { nep2LoginActions } from '../../actions/accountActions'
import LoginLocalStorage from './LoginLocalStorage'
-const mapStateToProps = (state: Object) => ({
- accounts: getAccounts(state)
+const mapAccountsDataToProps = (accounts) => ({
+ accounts
})
-const actionCreators = {
- setAccounts,
- loginNep2
-}
-
-const mapDispatchToProps = dispatch => bindActionCreators(actionCreators, dispatch)
+const mapActionsToProps = (actions) => ({
+ loginNep2: (passphrase, encryptedWIF) => actions.request({ passphrase, encryptedWIF })
+})
-export default connect(mapStateToProps, mapDispatchToProps)(LoginLocalStorage)
+export default compose(
+ withData(accountsActions, mapAccountsDataToProps),
+ withActions(nep2LoginActions, mapActionsToProps),
+ withFailureNotification(nep2LoginActions)
+)(LoginLocalStorage)
diff --git a/app/containers/LoginNep2/index.js b/app/containers/LoginNep2/index.js
index 13e58d545..28a3158be 100644
--- a/app/containers/LoginNep2/index.js
+++ b/app/containers/LoginNep2/index.js
@@ -1,15 +1,16 @@
// @flow
-import { connect } from 'react-redux'
-import { bindActionCreators } from 'redux'
-
-import { loginNep2 } from '../../modules/account'
+import { compose } from 'recompose'
import LoginNep2 from './LoginNep2'
+import withActions from '../../hocs/api/withActions'
+import withFailureNotification from '../../hocs/withFailureNotification'
+import { nep2LoginActions } from '../../actions/accountActions'
-const actionCreators = {
- loginNep2
-}
-
-const mapDispatchToProps = dispatch => bindActionCreators(actionCreators, dispatch)
+const mapActionsToProps = (actions) => ({
+ loginNep2: (passphrase, encryptedWIF) => actions.request({ passphrase, encryptedWIF })
+})
-export default connect(null, mapDispatchToProps)(LoginNep2)
+export default compose(
+ withActions(nep2LoginActions, mapActionsToProps),
+ withFailureNotification(nep2LoginActions)
+)(LoginNep2)
diff --git a/app/containers/LoginPrivateKey/LoginPrivateKey.jsx b/app/containers/LoginPrivateKey/LoginPrivateKey.jsx
index f3c138c0b..cec65c614 100644
--- a/app/containers/LoginPrivateKey/LoginPrivateKey.jsx
+++ b/app/containers/LoginPrivateKey/LoginPrivateKey.jsx
@@ -8,8 +8,7 @@ import Button from '../../components/Button'
import loginStyles from '../../styles/login.scss'
type Props = {
- loginWithPrivateKey: Function,
- history: Object
+ loginWithPrivateKey: Function
}
type State = {
@@ -22,14 +21,14 @@ export default class LoginPrivateKey extends Component {
}
render () {
- const { history, loginWithPrivateKey } = this.props
+ const { loginWithPrivateKey } = this.props
const { wif } = this.state
const loginButtonDisabled = wif === ''
return (
Login using a private key:
-