on master help sign in
Misc refactoring, renaming and cleanup
cc52956Fang
src/lib/invite.js+9−13
@@ -101,7 +101,7 @@ async function claimPointFromInvite({
101 web3,
101 web3,
102 contracts,
102 contracts,
103 onUpdate,
103 onUpdate,
104− transferEth,
104+ transferEth = false,
105}) {
105}) {
106 const askForFunding = (address, minBalance, balance) =>
106 const askForFunding = (address, minBalance, balance) =>
107 onUpdate({
107 onUpdate({
@@ -122,11 +122,12 @@ async function claimPointFromInvite({
122
122
123 // transfer to invite wallet, so it can configure
123 // transfer to invite wallet, so it can configure
124 //NOTE doing this in the invite wallet instead of the final wallet makes
124 //NOTE doing this in the invite wallet instead of the final wallet makes
125− // failure cases "solvable" by just telling the user to fully retry
125+ // failure cases "solvable" by just telling the user to fully retry.
126+ // in other words, the invite flow is effectively idempotent.
126
127
127 //TODO no harm done if we already owned it, but should still get a bool arg
128 //TODO no harm done if we already owned it, but should still get a bool arg
128 // for skipping this, if it isn't too big a burden for callers
129 // for skipping this, if it isn't too big a burden for callers
129− let transferTmpTx = azimuth.ecliptic.transferPoint(
130+ const transferTmpTx = azimuth.ecliptic.transferPoint(
130 contracts,
131 contracts,
131 point,
132 point,
132 inviteAddress,
133 inviteAddress,
@@ -153,7 +154,7 @@ async function claimPointFromInvite({
153
154
154 const networkKeys = kg.deriveNetworkKeys(networkSeed);
155 const networkKeys = kg.deriveNetworkKeys(networkSeed);
155
156
156− let keysTx = azimuth.ecliptic.configureKeys(
157+ const keysTx = azimuth.ecliptic.configureKeys(
157 contracts,
158 contracts,
158 point,
159 point,
159 addHexPrefix(networkKeys.crypt.public),
160 addHexPrefix(networkKeys.crypt.public),
@@ -165,7 +166,7 @@ async function claimPointFromInvite({
165
166
166 // configure management proxy
167 // configure management proxy
167
168
168− let managementTx = azimuth.ecliptic.setManagementProxy(
169+ const managementTx = azimuth.ecliptic.setManagementProxy(
169 contracts,
170 contracts,
170 point,
171 point,
171 wallet.management.keys.address
172 wallet.management.keys.address
@@ -178,7 +179,7 @@ async function claimPointFromInvite({
178 if (
179 if (
179 azimuth.azimuth.getPointSize(point) !== azimuth.azimuth.PointSize.Planet
180 azimuth.azimuth.getPointSize(point) !== azimuth.azimuth.PointSize.Planet
180 ) {
181 ) {
181− let spawnTx = azimuth.ecliptic.setSpawnProxy(
182+ const spawnTx = azimuth.ecliptic.setSpawnProxy(
182 contracts,
183 contracts,
183 point,
184 point,
184 wallet.spawn.keys.address
185 wallet.spawn.keys.address
@@ -189,7 +190,7 @@ async function claimPointFromInvite({
189 if (
190 if (
190 azimuth.azimuth.getPointSize(point) === azimuth.azimuth.PointSize.Galaxy
191 azimuth.azimuth.getPointSize(point) === azimuth.azimuth.PointSize.Galaxy
191 ) {
192 ) {
192− let votingTx = azimuth.ecliptic.setVotingProxy(
193+ const votingTx = azimuth.ecliptic.setVotingProxy(
193 contracts,
194 contracts,
194 point,
195 point,
195 wallet.voting.keys.address
196 wallet.voting.keys.address
@@ -201,7 +202,7 @@ async function claimPointFromInvite({
201
202
202 // transfer configured point to user's new wallet
203 // transfer configured point to user's new wallet
203
204
204− let transferFinalTx = azimuth.ecliptic.transferPoint(
205+ const transferFinalTx = azimuth.ecliptic.transferPoint(
205 contracts,
206 contracts,
206 point,
207 point,
207 wallet.ownership.keys.address,
208 wallet.ownership.keys.address,
@@ -250,7 +251,6 @@ async function claimPointFromInvite({
250 askForFunding,
251 askForFunding,
251 gotFunding
252 gotFunding
252 );
253 );
253− console.log('used tank', usedTank);
254
254
255 //
255 //
256 // sending and awaiting transactions
256 // sending and awaiting transactions
@@ -258,9 +258,7 @@ async function claimPointFromInvite({
258
258
259 progress(TRANSACTION_STATES.CLAIMING);
259 progress(TRANSACTION_STATES.CLAIMING);
260
260
261− console.log('sending txpairs', txPairs.length);
262 await sendAndAwaitConfirm(web3, txPairs.map(p => Just(p.signed)), usedTank);
261 await sendAndAwaitConfirm(web3, txPairs.map(p => Just(p.signed)), usedTank);
263− console.log('all done');
264
262
265 //
263 //
266 // move leftover eth
264 // move leftover eth
@@ -275,7 +273,6 @@ async function claimPointFromInvite({
275 const sendEthCost = gasPrice * gasLimit;
273 const sendEthCost = gasPrice * gasLimit;
276 if (transferEth && balance > sendEthCost) {
274 if (transferEth && balance > sendEthCost) {
277 const value = balance - sendEthCost;
275 const value = balance - sendEthCost;
278− console.log('sending', value);
279 const tx = {
276 const tx = {
280 to: wallet.ownership.keys.address,
277 to: wallet.ownership.keys.address,
281 value: value,
278 value: value,
@@ -289,7 +286,6 @@ async function claimPointFromInvite({
289 web3.eth.sendSignedTransaction(rawTx).catch(err => {
286 web3.eth.sendSignedTransaction(rawTx).catch(err => {
290 console.log('error sending value tx, who cares', err);
287 console.log('error sending value tx, who cares', err);
291 });
288 });
292− console.log('sent old balance');
293 }
289 }
294
290
295 progress(TRANSACTION_STATES.DONE);
291 progress(TRANSACTION_STATES.DONE);
src/views/Activate/ActivatePassport.js−1
@@ -1,6 +1,5 @@
1import React, { useMemo } from 'react';
1import React, { useMemo } from 'react';
2import cn from 'classnames';
2import cn from 'classnames';
3−import Maybe from 'folktale/maybe';
4import { Grid } from 'indigo-react';
3import { Grid } from 'indigo-react';
5
4
6import { LocalRouterProvider, useLocalRouter } from 'lib/LocalRouter';
5import { LocalRouterProvider, useLocalRouter } from 'lib/LocalRouter';
src/views/Admin.js+2−2
@@ -23,7 +23,7 @@ export default function Admin() {
23
23
24 const point = need.point(pointCursor);
24 const point = need.point(pointCursor);
25 const pointDetails = need.fromPointCache(pointCache, point);
25 const pointDetails = need.fromPointCache(pointCache, point);
26− const userAddress = need.wallet(wallet).address;
26+ const address = need.addressFromWallet(wallet);
27
27
28 const goRedownload = useCallback(() => history.push(ROUTE_NAMES.REDOWNLOAD), [
28 const goRedownload = useCallback(() => history.push(ROUTE_NAMES.REDOWNLOAD), [
29 history,
29 history,
@@ -42,7 +42,7 @@ export default function Admin() {
42 ]);
42 ]);
43
43
44 const canDownloadPassport = Just.hasInstance(urbitWallet);
44 const canDownloadPassport = Just.hasInstance(urbitWallet);
45− const isOwner = eqAddr(userAddress, pointDetails.owner);
45+ const isOwner = eqAddr(address, pointDetails.owner);
46
46
47 return (
47 return (
48 <View>
48 <View>
src/views/Permissions.js+3−15
@@ -4,14 +4,10 @@ import * as need from 'lib/need';
4import { azimuth } from 'azimuth-js';
4import { azimuth } from 'azimuth-js';
5import { Grid } from 'indigo-react';
5import { Grid } from 'indigo-react';
6
6
7−import { P } from 'indigo-react';
8import View from 'components/View';
7import View from 'components/View';
9import { ForwardButton } from 'components/Buttons';
8import { ForwardButton } from 'components/Buttons';
10import FooterButton from 'components/FooterButton';
9import FooterButton from 'components/FooterButton';
11−import Blinky, {
12− LOADING_CHARACTER,
13− INTERSTITIAL_CHARACTER,
14−} from 'components/Blinky';
10+import { matchBlinky } from 'components/Blinky';
15
11
16import { ROUTE_NAMES } from 'lib/routeNames';
12import { ROUTE_NAMES } from 'lib/routeNames';
17import { eqAddr } from 'lib/wallet';
13import { eqAddr } from 'lib/wallet';
@@ -122,22 +118,14 @@ export default function Permissions() {
122 ) : (
118 ) : (
123 <>
119 <>
124 {`Revision #${pointDetails.keyRevisionNumber}, since `}
120 {`Revision #${pointDetails.keyRevisionNumber}, since `}
125− {Just.hasInstance(rekeyDate) ? (
126− rekeyDate.value
121+ {matchBlinky(rekeyDate)}
127− ) : (
128− <Blinky a={LOADING_CHARACTER} b={INTERSTITIAL_CHARACTER} delayed />
129− )}
130 </>
122 </>
131 );
123 );
132
124
133 return (
125 return (
134 <View>
126 <View>
135 <Grid className="pt2">
127 <Grid className="pt2">
136− <Grid.Item
137− full
138− as={ForwardButton}
139− disabled="true"
140− detail={pointDetails.owner}>
128+ <Grid.Item full as={ForwardButton} disabled detail={pointDetails.owner}>
141 Ownership address
129 Ownership address
142 </Grid.Item>
130 </Grid.Item>
143 {proxyAction(
131 {proxyAction(
src/views/Redownload.js+16−12
@@ -23,24 +23,28 @@ export default function Redownload() {
23 downloadWallet(paper.value);
23 downloadWallet(paper.value);
24 };
24 };
25
25
26− const paperRenderer = Just.hasInstance(paper) ? null : (
26+ const paperRenderer = paper.matchWith({
27+ Nothing: () => null,
28+ Just: p => (
27− <PaperRenderer
29+ <PaperRenderer
28− point={point}
30+ point={point}
29− wallet={urbitWallet.value}
31+ wallet={urbitWallet.value}
30− callback={paper => {
32+ callback={paper => {
31− setPaper(Just(paper));
33+ setPaper(Just(paper));
32− }}
34+ }}
33− />
35+ />
36+ ),
34− );
37+ });
35
38
36 return (
39 return (
37 <View>
40 <View>
38 <DownloadButton
41 <DownloadButton
39 disabled={Nothing.hasInstance(paper)}
42 disabled={Nothing.hasInstance(paper)}
40 onClick={doDownload}>
43 onClick={doDownload}>
41− {Nothing.hasInstance(paper)
44+ {paper.matchWith({
42− ? 'Printing and folding...'
45+ Nothing: () => 'Printing and folding...',
43− : 'Download paper wallet'}
46+ Just: _ => 'Download paper wallet',
47+ })}
44 </DownloadButton>
48 </DownloadButton>
45 {paperRenderer}
49 {paperRenderer}
46 </View>
50 </View>
src/views/Reticket.js+7−9
@@ -20,28 +20,28 @@ import Download from './Reticket/Download';
20import Verify from './Reticket/Verify';
20import Verify from './Reticket/Verify';
21import DoReticket from './Reticket/DoReticket';
21import DoReticket from './Reticket/DoReticket';
22
22
23−const STEP_NAMES = {
23+const NAMES = {
24 CONFIRM: 'CONFIRM',
24 CONFIRM: 'CONFIRM',
25 DOWNLOAD: 'DOWNLOAD',
25 DOWNLOAD: 'DOWNLOAD',
26 VERIFY: 'VERIFY',
26 VERIFY: 'VERIFY',
27 RETICKET: 'RETICKET',
27 RETICKET: 'RETICKET',
28};
28};
29
29
30−const STEP_VIEWS = {
30+const VIEWS = {
31 CONFIRM: Confirm,
31 CONFIRM: Confirm,
32 DOWNLOAD: Download,
32 DOWNLOAD: Download,
33 VERIFY: Verify,
33 VERIFY: Verify,
34 RETICKET: DoReticket,
34 RETICKET: DoReticket,
35};
35};
36
36
37−const STEP_MAX = size(STEP_NAMES);
37+const STEP_MAX = size(NAMES);
38
38
39export default function Reticket() {
39export default function Reticket() {
40 const history = useHistory();
40 const history = useHistory();
41 const { Route, ...innerRouter } = useRouter({
41 const { Route, ...innerRouter } = useRouter({
42− names: STEP_NAMES,
42+ names: NAMES,
43− views: STEP_VIEWS,
43+ views: VIEWS,
44− initialRoutes: [{ key: STEP_NAMES.CONFIRM }],
44+ initialRoutes: [{ key: NAMES.CONFIRM }],
45 });
45 });
46 const { pointCursor } = usePointCursor();
46 const { pointCursor } = usePointCursor();
47 const point = need.point(pointCursor);
47 const point = need.point(pointCursor);
@@ -73,8 +73,7 @@ export default function Reticket() {
73 {
73 {
74 text: name,
74 text: name,
75 action: () => {
75 action: () => {
76− history.pop();
77− return history.pop();
76+ return history.pop(2);
78 },
77 },
79 },
78 },
80 {
79 {
@@ -86,7 +85,6 @@ export default function Reticket() {
86 <MiniBackButton onClick={innerRouter.pop} />
85 <MiniBackButton onClick={innerRouter.pop} />
87 Step {stepNumber} of {STEP_MAX}
86 Step {stepNumber} of {STEP_MAX}
88 <Route
87 <Route
89− STEP_NAMES={STEP_NAMES}
90 newWallet={newWallet}
88 newWallet={newWallet}
91 //
89 //
92 storeNewWallet={storeNewWallet}
90 storeNewWallet={storeNewWallet}
src/views/Reticket/Confirm.js+16−13
@@ -14,8 +14,8 @@ import { useLocalRouter } from 'lib/LocalRouter';
14
14
15import { isDevelopment } from 'lib/flags';
15import { isDevelopment } from 'lib/flags';
16
16
17−export default function Confirm({ STEP_NAMES, newWallet, storeNewWallet }) {
17+export default function Confirm({ newWallet, storeNewWallet }) {
18− const { push } = useLocalRouter();
18+ const { push, names } = useLocalRouter();
19 const { pointCursor } = usePointCursor();
19 const { pointCursor } = usePointCursor();
20 const point = need.point(pointCursor);
20 const point = need.point(pointCursor);
21
21
@@ -33,17 +33,20 @@ export default function Confirm({ STEP_NAMES, newWallet, storeNewWallet }) {
33 })();
33 })();
34 });
34 });
35
35
36− const next = useCallback(() => push(STEP_NAMES.DOWNLOAD), [push, STEP_NAMES]);
36+ const next = useCallback(() => push(names.DOWNLOAD), [push, names]);
37−
37+
38− const paperRenderer = Nothing.hasInstance(generatedWallet) ? null : (
38+ const paperRenderer = generatedWallet.matchWith({
39+ Nothing: () => null,
40+ Just: gw => (
39− <PaperRenderer
41+ <PaperRenderer
40− point={point}
42+ point={point}
41− wallet={generatedWallet.value}
43+ wallet={gw.value}
42− callback={paper => {
44+ callback={paper => {
43− storeNewWallet(generatedWallet.value, paper);
45+ storeNewWallet(gw.value, paper);
44− }}
46+ }}
45− />
47+ />
48+ ),
46− );
49+ });
47
50
48 return (
51 return (
49 <View>
52 <View>
src/views/Reticket/Download.js+3−3
@@ -7,8 +7,8 @@ import { ForwardButton, DownloadButton } from 'components/Buttons';
7import { useLocalRouter } from 'lib/LocalRouter';
7import { useLocalRouter } from 'lib/LocalRouter';
8import { downloadWallet } from 'lib/invite';
8import { downloadWallet } from 'lib/invite';
9
9
10−export default function Download({ STEP_NAMES, newWallet }) {
10+export default function Download({ newWallet }) {
11− const { push } = useLocalRouter();
11+ const { push, names } = useLocalRouter();
12
12
13 const [hasDownloaded, setHasDownloaded] = useState(false);
13 const [hasDownloaded, setHasDownloaded] = useState(false);
14
14
@@ -17,7 +17,7 @@ export default function Download({ STEP_NAMES, newWallet }) {
17 setHasDownloaded(true);
17 setHasDownloaded(true);
18 };
18 };
19
19
20− const next = useCallback(() => push(STEP_NAMES.VERIFY), [push, STEP_NAMES]);
20+ const next = useCallback(() => push(names.VERIFY), [push, names]);
21
21
22 return (
22 return (
23 <View>
23 <View>
src/views/Reticket/Verify.js+4−4
@@ -1,5 +1,5 @@
1import React, { useCallback, useMemo } from 'react';
1import React, { useCallback, useMemo } from 'react';
2−import { Input, AccessoryIcon } from 'indigo-react';
2+import { Input } from 'indigo-react';
3
3
4import View from 'components/View';
4import View from 'components/View';
5import { useTicketInput } from 'components/Inputs';
5import { useTicketInput } from 'components/Inputs';
@@ -11,8 +11,8 @@ import { validateExactly } from 'lib/validators';
11const STUB_VERIFY_TICKET = process.env.NODE_ENV === 'development';
11const STUB_VERIFY_TICKET = process.env.NODE_ENV === 'development';
12
12
13//TODO deduplicate with PassportVerify
13//TODO deduplicate with PassportVerify
14−export default function Verify({ STEP_NAMES, newWallet }) {
14+export default function Verify({ newWallet }) {
15− const { push } = useLocalRouter();
15+ const { push, names } = useLocalRouter();
16
16
17 const ticket = newWallet.value.wallet.ticket;
17 const ticket = newWallet.value.wallet.ticket;
18 const validators = useMemo(
18 const validators = useMemo(
@@ -28,7 +28,7 @@ export default function Verify({ STEP_NAMES, newWallet }) {
28 });
28 });
29 const { pass } = ticketInput;
29 const { pass } = ticketInput;
30
30
31− const next = useCallback(() => push(STEP_NAMES.RETICKET), [push, STEP_NAMES]);
31+ const next = useCallback(() => push(names.RETICKET), [push, names]);
32
32
33 return (
33 return (
34 <View>
34 <View>