on master help sign in
refactor: move Inputs.js to lib/useInputs.js and re-order relevant imports
commit1dbc526fc95989e811d4a819cf0d167b24154c4a authorMatt Condon (shrugs) <mattgcondon@gmail.com> dateTue 9 Jul 2019, 15:08 (7 years ago) parent9db5cc7
14 files changed+111−78
src/components/Inputs.js → src/lib/useInputs.js+2−28 src/views/Activate/ActivateCode.js+1−1 src/views/Activate/ActivateDisclaimer.js+3−2 src/views/Activate/PassportVerify.js+2−2 src/views/Admin/Reticket/ReticketVerify.js+47 src/views/Invite/InviteEmail.js+12−12 src/views/Login/Keystore.js+5−5 src/views/Login/Ledger.js+13−5 src/views/Login/Mnemonic.js+3−4 src/views/Login/PrivateKey.js+1−2 src/views/Login/Ticket.js+5−6 src/views/Login/Trezor.js+12−6 src/views/Reticket/Verify.js+4−4 src/views/ViewPoint.js+1−1
src/components/Inputs.js → src/lib/useInputs.jsrenamed+2−28
@@ -3,8 +3,6 @@ import { AccessoryIcon, useForm } from 'indigo-react';
33import { identity } from 'lodash';
44import * as bip39 from 'bip39';
55
6−import InputSigil from 'components/InputSigil';
7−
86import { DEFAULT_HD_PATH } from 'lib/wallet';
97import {
108 validateNotEmpty,
@@ -19,35 +17,11 @@ import {
1917} from 'lib/validators';
2018import { prependSig } from 'lib/transformers';
2119
20+import InputSigil from 'components/InputSigil';
21+
2222const EXAMPLE_PRIVATE_KEY =
2323 '0xa44de2416ee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3';
2424
25−// const RequiredInput = advancedInput({
26−// WrappedComponent: Input,
27−// validators: [validateNotEmpty],
28−// });
29−
30−// const NetworkKeyInput = advancedInput({
31−// WrappedComponent: Input,
32−// validators: [validateNotEmpty, validateNetworkKey],
33−// });
34−
35−// const NetworkSeedInput = advancedInput({
36−// WrappedComponent: Input,
37−// validators: [validateNotEmpty, validateNetworkSeed],
38−// });
39−
40−// const AddressInput = advancedInput({
41−// WrappedComponent: Input,
42−// validators: [validateEthereumAddress, validateNotEmpty],
43−// });
44−
45−// const GalaxyInput = advancedInput({
46−// WrappedComponent: Input,
47−// validators: [validateGalaxy, validateNotEmpty],
48−// transformers: [prependSig],
49−// });
50−
5125// pulls out the first input from a useForm() call
5226function useFirstOf({ inputs, setValue, ...rest }, mapper = identity) {
5327 // ask the mapper function for any values to overwrite
src/views/Activate/ActivateCode.js+1−1
@@ -1,7 +1,6 @@
11import React, { useCallback, useEffect, useState } from 'react';
22import { Just, Nothing } from 'folktale/maybe';
33import * as azimuth from 'azimuth-js';
4−import { useTicketInput } from 'components/Inputs';
54import { Grid, Input, H4, ErrorText } from 'indigo-react';
65
76import View from 'components/View';
@@ -10,6 +9,7 @@ import Passport from 'components/Passport';
109
1110import { useHistory } from 'store/history';
1211
12+import { useTicketInput } from 'lib/useInputs';
1313import * as need from 'lib/need';
1414import { ROUTE_NAMES } from 'lib/routeNames';
1515import { useSyncKnownPoints } from 'lib/useSyncPoints';
src/views/Activate/ActivateDisclaimer.js+3−2
@@ -2,10 +2,11 @@ import React, { useCallback } from 'react';
22import cn from 'classnames';
33import { Grid, H3, B, Text, CheckboxInput } from 'indigo-react';
44
5+import { useCheckboxInput } from 'lib/useInputs';
6+import { useLocalRouter } from 'lib/LocalRouter';
7+
58import View from 'components/View';
6−import { useCheckboxInput } from 'components/Inputs';
79import { ForwardButton } from 'components/Buttons';
8−import { useLocalRouter } from 'lib/LocalRouter';
910import WarningBox from 'components/WarningBox';
1011
1112const TEXT_STYLE = 'f5';
src/views/Activate/PassportVerify.js+2−2
@@ -4,13 +4,13 @@ import { Grid, H4, Input, P } from 'indigo-react';
44
55import * as need from 'lib/need';
66import { useLocalRouter } from 'lib/LocalRouter';
7+import { useTicketInput } from 'lib/useInputs';
8+import { validateExactly } from 'lib/validators';
79
810import { ForwardButton } from 'components/Buttons';
911import Steps from 'components/Steps';
10−import { useTicketInput } from 'components/Inputs';
1112
1213import { useActivateFlow } from './ActivateFlow';
13−import { validateExactly } from 'lib/validators';
1414
1515const STUB_VERIFY_TICKET = process.env.NODE_ENV === 'development';
1616
src/views/Admin/Reticket/ReticketVerify.jsnew file+47
@@ -0,0 +1,47 @@
1+import React, { useCallback, useMemo } from 'react';
2+import { Input, Text, Grid } from 'indigo-react';
3+
4+import { ForwardButton } from 'components/Buttons';
5+
6+import { useTicketInput } from 'lib/useInputs';
7+import { useLocalRouter } from 'lib/LocalRouter';
8+import { validateExactly } from 'lib/validators';
9+import { isDevelopment } from 'lib/flags';
10+
11+const STUB_VERIFY_TICKET = isDevelopment;
12+
13+export default function ReticketVerify({ newWallet }) {
14+ const { push, names } = useLocalRouter();
15+
16+ const ticket = newWallet.value.wallet.ticket;
17+ const validators = useMemo(
18+ () => [validateExactly(ticket, 'Does not match expected master ticket.')],
19+ [ticket]
20+ );
21+ const [ticketInput, { pass }] = useTicketInput({
22+ name: 'ticket',
23+ label: 'New master ticket',
24+ initialValue: STUB_VERIFY_TICKET ? ticket : undefined,
25+ autoFocus: true,
26+ validators,
27+ });
28+
29+ const goExecute = useCallback(() => push(names.EXECUTE), [push, names]);
30+
31+ return (
32+ <Grid gap={4} className="mt4">
33+ <Grid.Item full as={Text}>
34+ Verify New Master Ticket
35+ </Grid.Item>
36+ <Grid.Item full as={Input} {...ticketInput} />
37+ <Grid.Item
38+ full
39+ as={ForwardButton}
40+ solid
41+ disabled={!pass}
42+ onClick={goExecute}>
43+ Verify & Reticket
44+ </Grid.Item>
45+ </Grid>
46+ );
47+}
src/views/Invite/InviteEmail.js+12−12
@@ -11,11 +11,14 @@ import {
1111 Text,
1212 ErrorText,
1313 AccessoryIcon,
14+ useForm,
1415} from 'indigo-react';
1516import { uniq } from 'lodash';
1617
17−import * as need from 'lib/need';
18−import * as wg from 'lib/walletgen';
18+import { usePointCursor } from 'store/pointCursor';
19+import { useNetwork } from 'store/network';
20+import { usePointCache } from 'store/pointCache';
21+import { useWallet } from 'store/wallet';
1922
2023// for transaction generation and signing
2124import {
@@ -28,22 +31,19 @@ import {
2831} from 'lib/txn';
2932import * as tank from 'lib/tank';
3033import { useLocalRouter } from 'lib/LocalRouter';
31−
32−import MiniBackButton from 'components/MiniBackButton';
33−import { usePointCursor } from 'store/pointCursor';
34−import LoadableButton from 'components/LoadableButton';
3534import useArray from 'lib/useArray';
36−import useForm from 'indigo-react/lib/useForm';
37−import { buildEmailInputConfig } from 'components/Inputs';
35+import { buildEmailInputConfig } from 'lib/useInputs';
3836import { MIN_PLANET, GAS_LIMITS } from 'lib/constants';
39−import Highlighted from 'components/Highlighted';
40−import { useNetwork } from 'store/network';
41−import { usePointCache } from 'store/pointCache';
42−import { useWallet } from 'store/wallet';
37+import * as need from 'lib/need';
38+import * as wg from 'lib/walletgen';
4339import useSetState from 'lib/useSetState';
4440import pluralize from 'lib/pluralize';
4541import useMailer from 'lib/useMailer';
4642
43+import MiniBackButton from 'components/MiniBackButton';
44+import LoadableButton from 'components/LoadableButton';
45+import Highlighted from 'components/Highlighted';
46+
4747const GAS_PRICE_GWEI = 20; // we pay the premium for faster ux
4848const GAS_LIMIT = GAS_LIMITS.GIFT_PLANET;
4949const INVITE_COST = toWei((GAS_PRICE_GWEI * GAS_LIMIT).toString(), 'gwei');
src/views/Login/Keystore.js+5−5
@@ -1,18 +1,18 @@
11import React, { useState } from 'react';
22import { Just, Nothing } from 'folktale/maybe';
3−import * as keythereum from 'keythereum';
43import { P, Grid, Input, ErrorText } from 'indigo-react';
5−
6−import { usePassphraseInput } from 'components/Inputs';
7−import { ForwardButton } from 'components/Buttons';
4+import * as keythereum from 'keythereum';
85
96import { useWallet } from 'store/wallet';
107
8+import { usePassphraseInput } from 'lib/useInputs';
119import * as need from 'lib/need';
1210import { EthereumWallet, WALLET_TYPES } from 'lib/wallet';
13−import UploadButton from 'components/UploadButton';
1411import useLoginView from 'lib/useLoginView';
1512
13+import { ForwardButton } from 'components/Buttons';
14+import UploadButton from 'components/UploadButton';
15+
1616export default function Keystore({ className }) {
1717 useLoginView(WALLET_TYPES.KEYSTORE);
1818
src/views/Login/Ledger.js+13−5
@@ -1,21 +1,30 @@
11import React, { useCallback, useEffect } from 'react';
22import cn from 'classnames';
33import { Just, Nothing } from 'folktale/maybe';
4−import { P, Text, Input, Grid, H5, CheckboxInput } from 'indigo-react';
4+import {
5+ P,
6+ Text,
7+ Input,
8+ Grid,
9+ H5,
10+ CheckboxInput,
11+ SelectInput,
12+} from 'indigo-react';
513import { times } from 'lodash';
614import * as bip32 from 'bip32';
715import Transport from '@ledgerhq/hw-transport-u2f';
816import Eth from '@ledgerhq/hw-app-eth';
917import * as secp256k1 from 'secp256k1';
1018
19+import { useWallet } from 'store/wallet';
20+
1121import { ForwardButton } from 'components/Buttons';
22+
1223import {
1324 useCheckboxInput,
1425 useHdPathInput,
1526 useSelectInput,
16−} from 'components/Inputs';
17−
18−import { useWallet } from 'store/wallet';
27+} from 'lib/useInputs';
1928
2029import {
2130 LEDGER_LIVE_PATH,
@@ -25,7 +34,6 @@ import {
2534} from 'lib/ledger';
2635import { WALLET_TYPES } from 'lib/wallet';
2736import useLoginView from 'lib/useLoginView';
28−import SelectInput from 'indigo-react/components/SelectInput';
2937import useBreakpoints from 'lib/useBreakpoints';
3038
3139const PATH_OPTIONS = [
src/views/Login/Mnemonic.js+3−4
@@ -2,15 +2,14 @@ import React, { useEffect } from 'react';
22import { Just, Nothing } from 'folktale/maybe';
33import { Grid, Input, CheckboxInput } from 'indigo-react';
44
5+import { useWallet } from 'store/wallet';
6+
57import {
68 usePassphraseInput,
79 useMnemonicInput,
810 useHdPathInput,
911 useCheckboxInput,
10−} from 'components/Inputs';
11−
12−import { useWallet } from 'store/wallet';
13−
12+} from 'lib/useInputs';
1413import { walletFromMnemonic, WALLET_TYPES } from 'lib/wallet';
1514import useLoginView from 'lib/useLoginView';
1615
src/views/Login/PrivateKey.js+1−2
@@ -2,10 +2,9 @@ import React, { useEffect } from 'react';
22import { Just, Nothing } from 'folktale/maybe';
33import { Grid, Input } from 'indigo-react';
44
5−import { useHexInput } from 'components/Inputs';
6−
75import { useWallet } from 'store/wallet';
86
7+import { useHexInput } from 'lib/useInputs';
98import { EthereumWallet, WALLET_TYPES, stripHexPrefix } from 'lib/wallet';
109import useLoginView from 'lib/useLoginView';
1110
src/views/Login/Ticket.js+5−6
@@ -5,17 +5,16 @@ import * as ob from 'urbit-ob';
55import * as kg from 'urbit-key-generation/dist/index';
66import { Input, Grid, CheckboxInput } from 'indigo-react';
77
8+import { useNetwork } from 'store/network';
9+import { useWallet } from 'store/wallet';
10+import { usePointCursor } from 'store/pointCursor';
11+
812import {
913 usePointInput,
1014 useTicketInput,
1115 usePassphraseInput,
1216 useCheckboxInput,
13−} from 'components/Inputs';
14−
15−import { useNetwork } from 'store/network';
16−import { useWallet } from 'store/wallet';
17−import { usePointCursor } from 'store/pointCursor';
18−
17+} from 'lib/useInputs';
1918import * as need from 'lib/need';
2019import { WALLET_TYPES, urbitWalletFromTicket } from 'lib/wallet';
2120import useImpliedPoint from 'lib/useImpliedPoint';
src/views/Login/Trezor.js+12−6
@@ -4,21 +4,27 @@ import * as bip32 from 'bip32';
44import { times } from 'lodash';
55import TrezorConnect from 'trezor-connect';
66import * as secp256k1 from 'secp256k1';
7−import { Text, Input, Grid, H5, CheckboxInput } from 'indigo-react';
7+import {
8+ Text,
9+ Input,
10+ Grid,
11+ H5,
12+ CheckboxInput,
13+ SelectInput,
14+} from 'indigo-react';
815
9−import { ForwardButton } from 'components/Buttons';
16+import { useWallet } from 'store/wallet';
1017
1118import { TREZOR_PATH } from 'lib/trezor';
1219import { WALLET_TYPES } from 'lib/wallet';
13−
14−import { useWallet } from 'store/wallet';
1520import useLoginView from 'lib/useLoginView';
1621import {
1722 useHdPathInput,
1823 useCheckboxInput,
1924 useSelectInput,
20−} from 'components/Inputs';
21−import SelectInput from 'indigo-react/components/SelectInput';
25+} from 'lib/useInputs';
26+
27+import { ForwardButton } from 'components/Buttons';
2228
2329const ACCOUNT_OPTIONS = times(20, i => ({
2430 text: `Account #${i + 1}`,
src/views/Reticket/Verify.js+4−4
@@ -1,13 +1,13 @@
11import React, { useCallback, useMemo } from 'react';
22import { Input } from 'indigo-react';
33
4−import View from 'components/View';
5−import { useTicketInput } from 'components/Inputs';
6−import { ForwardButton } from 'components/Buttons';
7−
4+import { useTicketInput } from 'lib/useInputs';
85import { useLocalRouter } from 'lib/LocalRouter';
96import { validateExactly } from 'lib/validators';
107
8+import View from 'components/View';
9+import { ForwardButton } from 'components/Buttons';
10+
1111const STUB_VERIFY_TICKET = process.env.NODE_ENV === 'development';
1212
1313//TODO deduplicate with PassportVerify
src/views/ViewPoint.js+1−1
@@ -9,10 +9,10 @@ import { usePointCursor } from 'store/pointCursor';
99
1010import { ROUTE_NAMES } from 'lib/routeNames';
1111import patp2dec from 'lib/patp2dec';
12+import { usePointInput } from 'lib/useInputs';
1213
1314import View from 'components/View';
1415import { ForwardButton } from 'components/Buttons';
15−import { usePointInput } from 'components/Inputs';
1616
1717export default function ViewPoint() {
1818 const history = useHistory();