on master help sign in
- WIP: Add networkSeedCache to copy network seed used in setKeys to genKeyfile view
commit223a2ddaf657eb3efc939351dacee8b3ee917a8f authorChris Johnson <chris@cjohnson.io> dateThu 21 Mar 2019, 12:34 (8 years ago) parent7ae8f22
3 files changed+48−9
src/Bridge.js+21−3 src/views/GenKeyfile.js+7−1 src/views/SetKeys.js+20−5
src/Bridge.js+21−3
@@ -12,6 +12,11 @@ import { NETWORK_NAMES } from './lib/network'
1212import { WALLET_NAMES, DEFAULT_HD_PATH } from './lib/wallet'
1313import { BRIDGE_ERROR } from './lib/error'
1414
15+// import Web3 from 'web3'
16+// import * as azimuth from 'azimuth-js'
17+// import { CONTRACT_ADDRESSES } from './lib/contracts'
18+// import { walletFromMnemonic } from './lib/wallet'
19+
1520import './style/index.css'
1621
1722class Bridge extends React.Component {
@@ -51,6 +56,7 @@ class Bridge extends React.Component {
5156 // urbit wallet-related
5257 urbitWallet: Maybe.Nothing(),
5358 authMnemonic: Maybe.Nothing(),
59+ networkSeedCache: null,
5460 // point
5561 pointCursor: Maybe.Nothing(),
5662 pointCache: {},
@@ -70,6 +76,7 @@ class Bridge extends React.Component {
7076 this.setAuthMnemonic = this.setAuthMnemonic.bind(this)
7177 this.setPointCursor = this.setPointCursor.bind(this)
7278 this.setTxnHashCursor = this.setTxnHashCursor.bind(this)
79+ this.setNetworkSeedCache = this.setNetworkSeedCache.bind(this)
7380 this.addToPointCache = this.addToPointCache.bind(this)
7481 }
7582
@@ -82,7 +89,7 @@ class Bridge extends React.Component {
8289
8390 // if (process.env.NODE_ENV === 'development') {
8491 //
85− // const socket = 'wss://localhost:8545'
92+ // const socket = 'ws://localhost:8545'
8693 // const provider = new Web3.providers.WebsocketProvider(socket)
8794 // const web3 = new Web3(provider)
8895 // const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.DEV)
@@ -92,7 +99,8 @@ class Bridge extends React.Component {
9299 //
93100 // this.setState({
94101 // routeCrumbs: Stack([
95− // ROUTE_NAMES.CREATE_GALAXY,
102+ // // ROUTE_NAMES.CREATE_GALAXY,
103+ // // ROUTE_NAMES.SHIP,
96104 // ROUTE_NAMES.SHIPS,
97105 // // ROUTE_NAMES.MNEMONIC,
98106 // ROUTE_NAMES.WALLET,
@@ -100,12 +108,13 @@ class Bridge extends React.Component {
100108 // ROUTE_NAMES.LANDING
101109 // ]),
102110 // networkType: NETWORK_NAMES.LOCAL,
111+ // pointCursor: Maybe.Just(0),
103112 // web3: Maybe.Just(web3),
104113 // contracts: Maybe.Just(contracts),
105114 // walletType: WALLET_NAMES.MNEMONIC,
106115 // wallet: walletFromMnemonic(mnemonic, hdpath),
107116 // urbitWallet: Maybe.Nothing(),
108− // authMnemonic: Maybe.Nothing()
117+ // authMnemonic: Maybe.Just('benefit crew supreme gesture quantum web media hazard theory mercy wing kitten')
109118 // })
110119 // }
111120}
@@ -146,6 +155,12 @@ class Bridge extends React.Component {
146155 }
147156 }
148157
158+ setNetworkSeedCache(networkSeed) {
159+ this.setState({
160+ networkSeedCache: networkSeed
161+ })
162+ }
163+
149164 setNetwork(web3, contracts) {
150165 this.setState({
151166 web3: web3,
@@ -202,6 +217,7 @@ class Bridge extends React.Component {
202217 wallet,
203218 urbitWallet,
204219 authMnemonic,
220+ networkSeedCache,
205221 pointCursor,
206222 pointCache,
207223 txnHashCursor,
@@ -252,6 +268,8 @@ class Bridge extends React.Component {
252268 addToPointCache={ this.addToPointCache }
253269 pointCursor={ pointCursor }
254270 pointCache={ pointCache }
271+ networkSeedCache= { networkSeedCache }
272+ setNetworkSeedCache= { this.setNetworkSeedCache }
255273 // txn
256274 setTxnHashCursor={ this.setTxnHashCursor }
257275 txnHashCursor={ txnHashCursor } />
src/views/GenKeyfile.js+7−1
@@ -1,4 +1,5 @@
11import React from 'react'
2+import Maybe from 'folktale/maybe'
23
34import { Button } from '../components/Base'
45import { RequiredInput, InnerLabel } from '../components/Base'
@@ -34,7 +35,12 @@ class GenKeyfile extends React.Component {
3435
3536 async deriveSeed() {
3637 const next = false
37− const seed = await attemptSeedDerivation(next, this.props)
38+ let seed = await attemptSeedDerivation(next, this.props)
39+
40+ if (seed.getOrElse('') === '' && this.props.networkSeedCache) {
41+ seed = Maybe.Just(this.props.networkSeedCache)
42+ }
43+
3844 this.setState({
3945 networkSeed: seed.getOrElse('')
4046 })
src/views/SetKeys.js+20−5
@@ -10,6 +10,8 @@ import { BRIDGE_ERROR } from '../lib/error'
1010import { ROUTE_NAMES } from '../lib/router'
1111import { attemptSeedDerivation } from '../lib/keys'
1212
13+
14+
1315import { WALLET_NAMES } from '../lib/wallet'
1416
1517import * as kg from '../../node_modules/urbit-key-generation/dist/index'
@@ -122,22 +124,34 @@ class SetKeys extends React.Component {
122124 })
123125 }
124126
127+ randomHex(len) {
128+ let hex = "";
129+
130+ for (var i = 0; i < len; i++) {
131+ hex = hex + ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b',
132+ 'c', 'd', 'e', 'f'][Math.floor(Math.random() * 16)]
133+ }
134+
135+ return hex;
136+ }
137+
125138 async deriveSeed() {
126139 const next = true
127− const seed = await attemptSeedDerivation(next, this.props)
140+ let seed = await attemptSeedDerivation(next, this.props)
141+
142+ if (seed.getOrElse('') === '') {
143+ seed = Maybe.Just(this.randomHex(64));
144+ }
145+
128146 this.setState({
129147 networkSeed: seed.getOrElse('')
130148 })
131149 }
132150
133−
134−
135151 handleNetworkSeedInput(networkSeed) {
136152 this.setState({ networkSeed })
137153 }
138154
139−
140−
141155 handleCreateUnsignedTxn() {
142156 const txn = this.createUnsignedTxn()
143157 this.setState({ txn })
@@ -229,6 +243,7 @@ class SetKeys extends React.Component {
229243 sendSignedTransaction(props.web3.value, state.stx)
230244 .then(sent => {
231245 props.setTxnHashCursor(sent)
246+ props.setNetworkSeedCache(this.state.networkSeed)
232247 props.popRoute()
233248 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
234249 })