on master help sign in
WIP: L1 invites
75960c9Will Galebach
src/lib/useRoller.ts+13−10
@@ -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 * as ob from 'urbit-ob';
6import { Just, Nothing } from 'folktale/maybe';
5import { Just, Nothing } from 'folktale/maybe';
7
6
8import {
7import {
@@ -215,7 +214,6 @@ export default function useRoller() {
215 try {
214 try {
216 const curPoint = need.point(pointCursor);
215 const curPoint = need.point(pointCursor);
217 const newPending = await api.getPendingByShip(Number(curPoint));
216 const newPending = await api.getPendingByShip(Number(curPoint));
218− console.log('PENDING', newPending);
219 setPendingTransactions(newPending);
217 setPendingTransactions(newPending);
220
218
221 // const allTransactions = await api.getHistory()
219 // const allTransactions = await api.getHistory()
@@ -263,7 +261,6 @@ export default function useRoller() {
263 allSpawned.includes(p) &&
261 allSpawned.includes(p) &&
264 azimuth.azimuth.getPointSize(p) === azimuth.azimuth.PointSize.Planet
262 azimuth.azimuth.getPointSize(p) === azimuth.azimuth.PointSize.Planet
265 );
263 );
266− console.log('SPAWNED AND OWNED', possibleMissingInvites);
267 } else {
264 } else {
268 const maybeOutgoingPoints = controlledPoints.chain((points: any) =>
265 const maybeOutgoingPoints = controlledPoints.chain((points: any) =>
269 points.matchWith({
266 points.matchWith({
@@ -300,24 +297,28 @@ export default function useRoller() {
300 const _authToken = authToken.getOrElse(null);
297 const _authToken = authToken.getOrElse(null);
301 const _contracts = contracts.getOrElse(null);
298 const _contracts = contracts.getOrElse(null);
302
299
300+ const newClaimed = availableInvites.filter(
301+ ({ planet }) => !possibleMissingInvites.includes(planet)
302+ );
303+
303 if (_authToken && _contracts) {
304 if (_authToken && _contracts) {
304 for (let i = 0; i < possibleMissingInvites.length; i++) {
305 for (let i = 0; i < possibleMissingInvites.length; i++) {
305− const point = possibleMissingInvites[i];
306+ const planet = possibleMissingInvites[i];
306
307
307− if (!availableInvites.find(hasPoint(point))) {
308+ if (!availableInvites.find(hasPoint(planet))) {
308− console.log('MISSING IN AVAILABLE', point);
309+ console.log('MISSING IN AVAILABLE', planet);
309 const {
310 const {
310 ticket,
311 ticket,
311 owner,
312 owner,
312 } = await wg.generateTemporaryDeterministicWallet(
313 } = await wg.generateTemporaryDeterministicWallet(
313− point,
314+ planet,
314 _authToken
315 _authToken
315 );
316 );
316
317
317 availableInvites.push({
318 availableInvites.push({
318 ticket,
319 ticket,
319 status: 'available',
320 status: 'available',
320− planet: point,
321+ planet,
321 hash: '',
322 hash: '',
322 owner: owner.keys.address,
323 owner: owner.keys.address,
323 });
324 });
@@ -325,9 +326,11 @@ export default function useRoller() {
325 }
326 }
326
327
327 setStoredInvites(curPoint, {
328 setStoredInvites(curPoint, {
328− available: availableInvites,
329+ available: availableInvites.filter(({ planet }) =>
330+ possibleMissingInvites.includes(planet)
331+ ),
329 pending: stillPending,
332 pending: stillPending,
330− claimed: invites.claimed,
333+ claimed: invites.claimed.concat(newClaimed),
331 });
334 });
332 setInvites(availableInvites);
335 setInvites(availableInvites);
333 }
336 }
src/views/Invite/Cohort.js+32−8
@@ -42,6 +42,7 @@ export default function InviteCohort() {
42 currentL2,
42 currentL2,
43 pendingTransactions,
43 pendingTransactions,
44 invites,
44 invites,
45+ setInvites,
45 } = useRollerStore();
46 } = useRollerStore();
46 const { generateInviteCodes, getPendingTransactions } = useRoller();
47 const { generateInviteCodes, getPendingTransactions } = useRoller();
47 const { pointCursor } = usePointCursor();
48 const { pointCursor } = usePointCursor();
@@ -82,17 +83,22 @@ export default function InviteCohort() {
82
83
83 const invitePoint = possiblePoints.find(
84 const invitePoint = possiblePoints.find(
84 p =>
85 p =>
86+ azimuth.azimuth.getPointSize(p) ===
85− azimuth.azimuth.getPointSize(p) === azimuth.azimuth.PointSize.Planet
87+ azimuth.azimuth.PointSize.Planet &&
88+ !invites.find(({ planet }) => planet === p)
86 );
89 );
87
90
88 if (invitePoint) {
91 if (invitePoint) {
89 const { ticket, owner } = await wg.generateTemporaryDeterministicWallet(
92 const { ticket, owner } = await wg.generateTemporaryDeterministicWallet(
90− point,
93+ invitePoint,
91 _authToken
94 _authToken
92 );
95 );
93
96
97+ console.log('INVITE POINT', invitePoint, owner.keys.address)
98+
94 construct(invitePoint, owner.keys.address);
99 construct(invitePoint, owner.keys.address);
95 setL1Invite({ ticket, planet: invitePoint });
100 setL1Invite({ ticket, planet: invitePoint });
101+ console.log(0, { ticket, planet: invitePoint })
96 } else {
102 } else {
97 setError('No available planets');
103 setError('No available planets');
98 }
104 }
@@ -101,6 +107,7 @@ export default function InviteCohort() {
101 };
107 };
102
108
103 if (!currentL2 && _contracts && point && _authToken && showInviteForm) {
109 if (!currentL2 && _contracts && point && _authToken && showInviteForm) {
110+ console.log(1, 'NEW SETUP for L1')
104 setUpInvite();
111 setUpInvite();
105 } else {
112 } else {
106 unconstruct();
113 unconstruct();
@@ -113,19 +120,36 @@ export default function InviteCohort() {
113 construct,
120 construct,
114 showInviteForm,
121 showInviteForm,
115 unconstruct,
122 unconstruct,
123+ invites,
116 ]);
124 ]);
117
125
118− const l1Complete = useCallback(() => {
126+ useEffect(() => {
119 const { available, pending, claimed } = getStoredInvites(point);
127 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+
120 setStoredInvites(point, {
140 setStoredInvites(point, {
121− available: [...available, l1Invite],
141+ available: [...invites, l1Invite],
122 pending,
142 pending,
123 claimed,
143 claimed,
124 });
144 });
125− setShowInviteForm(false);
126− }, [l1Invite, point]);
127
145
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
129
153
130 const [page, setPage] = useState(0);
154 const [page, setPage] = useState(0);
131
155
@@ -290,7 +314,7 @@ export default function InviteCohort() {
290 as={InlineEthereumTransaction}
314 as={InlineEthereumTransaction}
291 label="Generate Planet Code"
315 label="Generate Planet Code"
292 {...bind}
316 {...bind}
293− onReturn={() => pop()}
317+ onReturn={pop}
294 />
318 />
295 )}
319 )}
296 </div>
320 </div>
src/views/IssueChild.js+1−1
@@ -43,7 +43,7 @@ export function useIssueChild() {
43 return useEthereumTransaction(
43 return useEthereumTransaction(
44 useCallback(
44 useCallback(
45 (spawnedPoint, owner) => {
45 (spawnedPoint, owner) => {
46− console.log(1, spawnedPoint, owner, _contracts)
46+ console.log(5, spawnedPoint, owner)
47 setSpawnedPoint(spawnedPoint);
47 setSpawnedPoint(spawnedPoint);
48 return azimuth.ecliptic.spawn(_contracts, spawnedPoint, owner);
48 return azimuth.ecliptic.spawn(_contracts, spawnedPoint, owner);
49 },
49 },
src/views/Points.js+10−3
@@ -40,6 +40,10 @@ 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 isLocked = details =>
44+ details.owner === '0x86cd9cd0992f04231751e3761de45cecea5d1801' ||
45+ details.owner === '0x8c241098c3d3498fe1261421633fd57986d74aea';
46+
43const PointList = function({
47const PointList = function({
44 points,
48 points,
45 className,
49 className,
@@ -114,10 +118,13 @@ export default function Points() {
114 points.matchWith({
118 points.matchWith({
115 Error: () => Nothing(),
119 Error: () => Nothing(),
116 Ok: c => {
120 Ok: c => {
117− const points = c.value.ownedPoints.map(point =>
121+ const points = c.value.ownedPoints.map(point => {
122+ console.log(point, getDetails(point))
118− getDetails(point).chain(details =>
123+ return getDetails(point).chain(details =>
119 Just({ point: point, has: hasTransferProxy(details) })
124 Just({ point: point, has: hasTransferProxy(details) })
120 )
125 )
126+ }
127+
121 );
128 );
122 // if we have details for every point,
129 // if we have details for every point,
123 // return the array of pending transfers.
130 // return the array of pending transfers.
@@ -144,7 +151,7 @@ export default function Points() {
144 // TODO: how to determine this?
151 // TODO: how to determine this?
145 const points = c.value.ownedPoints.map(point =>
152 const points = c.value.ownedPoints.map(point =>
146 getDetails(point).chain(details =>
153 getDetails(point).chain(details =>
147− Just({ point: point, has: hasTransferProxy(details) })
154+ Just({ point, has: isLocked(details) })
148 )
155 )
149 );
156 );
150 // if we have details for every point,
157 // if we have details for every point,