on master help sign in
reticket: L1 points with L2 spawn proxy can reticket

This changes the conditional check in `performL2reticket` so that L1 points with dominion of 'spawn' use the L2 flow. This also updates the L2 implementation to hook into the progress bar animation as the 4 TXes are performed.

commitd3d9e914981ab393e98ab790350107c837d086b3 authortomholford <tomholford@users.noreply.github.com> dateTue 8 Feb 2022, 20:04 (5 years ago) parent54f5889
3 files changed+81−37
src/lib/types/L2Transaction.ts+13 src/lib/useRoller.ts+12 src/views/UrbitID/ResetKeys/ResetExecute.js+56−37
src/lib/types/L2Transaction.ts+13
@@ -40,10 +40,23 @@ export interface TransactionData {
4040 method: Function;
4141}
4242
43+interface ReticketProgressCallback {
44+ ({
45+ type,
46+ state,
47+ value,
48+ }: {
49+ type: string;
50+ state: number;
51+ value?: string;
52+ }): void;
53+}
54+
4355export interface ReticketParams {
4456 point: Ship;
4557 to: EthAddress;
4658 manager: EthAddress;
4759 fromWallet: BridgeWallet;
4860 toWallet: UrbitWallet;
61+ onUpdate?: ReticketProgressCallback;
4962}
src/lib/useRoller.ts+12
@@ -51,6 +51,7 @@ import { ddmmmYYYY } from './utils/date';
5151import { showNotification } from './utils/notifications';
5252import { useWalletConnect } from './useWalletConnect';
5353import { PendingL1Txn } from './types/PendingL1Transaction';
54+import { TRANSACTION_PROGRESS } from './reticket';
5455
5556const ONE_SECOND = 1000;
5657
@@ -700,15 +701,20 @@ export default function useRoller() {
700701 manager,
701702 fromWallet,
702703 toWallet,
704+ onUpdate,
703705 }: ReticketParams) => {
704706 const azimuthPoint = await api.getPoint(point);
705707 const proxy = 'own';
706708 const _web3 = web3.getOrElse(null);
707709 let nonce = await api.getNonce({ ship: point, proxy });
710+ const progress = onUpdate
711+ ? (state: number) => onUpdate({ type: 'progress', state })
712+ : () => {};
708713
709714 let requests = [];
710715
711716 // 1. Update networking keys
717+ progress(TRANSACTION_PROGRESS.GENERATING);
712718 const networkRevision = convertToInt(azimuthPoint.network.keys.life, 10);
713719 const nextRevision = networkRevision + 1;
714720 const networkSeed = await deriveNetworkSeedFromUrbitWallet(
@@ -731,6 +737,7 @@ export default function useRoller() {
731737 requests.push(configureKeysRequest);
732738
733739 // 2. Set Management Proxy
740+ progress(TRANSACTION_PROGRESS.SIGNING);
734741 const registerMgmtRequest = await registerProxyAddress(
735742 api,
736743 fromWallet,
@@ -747,6 +754,7 @@ export default function useRoller() {
747754 requests.push(registerMgmtRequest);
748755
749756 // 3. Set Spawn Proxy
757+ progress(TRANSACTION_PROGRESS.FUNDING);
750758 if (!isPlanet(Number(point))) {
751759 const registerSpawnRequest = await registerProxyAddress(
752760 api,
@@ -764,6 +772,7 @@ export default function useRoller() {
764772 requests.push(registerSpawnRequest);
765773 }
766774 // 4. Transfer point
775+ progress(TRANSACTION_PROGRESS.TRANSFERRING);
767776 const transferTxRequest = await submitL2Transaction({
768777 api,
769778 wallet: fromWallet,
@@ -778,7 +787,10 @@ export default function useRoller() {
778787 });
779788 requests.push(transferTxRequest);
780789
790+ progress(TRANSACTION_PROGRESS.CLEANING);
781791 const hashes = await Promise.all(requests);
792+
793+ progress(TRANSACTION_PROGRESS.DONE);
782794 return hashes;
783795 };
784796
src/views/UrbitID/ResetKeys/ResetExecute.js+56−37
@@ -57,7 +57,7 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
5757 } = useWallet();
5858 const { performL2Reticket } = useRoller();
5959 const {
60− point: { isL2 },
60+ point: { isL2Spawn },
6161 } = useRollerStore();
6262 const { pointCursor } = usePointCursor();
6363 const { getDetails } = usePointCache();
@@ -74,8 +74,38 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
7474
7575 useBlockWindowClose();
7676
77− // start reticketing transactions on mount
78− useEffect(() => {
77+ const goToRestart = useCallback(() => {
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 () => {
79109 (async () => {
80110 // due to react shenanigans we may need to wait for the connector
81111 if (
@@ -98,17 +128,16 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
98128 walletType === WALLET_TYPES.WALLET_CONNECT ? wcSend : undefined;
99129
100130 try {
101− if (isL2) {
102− console.log(newWallet.value);
131+ if (isL2Spawn) {
103132 // FIXME: the useEffect is called twice, which is fine since the duplicate
104133 // L2 txs will be discarded
105− //
106134 await performL2Reticket({
107135 point,
108136 to: newWallet.value.wallet.ownership.keys.address,
109137 manager: newWallet.value.wallet.management.keys.address,
110138 toWallet: newWallet.value.wallet,
111139 fromWallet: need.wallet(wallet),
140+ onUpdate: handleUpdate,
112141 });
113142 } else
114143 await reticketPointBetweenWallets({
@@ -130,43 +159,33 @@ export default function ResetExecute({ newWallet, setNewWallet }) {
130159 setGeneralError(err);
131160 }
132161 })();
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();
133183 //NOTE this was using useLifecycle previously (which is useEffect without
134184 // dependencies) and worked fine, but in the wc case we might need to
135185 // wait for the connector to get set due to react state shenanigans.
136186 // eslint-disable-next-line react-hooks/exhaustive-deps
137187 }, [connector]);
138188
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−
170189 const renderAdditionalInfo = () => {
171190 if (generalError) {
172191 console.log(generalError);