on master help sign in
Updated invite sync logic
d8aa1caWill Galebach
src/lib/useRoller.ts+3−10
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
2import * as wg from 'lib/walletgen';
2import * as wg from 'lib/walletgen';
3import * as need from 'lib/need';
3import * as need from 'lib/need';
4import * as azimuth from 'azimuth-js';
4import * as azimuth from 'azimuth-js';
5+import * as ob from 'urbit-ob';
5
6
6import {
7import {
7 Config,
8 Config,
@@ -224,7 +225,7 @@ export default function useRoller() {
224 const getInvites = useCallback(
225 const getInvites = useCallback(
225 async (isL2: boolean) => {
226 async (isL2: boolean) => {
226 try {
227 try {
227− const curPoint: string = need.point(pointCursor);
228+ const curPoint: number = Number(need.point(pointCursor));
228 const invites = getStoredInvites(curPoint);
229 const invites = getStoredInvites(curPoint);
229 const availableInvites = invites.available;
230 const availableInvites = invites.available;
230
231
@@ -236,20 +237,17 @@ export default function useRoller() {
236
237
237 const stillPending = invites.pending.filter(invite => {
238 const stillPending = invites.pending.filter(invite => {
238 const completed = !pendingTransactions.find(
239 const completed = !pendingTransactions.find(
239− p => p?.rawTx?.tx?.tx?.data?.ship === invite.planet
240+ p => `~${p?.rawTx?.tx?.tx?.data?.ship}` === ob.patp(invite.planet)
240 );
241 );
241−
242 if (completed) {
242 if (completed) {
243 availableInvites.push({ ...invite, status: 'available' });
243 availableInvites.push({ ...invite, status: 'available' });
244 }
244 }
245−
246 return !completed;
245 return !completed;
247 });
246 });
248
247
249 setStoredInvites(curPoint, {
248 setStoredInvites(curPoint, {
250 available: availableInvites,
249 available: availableInvites,
251 pending: stillPending,
250 pending: stillPending,
252− claimed: invites.claimed,
253 });
251 });
254 setInvites(availableInvites);
252 setInvites(availableInvites);
255
253
@@ -296,10 +294,6 @@ export default function useRoller() {
296 console.log('POSSIBLE MISSING', possibleMissingInvites);
294 console.log('POSSIBLE MISSING', possibleMissingInvites);
297 }
295 }
298
296
299− const newClaimed = availableInvites.filter(
300− ({ planet }) => !possibleMissingInvites.includes(planet)
301− );
302−
303 for (let i = 0; i < possibleMissingInvites.length; i++) {
297 for (let i = 0; i < possibleMissingInvites.length; i++) {
304 const planet = possibleMissingInvites[i];
298 const planet = possibleMissingInvites[i];
305
299
@@ -331,7 +325,6 @@ export default function useRoller() {
331 possibleMissingInvites.includes(planet)
325 possibleMissingInvites.includes(planet)
332 ),
326 ),
333 pending: stillPending,
327 pending: stillPending,
334− claimed: invites.claimed.concat(newClaimed),
335 });
328 });
336 setInvites(availableInvites);
329 setInvites(availableInvites);
337 }
330 }
src/store/storage/roller.ts+7−10
@@ -5,30 +5,27 @@ const INVITES_KEY = 'invites';
5export interface StoredInvites {
5export interface StoredInvites {
6 available: Invite[];
6 available: Invite[];
7 pending: Invite[];
7 pending: Invite[];
8− claimed: Invite[];
9}
8}
10
9
11−export const getStoredInvites = (point: string): StoredInvites => {
10+export const getStoredInvites = (point: number): StoredInvites => {
12 const invitesString = localStorage.getItem(INVITES_KEY) || '{}';
11 const invitesString = localStorage.getItem(INVITES_KEY) || '{}';
13 const invites = JSON.parse(invitesString);
12 const invites = JSON.parse(invitesString);
14
13
15− console.log('STORED INVITES', invites);
16−
17− if (invites[point]) {
14+ if (invites[String(point)]) {
18− return invites[point];
15+ return invites[String(point)];
19 }
16 }
20
17
21− return { available: [], pending: [], claimed: [] };
18+ return { available: [], pending: [] };
22};
19};
23
20
24−export const setStoredInvites = (point: string, newInvites: StoredInvites) => {
21+export const setStoredInvites = (point: number, newInvites: StoredInvites) => {
25 const invitesString = localStorage.getItem(INVITES_KEY) || '{}';
22 const invitesString = localStorage.getItem(INVITES_KEY) || '{}';
26 const invites = JSON.parse(invitesString);
23 const invites = JSON.parse(invitesString);
27− invites[point] = newInvites;
24+ invites[Number(point)] = newInvites;
28 localStorage.setItem(INVITES_KEY, JSON.stringify(invites));
25 localStorage.setItem(INVITES_KEY, JSON.stringify(invites));
29};
26};
30
27
31−export const setPendingInvites = (point: string, pendingInvites: Invite[]) => {
28+export const setPendingInvites = (point: number, pendingInvites: Invite[]) => {
32 const invites = getStoredInvites(point);
29 const invites = getStoredInvites(point);
33 invites.pending.push(...pendingInvites);
30 invites.pending.push(...pendingInvites);
34 setStoredInvites(point, invites);
31 setStoredInvites(point, invites);
src/views/Invite/Cohort.js+1−7
@@ -45,11 +45,7 @@ export default function InviteCohort() {
45 invites,
45 invites,
46 setInvites,
46 setInvites,
47 } = useRollerStore();
47 } = useRollerStore();
48− const {
49− generateInviteCodes,
50− getPendingTransactions,
48+ const { generateInviteCodes, getPendingTransactions } = useRoller();
51− getInvites,
52− } = useRoller();
53 const { pointCursor } = usePointCursor();
49 const { pointCursor } = usePointCursor();
54 const { contracts } = useNetwork();
50 const { contracts } = useNetwork();
55 const { getDetails, syncControlledPoints } = usePointCache();
51 const { getDetails, syncControlledPoints } = usePointCache();
@@ -75,8 +71,6 @@ export default function InviteCohort() {
75
71
76 const { construct, unconstruct, completed, bind } = useIssueChild();
72 const { construct, unconstruct, completed, bind } = useIssueChild();
77
73
78− useEffect(() => getInvites(), []); // eslint-disable-line react-hooks/exhaustive-deps
79−
80 // Set up the invite spawn if on L1
74 // Set up the invite spawn if on L1
81 useEffect(() => {
75 useEffect(() => {
82 const _authToken = authToken.getOrElse(null);
76 const _authToken = authToken.getOrElse(null);