on master help sign in
Updated invite sync logic
commitd8aa1ca49db98943694a673128fc4f0fae0291f3 authorWill Galebach <willbach@gmail.com> dateTue 7 Sep 2021, 22:48 (5 years ago) parent1ac970d
3 files changed+11−27
src/lib/useRoller.ts+3−10 src/store/storage/roller.ts+7−10 src/views/Invite/Cohort.js+1−7
src/lib/useRoller.ts+3−10
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
22import * as wg from 'lib/walletgen';
33import * as need from 'lib/need';
44import * as azimuth from 'azimuth-js';
5+import * as ob from 'urbit-ob';
56
67import {
78 Config,
@@ -224,7 +225,7 @@ export default function useRoller() {
224225 const getInvites = useCallback(
225226 async (isL2: boolean) => {
226227 try {
227− const curPoint: string = need.point(pointCursor);
228+ const curPoint: number = Number(need.point(pointCursor));
228229 const invites = getStoredInvites(curPoint);
229230 const availableInvites = invites.available;
230231
@@ -236,20 +237,17 @@ export default function useRoller() {
236237
237238 const stillPending = invites.pending.filter(invite => {
238239 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)
240241 );
241−
242242 if (completed) {
243243 availableInvites.push({ ...invite, status: 'available' });
244244 }
245−
246245 return !completed;
247246 });
248247
249248 setStoredInvites(curPoint, {
250249 available: availableInvites,
251250 pending: stillPending,
252− claimed: invites.claimed,
253251 });
254252 setInvites(availableInvites);
255253
@@ -296,10 +294,6 @@ export default function useRoller() {
296294 console.log('POSSIBLE MISSING', possibleMissingInvites);
297295 }
298296
299− const newClaimed = availableInvites.filter(
300− ({ planet }) => !possibleMissingInvites.includes(planet)
301− );
302−
303297 for (let i = 0; i < possibleMissingInvites.length; i++) {
304298 const planet = possibleMissingInvites[i];
305299
@@ -331,7 +325,6 @@ export default function useRoller() {
331325 possibleMissingInvites.includes(planet)
332326 ),
333327 pending: stillPending,
334− claimed: invites.claimed.concat(newClaimed),
335328 });
336329 setInvites(availableInvites);
337330 }
src/store/storage/roller.ts+7−10
@@ -5,30 +5,27 @@ const INVITES_KEY = 'invites';
55export interface StoredInvites {
66 available: Invite[];
77 pending: Invite[];
8− claimed: Invite[];
98}
109
11−export const getStoredInvites = (point: string): StoredInvites => {
10+export const getStoredInvites = (point: number): StoredInvites => {
1211 const invitesString = localStorage.getItem(INVITES_KEY) || '{}';
1312 const invites = JSON.parse(invitesString);
1413
15− console.log('STORED INVITES', invites);
16−
17− if (invites[point]) {
18− return invites[point];
14+ if (invites[String(point)]) {
15+ return invites[String(point)];
1916 }
2017
21− return { available: [], pending: [], claimed: [] };
18+ return { available: [], pending: [] };
2219};
2320
24−export const setStoredInvites = (point: string, newInvites: StoredInvites) => {
21+export const setStoredInvites = (point: number, newInvites: StoredInvites) => {
2522 const invitesString = localStorage.getItem(INVITES_KEY) || '{}';
2623 const invites = JSON.parse(invitesString);
27− invites[point] = newInvites;
24+ invites[Number(point)] = newInvites;
2825 localStorage.setItem(INVITES_KEY, JSON.stringify(invites));
2926};
3027
31−export const setPendingInvites = (point: string, pendingInvites: Invite[]) => {
28+export const setPendingInvites = (point: number, pendingInvites: Invite[]) => {
3229 const invites = getStoredInvites(point);
3330 invites.pending.push(...pendingInvites);
3431 setStoredInvites(point, invites);
src/views/Invite/Cohort.js+1−7
@@ -45,11 +45,7 @@ export default function InviteCohort() {
4545 invites,
4646 setInvites,
4747 } = useRollerStore();
48− const {
49− generateInviteCodes,
50− getPendingTransactions,
51− getInvites,
52− } = useRoller();
48+ const { generateInviteCodes, getPendingTransactions } = useRoller();
5349 const { pointCursor } = usePointCursor();
5450 const { contracts } = useNetwork();
5551 const { getDetails, syncControlledPoints } = usePointCache();
@@ -75,8 +71,6 @@ export default function InviteCohort() {
7571
7672 const { construct, unconstruct, completed, bind } = useIssueChild();
7773
78− useEffect(() => getInvites(), []); // eslint-disable-line react-hooks/exhaustive-deps
79−
8074 // Set up the invite spawn if on L1
8175 useEffect(() => {
8276 const _authToken = authToken.getOrElse(null);