on master help sign in
WIP: L1 invites
commit75960c9284ffac33f73dfc07ba1be1062bff6514 authorWill Galebach <willbach@gmail.com> dateSun 5 Sep 2021, 12:07 (5 years ago) parentdedd4b5
4 files changed+56−22
src/lib/useRoller.ts+13−10 src/views/Invite/Cohort.js+32−8 src/views/IssueChild.js+1−1 src/views/Points.js+10−3
src/lib/useRoller.ts+13−10
@@ -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 * as ob from 'urbit-ob';
65import { Just, Nothing } from 'folktale/maybe';
76
87import {
@@ -215,7 +214,6 @@ export default function useRoller() {
215214 try {
216215 const curPoint = need.point(pointCursor);
217216 const newPending = await api.getPendingByShip(Number(curPoint));
218− console.log('PENDING', newPending);
219217 setPendingTransactions(newPending);
220218
221219 // const allTransactions = await api.getHistory()
@@ -263,7 +261,6 @@ export default function useRoller() {
263261 allSpawned.includes(p) &&
264262 azimuth.azimuth.getPointSize(p) === azimuth.azimuth.PointSize.Planet
265263 );
266− console.log('SPAWNED AND OWNED', possibleMissingInvites);
267264 } else {
268265 const maybeOutgoingPoints = controlledPoints.chain((points: any) =>
269266 points.matchWith({
@@ -300,24 +297,28 @@ export default function useRoller() {
300297 const _authToken = authToken.getOrElse(null);
301298 const _contracts = contracts.getOrElse(null);
302299
300+ const newClaimed = availableInvites.filter(
301+ ({ planet }) => !possibleMissingInvites.includes(planet)
302+ );
303+
303304 if (_authToken && _contracts) {
304305 for (let i = 0; i < possibleMissingInvites.length; i++) {
305− const point = possibleMissingInvites[i];
306+ const planet = possibleMissingInvites[i];
306307
307− if (!availableInvites.find(hasPoint(point))) {
308− console.log('MISSING IN AVAILABLE', point);
308+ if (!availableInvites.find(hasPoint(planet))) {
309+ console.log('MISSING IN AVAILABLE', planet);
309310 const {
310311 ticket,
311312 owner,
312313 } = await wg.generateTemporaryDeterministicWallet(
313− point,
314+ planet,
314315 _authToken
315316 );
316317
317318 availableInvites.push({
318319 ticket,
319320 status: 'available',
320− planet: point,
321+ planet,
321322 hash: '',
322323 owner: owner.keys.address,
323324 });
@@ -325,9 +326,11 @@ export default function useRoller() {
325326 }
326327
327328 setStoredInvites(curPoint, {
328− available: availableInvites,
329+ available: availableInvites.filter(({ planet }) =>
330+ possibleMissingInvites.includes(planet)
331+ ),
329332 pending: stillPending,
330− claimed: invites.claimed,
333+ claimed: invites.claimed.concat(newClaimed),
331334 });
332335 setInvites(availableInvites);
333336 }
src/views/Invite/Cohort.js+32−8
@@ -42,6 +42,7 @@ export default function InviteCohort() {
4242 currentL2,
4343 pendingTransactions,
4444 invites,
45+ setInvites,
4546 } = useRollerStore();
4647 const { generateInviteCodes, getPendingTransactions } = useRoller();
4748 const { pointCursor } = usePointCursor();
@@ -82,17 +83,22 @@ export default function InviteCohort() {
8283
8384 const invitePoint = possiblePoints.find(
8485 p =>
85− azimuth.azimuth.getPointSize(p) === azimuth.azimuth.PointSize.Planet
86+ azimuth.azimuth.getPointSize(p) ===
87+ azimuth.azimuth.PointSize.Planet &&
88+ !invites.find(({ planet }) => planet === p)
8689 );
8790
8891 if (invitePoint) {
8992 const { ticket, owner } = await wg.generateTemporaryDeterministicWallet(
90− point,
93+ invitePoint,
9194 _authToken
9295 );
9396
97+ console.log('INVITE POINT', invitePoint, owner.keys.address)
98+
9499 construct(invitePoint, owner.keys.address);
95100 setL1Invite({ ticket, planet: invitePoint });
101+ console.log(0, { ticket, planet: invitePoint })
96102 } else {
97103 setError('No available planets');
98104 }
@@ -101,6 +107,7 @@ export default function InviteCohort() {
101107 };
102108
103109 if (!currentL2 && _contracts && point && _authToken && showInviteForm) {
110+ console.log(1, 'NEW SETUP for L1')
104111 setUpInvite();
105112 } else {
106113 unconstruct();
@@ -113,19 +120,36 @@ export default function InviteCohort() {
113120 construct,
114121 showInviteForm,
115122 unconstruct,
123+ invites,
116124 ]);
117125
118− const l1Complete = useCallback(() => {
126+ useEffect(() => {
119127 const { available, pending, claimed } = getStoredInvites(point);
128+ console.log(2, completed, l1Invite)
129+
130+ if (
131+ !completed ||
132+ !l1Invite ||
133+ available.find(({ planet }) => planet === l1Invite.planet)
134+ ) {
135+ return;
136+ }
137+
138+ console.log(3, available)
139+
120140 setStoredInvites(point, {
121− available: [...available, l1Invite],
141+ available: [...invites, l1Invite],
122142 pending,
123143 claimed,
124144 });
125− setShowInviteForm(false);
126− }, [l1Invite, point]);
127145
128− useEffect(() => (completed ? l1Complete() : null), [completed, l1Complete]);
146+ console.log('SETTING', [...invites, l1Invite])
147+ setInvites([...invites, l1Invite]);
148+ // setShowInviteForm(false);
149+ // setL1Invite(null);
150+ unconstruct();
151+ pop();
152+ }, [completed]); // eslint-disable-line react-hooks/exhaustive-deps
129153
130154 const [page, setPage] = useState(0);
131155
@@ -290,7 +314,7 @@ export default function InviteCohort() {
290314 as={InlineEthereumTransaction}
291315 label="Generate Planet Code"
292316 {...bind}
293− onReturn={() => pop()}
317+ onReturn={pop}
294318 />
295319 )}
296320 </div>
src/views/IssueChild.js+1−1
@@ -43,7 +43,7 @@ export function useIssueChild() {
4343 return useEthereumTransaction(
4444 useCallback(
4545 (spawnedPoint, owner) => {
46− console.log(1, spawnedPoint, owner, _contracts)
46+ console.log(5, spawnedPoint, owner)
4747 setSpawnedPoint(spawnedPoint);
4848 return azimuth.ecliptic.spawn(_contracts, spawnedPoint, owner);
4949 },
src/views/Points.js+10−3
@@ -40,6 +40,10 @@ export const maybeGetResult = (obj, key, defaultValue) =>
4040export const hasTransferProxy = details =>
4141 !isZeroAddress(details.transferProxy);
4242
43+export const isLocked = details =>
44+ details.owner === '0x86cd9cd0992f04231751e3761de45cecea5d1801' ||
45+ details.owner === '0x8c241098c3d3498fe1261421633fd57986d74aea';
46+
4347const PointList = function({
4448 points,
4549 className,
@@ -114,10 +118,13 @@ export default function Points() {
114118 points.matchWith({
115119 Error: () => Nothing(),
116120 Ok: c => {
117− const points = c.value.ownedPoints.map(point =>
118− getDetails(point).chain(details =>
121+ const points = c.value.ownedPoints.map(point => {
122+ console.log(point, getDetails(point))
123+ return getDetails(point).chain(details =>
119124 Just({ point: point, has: hasTransferProxy(details) })
120125 )
126+ }
127+
121128 );
122129 // if we have details for every point,
123130 // return the array of pending transfers.
@@ -144,7 +151,7 @@ export default function Points() {
144151 // TODO: how to determine this?
145152 const points = c.value.ownedPoints.map(point =>
146153 getDetails(point).chain(details =>
147− Just({ point: point, has: hasTransferProxy(details) })
154+ Just({ point, has: isLocked(details) })
148155 )
149156 );
150157 // if we have details for every point,