on master help sign in
reticket: L1 points with L2 spawn proxy can reticket
d3d9e91tomholford
src/lib/types/L2Transaction.ts+13
@@ -40,10 +40,23 @@ export interface TransactionData {
40 method: Function;
40 method: Function;
41}
41}
42
42
43+interface ReticketProgressCallback {
44+ ({
45+ type,
46+ state,
47+ value,
48+ }: {
49+ type: string;
50+ state: number;
51+ value?: string;
52+ }): void;
53+}
54+
43export interface ReticketParams {
55export interface ReticketParams {
44 point: Ship;
56 point: Ship;
45 to: EthAddress;
57 to: EthAddress;
46 manager: EthAddress;
58 manager: EthAddress;
47 fromWallet: BridgeWallet;
59 fromWallet: BridgeWallet;
48 toWallet: UrbitWallet;
60 toWallet: UrbitWallet;
61+ onUpdate?: ReticketProgressCallback;
49}
62}
src/lib/useRoller.ts+12
@@ -51,6 +51,7 @@ import { ddmmmYYYY } from './utils/date';
51import { showNotification } from './utils/notifications';
51import { showNotification } from './utils/notifications';
52import { useWalletConnect } from './useWalletConnect';
52import { useWalletConnect } from './useWalletConnect';
53import { PendingL1Txn } from './types/PendingL1Transaction';
53import { PendingL1Txn } from './types/PendingL1Transaction';
54+import { TRANSACTION_PROGRESS } from './reticket';
54
55
55const ONE_SECOND = 1000;
56const ONE_SECOND = 1000;
56
57
@@ -700,15 +701,20 @@ export default function useRoller() {
700 manager,
701 manager,
701 fromWallet,
702 fromWallet,
702 toWallet,
703 toWallet,
704+ onUpdate,
703 }: ReticketParams) => {
705 }: ReticketParams) => {
704 const azimuthPoint = await api.getPoint(point);
706 const azimuthPoint = await api.getPoint(point);
705 const proxy = 'own';
707 const proxy = 'own';
706 const _web3 = web3.getOrElse(null);
708 const _web3 = web3.getOrElse(null);
707 let nonce = await api.getNonce({ ship: point, proxy });
709 let nonce = await api.getNonce({ ship: point, proxy });
710+ const progress = onUpdate
711+ ? (state: number) => onUpdate({ type: 'progress', state })
712+ : () => {};
708
713
709 let requests = [];
714 let requests = [];
710
715
711 // 1. Update networking keys
716 // 1. Update networking keys
717+ progress(TRANSACTION_PROGRESS.GENERATING);
712 const networkRevision = convertToInt(azimuthPoint.network.keys.life, 10);
718 const networkRevision = convertToInt(azimuthPoint.network.keys.life, 10);
713 const nextRevision = networkRevision + 1;
719 const nextRevision = networkRevision + 1;
714 const networkSeed = await deriveNetworkSeedFromUrbitWallet(
720 const networkSeed = await deriveNetworkSeedFromUrbitWallet(
@@ -731,6 +737,7 @@ export default function useRoller() {
731 requests.push(configureKeysRequest);
737 requests.push(configureKeysRequest);
732
738
733 // 2. Set Management Proxy
739 // 2. Set Management Proxy
740+ progress(TRANSACTION_PROGRESS.SIGNING);
734 const registerMgmtRequest = await registerProxyAddress(
741 const registerMgmtRequest = await registerProxyAddress(
735 api,
742 api,
736 fromWallet,
743 fromWallet,
@@ -747,6 +754,7 @@ export default function useRoller() {
747 requests.push(registerMgmtRequest);
754 requests.push(registerMgmtRequest);
748
755
749 // 3. Set Spawn Proxy
756 // 3. Set Spawn Proxy
757+ progress(TRANSACTION_PROGRESS.FUNDING);
750 if (!isPlanet(Number(point))) {
758 if (!isPlanet(Number(point))) {
751 const registerSpawnRequest = await registerProxyAddress(
759 const registerSpawnRequest = await registerProxyAddress(
752 api,
760 api,
@@ -764,6 +772,7 @@ export default function useRoller() {
764 requests.push(registerSpawnRequest);
772 requests.push(registerSpawnRequest);
765 }
773 }
766 // 4. Transfer point
774 // 4. Transfer point
775+ progress(TRANSACTION_PROGRESS.TRANSFERRING);
767 const transferTxRequest = await submitL2Transaction({
776 const transferTxRequest = await submitL2Transaction({
768 api,
777 api,
769 wallet: fromWallet,
778 wallet: fromWallet,
@@ -778,7 +787,10 @@ export default function useRoller() {
778 });
787 });
779 requests.push(transferTxRequest);
788 requests.push(transferTxRequest);
780
789
790+ progress(TRANSACTION_PROGRESS.CLEANING);
781 const hashes = await Promise.all(requests);
791 const hashes = await Promise.all(requests);
792+
793+ progress(TRANSACTION_PROGRESS.DONE);
782 return hashes;
794 return hashes;
783 };
795 };
784
796
src/views/UrbitID/ResetKeys/ResetExecute.js+56−37
@@ -57,7 +57,7 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
57 } = useWallet();
57 } = useWallet();
58 const { performL2Reticket } = useRoller();
58 const { performL2Reticket } = useRoller();
59 const {
59 const {
60− point: { isL2 },
60+ point: { isL2Spawn },
61 } = useRollerStore();
61 } = useRollerStore();
62 const { pointCursor } = usePointCursor();
62 const { pointCursor } = usePointCursor();
63 const { getDetails } = usePointCache();
63 const { getDetails } = usePointCache();
@@ -74,8 +74,38 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
74
74
75 useBlockWindowClose();
75 useBlockWindowClose();
76
76
77− // start reticketing transactions on mount
77+ const goToRestart = useCallback(() => {
78− useEffect(() => {
78+ reset();
79+ setNewWallet(Nothing());
80+ }, [reset, setNewWallet]);
81+
82+ const loginAndGoHome = useCallback(() => {
83+ // set wallet state
84+ resetWallet();
85+ setWalletType(WALLET_TYPES.TICKET);
86+ setUrbitWallet(Just(newWallet.value.wallet));
87+ // (implicit) pointCursor stays the same
88+ // redirect to point
89+ popTo(names.POINT);
90+ }, [resetWallet, setWalletType, setUrbitWallet, newWallet, popTo, names]);
91+
92+ const handleUpdate = useCallback(
93+ ({ type, state, value }) => {
94+ switch (type) {
95+ case 'progress':
96+ return setProgress(state);
97+ case 'askFunding':
98+ return setNeedFunds(value);
99+ case 'gotFunding':
100+ return setNeedFunds(false);
101+ default:
102+ console.error(`Unknown update: ${type}`);
103+ }
104+ },
105+ [setProgress, setNeedFunds]
106+ );
107+
108+ const performReticket = useCallback(async () => {
79 (async () => {
109 (async () => {
80 // due to react shenanigans we may need to wait for the connector
110 // due to react shenanigans we may need to wait for the connector
81 if (
111 if (
@@ -98,17 +128,16 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
98 walletType === WALLET_TYPES.WALLET_CONNECT ? wcSend : undefined;
128 walletType === WALLET_TYPES.WALLET_CONNECT ? wcSend : undefined;
99
129
100 try {
130 try {
101− if (isL2) {
131+ if (isL2Spawn) {
102− console.log(newWallet.value);
103 // FIXME: the useEffect is called twice, which is fine since the duplicate
132 // FIXME: the useEffect is called twice, which is fine since the duplicate
104 // L2 txs will be discarded
133 // L2 txs will be discarded
105− //
106 await performL2Reticket({
134 await performL2Reticket({
107 point,
135 point,
108 to: newWallet.value.wallet.ownership.keys.address,
136 to: newWallet.value.wallet.ownership.keys.address,
109 manager: newWallet.value.wallet.management.keys.address,
137 manager: newWallet.value.wallet.management.keys.address,
110 toWallet: newWallet.value.wallet,
138 toWallet: newWallet.value.wallet,
111 fromWallet: need.wallet(wallet),
139 fromWallet: need.wallet(wallet),
140+ onUpdate: handleUpdate,
112 });
141 });
113 } else
142 } else
114 await reticketPointBetweenWallets({
143 await reticketPointBetweenWallets({
@@ -130,43 +159,33 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
130 setGeneralError(err);
159 setGeneralError(err);
131 }
160 }
132 })();
161 })();
162+ }, [
163+ connector,
164+ contracts,
165+ getDetails,
166+ handleUpdate,
167+ isL2Spawn,
168+ networkType,
169+ newWallet.value.wallet,
170+ performL2Reticket,
171+ pointCursor,
172+ wallet,
173+ walletHdPath,
174+ walletType,
175+ wcSend,
176+ wcSign,
177+ web3,
178+ ]);
179+
180+ // start reticketing transactions on mount
181+ useEffect(() => {
182+ performReticket();
133 //NOTE this was using useLifecycle previously (which is useEffect without
183 //NOTE this was using useLifecycle previously (which is useEffect without
134 // dependencies) and worked fine, but in the wc case we might need to
184 // dependencies) and worked fine, but in the wc case we might need to
135 // wait for the connector to get set due to react state shenanigans.
185 // wait for the connector to get set due to react state shenanigans.
136 // eslint-disable-next-line react-hooks/exhaustive-deps
186 // eslint-disable-next-line react-hooks/exhaustive-deps
137 }, [connector]);
187 }, [connector]);
138
188
139− const goToRestart = useCallback(() => {
140− reset();
141− setNewWallet(Nothing());
142− }, [reset, setNewWallet]);
143−
144− const loginAndGoHome = useCallback(() => {
145− // set wallet state
146− resetWallet();
147− setWalletType(WALLET_TYPES.TICKET);
148− setUrbitWallet(Just(newWallet.value.wallet));
149− // (implicit) pointCursor stays the same
150− // redirect to point
151− popTo(names.POINT);
152− }, [resetWallet, setWalletType, setUrbitWallet, newWallet, popTo, names]);
153−
154− const handleUpdate = useCallback(
155− ({ type, state, value }) => {
156− switch (type) {
157− case 'progress':
158− return setProgress(state);
159− case 'askFunding':
160− return setNeedFunds(value);
161− case 'gotFunding':
162− return setNeedFunds(false);
163− default:
164− console.error(`Unknown update: ${type}`);
165− }
166− },
167− [setProgress, setNeedFunds]
168− );
169−
170 const renderAdditionalInfo = () => {
189 const renderAdditionalInfo = () => {
171 if (generalError) {
190 if (generalError) {
172 console.log(generalError);
191 console.log(generalError);