mirror of
https://github.com/hanzo-labs/wallet-2.git
synced 2026-10-30 18:54:05 +00:00
62 lines
1.3 KiB
JavaScript
62 lines
1.3 KiB
JavaScript
import React from 'react'
|
|
import Router from 'next/router'
|
|
import Emitter from '../../src/emitter'
|
|
import { watch } from 'react-referential'
|
|
import { loadable } from '../../components/app/loader'
|
|
import MnemonicForm from '../../components/forms/mnemonic'
|
|
import {
|
|
getIdentity,
|
|
removeIdentity,
|
|
setEncodedPrivateKeyFromMnemonic,
|
|
} from '../../src/wallet'
|
|
|
|
@watch('mnemonicPage')
|
|
@loadable
|
|
class Account extends React.Component {
|
|
constructor(props) {
|
|
super(props)
|
|
|
|
this.emitter = new Emitter()
|
|
|
|
this.emitter.once('mnemonic:finish', (mnemonic) => {
|
|
this.setMnemonic(mnemonic)
|
|
})
|
|
|
|
let id = props.rootData.get('account.id')
|
|
let token = props.rootData.get('account.token')
|
|
let identity = getIdentity()
|
|
|
|
if ((!token && !id) || !identity) {
|
|
this.logout()
|
|
}
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
this.emitter.off('mnemonic:finish')
|
|
}
|
|
|
|
setMnemonic(mnemonic) {
|
|
setEncodedPrivateKeyFromMnemonic(mnemonic)
|
|
|
|
Router.push('/account')
|
|
}
|
|
|
|
logout() {
|
|
this.props.rootData.ref('account').clear()
|
|
removeIdentity()
|
|
Router.push('/')
|
|
}
|
|
|
|
render() {
|
|
let props = this.props
|
|
|
|
return pug`
|
|
main#account-mnemonic.hero.columns
|
|
.content.columns
|
|
MnemonicForm(emitter=this.emitter)
|
|
`
|
|
}
|
|
}
|
|
|
|
export default Account
|