on master help sign in
Misc refactoring, renaming and cleanup
commitcc52956b191ecb3560c92412a4d2247a2a9c119a authorFang <git@fang.io> dateThu 4 Jul 2019, 11:44 (7 years ago) parent087e4d5
9 files changed+60−72
src/lib/invite.js+9−13 src/views/Activate/ActivatePassport.js−1 src/views/Admin.js+2−2 src/views/Permissions.js+3−15 src/views/Redownload.js+16−12 src/views/Reticket.js+7−9 src/views/Reticket/Confirm.js+16−13 src/views/Reticket/Download.js+3−3 src/views/Reticket/Verify.js+4−4
src/lib/invite.js+9−13
@@ -101,7 +101,7 @@ async function claimPointFromInvite({
101101 web3,
102102 contracts,
103103 onUpdate,
104− transferEth,
104+ transferEth = false,
105105}) {
106106 const askForFunding = (address, minBalance, balance) =>
107107 onUpdate({
@@ -122,11 +122,12 @@ async function claimPointFromInvite({
122122
123123 // transfer to invite wallet, so it can configure
124124 //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.
126127
127128 //TODO no harm done if we already owned it, but should still get a bool arg
128129 // 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(
130131 contracts,
131132 point,
132133 inviteAddress,
@@ -153,7 +154,7 @@ async function claimPointFromInvite({
153154
154155 const networkKeys = kg.deriveNetworkKeys(networkSeed);
155156
156− let keysTx = azimuth.ecliptic.configureKeys(
157+ const keysTx = azimuth.ecliptic.configureKeys(
157158 contracts,
158159 point,
159160 addHexPrefix(networkKeys.crypt.public),
@@ -165,7 +166,7 @@ async function claimPointFromInvite({
165166
166167 // configure management proxy
167168
168− let managementTx = azimuth.ecliptic.setManagementProxy(
169+ const managementTx = azimuth.ecliptic.setManagementProxy(
169170 contracts,
170171 point,
171172 wallet.management.keys.address
@@ -178,7 +179,7 @@ async function claimPointFromInvite({
178179 if (
179180 azimuth.azimuth.getPointSize(point) !== azimuth.azimuth.PointSize.Planet
180181 ) {
181− let spawnTx = azimuth.ecliptic.setSpawnProxy(
182+ const spawnTx = azimuth.ecliptic.setSpawnProxy(
182183 contracts,
183184 point,
184185 wallet.spawn.keys.address
@@ -189,7 +190,7 @@ async function claimPointFromInvite({
189190 if (
190191 azimuth.azimuth.getPointSize(point) === azimuth.azimuth.PointSize.Galaxy
191192 ) {
192− let votingTx = azimuth.ecliptic.setVotingProxy(
193+ const votingTx = azimuth.ecliptic.setVotingProxy(
193194 contracts,
194195 point,
195196 wallet.voting.keys.address
@@ -201,7 +202,7 @@ async function claimPointFromInvite({
201202
202203 // transfer configured point to user's new wallet
203204
204− let transferFinalTx = azimuth.ecliptic.transferPoint(
205+ const transferFinalTx = azimuth.ecliptic.transferPoint(
205206 contracts,
206207 point,
207208 wallet.ownership.keys.address,
@@ -250,7 +251,6 @@ async function claimPointFromInvite({
250251 askForFunding,
251252 gotFunding
252253 );
253− console.log('used tank', usedTank);
254254
255255 //
256256 // sending and awaiting transactions
@@ -258,9 +258,7 @@ async function claimPointFromInvite({
258258
259259 progress(TRANSACTION_STATES.CLAIMING);
260260
261− console.log('sending txpairs', txPairs.length);
262261 await sendAndAwaitConfirm(web3, txPairs.map(p => Just(p.signed)), usedTank);
263− console.log('all done');
264262
265263 //
266264 // move leftover eth
@@ -275,7 +273,6 @@ async function claimPointFromInvite({
275273 const sendEthCost = gasPrice * gasLimit;
276274 if (transferEth && balance > sendEthCost) {
277275 const value = balance - sendEthCost;
278− console.log('sending', value);
279276 const tx = {
280277 to: wallet.ownership.keys.address,
281278 value: value,
@@ -289,7 +286,6 @@ async function claimPointFromInvite({
289286 web3.eth.sendSignedTransaction(rawTx).catch(err => {
290287 console.log('error sending value tx, who cares', err);
291288 });
292− console.log('sent old balance');
293289 }
294290
295291 progress(TRANSACTION_STATES.DONE);
src/views/Activate/ActivatePassport.js−1
@@ -1,6 +1,5 @@
11import React, { useMemo } from 'react';
22import cn from 'classnames';
3−import Maybe from 'folktale/maybe';
43import { Grid } from 'indigo-react';
54
65import { LocalRouterProvider, useLocalRouter } from 'lib/LocalRouter';
src/views/Admin.js+2−2
@@ -23,7 +23,7 @@ export default function Admin() {
2323
2424 const point = need.point(pointCursor);
2525 const pointDetails = need.fromPointCache(pointCache, point);
26− const userAddress = need.wallet(wallet).address;
26+ const address = need.addressFromWallet(wallet);
2727
2828 const goRedownload = useCallback(() => history.push(ROUTE_NAMES.REDOWNLOAD), [
2929 history,
@@ -42,7 +42,7 @@ export default function Admin() {
4242 ]);
4343
4444 const canDownloadPassport = Just.hasInstance(urbitWallet);
45− const isOwner = eqAddr(userAddress, pointDetails.owner);
45+ const isOwner = eqAddr(address, pointDetails.owner);
4646
4747 return (
4848 <View>
src/views/Permissions.js+3−15
@@ -4,14 +4,10 @@ import * as need from 'lib/need';
44import { azimuth } from 'azimuth-js';
55import { Grid } from 'indigo-react';
66
7−import { P } from 'indigo-react';
87import View from 'components/View';
98import { ForwardButton } from 'components/Buttons';
109import FooterButton from 'components/FooterButton';
11−import Blinky, {
12− LOADING_CHARACTER,
13− INTERSTITIAL_CHARACTER,
14−} from 'components/Blinky';
10+import { matchBlinky } from 'components/Blinky';
1511
1612import { ROUTE_NAMES } from 'lib/routeNames';
1713import { eqAddr } from 'lib/wallet';
@@ -122,22 +118,14 @@ export default function Permissions() {
122118 ) : (
123119 <>
124120 {`Revision #${pointDetails.keyRevisionNumber}, since `}
125− {Just.hasInstance(rekeyDate) ? (
126− rekeyDate.value
127− ) : (
128− <Blinky a={LOADING_CHARACTER} b={INTERSTITIAL_CHARACTER} delayed />
129− )}
121+ {matchBlinky(rekeyDate)}
130122 </>
131123 );
132124
133125 return (
134126 <View>
135127 <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}>
141129 Ownership address
142130 </Grid.Item>
143131 {proxyAction(
src/views/Redownload.js+16−12
@@ -23,24 +23,28 @@ export default function Redownload() {
2323 downloadWallet(paper.value);
2424 };
2525
26− const paperRenderer = Just.hasInstance(paper) ? null : (
27− <PaperRenderer
28− point={point}
29− wallet={urbitWallet.value}
30− callback={paper => {
31− setPaper(Just(paper));
32− }}
33− />
34− );
26+ const paperRenderer = paper.matchWith({
27+ Nothing: () => null,
28+ Just: p => (
29+ <PaperRenderer
30+ point={point}
31+ wallet={urbitWallet.value}
32+ callback={paper => {
33+ setPaper(Just(paper));
34+ }}
35+ />
36+ ),
37+ });
3538
3639 return (
3740 <View>
3841 <DownloadButton
3942 disabled={Nothing.hasInstance(paper)}
4043 onClick={doDownload}>
41− {Nothing.hasInstance(paper)
42− ? 'Printing and folding...'
43− : 'Download paper wallet'}
44+ {paper.matchWith({
45+ Nothing: () => 'Printing and folding...',
46+ Just: _ => 'Download paper wallet',
47+ })}
4448 </DownloadButton>
4549 {paperRenderer}
4650 </View>
src/views/Reticket.js+7−9
@@ -20,28 +20,28 @@ import Download from './Reticket/Download';
2020import Verify from './Reticket/Verify';
2121import DoReticket from './Reticket/DoReticket';
2222
23−const STEP_NAMES = {
23+const NAMES = {
2424 CONFIRM: 'CONFIRM',
2525 DOWNLOAD: 'DOWNLOAD',
2626 VERIFY: 'VERIFY',
2727 RETICKET: 'RETICKET',
2828};
2929
30−const STEP_VIEWS = {
30+const VIEWS = {
3131 CONFIRM: Confirm,
3232 DOWNLOAD: Download,
3333 VERIFY: Verify,
3434 RETICKET: DoReticket,
3535};
3636
37−const STEP_MAX = size(STEP_NAMES);
37+const STEP_MAX = size(NAMES);
3838
3939export default function Reticket() {
4040 const history = useHistory();
4141 const { Route, ...innerRouter } = useRouter({
42− names: STEP_NAMES,
43− views: STEP_VIEWS,
44− initialRoutes: [{ key: STEP_NAMES.CONFIRM }],
42+ names: NAMES,
43+ views: VIEWS,
44+ initialRoutes: [{ key: NAMES.CONFIRM }],
4545 });
4646 const { pointCursor } = usePointCursor();
4747 const point = need.point(pointCursor);
@@ -73,8 +73,7 @@ export default function Reticket() {
7373 {
7474 text: name,
7575 action: () => {
76− history.pop();
77− return history.pop();
76+ return history.pop(2);
7877 },
7978 },
8079 {
@@ -86,7 +85,6 @@ export default function Reticket() {
8685 <MiniBackButton onClick={innerRouter.pop} />
8786 Step {stepNumber} of {STEP_MAX}
8887 <Route
89− STEP_NAMES={STEP_NAMES}
9088 newWallet={newWallet}
9189 //
9290 storeNewWallet={storeNewWallet}
src/views/Reticket/Confirm.js+16−13
@@ -14,8 +14,8 @@ import { useLocalRouter } from 'lib/LocalRouter';
1414
1515import { isDevelopment } from 'lib/flags';
1616
17−export default function Confirm({ STEP_NAMES, newWallet, storeNewWallet }) {
18− const { push } = useLocalRouter();
17+export default function Confirm({ newWallet, storeNewWallet }) {
18+ const { push, names } = useLocalRouter();
1919 const { pointCursor } = usePointCursor();
2020 const point = need.point(pointCursor);
2121
@@ -33,17 +33,20 @@ export default function Confirm({ STEP_NAMES, newWallet, storeNewWallet }) {
3333 })();
3434 });
3535
36− const next = useCallback(() => push(STEP_NAMES.DOWNLOAD), [push, STEP_NAMES]);
37−
38− const paperRenderer = Nothing.hasInstance(generatedWallet) ? null : (
39− <PaperRenderer
40− point={point}
41− wallet={generatedWallet.value}
42− callback={paper => {
43− storeNewWallet(generatedWallet.value, paper);
44− }}
45− />
46− );
36+ const next = useCallback(() => push(names.DOWNLOAD), [push, names]);
37+
38+ const paperRenderer = generatedWallet.matchWith({
39+ Nothing: () => null,
40+ Just: gw => (
41+ <PaperRenderer
42+ point={point}
43+ wallet={gw.value}
44+ callback={paper => {
45+ storeNewWallet(gw.value, paper);
46+ }}
47+ />
48+ ),
49+ });
4750
4851 return (
4952 <View>
src/views/Reticket/Download.js+3−3
@@ -7,8 +7,8 @@ import { ForwardButton, DownloadButton } from 'components/Buttons';
77import { useLocalRouter } from 'lib/LocalRouter';
88import { downloadWallet } from 'lib/invite';
99
10−export default function Download({ STEP_NAMES, newWallet }) {
11− const { push } = useLocalRouter();
10+export default function Download({ newWallet }) {
11+ const { push, names } = useLocalRouter();
1212
1313 const [hasDownloaded, setHasDownloaded] = useState(false);
1414
@@ -17,7 +17,7 @@ export default function Download({ STEP_NAMES, newWallet }) {
1717 setHasDownloaded(true);
1818 };
1919
20− const next = useCallback(() => push(STEP_NAMES.VERIFY), [push, STEP_NAMES]);
20+ const next = useCallback(() => push(names.VERIFY), [push, names]);
2121
2222 return (
2323 <View>
src/views/Reticket/Verify.js+4−4
@@ -1,5 +1,5 @@
11import React, { useCallback, useMemo } from 'react';
2−import { Input, AccessoryIcon } from 'indigo-react';
2+import { Input } from 'indigo-react';
33
44import View from 'components/View';
55import { useTicketInput } from 'components/Inputs';
@@ -11,8 +11,8 @@ import { validateExactly } from 'lib/validators';
1111const STUB_VERIFY_TICKET = process.env.NODE_ENV === 'development';
1212
1313//TODO deduplicate with PassportVerify
14−export default function Verify({ STEP_NAMES, newWallet }) {
15− const { push } = useLocalRouter();
14+export default function Verify({ newWallet }) {
15+ const { push, names } = useLocalRouter();
1616
1717 const ticket = newWallet.value.wallet.ticket;
1818 const validators = useMemo(
@@ -28,7 +28,7 @@ export default function Verify({ STEP_NAMES, newWallet }) {
2828 });
2929 const { pass } = ticketInput;
3030
31− const next = useCallback(() => push(STEP_NAMES.RETICKET), [push, STEP_NAMES]);
31+ const next = useCallback(() => push(names.RETICKET), [push, names]);
3232
3333 return (
3434 <View>