From 0939000f0e98f0faaf76205fed7a5c9169af13b2 Mon Sep 17 00:00:00 2001 From: Barry Gitarts Date: Sat, 17 Nov 2018 12:46:31 -0500 Subject: [PATCH] add create account and destroy account --- app/components/Home.js | 31 ++++++++++++++------------- app/components/Login.js | 43 +++++++++++++++++++++++++------------- app/utils/keyManagement.js | 1 + 3 files changed, 47 insertions(+), 28 deletions(-) diff --git a/app/components/Home.js b/app/components/Home.js index 084fc9a..61cfd67 100644 --- a/app/components/Home.js +++ b/app/components/Home.js @@ -10,19 +10,15 @@ import Login from './Login'; import { User } from '../utils/actors'; import { ChatContext } from '../context'; import { isContactCode } from '../utils/parsers'; -import { getKeyData, createVault, restoreVault } from '../utils/keyManagement'; +import { getKeyData, createVault, restoreVault, wipeVault } from '../utils/keyManagement'; import { FullScreenLoader } from './Loaders'; -const mnemonic = "example exile argue silk regular smile grass bomb merge arm assist farm"; - const typingNotificationsTimestamp = {}; const DEFAULT_CHANNEL = "mytest"; const URL = "ws://localhost:8546"; const status = new StatusJS(); -// let userPubKey = await status.getPublicKey(); - type Props = {}; export default class Home extends Component { @@ -37,12 +33,11 @@ export default class Home extends Component { currentChannel: DEFAULT_CHANNEL, usersTyping: { [DEFAULT_CHANNEL]: [] }, identity: {}, - loading: false + loading: false, + keyStore: getKeyData() }; - componentDidMount() { - //this.setupKeyringController(); - } + componentDidMount() {} componentWillUnmount() { clearInterval(this.pingInterval); @@ -71,9 +66,9 @@ export default class Home extends Component { }, 5 * 1000) } - setupKeyringController = async (password) => { + setupKeyringController = async (password, mnemonic) => { this.setState({ loading: true }); - const keyStore = getKeyData(); + const { keyStore } = this.state; if (!keyStore) { this.keyringController = await createVault(password, mnemonic); } else { @@ -83,6 +78,11 @@ export default class Home extends Component { this.connect(accounts[0]); } + wipeKeyStore = () => { + wipeVault(); + this.setState({ keyStore: null }); + } + setActiveChannel = channelName => { this.setState({ currentChannel: channelName, }); } @@ -237,9 +237,9 @@ export default class Home extends Component { } render() { - const { messages, channels, currentChannel, users, usersTyping, identity, loading } = this.state; + const { messages, channels, currentChannel, users, usersTyping, identity, loading, keyStore } = this.state; const channelUsers = channels[currentChannel].users; - const { setActiveChannel, setupKeyringController } = this; + const { setActiveChannel, setupKeyringController, wipeKeyStore } = this; const chatContext = { setActiveChannel, currentChannel, users, channels }; console.log(identity) @@ -249,7 +249,10 @@ export default class Home extends Component { ? : {!identity.publicKey - ? + ? : {!isNil(channels) && ( +const Login = ({ setupKeyringController, keyStore, wipeKeyStore }) => ( ( style={{ height: '100%' }} > { - const { password } = values; - setupKeyringController(password); + const { password, seed } = values; + setupKeyringController(password, seed); resetForm(); }} > {({ - values, - errors, - touched, - handleChange, - handleBlur, - handleSubmit + values, + errors, + touched, + handleChange, + handleBlur, + handleSubmit }) => (
+ {isNull(keyStore) && } ( onChange={handleChange} /> {errors.password && touched.password && errors.password} - + } )}
@@ -59,7 +73,8 @@ const Login = ({ setupKeyringController }) => ( ); Login.propTypes = { - setupKeyringController: func.isRequired + setupKeyringController: func.isRequired, + wipeKeyStore: func.isRequired }; export default Login; diff --git a/app/utils/keyManagement.js b/app/utils/keyManagement.js index f270f98..7f0ed6c 100644 --- a/app/utils/keyManagement.js +++ b/app/utils/keyManagement.js @@ -23,3 +23,4 @@ export const getKeyData = () => store.get('vault'); export const storeKeyData = vault => { store.set('vault', vault); } +export const wipeVault = () => { store.set('vault', null); }