on master help sign in
Update isL2Spawn check for getInvites
commita9c417173f4c1e961908e85d2c4becfd0a5faeb5 authorWill Galebach <willbach@gmail.com> dateSun 21 Nov 2021, 20:44 (5 years ago) parent9c28b5a
3 files changed+90−90
src/lib/useRoller.ts+87−87 src/views/Invite/Cohort.tsx+1−1 src/views/Point/Point.tsx+2−2
src/lib/useRoller.ts+87−87
@@ -319,97 +319,97 @@ export default function useRoller() {
319319 return inviteTemplate(planet, ticket, inviteWallet.ownership.keys.address);
320320 };
321321
322− const getInvites = useCallback(
323− async (isL2: boolean) => {
324− try {
325− setInvitesLoading(true);
326− const curPoint: number = Number(need.point(pointCursor));
327− const _authToken = authToken.getOrElse(null);
328− const _contracts = contracts.getOrElse(null);
329−
330− if (_authToken && _contracts) {
331− const spawnedPoints = isL2 ? await api.getSpawned(curPoint) : [];
332−
333− const newPending = await api.getPendingByShip(curPoint);
334− setPendingTransactions(newPending);
335− const pendingSpawns = getPendingSpawns(newPending);
336−
337− const availablePoints = await azimuth.azimuth.getUnspawnedChildren(
338− _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,
356− invitePlanets.map(p => inviteTemplate(p))
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);
322+ const getInvites = useCallback(async () => {
323+ try {
324+ setInvitesLoading(true);
325+ const curPoint: number = Number(need.point(pointCursor));
326+ const _authToken = authToken.getOrElse(null);
327+ const _contracts = contracts.getOrElse(null);
328+
329+ if (_authToken && _contracts) {
330+ const spawnedPoints = point.isL2Spawn
331+ ? await api.getSpawned(curPoint)
332+ : [];
333+
334+ const newPending = await api.getPendingByShip(curPoint);
335+ setPendingTransactions(newPending);
336+ const pendingSpawns = getPendingSpawns(newPending);
337+
338+ const availablePoints = await azimuth.azimuth.getUnspawnedChildren(
339+ _contracts,
340+ curPoint
341+ );
373342
374− if (
375− invite.owner.toLowerCase() ===
376− planetInfo.ownership?.owner?.address ||
377− planetInfo.ownership?.transferProxy?.address !== ETH_ZERO_ADDR
378− ) {
379− newInvites.push(invite);
380− updateInvite(curPoint, invite);
381− } else {
382− removeInvite(curPoint, invite.planet);
383− }
384−
385− if (storedInvite) {
386− setStoredInvite(ls, invite);
387− }
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 (
376+ invite.owner.toLowerCase() ===
377+ planetInfo.ownership?.owner?.address ||
378+ planetInfo.ownership?.transferProxy?.address !== ETH_ZERO_ADDR
379+ ) {
380+ newInvites.push(invite);
381+ updateInvite(curPoint, invite);
382+ } else {
383+ removeInvite(curPoint, invite.planet);
384+ }
385+
386+ if (storedInvite) {
387+ setStoredInvite(ls, invite);
388388 }
389− setInvites(curPoint, newInvites);
390− setInvitesLoading(false);
391− return newInvites;
392389 }
393− } catch (error) {
394− console.warn('ERROR GETTING INVITES', error);
390+ setInvites(curPoint, newInvites);
391+ setInvitesLoading(false);
392+ return newInvites;
395393 }
396− },
397− [
398− api,
399− authToken,
400− contracts,
401− controlledPoints,
402− getDetails,
403− pointCursor,
404− ls,
405− removeInvite,
406− setInvites,
407− setInvitesLoading,
408− setInviteGeneratingNum,
409− setPendingTransactions,
410− updateInvite,
411− ]
412− );
394+ } catch (error) {
395+ console.warn('ERROR GETTING INVITES', error);
396+ }
397+ }, [
398+ api,
399+ authToken,
400+ contracts,
401+ controlledPoints,
402+ getDetails,
403+ pointCursor,
404+ ls,
405+ point,
406+ removeInvite,
407+ setInvites,
408+ setInvitesLoading,
409+ setInviteGeneratingNum,
410+ setPendingTransactions,
411+ updateInvite,
412+ ]);
413413
414414 interface ConfigureKeysParams {
415415 breach: boolean;
src/views/Invite/Cohort.tsx+1−1
@@ -207,7 +207,7 @@ export default function InviteCohort() {
207207 const downloadCsv = useCallback(() => {
208208 const generateAndDownload = async () => {
209209 setLoading(true);
210− const invites = await getInvites(currentL2);
210+ const invites = await getInvites();
211211 if (invites) {
212212 const csv = invites.reduce(
213213 (csvData, { ticket, planet }, ind) =>
src/views/Point/Point.tsx+2−2
@@ -67,12 +67,12 @@ export default function Point() {
6767 const getTransactions = async () => {
6868 setLoading(true);
6969 getPendingTransactions();
70− getInvites(point.isL2);
70+ getInvites();
7171 setTimeout(() => setLoading(false), 100);
7272 };
7373
7474 await getTransactions();
75− }, [point, getInvites, getPendingTransactions, setLoading]);
75+ }, [getInvites, getPendingTransactions, setLoading]);
7676
7777 useEffect(() => {
7878 loadL1Info();