@@ -1,4 +1,4 @@
1−import React, { useCallback, useEffect, useState } from 'react';
1+import React, { useCallback, useEffect, useRef, useState } from 'react';
22import { Just, Nothing } from 'folktale/maybe';
33import {
44 Grid,
@@ -39,6 +39,7 @@ import DownloadKeyfileButton from 'components/DownloadKeyfileButton';
3939import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
4040import NoticeBox from 'components/NoticeBox';
4141import { useHexInput, useCheckboxInput } from 'lib/useInputs';
42+import useKeyfileGenerator from 'lib/useKeyfileGenerator';
4243
4344const chainKeyProp = name => d =>
4445 d[name] === CURVE_ZERO_ADDR ? Nothing() : Just(d[name]);
@@ -61,19 +62,29 @@ function useSetKeys() {
6162 const _point = need.point(pointCursor);
6263 const _contracts = need.contracts(contracts);
6364
65+ const randomSeed = useRef();
66+
6467 // NOTE: nd = 'nondeterministic' (can also be a 'manual' seed)
6568 const [ndNetworkSeed, setNdNetworkSeed] = useState();
6669
70+ const {
71+ available: keyfileAvailable,
72+ bind: keyfileBind,
73+ } = useKeyfileGenerator(ndNetworkSeed);
74+
6775 const {
6876 isDefaultState,
6977 construct: _construct,
7078 unconstruct,
7179 broadcasting,
72− confirmed,
80+ confirmed: _confirmed,
7381 inputsLocked,
7482 bind,
7583 } = useEthereumTransaction(GAS_LIMITS.CONFIGURE_KEYS);
7684
85+ // only treat the transaction as confirmed once we also have keys to download
86+ const confirmed = _confirmed && keyfileAvailable;
87+
7788 // sync point details after success
7889 useEffect(() => {
7990 if (confirmed) {
@@ -98,14 +109,14 @@ function useSetKeys() {
98109 revision: networkRevision + 1,
99110 });
100111
101− return networkSeed.matchWith({
102− Nothing: () => {
103− const ndSeed = randomHex(64);
104− setNdNetworkSeed(ndSeed);
105− return ndSeed;
106− },
107− Just: p => p.value,
108− });
112+ if (Just.hasInstance(networkSeed)) {
113+ return networkSeed.value;
114+ }
115+
116+ randomSeed.current = randomSeed.current || randomHex(64);
117+ setNdNetworkSeed(randomSeed.current);
118+
119+ return randomSeed.current;
109120 }
110121 },
111122 [_point, authMnemonic, getDetails, urbitWallet, wallet]
@@ -139,6 +150,7 @@ function useSetKeys() {
139150 ndNetworkSeed,
140151 inputsLocked,
141152 bind,
153+ keyfileBind,
142154 };
143155}
144156
@@ -162,8 +174,8 @@ export default function AdminNetworkingKeys() {
162174 broadcasting,
163175 confirmed,
164176 inputsLocked,
165− ndNetworkSeed,
166177 bind,
178+ keyfileBind,
167179 } = useSetKeys();
168180
169181 const [showNetworkSeedInput, { data: showNetworkSeed }] = useCheckboxInput({
@@ -205,10 +217,10 @@ export default function AdminNetworkingKeys() {
205217 }
206218 }, [
207219 construct,
220+ unconstruct,
208221 isDiscontinuity,
209222 networkSeed,
210223 showNetworkSeed,
211− unconstruct,
212224 validDiscontinuity,
213225 validNetworkSeed,
214226 ]);
@@ -334,12 +346,7 @@ export default function AdminNetworkingKeys() {
334346 <Grid.Item full as={NoticeBox} className="mb3">
335347 You need this keyfile to authenticate with Arvo.
336348 </Grid.Item>
337− <Grid.Item
338− full
339− as={DownloadKeyfileButton}
340− solid
341− networkSeed={ndNetworkSeed}
342− />
349+ <Grid.Item full as={DownloadKeyfileButton} solid {...keyfileBind} />
343350 </>
344351 )}
345352