on master help sign in
invite: clear stored invite from cache on reticket
15bea83tomholford
src/store/storage/roller.ts+14
@@ -34,6 +34,20 @@ export const setStoredInvite = (ls: SecureLS, newInvite: Invite) => {
34 ls.set(INVITES_KEY, invites);
34 ls.set(INVITES_KEY, invites);
35};
35};
36
36
37+export const removeStoredInvite = (ls: SecureLS, key: number) => {
38+ let invites: InviteTickets = {};
39+ try {
40+ invites = ls.get(INVITES_KEY) || {};
41+ } catch (e) {}
42+
43+ if (key in invites) {
44+ let { [key]: _, ...filtered } = invites;
45+ invites = filtered;
46+ }
47+
48+ ls.set(INVITES_KEY, invites);
49+};
50+
37export const clearInvitesStorage = () => localStorage.removeItem(INVITES_KEY);
51export const clearInvitesStorage = () => localStorage.removeItem(INVITES_KEY);
38
52
39export const getHideMigrationMessage = () =>
53export const getHideMigrationMessage = () =>
src/views/Invite/useInvites.ts+17−15
@@ -13,12 +13,13 @@ import {
13 submitL2Transaction,
13 submitL2Transaction,
14 registerProxyAddress,
14 registerProxyAddress,
15} from 'lib/utils/roller';
15} from 'lib/utils/roller';
16−import { useCallback, useRef } from 'react';
16+import { useCallback } from 'react';
17import { useNetwork } from 'store/network';
17import { useNetwork } from 'store/network';
18import { usePointCursor } from 'store/pointCursor';
18import { usePointCursor } from 'store/pointCursor';
19import { useRollerStore } from 'store/rollerStore';
19import { useRollerStore } from 'store/rollerStore';
20import {
20import {
21 getStoredInvites,
21 getStoredInvites,
22+ removeStoredInvite,
22 setStoredInvite,
23 setStoredInvite,
23 setStoredInvites,
24 setStoredInvites,
24} from 'store/storage/roller';
25} from 'store/storage/roller';
@@ -170,21 +171,21 @@ export function useInvites() {
170 const invite =
171 const invite =
171 storedInvite || (await generateInviteInfo(planet, _authToken));
172 storedInvite || (await generateInviteInfo(planet, _authToken));
172
173
173− // TODO: check if the invite point's owner still matches the deterministic wallet address
174 const planetInfo = await api.getPoint(planet);
174 const planetInfo = await api.getPoint(planet);
175− setStoredInvite(ls, invite);
175+ // unclaimed point: if still owned by the deterministic invite wallet
176−
177 if (
176 if (
178 invite.owner.toLowerCase() ===
177 invite.owner.toLowerCase() ===
179 planetInfo.ownership?.owner?.address &&
178 planetInfo.ownership?.owner?.address &&
180 planetInfo.dominion === POINT_DOMINIONS.L2
179 planetInfo.dominion === POINT_DOMINIONS.L2
181 ) {
180 ) {
181+ setStoredInvite(ls, invite);
182 addInvite(curPoint, invite);
182 addInvite(curPoint, invite);
183 newInvites.push(invite);
183 newInvites.push(invite);
184− }
184+ } else {
185−
185+ // The point has been claimed, remove if it's in the cache
186− if (storedInvite) {
186+ if (storedInvite) {
187− setStoredInvite(ls, invite);
187+ removeStoredInvite(ls, planet);
188+ }
188 }
189 }
189 }
190 }
190
191
@@ -225,14 +226,8 @@ export function useInvites() {
225 throw new Error('Internal Error: Missing Contracts/Web3/Wallet');
226 throw new Error('Internal Error: Missing Contracts/Web3/Wallet');
226 }
227 }
227
228
228− // TODO: remove when UI disables management proxy from spawning invites
229− // if (Just.hasInstance(authMnemonic)) {
230− // throw new Error(
231− // "Auth key Error: A management mnemonic can't create invite codes"
232− // );
233− // }
234−
235 const invites: Invite[] = [];
229 const invites: Invite[] = [];
230+ const storedInvites = getStoredInvites(ls);
236
231
237 const proxy = point.getSpawnProxy();
232 const proxy = point.getSpawnProxy();
238
233
@@ -249,6 +244,13 @@ export function useInvites() {
249 const planet = planets[i];
244 const planet = planets[i];
250 const nonceInc = i + nonce;
245 const nonceInc = i + nonce;
251
246
247+ // When reticketing a planet in a browser that previously generated
248+ // the invite, we need to remove it from the cache.
249+ const storedInvite = storedInvites[planet];
250+ if (storedInvite) {
251+ removeStoredInvite(ls, planet);
252+ }
253+
252 const { ticket, inviteWallet } = await generateInviteWallet(
254 const { ticket, inviteWallet } = await generateInviteWallet(
253 planet,
255 planet,
254 _authToken
256 _authToken