on master help sign in
Update isL2Spawn check for getInvites
a9c4171Will Galebach
src/lib/useRoller.ts+87−87
@@ -319,97 +319,97 @@ export default function useRoller() {
319 return inviteTemplate(planet, ticket, inviteWallet.ownership.keys.address);
319 return inviteTemplate(planet, ticket, inviteWallet.ownership.keys.address);
320 };
320 };
321
321
322− const getInvites = useCallback(
322+ const getInvites = useCallback(async () => {
323− async (isL2: boolean) => {
324− try {
323+ try {
325− setInvitesLoading(true);
324+ setInvitesLoading(true);
326− const curPoint: number = Number(need.point(pointCursor));
325+ const curPoint: number = Number(need.point(pointCursor));
327− const _authToken = authToken.getOrElse(null);
326+ const _authToken = authToken.getOrElse(null);
328− const _contracts = contracts.getOrElse(null);
327+ const _contracts = contracts.getOrElse(null);
329−
328+
330− if (_authToken && _contracts) {
329+ if (_authToken && _contracts) {
330+ const spawnedPoints = point.isL2Spawn
331− const spawnedPoints = isL2 ? await api.getSpawned(curPoint) : [];
331+ ? await api.getSpawned(curPoint)
332−
332+ : [];
333+
333− const newPending = await api.getPendingByShip(curPoint);
334+ const newPending = await api.getPendingByShip(curPoint);
334− setPendingTransactions(newPending);
335+ setPendingTransactions(newPending);
335− const pendingSpawns = getPendingSpawns(newPending);
336+ const pendingSpawns = getPendingSpawns(newPending);
336−
337+
337− const availablePoints = await azimuth.azimuth.getUnspawnedChildren(
338+ const availablePoints = await azimuth.azimuth.getUnspawnedChildren(
338− _contracts,
339+ _contracts,
339− curPoint
340− );
341−
342− const outgoingPoints = getOutgoingPoints(
343− controlledPoints,
344− getDetails
345− ).filter((p: number) => isPlanet(p) && availablePoints.includes(p));
346−
347− const invitePlanets = spawnedPoints
348− .concat(
349− outgoingPoints.filter((p: number) => !spawnedPoints.includes(p))
350− )
351− .filter((p: number) => !pendingSpawns.has(p))
352− .sort();
353−
354− setInvites(
355− curPoint,
340+ curPoint
356− invitePlanets.map(p => inviteTemplate(p))
341+ );
357− );
358−
359− const newInvites: Invite[] = [];
360− // Iterate over all of the stored invites, generating wallet info as necessary
361− const storedInvites = getStoredInvites(ls);
362−
363− for (let i = 0; i < invitePlanets.length; i++) {
364− setInviteGeneratingNum(i + 1);
365− const planet = invitePlanets[i];
366− const storedInvite = storedInvites[planet];
367− const invite =
368− storedInvite || (await generateInviteInfo(planet, _authToken));
369−
370− // TODO: check if the invite point's owner still matches the deterministic wallet address
371− const planetInfo = await api.getPoint(planet);
372− setStoredInvite(ls, invite);
373
342
374− if (
343+ const outgoingPoints = getOutgoingPoints(
344+ controlledPoints,
345+ getDetails
346+ ).filter((p: number) => isPlanet(p) && availablePoints.includes(p));
347+
348+ const invitePlanets = spawnedPoints
349+ .concat(
350+ outgoingPoints.filter((p: number) => !spawnedPoints.includes(p))
351+ )
352+ .filter((p: number) => !pendingSpawns.has(p))
353+ .sort();
354+
355+ setInvites(
356+ curPoint,
357+ invitePlanets.map(p => inviteTemplate(p))
358+ );
359+
360+ const newInvites: Invite[] = [];
361+ // Iterate over all of the stored invites, generating wallet info as necessary
362+ const storedInvites = getStoredInvites(ls);
363+
364+ for (let i = 0; i < invitePlanets.length; i++) {
365+ setInviteGeneratingNum(i + 1);
366+ const planet = invitePlanets[i];
367+ const storedInvite = storedInvites[planet];
368+ const invite =
369+ storedInvite || (await generateInviteInfo(planet, _authToken));
370+
371+ // TODO: check if the invite point's owner still matches the deterministic wallet address
372+ const planetInfo = await api.getPoint(planet);
373+ setStoredInvite(ls, invite);
374+
375+ if (
375− invite.owner.toLowerCase() ===
376+ invite.owner.toLowerCase() ===
376− planetInfo.ownership?.owner?.address ||
377+ planetInfo.ownership?.owner?.address ||
377− planetInfo.ownership?.transferProxy?.address !== ETH_ZERO_ADDR
378+ planetInfo.ownership?.transferProxy?.address !== ETH_ZERO_ADDR
378− ) {
379+ ) {
379− newInvites.push(invite);
380+ newInvites.push(invite);
380− updateInvite(curPoint, invite);
381+ updateInvite(curPoint, invite);
381− } else {
382+ } else {
382− removeInvite(curPoint, invite.planet);
383+ removeInvite(curPoint, invite.planet);
383− }
384+ }
384−
385+
385− if (storedInvite) {
386+ if (storedInvite) {
386− setStoredInvite(ls, invite);
387+ setStoredInvite(ls, invite);
387− }
388 }
388 }
389− setInvites(curPoint, newInvites);
390− setInvitesLoading(false);
391− return newInvites;
392 }
389 }
393− } catch (error) {
390+ setInvites(curPoint, newInvites);
394− console.warn('ERROR GETTING INVITES', error);
391+ setInvitesLoading(false);
392+ return newInvites;
395 }
393 }
396− },
394+ } catch (error) {
395+ console.warn('ERROR GETTING INVITES', error);
396+ }
397− [
397+ }, [
398− api,
398+ api,
399− authToken,
399+ authToken,
400− contracts,
400+ contracts,
401− controlledPoints,
401+ controlledPoints,
402− getDetails,
402+ getDetails,
403− pointCursor,
403+ pointCursor,
404− ls,
404+ ls,
405+ point,
405− removeInvite,
406+ removeInvite,
406− setInvites,
407+ setInvites,
407− setInvitesLoading,
408+ setInvitesLoading,
408− setInviteGeneratingNum,
409+ setInviteGeneratingNum,
409− setPendingTransactions,
410+ setPendingTransactions,
410− updateInvite,
411+ updateInvite,
411− ]
412− );
412+ ]);
413
413
414 interface ConfigureKeysParams {
414 interface ConfigureKeysParams {
415 breach: boolean;
415 breach: boolean;
src/views/Invite/Cohort.tsx+1−1
@@ -207,7 +207,7 @@ export default function InviteCohort() {
207 const downloadCsv = useCallback(() => {
207 const downloadCsv = useCallback(() => {
208 const generateAndDownload = async () => {
208 const generateAndDownload = async () => {
209 setLoading(true);
209 setLoading(true);
210− const invites = await getInvites(currentL2);
210+ const invites = await getInvites();
211 if (invites) {
211 if (invites) {
212 const csv = invites.reduce(
212 const csv = invites.reduce(
213 (csvData, { ticket, planet }, ind) =>
213 (csvData, { ticket, planet }, ind) =>
src/views/Point/Point.tsx+2−2
@@ -67,12 +67,12 @@ export default function Point() {
67 const getTransactions = async () => {
67 const getTransactions = async () => {
68 setLoading(true);
68 setLoading(true);
69 getPendingTransactions();
69 getPendingTransactions();
70− getInvites(point.isL2);
70+ getInvites();
71 setTimeout(() => setLoading(false), 100);
71 setTimeout(() => setLoading(false), 100);
72 };
72 };
73
73
74 await getTransactions();
74 await getTransactions();
75− }, [point, getInvites, getPendingTransactions, setLoading]);
75+ }, [getInvites, getPendingTransactions, setLoading]);
76
76
77 useEffect(() => {
77 useEffect(() => {
78 loadL1Info();
78 loadL1Info();