on master help sign in
Updated L1 invites
50fd852Will Galebach
src/lib/useRoller.ts+19−30
@@ -2,7 +2,6 @@ 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 { Just, Nothing } from 'folktale/maybe';
6
5
7import {
6import {
8 Config,
7 Config,
@@ -30,7 +29,7 @@ import {
30 setStoredInvites,
29 setStoredInvites,
31} from 'store/storage/roller';
30} from 'store/storage/roller';
32import { usePointCache } from 'store/pointCache';
31import { usePointCache } from 'store/pointCache';
33−import { hasTransferProxy, maybeGetResult } from 'views/Points';
32+import { getOutgoingPoints, hasTransferProxy, maybeGetResult } from 'views/Points';
34
33
35const hasPoint = (point: number) => (invite: Invite) => invite.planet === point;
34const hasPoint = (point: number) => (invite: Invite) => invite.planet === point;
36
35
@@ -228,6 +227,7 @@ export default function useRoller() {
228 const curPoint: string = need.point(pointCursor);
227 const curPoint: string = need.point(pointCursor);
229 const invites = getStoredInvites(curPoint);
228 const invites = getStoredInvites(curPoint);
230 const availableInvites = invites.available;
229 const availableInvites = invites.available;
230+ console.log('WHAT', curPoint, invites, availableInvites)
231
231
232 const pendingTransactions = await api.getPendingByShip(curPoint);
232 const pendingTransactions = await api.getPendingByShip(curPoint);
233 console.log('PENDING', pendingTransactions);
233 console.log('PENDING', pendingTransactions);
@@ -260,37 +260,21 @@ export default function useRoller() {
260 possibleMissingInvites = allSpawned.filter(
260 possibleMissingInvites = allSpawned.filter(
261 (p: number) =>
261 (p: number) =>
262 ownedPoints.includes(p) &&
262 ownedPoints.includes(p) &&
263+ azimuth.azimuth.getPointSize(p) ===
263− azimuth.azimuth.getPointSize(p) === azimuth.azimuth.PointSize.Planet
264+ azimuth.azimuth.PointSize.Planet
264 );
265 );
265 } else {
266 } else {
267+ // How to get outgoing points by star?
268+ const outgoingPoints = getOutgoingPoints(
266− const maybeOutgoingPoints = controlledPoints.chain((points: any) =>
269+ controlledPoints,
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) =>
270+ getDetails
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− })
285 );
271 );
286
272
287− possibleMissingInvites = maybeOutgoingPoints
273+ possibleMissingInvites = outgoingPoints.filter(
288− .getOrElse([])
289− .filter(
290− (p: number) =>
274+ (p: number) =>
291− azimuth.azimuth.getPointSize(p) ===
275+ azimuth.azimuth.getPointSize(p) ===
292− azimuth.azimuth.PointSize.Planet
276+ azimuth.azimuth.PointSize.Planet
293− );
277+ );
294 }
278 }
295
279
296 // Iterate over all spawned and controlled planets
280 // Iterate over all spawned and controlled planets
@@ -298,6 +282,8 @@ export default function useRoller() {
298 const _authToken = authToken.getOrElse(null);
282 const _authToken = authToken.getOrElse(null);
299 const _contracts = contracts.getOrElse(null);
283 const _contracts = contracts.getOrElse(null);
300
284
285+ console.log('POSSIBLE MISSING', possibleMissingInvites)
286+
301 const newClaimed = availableInvites.filter(
287 const newClaimed = availableInvites.filter(
302 ({ planet }) => !possibleMissingInvites.includes(planet)
288 ({ planet }) => !possibleMissingInvites.includes(planet)
303 );
289 );
@@ -306,7 +292,10 @@ export default function useRoller() {
306 for (let i = 0; i < possibleMissingInvites.length; i++) {
292 for (let i = 0; i < possibleMissingInvites.length; i++) {
307 const planet = possibleMissingInvites[i];
293 const planet = possibleMissingInvites[i];
308
294
295+ if (
309− if (!availableInvites.find(hasPoint(planet))) {
296+ !availableInvites.find(hasPoint(planet)) &&
297+ !(await azimuth.azimuth.isActive(_contracts, planet))
298+ ) {
310 console.log('MISSING IN AVAILABLE', planet);
299 console.log('MISSING IN AVAILABLE', planet);
311 const {
300 const {
312 ticket,
301 ticket,
src/store/lib/useControlledPointsStore.js+1−1
@@ -39,7 +39,7 @@ export default function useControlledPointsStore() {
39 getPoints('spawn', address),
39 getPoints('spawn', address),
40 ]);
40 ]);
41
41
42− console.log(ownedPoints)
42+ console.log('OWNED POINTS', ownedPoints)
43
43
44 if (
44 if (
45 ownedPoints === null &&
45 ownedPoints === null &&
src/views/Invite/Cohort.js+16−18
@@ -30,6 +30,7 @@ import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
30
30
31import './Cohort.scss';
31import './Cohort.scss';
32import { getStoredInvites, setStoredInvites } from 'store/storage/roller';
32import { getStoredInvites, setStoredInvites } from 'store/storage/roller';
33+import { ETH_ZERO_ADDR } from 'lib/constants';
33
34
34const INVITES_PER_PAGE = 7;
35const INVITES_PER_PAGE = 7;
35const DEFAULT_NUM_INVITES = 5;
36const DEFAULT_NUM_INVITES = 5;
@@ -81,12 +82,19 @@ export default function InviteCohort() {
81 point
82 point
82 );
83 );
83
84
85+ let invitePoint;
86+ for (let i = 0; i < possiblePoints.length; i++) {
84− const invitePoint = possiblePoints.find(
87+ const p = possiblePoints[i];
85− p =>
88+ if (
89+ !invites.find(({ planet }) => planet === p) &&
86 azimuth.azimuth.getPointSize(p) ===
90 azimuth.azimuth.getPointSize(p) ===
87 azimuth.azimuth.PointSize.Planet &&
91 azimuth.azimuth.PointSize.Planet &&
88− !invites.find(({ planet }) => planet === p)
92+ (await azimuth.azimuth.getOwner(_contracts, p)) === ETH_ZERO_ADDR
89− );
93+ ) {
94+ invitePoint = p;
95+ break;
96+ }
97+ }
90
98
91 if (invitePoint) {
99 if (invitePoint) {
92 const { ticket, owner } = await wg.generateTemporaryDeterministicWallet(
100 const { ticket, owner } = await wg.generateTemporaryDeterministicWallet(
@@ -107,7 +115,6 @@ export default function InviteCohort() {
107 };
115 };
108
116
109 if (!currentL2 && _contracts && point && _authToken && showInviteForm) {
117 if (!currentL2 && _contracts && point && _authToken && showInviteForm) {
110− console.log(1, 'NEW SETUP for L1')
111 setUpInvite();
118 setUpInvite();
112 } else {
119 } else {
113 unconstruct();
120 unconstruct();
@@ -124,7 +131,7 @@ export default function InviteCohort() {
124 ]);
131 ]);
125
132
126 useEffect(() => {
133 useEffect(() => {
127− const { available, pending, claimed } = getStoredInvites(point);
134+ const { available } = getStoredInvites(point);
128 console.log(2, completed, l1Invite)
135 console.log(2, completed, l1Invite)
129
136
130 if (
137 if (
@@ -135,18 +142,9 @@ export default function InviteCohort() {
135 return;
142 return;
136 }
143 }
137
144
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])
147 setInvites([...invites, l1Invite]);
145 setInvites([...invites, l1Invite]);
148− // setShowInviteForm(false);
146+ setShowInviteForm(false);
149− // setL1Invite(null);
147+ setL1Invite(null);
150 unconstruct();
148 unconstruct();
151 pop();
149 pop();
152 }, [completed]); // eslint-disable-line react-hooks/exhaustive-deps
150 }, [completed]); // eslint-disable-line react-hooks/exhaustive-deps
@@ -176,7 +174,7 @@ export default function InviteCohort() {
176 }, [generateInviteCodes, numInvites, getPendingTransactions, point, pop]);
174 }, [generateInviteCodes, numInvites, getPendingTransactions, point, pop]);
177
175
178 const getContent = () => {
176 const getContent = () => {
179− if (hasInvites) {
177+ if (hasInvites && !networkKeysNotSet) {
180 return (
178 return (
181 <>
179 <>
182 <div>
180 <div>
src/views/Points.js+33−31
@@ -40,6 +40,34 @@ export const maybeGetResult = (obj, key, defaultValue) =>
40export const hasTransferProxy = details =>
40export const hasTransferProxy = details =>
41 !isZeroAddress(details.transferProxy);
41 !isZeroAddress(details.transferProxy);
42
42
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+
43export const isLocked = details =>
71export const isLocked = details =>
44 details.owner === '0x86cd9cd0992f04231751e3761de45cecea5d1801' ||
72 details.owner === '0x86cd9cd0992f04231751e3761de45cecea5d1801' ||
45 details.owner === '0x8c241098c3d3498fe1261421633fd57986d74aea';
73 details.owner === '0x8c241098c3d3498fe1261421633fd57986d74aea';
@@ -112,30 +140,8 @@ export default function Points() {
112 ] = useRejectedIncomingPointTransfers();
140 ] = useRejectedIncomingPointTransfers();
113 const { syncStarReleaseDetails, starReleaseDetails } = useStarReleaseCache();
141 const { syncStarReleaseDetails, starReleaseDetails } = useStarReleaseCache();
114
142
115− const maybeOutgoingPoints = useMemo(
143+ const outgoingPoints = useMemo(
116− () =>
117− controlledPoints.chain(points =>
144+ () => getOutgoingPoints(controlledPoints, getDetails),
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− ),
139 [getDetails, controlledPoints]
145 [getDetails, controlledPoints]
140 );
146 );
141
147
@@ -172,10 +178,7 @@ export default function Points() {
172 // if there are any pending transfers, incoming or outgoing, stay on this
178 // if there are any pending transfers, incoming or outgoing, stay on this
173 // page, because those can only be completed/cancelled here.
179 // page, because those can only be completed/cancelled here.
174 useEffect(() => {
180 useEffect(() => {
175− if (
176− Nothing.hasInstance(maybeOutgoingPoints) ||
177− Nothing.hasInstance(starReleaseDetails)
181+ if (outgoingPoints.length < 1 || Nothing.hasInstance(starReleaseDetails)) {
178− ) {
179 return;
182 return;
180 }
183 }
181 controlledPoints.matchWith({
184 controlledPoints.matchWith({
@@ -196,7 +199,7 @@ export default function Points() {
196 if (
199 if (
197 all.length === 1 &&
200 all.length === 1 &&
198 incoming.length === 0 &&
201 incoming.length === 0 &&
199− maybeOutgoingPoints.value.length === 0 &&
202+ outgoingPoints.length === 0 &&
200 (starReleaseDetails.value === null ||
203 (starReleaseDetails.value === null ||
201 starReleaseDetails.value.total === 0)
204 starReleaseDetails.value.total === 0)
202 ) {
205 ) {
@@ -210,7 +213,7 @@ export default function Points() {
210 }, [
213 }, [
211 controlledPoints,
214 controlledPoints,
212 rejectedPoints,
215 rejectedPoints,
213− maybeOutgoingPoints,
216+ outgoingPoints,
214 setPointCursor,
217 setPointCursor,
215 popAndPush,
218 popAndPush,
216 names,
219 names,
@@ -230,7 +233,6 @@ export default function Points() {
230 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
233 const managingPoints = maybeGetResult(controlledPoints, 'managingPoints', []);
231 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
234 const votingPoints = maybeGetResult(controlledPoints, 'votingPoints', []);
232 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
235 const spawningPoints = maybeGetResult(controlledPoints, 'spawningPoints', []);
233− const outgoingPoints = maybeOutgoingPoints.getOrElse([]);
234 const lockedPoints = maybeLockedPoints.getOrElse([]);
236 const lockedPoints = maybeLockedPoints.getOrElse([]);
235
237
236 const allPoints = [
238 const allPoints = [