on master help sign in
- WIP: Add networkSeedCache to copy network seed used in setKeys to genKeyfile view
223a2ddChris Johnson
src/Bridge.js+21−3
@@ -12,6 +12,11 @@ import { NETWORK_NAMES } from './lib/network'
12import { WALLET_NAMES, DEFAULT_HD_PATH } from './lib/wallet'
12import { WALLET_NAMES, DEFAULT_HD_PATH } from './lib/wallet'
13import { BRIDGE_ERROR } from './lib/error'
13import { BRIDGE_ERROR } from './lib/error'
14
14
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+
15import './style/index.css'
20import './style/index.css'
16
21
17class Bridge extends React.Component {
22class Bridge extends React.Component {
@@ -51,6 +56,7 @@ class Bridge extends React.Component {
51 // urbit wallet-related
56 // urbit wallet-related
52 urbitWallet: Maybe.Nothing(),
57 urbitWallet: Maybe.Nothing(),
53 authMnemonic: Maybe.Nothing(),
58 authMnemonic: Maybe.Nothing(),
59+ networkSeedCache: null,
54 // point
60 // point
55 pointCursor: Maybe.Nothing(),
61 pointCursor: Maybe.Nothing(),
56 pointCache: {},
62 pointCache: {},
@@ -70,6 +76,7 @@ class Bridge extends React.Component {
70 this.setAuthMnemonic = this.setAuthMnemonic.bind(this)
76 this.setAuthMnemonic = this.setAuthMnemonic.bind(this)
71 this.setPointCursor = this.setPointCursor.bind(this)
77 this.setPointCursor = this.setPointCursor.bind(this)
72 this.setTxnHashCursor = this.setTxnHashCursor.bind(this)
78 this.setTxnHashCursor = this.setTxnHashCursor.bind(this)
79+ this.setNetworkSeedCache = this.setNetworkSeedCache.bind(this)
73 this.addToPointCache = this.addToPointCache.bind(this)
80 this.addToPointCache = this.addToPointCache.bind(this)
74 }
81 }
75
82
@@ -82,7 +89,7 @@ class Bridge extends React.Component {
82
89
83 // if (process.env.NODE_ENV === 'development') {
90 // if (process.env.NODE_ENV === 'development') {
84 //
91 //
85− // const socket = 'wss://localhost:8545'
92+ // const socket = 'ws://localhost:8545'
86 // const provider = new Web3.providers.WebsocketProvider(socket)
93 // const provider = new Web3.providers.WebsocketProvider(socket)
87 // const web3 = new Web3(provider)
94 // const web3 = new Web3(provider)
88 // const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.DEV)
95 // const contracts = azimuth.initContracts(web3, CONTRACT_ADDRESSES.DEV)
@@ -92,7 +99,8 @@ class Bridge extends React.Component {
92 //
99 //
93 // this.setState({
100 // this.setState({
94 // routeCrumbs: Stack([
101 // routeCrumbs: Stack([
95− // ROUTE_NAMES.CREATE_GALAXY,
102+ // // ROUTE_NAMES.CREATE_GALAXY,
103+ // // ROUTE_NAMES.SHIP,
96 // ROUTE_NAMES.SHIPS,
104 // ROUTE_NAMES.SHIPS,
97 // // ROUTE_NAMES.MNEMONIC,
105 // // ROUTE_NAMES.MNEMONIC,
98 // ROUTE_NAMES.WALLET,
106 // ROUTE_NAMES.WALLET,
@@ -100,12 +108,13 @@ class Bridge extends React.Component {
100 // ROUTE_NAMES.LANDING
108 // ROUTE_NAMES.LANDING
101 // ]),
109 // ]),
102 // networkType: NETWORK_NAMES.LOCAL,
110 // networkType: NETWORK_NAMES.LOCAL,
111+ // pointCursor: Maybe.Just(0),
103 // web3: Maybe.Just(web3),
112 // web3: Maybe.Just(web3),
104 // contracts: Maybe.Just(contracts),
113 // contracts: Maybe.Just(contracts),
105 // walletType: WALLET_NAMES.MNEMONIC,
114 // walletType: WALLET_NAMES.MNEMONIC,
106 // wallet: walletFromMnemonic(mnemonic, hdpath),
115 // wallet: walletFromMnemonic(mnemonic, hdpath),
107 // urbitWallet: Maybe.Nothing(),
116 // urbitWallet: Maybe.Nothing(),
108− // authMnemonic: Maybe.Nothing()
117+ // authMnemonic: Maybe.Just('benefit crew supreme gesture quantum web media hazard theory mercy wing kitten')
109 // })
118 // })
110 // }
119 // }
111}
120}
@@ -146,6 +155,12 @@ class Bridge extends React.Component {
146 }
155 }
147 }
156 }
148
157
158+ setNetworkSeedCache(networkSeed) {
159+ this.setState({
160+ networkSeedCache: networkSeed
161+ })
162+ }
163+
149 setNetwork(web3, contracts) {
164 setNetwork(web3, contracts) {
150 this.setState({
165 this.setState({
151 web3: web3,
166 web3: web3,
@@ -202,6 +217,7 @@ class Bridge extends React.Component {
202 wallet,
217 wallet,
203 urbitWallet,
218 urbitWallet,
204 authMnemonic,
219 authMnemonic,
220+ networkSeedCache,
205 pointCursor,
221 pointCursor,
206 pointCache,
222 pointCache,
207 txnHashCursor,
223 txnHashCursor,
@@ -252,6 +268,8 @@ class Bridge extends React.Component {
252 addToPointCache={ this.addToPointCache }
268 addToPointCache={ this.addToPointCache }
253 pointCursor={ pointCursor }
269 pointCursor={ pointCursor }
254 pointCache={ pointCache }
270 pointCache={ pointCache }
271+ networkSeedCache= { networkSeedCache }
272+ setNetworkSeedCache= { this.setNetworkSeedCache }
255 // txn
273 // txn
256 setTxnHashCursor={ this.setTxnHashCursor }
274 setTxnHashCursor={ this.setTxnHashCursor }
257 txnHashCursor={ txnHashCursor } />
275 txnHashCursor={ txnHashCursor } />
src/views/GenKeyfile.js+7−1
@@ -1,4 +1,5 @@
1import React from 'react'
1import React from 'react'
2+import Maybe from 'folktale/maybe'
2
3
3import { Button } from '../components/Base'
4import { Button } from '../components/Base'
4import { RequiredInput, InnerLabel } from '../components/Base'
5import { RequiredInput, InnerLabel } from '../components/Base'
@@ -34,7 +35,12 @@ class GenKeyfile extends React.Component {
34
35
35 async deriveSeed() {
36 async deriveSeed() {
36 const next = false
37 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+
38 this.setState({
44 this.setState({
39 networkSeed: seed.getOrElse('')
45 networkSeed: seed.getOrElse('')
40 })
46 })
src/views/SetKeys.js+20−5
@@ -10,6 +10,8 @@ import { BRIDGE_ERROR } from '../lib/error'
10import { ROUTE_NAMES } from '../lib/router'
10import { ROUTE_NAMES } from '../lib/router'
11import { attemptSeedDerivation } from '../lib/keys'
11import { attemptSeedDerivation } from '../lib/keys'
12
12
13+
14+
13import { WALLET_NAMES } from '../lib/wallet'
15import { WALLET_NAMES } from '../lib/wallet'
14
16
15import * as kg from '../../node_modules/urbit-key-generation/dist/index'
17import * as kg from '../../node_modules/urbit-key-generation/dist/index'
@@ -122,22 +124,34 @@ class SetKeys extends React.Component {
122 })
124 })
123 }
125 }
124
126
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+
125 async deriveSeed() {
138 async deriveSeed() {
126 const next = true
139 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+
128 this.setState({
146 this.setState({
129 networkSeed: seed.getOrElse('')
147 networkSeed: seed.getOrElse('')
130 })
148 })
131 }
149 }
132
150
133−
134−
135 handleNetworkSeedInput(networkSeed) {
151 handleNetworkSeedInput(networkSeed) {
136 this.setState({ networkSeed })
152 this.setState({ networkSeed })
137 }
153 }
138
154
139−
140−
141 handleCreateUnsignedTxn() {
155 handleCreateUnsignedTxn() {
142 const txn = this.createUnsignedTxn()
156 const txn = this.createUnsignedTxn()
143 this.setState({ txn })
157 this.setState({ txn })
@@ -229,6 +243,7 @@ class SetKeys extends React.Component {
229 sendSignedTransaction(props.web3.value, state.stx)
243 sendSignedTransaction(props.web3.value, state.stx)
230 .then(sent => {
244 .then(sent => {
231 props.setTxnHashCursor(sent)
245 props.setTxnHashCursor(sent)
246+ props.setNetworkSeedCache(this.state.networkSeed)
232 props.popRoute()
247 props.popRoute()
233 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
248 props.pushRoute(ROUTE_NAMES.SENT_TRANSACTION)
234 })
249 })