@@ -13,7 +13,11 @@ import { useNetwork } from 'store/network';
1313import { usePointCursor } from 'store/pointCursor';
1414import { EMPTY_POINT, useRollerStore } from 'store/rollerStore';
1515import { useWallet } from 'store/wallet';
16−import { getStoredInvites, setStoredInvites } from 'store/storage/roller';
16+import {
17+ getStoredInvites,
18+ setStoredInvite,
19+ setStoredInvites,
20+} from 'store/storage/roller';
1721import { usePointCache } from 'store/pointCache';
1822import { getOutgoingPoints } from 'views/Points';
1923
@@ -86,13 +90,14 @@ export default function useRoller() {
8690 nextBatchTime,
8791 point,
8892 invitePoints,
89− invites,
93+ removeInvite,
9094 setNextBatchTime,
9195 setPendingTransactions,
9296 setInvites,
9397 setInvitePoints,
9498 setInviteGeneratingNum,
9599 setPoints,
100+ updateInvite,
96101 } = useRollerStore();
97102 const [config, setConfig] = useState<Config | null>(null);
98103
@@ -120,6 +125,15 @@ export default function useRoller() {
120125 return new RollerRPCAPI(options);
121126 }, [options]);
122127
128+ const ls = useMemo(
129+ () =>
130+ new SecureLS({
131+ isCompression: false,
132+ encryptionSecret: authToken.getOrElse('default'),
133+ }),
134+ [authToken]
135+ );
136+
123137 const fetchConfig = useCallback(async () => {
124138 api
125139 .getRollerConfig()
@@ -136,15 +150,6 @@ export default function useRoller() {
136150 });
137151 }, [api]); // eslint-disable-line react-hooks/exhaustive-deps
138152
139− const ls = useMemo(
140− () =>
141− new SecureLS({
142− isCompression: false,
143− encryptionSecret: authToken.getOrElse('default'),
144− }),
145− [authToken]
146− );
147−
148153 const generateInviteCodes = useCallback(
149154 async (numInvites: number) => {
150155 const _point = need.point(pointCursor);
@@ -346,21 +351,20 @@ export default function useRoller() {
346351 for (let i = 0; i < invitePlanets.length; i++) {
347352 setInviteGeneratingNum(i + 1);
348353 const planet = invitePlanets[i];
349− const invite = storedInvites[planet];
354+ const invite =
355+ storedInvites[planet] ||
356+ (await generateInviteInfo(planet, _authToken));
350357
351− if (invite?.ticket) {
358+ // TODO: check if the invite point's owner still matches the deterministic wallet address
359+ const planetInfo = await api.getPoint(planet);
360+ if (invite.owner === planetInfo.ownership?.transferProxy?.address) {
352361 newInvites.push(invite);
353− } else if (getAll) {
354− if (isDevelopment) {
355− console.log('MISSING INVITE INFO', planet);
356− }
357− const newInvite = await generateInviteInfo(planet, _authToken);
358− newInvites.push(newInvite);
362+ updateInvite(invite);
363+ setStoredInvite(ls, invite);
359364 } else {
360− newInvites.push(inviteTemplate(planet));
365+ removeInvite(planet);
361366 }
362367 }
363−
364368 setStoredInvites(ls, newInvites);
365369 setInvites(newInvites);
366370
@@ -379,27 +383,13 @@ export default function useRoller() {
379383 pointCursor,
380384 invitePoints,
381385 ls,
386+ removeInvite,
382387 setInvites,
383388 setInviteGeneratingNum,
389+ updateInvite,
384390 ]
385391 );
386392
387− const showInvite = useCallback(
388− async (planet: number) => {
389− const _authToken = authToken.getOrElse(null);
390−
391− if (_authToken) {
392− const newInvite = await generateInviteInfo(planet, _authToken);
393− const newInvites = invites.map(invite =>
394− invite.planet === planet ? newInvite : invite
395− );
396− setInvites(newInvites);
397− setStoredInvites(ls, newInvites);
398− }
399− },
400− [authToken, invites, ls, setInvites]
401− );
402−
403393 const getNumInvites = useCallback(
404394 async (isL2: boolean) => {
405395 try {
@@ -887,6 +877,5 @@ export default function useRoller() {
887877 ls,
888878 performL2Reticket,
889879 setProxyAddress,
890− showInvite,
891880 };
892881}