on master help sign in
Updated L1 invites
commit50fd8523e674e151a4d167420fe14b95f3bbab47 authorWill Galebach <willbach@gmail.com> dateMon 6 Sep 2021, 15:28 (5 years ago) parent200d8b8
4 files changed+69−80
src/lib/useRoller.ts+19−30 src/store/lib/useControlledPointsStore.js+1−1 src/views/Invite/Cohort.js+16−18 src/views/Points.js+33−31
src/lib/useRoller.ts+19−30
@@ -2,7 +2,6 @@ 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 { Just, Nothing } from 'folktale/maybe';
65
76import {
87 Config,
@@ -30,7 +29,7 @@ import {
3029 setStoredInvites,
3130} from 'store/storage/roller';
3231import { usePointCache } from 'store/pointCache';
33−import { hasTransferProxy, maybeGetResult } from 'views/Points';
32+import { getOutgoingPoints, hasTransferProxy, maybeGetResult } from 'views/Points';
3433
3534const hasPoint = (point: number) => (invite: Invite) => invite.planet === point;
3635
@@ -228,6 +227,7 @@ export default function useRoller() {
228227 const curPoint: string = need.point(pointCursor);
229228 const invites = getStoredInvites(curPoint);
230229 const availableInvites = invites.available;
230+ console.log('WHAT', curPoint, invites, availableInvites)
231231
232232 const pendingTransactions = await api.getPendingByShip(curPoint);
233233 console.log('PENDING', pendingTransactions);
@@ -260,37 +260,21 @@ export default function useRoller() {
260260 possibleMissingInvites = allSpawned.filter(
261261 (p: number) =>
262262 ownedPoints.includes(p) &&
263− azimuth.azimuth.getPointSize(p) === azimuth.azimuth.PointSize.Planet
263+ azimuth.azimuth.getPointSize(p) ===
264+ azimuth.azimuth.PointSize.Planet
264265 );
265266 } else {
266− const maybeOutgoingPoints = controlledPoints.chain((points: any) =>
267− points.matchWith({
268− Error: () => Nothing(),
269− Ok: (c: any) => {
270− const points = c.value.ownedPoints.map((point: number) =>
271− getDetails(point).chain((details: any) =>
272− Just({ point: point, has: hasTransferProxy(details) })
273− )
274− );
275− if (points.every((p: any) => Just.hasInstance(p))) {
276− const outgoing = points
277− .filter((p: any) => p.value.has)
278− .map((p: any) => p.value.point);
279− return Just(outgoing);
280− } else {
281− return Nothing();
282− }
283− },
284− })
267+ // How to get outgoing points by star?
268+ const outgoingPoints = getOutgoingPoints(
269+ controlledPoints,
270+ getDetails
285271 );
286272
287− possibleMissingInvites = maybeOutgoingPoints
288− .getOrElse([])
289− .filter(
290− (p: number) =>
291− azimuth.azimuth.getPointSize(p) ===
292− azimuth.azimuth.PointSize.Planet
293− );
273+ possibleMissingInvites = outgoingPoints.filter(
274+ (p: number) =>
275+ azimuth.azimuth.getPointSize(p) ===
276+ azimuth.azimuth.PointSize.Planet
277+ );
294278 }
295279
296280 // Iterate over all spawned and controlled planets
@@ -298,6 +282,8 @@ export default function useRoller() {
298282 const _authToken = authToken.getOrElse(null);
299283 const _contracts = contracts.getOrElse(null);
300284
285+ console.log('POSSIBLE MISSING', possibleMissingInvites)
286+
301287 const newClaimed = availableInvites.filter(
302288 ({ planet }) => !possibleMissingInvites.includes(planet)
303289 );
@@ -306,7 +292,10 @@ export default function useRoller() {
306292 for (let i = 0; i < possibleMissingInvites.length; i++) {
307293 const planet = possibleMissingInvites[i];
308294
309− if (!availableInvites.find(hasPoint(planet))) {
295+ if (
296+ !availableInvites.find(hasPoint(planet)) &&
297+ !(await azimuth.azimuth.isActive(_contracts, planet))
298+ ) {
310299 console.log('MISSING IN AVAILABLE', planet);
311300 const {
312301 ticket,
src/store/lib/useControlledPointsStore.js+1−1
@@ -39,7 +39,7 @@ export default function useControlledPointsStore() {
3939 getPoints('spawn', address),
4040 ]);
4141
42− console.log(ownedPoints)
42+ console.log('OWNED POINTS', ownedPoints)
4343
4444 if (
4545 ownedPoints === null &&
src/views/Invite/Cohort.js+16−18
@@ -30,6 +30,7 @@ import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
3030
3131import './Cohort.scss';
3232import { getStoredInvites, setStoredInvites } from 'store/storage/roller';
33+import { ETH_ZERO_ADDR } from 'lib/constants';
3334
3435const INVITES_PER_PAGE = 7;
3536const DEFAULT_NUM_INVITES = 5;
@@ -81,12 +82,19 @@ export default function InviteCohort() {
8182 point
8283 );
8384
84− const invitePoint = possiblePoints.find(
85− p =>
85+ let invitePoint;
86+ for (let i = 0; i < possiblePoints.length; i++) {
87+ const p = possiblePoints[i];
88+ if (
89+ !invites.find(({ planet }) => planet === p) &&
8690 azimuth.azimuth.getPointSize(p) ===
8791 azimuth.azimuth.PointSize.Planet &&
88− !invites.find(({ planet }) => planet === p)
89− );
92+ (await azimuth.azimuth.getOwner(_contracts, p)) === ETH_ZERO_ADDR
93+ ) {
94+ invitePoint = p;
95+ break;
96+ }
97+ }
9098
9199 if (invitePoint) {
92100 const { ticket, owner } = await wg.generateTemporaryDeterministicWallet(
@@ -107,7 +115,6 @@ export default function InviteCohort() {
107115 };
108116
109117 if (!currentL2 && _contracts && point && _authToken && showInviteForm) {
110− console.log(1, 'NEW SETUP for L1')
111118 setUpInvite();
112119 } else {
113120 unconstruct();
@@ -124,7 +131,7 @@ export default function InviteCohort() {
124131 ]);
125132
126133 useEffect(() => {
127− const { available, pending, claimed } = getStoredInvites(point);
134+ const { available } = getStoredInvites(point);
128135 console.log(2, completed, l1Invite)
129136
130137 if (
@@ -135,18 +142,9 @@ export default function InviteCohort() {
135142 return;
136143 }
137144
138− console.log(3, available)
139−
140− setStoredInvites(point, {
141− available: [...invites, l1Invite],
142− pending,
143− claimed,
144− });
145−
146− console.log('SETTING', [...invites, l1Invite])
147145 setInvites([...invites, l1Invite]);
148− // setShowInviteForm(false);
149− // setL1Invite(null);
146+ setShowInviteForm(false);
147+ setL1Invite(null);
150148 unconstruct();
151149 pop();
152150 }, [completed]); // eslint-disable-line react-hooks/exhaustive-deps
@@ -176,7 +174,7 @@ export default function InviteCohort() {
176174 }, [generateInviteCodes, numInvites, getPendingTransactions, point, pop]);
177175
178176 const getContent = () => {
179− if (hasInvites) {
177+ if (hasInvites && !networkKeysNotSet) {
180178 return (
181179 <>
182180 <div>
src/views/Points.js+33−31
@@ -40,6 +40,34 @@ export const maybeGetResult = (obj, key, defaultValue) =>
4040export const hasTransferProxy = details =>
4141 !isZeroAddress(details.transferProxy);
4242
43+export const getOutgoingPoints = (controlledPoints, getDetails) => {
44+ return controlledPoints.chain((points) =>
45+ points.matchWith({
46+ Error: () => Nothing(),
47+ Ok: (c) => {
48+ const points = c.value.ownedPoints.map((point) =>
49+ getDetails(point).chain((details) => {
50+ // need those that are inactive
51+ if (!details.active) {
52+ console.log(point, details)
53+ }
54+ return Just({ point: point, has: hasTransferProxy(details) })
55+ }
56+ )
57+ );
58+ if (points.every((p) => Just.hasInstance(p))) {
59+ const outgoing = points
60+ .filter((p) => p.value.has)
61+ .map((p) => p.value.point);
62+ return Just(outgoing);
63+ } else {
64+ return Nothing();
65+ }
66+ },
67+ })
68+ ).getOrElse([]);
69+}
70+
4371export const isLocked = details =>
4472 details.owner === '0x86cd9cd0992f04231751e3761de45cecea5d1801' ||
4573 details.owner === '0x8c241098c3d3498fe1261421633fd57986d74aea';
@@ -112,30 +140,8 @@ export default function Points() {
112140 ] = useRejectedIncomingPointTransfers();
113141 const { syncStarReleaseDetails, starReleaseDetails } = useStarReleaseCache();
114142
115− const maybeOutgoingPoints = useMemo(
116− () =>
117− controlledPoints.chain(points =>
118− points.matchWith({
119− Error: () => Nothing(),
120− Ok: c => {
121− const points = c.value.ownedPoints.map(point =>
122− getDetails(point).chain(details =>
123− Just({ point: point, has: hasTransferProxy(details) })
124− )
125− );
126− // if we have details for every point,
127− // return the array of pending transfers.
128− if (points.every(p => Just.hasInstance(p))) {
129− const outgoing = points
130− .filter(p => p.value.has)
131− .map(p => p.value.point);
132− return Just(outgoing);
133− } else {
134− return Nothing();
135− }
136− },
137− })
138− ),
143+ const outgoingPoints = useMemo(
144+ () => getOutgoingPoints(controlledPoints, getDetails),
139145 [getDetails, controlledPoints]
140146 );
141147
@@ -172,10 +178,7 @@ export default function Points() {
172178 // if there are any pending transfers, incoming or outgoing, stay on this
173179 // page, because those can only be completed/cancelled here.
174180 useEffect(() => {
175− if (
176− Nothing.hasInstance(maybeOutgoingPoints) ||
177− Nothing.hasInstance(starReleaseDetails)
178− ) {
181+ if (outgoingPoints.length < 1 || Nothing.hasInstance(starReleaseDetails)) {
179182 return;
180183 }
181184 controlledPoints.matchWith({
@@ -196,7 +199,7 @@ export default function Points() {
196199 if (
197200 all.length === 1 &&
198201 incoming.length === 0 &&
199− maybeOutgoingPoints.value.length === 0 &&
202+ outgoingPoints.length === 0 &&
200203 (starReleaseDetails.value === null ||
201204 starReleaseDetails.value.total === 0)
202205 ) {
@@ -210,7 +213,7 @@ export default function Points() {
210213 }, [
211214 controlledPoints,
212215 rejectedPoints,
213− maybeOutgoingPoints,
216+ outgoingPoints,
214217 setPointCursor,
215218 popAndPush,
216219 names,
@@ -230,7 +233,6 @@ export default function Points() {
230233 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
231234 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
232235 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
233− const outgoingPoints = maybeOutgoingPoints.getOrElse([]);
234236 const lockedPoints = maybeLockedPoints.getOrElse([]);
235237
236238 const allPoints = [