@@ -29,7 +29,7 @@ import {
29} from 'form/validators';
29} from 'form/validators';
30import FormError from 'form/FormError';
30import FormError from 'form/FormError';
32−import ContinueButton from './ContinueButton';
32+import SubmitButton from 'form/SubmitButton';
33import useSetState from 'lib/useSetState';
33import useSetState from 'lib/useSetState';
35export default function Ticket({ className, goHome }) {
35export default function Ticket({ className, goHome }) {
@@ -41,16 +41,38 @@ export default function Ticket({ className, goHome }) {
41 const impliedPoint = useImpliedPoint();
41 const impliedPoint = useImpliedPoint();
42 const [warnings, addWarning] = useSetState();
42 const [warnings, addWarning] = useSetState();
44− const cachedUrbitWallet = useRef(Nothing());
44+ const validateForm = useCallback(
45+ (values, errors) => {
47+ addWarning({ point: null });
51+ if (values.useShards) {
52+ if (errors.shard1 || errors.shard2 || errors.shard3) {
64+ const onSubmit = useCallback(
66+ const ticket = values.useShards
67+ ? kg.combine([values.shard1, values.shard2, values.shard3])
46− const validateFormAsync = useCallback(
47− async (values, ticket) => {
49 const _contracts = need.contracts(contracts);
71 const _contracts = need.contracts(contracts);
50 const point = patp2dec(values.point);
72 const point = patp2dec(values.point);
52 await timeout(16); // allow ui events to flush
74 await timeout(16); // allow ui events to flush
53− cachedUrbitWallet.current = await urbitWalletFromTicket(
75+ const urbitWallet = await urbitWalletFromTicket(
56 values.passphrase
78 values.passphrase
@@ -60,23 +82,27 @@ export default function Ticket({ className, goHome }) {
60 azimuth.azimuth.isOwner(
82 azimuth.azimuth.isOwner(
61 _contracts,
83 _contracts,
63− cachedUrbitWallet.current.ownership.keys.address
85+ urbitWallet.ownership.keys.address
65 azimuth.azimuth.isTransferProxy(
87 azimuth.azimuth.isTransferProxy(
66 _contracts,
88 _contracts,
68− cachedUrbitWallet.current.ownership.keys.address
90+ urbitWallet.ownership.keys.address
72 const noPermissions = !isOwner && !isTransferProxy;
94 const noPermissions = !isOwner && !isTransferProxy;
73 // notify the user, but allow login regardless
95 // notify the user, but allow login regardless
96+ // TODO: how should the warning work now that we generate onSubmit?
74 if (noPermissions) {
97 if (noPermissions) {
75 addWarning({
98 addWarning({
77 'This wallet is not the owner or transfer proxy for this point.',
100 'This wallet is not the owner or transfer proxy for this point.',
104+ setUrbitWallet(Just(urbitWallet));
105+ setPointCursor(Just(patp2dec(values.point)));
80 } catch (error) {
106 } catch (error) {
81 console.error(error);
107 console.error(error);
@@ -86,34 +112,7 @@ export default function Ticket({ className, goHome }) {
89− [addWarning, contracts]
115+ [addWarning, contracts, setPointCursor, setUrbitWallet]
92− const validateForm = useCallback(
93− (values, errors) => {
95− addWarning({ point: null });
100− if (values.useShards) {
101− if (errors.shard1 || errors.shard2 || errors.shard3) {
105− ticket = kg.combine([values.shard1, values.shard2, values.shard3]);
107− if (errors.ticket) {
111− ticket = values.ticket;
114− return validateFormAsync(values, ticket);
116− [addWarning, validateFormAsync]
119 const validate = useMemo(
118 const validate = useMemo(
@@ -134,18 +133,6 @@ export default function Ticket({ className, goHome }) {
134 [validateForm]
133 [validateForm]
137− const onValues = useCallback(
138− ({ valid, values }) => {
140− setUrbitWallet(Just(cachedUrbitWallet.current));
141− setPointCursor(Just(patp2dec(values.point)));
143− setUrbitWallet(Nothing());
146− [setPointCursor, setUrbitWallet]
149 const initialValues = useMemo(
136 const initialValues = useMemo(
151 point: impliedPoint || '',
138 point: impliedPoint || '',
@@ -159,7 +146,7 @@ export default function Ticket({ className, goHome }) {
159 <Grid className={cn('mt4', className)}>
146 <Grid className={cn('mt4', className)}>
160 <BridgeForm
147 <BridgeForm
161 validate={validate}
148 validate={validate}
162− onValues={onValues}
149+ onSubmit={onSubmit}
163 afterSubmit={goHome}
150 afterSubmit={goHome}
164 initialValues={initialValues}>
151 initialValues={initialValues}>
165 {({ handleSubmit }) => (
152 {({ handleSubmit }) => (
@@ -210,7 +197,9 @@ export default function Ticket({ className, goHome }) {
211 <Grid.Item full as={FormError} />
198 <Grid.Item full as={FormError} />
213− <Grid.Item full as={ContinueButton} handleSubmit={handleSubmit} />
200+ <Grid.Item full as={SubmitButton} handleSubmit={handleSubmit}>
216 </BridgeForm>
205 </BridgeForm>