@@ -29,7 +29,7 @@ import {
2929} from 'form/validators';
3030import FormError from 'form/FormError';
3131
32−import ContinueButton from './ContinueButton';
32+import SubmitButton from 'form/SubmitButton';
3333import useSetState from 'lib/useSetState';
3434
3535export default function Ticket({ className, goHome }) {
@@ -41,16 +41,38 @@ export default function Ticket({ className, goHome }) {
4141 const impliedPoint = useImpliedPoint();
4242 const [warnings, addWarning] = useSetState();
4343
44− const cachedUrbitWallet = useRef(Nothing());
44+ const validateForm = useCallback(
45+ (values, errors) => {
46+ if (errors.point) {
47+ addWarning({ point: null });
48+ return errors;
49+ }
50+
51+ if (values.useShards) {
52+ if (errors.shard1 || errors.shard2 || errors.shard3) {
53+ return errors;
54+ }
55+ } else {
56+ if (errors.ticket) {
57+ return errors;
58+ }
59+ }
60+ },
61+ [addWarning]
62+ );
63+
64+ const onSubmit = useCallback(
65+ async values => {
66+ const ticket = values.useShards
67+ ? kg.combine([values.shard1, values.shard2, values.shard3])
68+ : values.ticket;
4569
46− const validateFormAsync = useCallback(
47− async (values, ticket) => {
4870 try {
4971 const _contracts = need.contracts(contracts);
5072 const point = patp2dec(values.point);
5173
5274 await timeout(16); // allow ui events to flush
53− cachedUrbitWallet.current = await urbitWalletFromTicket(
75+ const urbitWallet = await urbitWalletFromTicket(
5476 ticket,
5577 point,
5678 values.passphrase
@@ -60,23 +82,27 @@ export default function Ticket({ className, goHome }) {
6082 azimuth.azimuth.isOwner(
6183 _contracts,
6284 point,
63− cachedUrbitWallet.current.ownership.keys.address
85+ urbitWallet.ownership.keys.address
6486 ),
6587 azimuth.azimuth.isTransferProxy(
6688 _contracts,
6789 point,
68− cachedUrbitWallet.current.ownership.keys.address
90+ urbitWallet.ownership.keys.address
6991 ),
7092 ]);
7193
7294 const noPermissions = !isOwner && !isTransferProxy;
7395 // notify the user, but allow login regardless
96+ // TODO: how should the warning work now that we generate onSubmit?
7497 if (noPermissions) {
7598 addWarning({
7699 point:
77100 'This wallet is not the owner or transfer proxy for this point.',
78101 });
79102 }
103+
104+ setUrbitWallet(Just(urbitWallet));
105+ setPointCursor(Just(patp2dec(values.point)));
80106 } catch (error) {
81107 console.error(error);
82108 return {
@@ -86,34 +112,7 @@ export default function Ticket({ className, goHome }) {
86112 };
87113 }
88114 },
89− [addWarning, contracts]
90− );
91−
92− const validateForm = useCallback(
93− (values, errors) => {
94− if (errors.point) {
95− addWarning({ point: null });
96− return errors;
97− }
98−
99− let ticket;
100− if (values.useShards) {
101− if (errors.shard1 || errors.shard2 || errors.shard3) {
102− return errors;
103− }
104−
105− ticket = kg.combine([values.shard1, values.shard2, values.shard3]);
106− } else {
107− if (errors.ticket) {
108− return errors;
109− }
110−
111− ticket = values.ticket;
112− }
113−
114− return validateFormAsync(values, ticket);
115− },
116− [addWarning, validateFormAsync]
115+ [addWarning, contracts, setPointCursor, setUrbitWallet]
117116 );
118117
119118 const validate = useMemo(
@@ -134,18 +133,6 @@ export default function Ticket({ className, goHome }) {
134133 [validateForm]
135134 );
136135
137− const onValues = useCallback(
138− ({ valid, values }) => {
139− if (valid) {
140− setUrbitWallet(Just(cachedUrbitWallet.current));
141− setPointCursor(Just(patp2dec(values.point)));
142− } else {
143− setUrbitWallet(Nothing());
144− }
145− },
146− [setPointCursor, setUrbitWallet]
147− );
148−
149136 const initialValues = useMemo(
150137 () => ({
151138 point: impliedPoint || '',
@@ -159,7 +146,7 @@ export default function Ticket({ className, goHome }) {
159146 <Grid className={cn('mt4', className)}>
160147 <BridgeForm
161148 validate={validate}
162− onValues={onValues}
149+ onSubmit={onSubmit}
163150 afterSubmit={goHome}
164151 initialValues={initialValues}>
165152 {({ handleSubmit }) => (
@@ -210,7 +197,9 @@ export default function Ticket({ className, goHome }) {
210197
211198 <Grid.Item full as={FormError} />
212199
213− <Grid.Item full as={ContinueButton} handleSubmit={handleSubmit} />
200+ <Grid.Item full as={SubmitButton} handleSubmit={handleSubmit}>
201+ Continue
202+ </Grid.Item>
214203 </>
215204 )}
216205 </BridgeForm>