on master help sign in
Get superset of L1 and L2 points
commit8da9642a158a953aa72960a304b850430fb3c9de authorWill Galebach <willbach@gmail.com> dateMon 6 Sep 2021, 17:18 (5 years ago) parent50fd852
11 files changed+148−115
src/components/InlineEthereumTransaction.js+32−22 src/components/Passport.js+1−1 src/components/copiable/CopiableWithTooltip.js−1 src/lib/useInviter.js+1−1 src/lib/useRoller.ts+43−36 src/store/lib/useControlledPointsStore.js+36−6 src/store/storage/roller.ts+1−1 src/views/Invite/Cohort.js+10−7 src/views/IssueChild.js+1−1 src/views/Point.js+1−14 src/views/Points.js+22−25
src/components/InlineEthereumTransaction.js+32−22
@@ -221,18 +221,16 @@ export default function InlineEthereumTransaction({
221221 {renderPrimarySection()}
222222
223223 {error && (
224− <Grid.Item
225− className="eth-tx-button" full as={ErrorText} className="mv1">
224+ <Grid.Item className="mv1 eth-tx-button" full as={ErrorText}>
226225 {error.message}
227226 </Grid.Item>
228227 )}
229228
230229 {needFunds && (
231230 <Grid.Item
232− className="eth-tx-button"
231+ className="mt3 eth-tx-button"
233232 full
234233 as={NeedFundsNotice}
235− className="mt3"
236234 {...needFunds}
237235 />
238236 )}
@@ -251,16 +249,14 @@ export default function InlineEthereumTransaction({
251249 />
252250
253251 <Condition when="useAdvanced" is={true}>
254− <Grid.Item
255− className="eth-tx-button" full className="mb2"></Grid.Item>
252+ <Grid.Item className="mb2 eth-tx-button" full></Grid.Item>
256253 <Grid.Divider />
257254 <Grid.Item
258− className="eth-tx-button"
255+ className="mt2 eth-tx-button"
259256 full
260257 as={Flex}
261258 row
262− justify="between"
263− className="mt2">
259+ justify="between">
264260 <Flex.Item as={H5}>Transaction Fee</Flex.Item>
265261
266262 <Flex.Item as={H5}>
@@ -286,12 +282,11 @@ export default function InlineEthereumTransaction({
286282 }
287283 />
288284 <Grid.Item
289− className="eth-tx-button"
285+ className="f6 mt1 eth-tx-button"
290286 full
291287 as={Flex}
292288 row
293− justify="between"
294− className="f6 mt1">
289+ justify="between">
295290 <Flex.Item as={Text}>Cheap</Flex.Item>
296291 <Flex.Item as={Text}>Fast</Flex.Item>
297292 </Grid.Item>
@@ -302,8 +297,7 @@ export default function InlineEthereumTransaction({
302297
303298 {showSignedTx && fakeSigned && (
304299 <>
305− <Grid.Item
306− className="eth-tx-button" full as={NoticeBox} className="mt2">
300+ <Grid.Item className="mt2 eth-tx-button" full as={NoticeBox}>
307301 Your wallet will sign the transaction upon sending it.
308302 </Grid.Item>
309303 </>
@@ -341,24 +335,35 @@ function SignedTransactionList({ serializedTxsHex, nonce, maxCost }) {
341335 <React.Fragment key={i}>
342336 <Grid.Divider />
343337 <Grid.Item
344− className="eth-tx-button" full as={Flex} justify="between" className="pv4 black f5">
338+ className="pv4 black f5 eth-tx-button"
339+ full
340+ as={Flex}
341+ justify="between">
345342 <Flex.Item>Nonce</Flex.Item>
346343 <Flex.Item>{nonce + i}</Flex.Item>
347344 </Grid.Item>
348345 <Grid.Divider />
349346 <Grid.Item
350− className="eth-tx-button" full as={Flex} justify="between" className="pv4 black f5">
347+ className="pv4 black f5 eth-tx-button"
348+ full
349+ as={Flex}
350+ justify="between">
351351 <Flex.Item>Transaction Cost</Flex.Item>
352352 <Flex.Item>{maxCost} ETH</Flex.Item>
353353 </Grid.Item>
354354 <Grid.Divider />
355355 <Grid.Item
356− className="eth-tx-button" full as={Flex} justify="between" className="mt3 mb2">
356+ className="mt3 mb2 eth-tx-button"
357+ full
358+ as={Flex}
359+ justify="between">
357360 <Flex.Item as={H5}>Signed Transaction Hex</Flex.Item>
358361 <Flex.Item as={CopyButton} text={serializedTxHex} />
359362 </Grid.Item>
360363 <Grid.Item
361− className="eth-tx-button" full as="code" className="mb4 f6 mono gray4 wrap">
364+ className="mb4 f6 mono gray4 wrap eth-tx-button"
365+ full
366+ as="code">
362367 {serializedTxHex}
363368 </Grid.Item>
364369 <Grid.Divider />
@@ -371,20 +376,25 @@ function TransactionReceipt({ txHashes, finalCost, onClose }) {
371376 return (
372377 <>
373378 <Grid.Item
374− className="eth-tx-button" full as={Flex} justify="between" className="pv2 black f5">
379+ className="pv2 black f5 eth-tx-button"
380+ full
381+ as={Flex}
382+ justify="between">
375383 <Flex.Item>Receipt</Flex.Item>
376384 <Flex.Item onClick={onClose} className="underline pointer">
377385 Close
378386 </Flex.Item>
379387 </Grid.Item>
380388 <Grid.Item
381− className="eth-tx-button" full as={Flex} justify="between" className="pv2 black f5">
389+ className="pv2 black f5 eth-tx-button"
390+ full
391+ as={Flex}
392+ justify="between">
382393 <Flex.Item>Transaction Cost</Flex.Item>
383394 <Flex.Item className="mono">{finalCost} ETH</Flex.Item>
384395 </Grid.Item>
385396 <Grid.Divider />
386− <Grid.Item
387− className="eth-tx-button" full as={Flex} col className="pv4">
397+ <Grid.Item className="pv4 eth-tx-button" full as={Flex} col>
388398 <Flex.Item as={H5}>Receipt</Flex.Item>
389399
390400 {txHashes &&
src/components/Passport.js+1−1
@@ -222,7 +222,7 @@ function MiniPassport({ point, inverted, locked = false, ...rest }) {
222222 const permissions = usePermissionsForPoint(address, point);
223223 const keyType = buildKeyType(permissions);
224224
225− const contrast = locked ? '#666666' : 'black'
225+ const contrast = locked ? '#666666' : 'black';
226226
227227 const sigil = useMemo(
228228 () =>
src/components/copiable/CopiableWithTooltip.js−1
@@ -1,5 +1,4 @@
11import React from 'react';
2−import { ReactComponent as Copy } from 'assets/copy.svg';
32
43import useCopiable from 'lib/useCopiable';
54import WithTooltip from 'components/WithTooltip';
src/lib/useInviter.js+1−1
@@ -193,7 +193,7 @@ const useInviter = () => {
193193 };
194194 }
195195
196− console.log('INVITES', confirmedInvites)
196+ console.log('INVITES', confirmedInvites);
197197 // TODO: store these locally, and also handle the situation
198198 return { invites: confirmedInvites };
199199 },
src/lib/useRoller.ts+43−36
@@ -29,7 +29,7 @@ import {
2929 setStoredInvites,
3030} from 'store/storage/roller';
3131import { usePointCache } from 'store/pointCache';
32−import { getOutgoingPoints, hasTransferProxy, maybeGetResult } from 'views/Points';
32+import { getOutgoingPoints, maybeGetResult } from 'views/Points';
3333
3434const hasPoint = (point: number) => (invite: Invite) => invite.planet === point;
3535
@@ -227,7 +227,6 @@ export default function useRoller() {
227227 const curPoint: string = need.point(pointCursor);
228228 const invites = getStoredInvites(curPoint);
229229 const availableInvites = invites.available;
230− console.log('WHAT', curPoint, invites, availableInvites)
231230
232231 const pendingTransactions = await api.getPendingByShip(curPoint);
233232 console.log('PENDING', pendingTransactions);
@@ -252,43 +251,51 @@ export default function useRoller() {
252251 });
253252 setInvites(availableInvites);
254253
255− let possibleMissingInvites: number[] = [];
256−
257− if (isL2) {
258− const allSpawned = await api.getSpawned(Number(curPoint));
259− const ownedPoints = maybeGetResult(controlledPoints, 'ownedPoints', []);
260− possibleMissingInvites = allSpawned.filter(
261− (p: number) =>
262− ownedPoints.includes(p) &&
263− azimuth.azimuth.getPointSize(p) ===
264− azimuth.azimuth.PointSize.Planet
265− );
266− } else {
267− // How to get outgoing points by star?
268− const outgoingPoints = getOutgoingPoints(
269− controlledPoints,
270− getDetails
271− );
272−
273− possibleMissingInvites = outgoingPoints.filter(
274− (p: number) =>
275− azimuth.azimuth.getPointSize(p) ===
276− azimuth.azimuth.PointSize.Planet
277− );
278− }
279−
280− // Iterate over all spawned and controlled planets
281− // If the planet is not in available invites, generate the ticket and add it
282254 const _authToken = authToken.getOrElse(null);
283255 const _contracts = contracts.getOrElse(null);
284256
285− console.log('POSSIBLE MISSING', possibleMissingInvites)
257+ if (_authToken && _contracts) {
258+ let possibleMissingInvites: number[] = [];
259+ if (isL2) {
260+ const allSpawned = await api.getSpawned(Number(curPoint));
261+ const ownedPoints = maybeGetResult(
262+ controlledPoints,
263+ 'ownedPoints',
264+ []
265+ );
266+ possibleMissingInvites = allSpawned.filter(
267+ (p: number) =>
268+ ownedPoints.includes(p) &&
269+ azimuth.azimuth.getPointSize(p) ===
270+ azimuth.azimuth.PointSize.Planet
271+ );
272+ } else {
273+ const outgoingPoints = getOutgoingPoints(
274+ controlledPoints,
275+ getDetails
276+ );
277+
278+ const availablePoints = await azimuth.azimuth.getUnspawnedChildren(
279+ _contracts,
280+ curPoint
281+ );
282+
283+ possibleMissingInvites = outgoingPoints.filter(
284+ (p: number) =>
285+ azimuth.azimuth.getPointSize(p) ===
286+ azimuth.azimuth.PointSize.Planet &&
287+ availablePoints.includes(p)
288+ );
289+ }
286290
287− const newClaimed = availableInvites.filter(
288− ({ planet }) => !possibleMissingInvites.includes(planet)
289− );
291+ // Iterate over all spawned and controlled planets
292+ // If the planet is not in available invites, generate the ticket and add it
293+ console.log('POSSIBLE MISSING', possibleMissingInvites);
294+
295+ const newClaimed = availableInvites.filter(
296+ ({ planet }) => !possibleMissingInvites.includes(planet)
297+ );
290298
291− if (_authToken && _contracts) {
292299 for (let i = 0; i < possibleMissingInvites.length; i++) {
293300 const planet = possibleMissingInvites[i];
294301
@@ -359,12 +366,12 @@ export default function useRoller() {
359366 setNextBatchTime(response.nextBatch);
360367 });
361368
362− getInvites();
369+ getInvites(currentL2);
363370 }
364371 }, 1000);
365372
366373 return () => clearInterval(interval);
367− }, [nextBatchTime, getPendingTransactions]); // eslint-disable-line react-hooks/exhaustive-deps
374+ }, [nextBatchTime, getPendingTransactions, currentL2]); // eslint-disable-line react-hooks/exhaustive-deps
368375
369376 return {
370377 api,
src/store/lib/useControlledPointsStore.js+36−6
@@ -1,11 +1,14 @@
11import { useState, useEffect, useCallback } from 'react';
22import { Just, Nothing } from 'folktale/maybe';
33import Result from 'folktale/result';
4+import * as azimuth from 'azimuth-js';
45
56import { useNetwork } from '../network';
67import { useWallet } from 'store/wallet';
78import useRoller from 'lib/useRoller';
89
10+const onlyUnique = (value, index, self) => self.indexOf(value) === index;
11+
912export default function useControlledPointsStore() {
1013 const { contracts } = useNetwork();
1114 const { wallet } = useWallet();
@@ -39,7 +42,19 @@ export default function useControlledPointsStore() {
3942 getPoints('spawn', address),
4043 ]);
4144
42− console.log('OWNED POINTS', ownedPoints)
45+ const [
46+ ownedPointsL1,
47+ incomingPointsL1,
48+ managingPointsL1,
49+ votingPointsL1,
50+ spawningPointsL1,
51+ ] = await Promise.all([
52+ azimuth.azimuth.getOwnedPoints(_contracts, address),
53+ azimuth.azimuth.getTransferringFor(_contracts, address),
54+ azimuth.azimuth.getManagerFor(_contracts, address),
55+ azimuth.azimuth.getVotingFor(_contracts, address),
56+ azimuth.azimuth.getSpawningFor(_contracts, address),
57+ ]);
4358
4459 if (
4560 ownedPoints === null &&
@@ -55,11 +70,26 @@ export default function useControlledPointsStore() {
5570 _setControlledPoints(
5671 Just(
5772 Result.Ok({
58− ownedPoints,
59− incomingPoints,
60− managingPoints,
61− votingPoints,
62− spawningPoints,
73+ ownedPoints: ownedPoints
74+ .concat(ownedPointsL1)
75+ .map(Number)
76+ .filter(onlyUnique),
77+ incomingPoints: incomingPoints
78+ .concat(incomingPointsL1)
79+ .map(Number)
80+ .filter(onlyUnique),
81+ managingPoints: managingPoints
82+ .concat(managingPointsL1)
83+ .map(Number)
84+ .filter(onlyUnique),
85+ votingPoints: votingPoints
86+ .concat(votingPointsL1)
87+ .map(Number)
88+ .filter(onlyUnique),
89+ spawningPoints: spawningPoints
90+ .concat(spawningPointsL1)
91+ .map(Number)
92+ .filter(onlyUnique),
6393 })
6494 )
6595 );
src/store/storage/roller.ts+1−1
@@ -1,4 +1,4 @@
1−import { Invite } from "types/Invite";
1+import { Invite } from 'types/Invite';
22
33const INVITES_KEY = 'invites';
44
src/views/Invite/Cohort.js+10−7
@@ -29,7 +29,7 @@ import Paginator from 'components/L2/Paginator';
2929import InlineEthereumTransaction from 'components/InlineEthereumTransaction';
3030
3131import './Cohort.scss';
32−import { getStoredInvites, setStoredInvites } from 'store/storage/roller';
32+import { getStoredInvites } from 'store/storage/roller';
3333import { ETH_ZERO_ADDR } from 'lib/constants';
3434
3535const INVITES_PER_PAGE = 7;
@@ -45,10 +45,14 @@ export default function InviteCohort() {
4545 invites,
4646 setInvites,
4747 } = useRollerStore();
48− const { generateInviteCodes, getPendingTransactions } = useRoller();
48+ const {
49+ generateInviteCodes,
50+ getPendingTransactions,
51+ getInvites,
52+ } = useRoller();
4953 const { pointCursor } = usePointCursor();
5054 const { contracts } = useNetwork();
51− const { getDetails } = usePointCache();
55+ const { getDetails, syncControlledPoints } = usePointCache();
5256
5357 const point = need.point(pointCursor);
5458 const _contracts = need.contracts(contracts);
@@ -71,6 +75,8 @@ export default function InviteCohort() {
7175
7276 const { construct, unconstruct, completed, bind } = useIssueChild();
7377
78+ useEffect(() => getInvites(), []); // eslint-disable-line react-hooks/exhaustive-deps
79+
7480 // Set up the invite spawn if on L1
7581 useEffect(() => {
7682 const _authToken = authToken.getOrElse(null);
@@ -102,11 +108,8 @@ export default function InviteCohort() {
102108 _authToken
103109 );
104110
105− console.log('INVITE POINT', invitePoint, owner.keys.address)
106−
107111 construct(invitePoint, owner.keys.address);
108112 setL1Invite({ ticket, planet: invitePoint });
109− console.log(0, { ticket, planet: invitePoint })
110113 } else {
111114 setError('No available planets');
112115 }
@@ -132,7 +135,6 @@ export default function InviteCohort() {
132135
133136 useEffect(() => {
134137 const { available } = getStoredInvites(point);
135− console.log(2, completed, l1Invite)
136138
137139 if (
138140 !completed ||
@@ -142,6 +144,7 @@ export default function InviteCohort() {
142144 return;
143145 }
144146
147+ syncControlledPoints();
145148 setInvites([...invites, l1Invite]);
146149 setShowInviteForm(false);
147150 setL1Invite(null);
src/views/IssueChild.js+1−1
@@ -43,7 +43,7 @@ export function useIssueChild() {
4343 return useEthereumTransaction(
4444 useCallback(
4545 (spawnedPoint, owner) => {
46− console.log(5, spawnedPoint, owner)
46+ console.log(5, spawnedPoint, owner);
4747 setSpawnedPoint(spawnedPoint);
4848 return azimuth.ecliptic.spawn(_contracts, spawnedPoint, owner);
4949 },
src/views/Point.js+1−14
@@ -7,7 +7,6 @@ import { azimuth } from 'azimuth-js';
77
88import { usePointCursor } from 'store/pointCursor';
99import { useWallet } from 'store/wallet';
10−import { usePointCache } from 'store/pointCache';
1110import { isL2, useRollerStore } from 'store/roller';
1211
1312import View from 'components/View';
@@ -123,13 +122,11 @@ export default function Point() {
123122 const { pointCursor } = usePointCursor();
124123 const point = need.point(pointCursor);
125124
126− const { getResidents } = usePointCache();
127125 const { api, getInvites } = useRoller();
128126 const {
129127 pendingTransactions,
130128 nextRoll,
131129 invites,
132− recentlyCompleted,
133130 setCurrentPoint,
134131 setPendingTransactions,
135132 } = useRollerStore();
@@ -154,15 +151,7 @@ export default function Point() {
154151 loadL2Info();
155152 }, [api, point, authToken, setPendingTransactions, loaded]); // eslint-disable-line
156153
157− const { residentCount, requestCount } = getResidents(point);
158−
159− const {
160− isParent,
161− isActiveOwner,
162− canManage,
163− canSpawn,
164− canVote,
165− } = useCurrentPermissions();
154+ const { isParent, canManage, canSpawn, canVote } = useCurrentPermissions();
166155
167156 // L1 invites
168157 const l1Invites = useInvites(point);
@@ -225,8 +214,6 @@ export default function Point() {
225214 useSyncExtras([point]);
226215
227216 const address = need.addressFromWallet(wallet);
228−
229− const _requestCount = requestCount.getOrElse(0);
230217 const numPending = pendingTransactions.length;
231218
232219 return (
src/views/Points.js+22−25
@@ -41,32 +41,29 @@ export const hasTransferProxy = details =>
4141 !isZeroAddress(details.transferProxy);
4242
4343export 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) })
44+ return controlledPoints
45+ .chain(points =>
46+ points.matchWith({
47+ Error: () => Nothing(),
48+ Ok: c => {
49+ const points = c.value.ownedPoints.map(point =>
50+ getDetails(point).chain(details =>
51+ Just({ point: point, has: hasTransferProxy(details) })
52+ )
53+ );
54+ if (points.every(p => Just.hasInstance(p))) {
55+ const outgoing = points
56+ .filter(p => p.value.has)
57+ .map(p => p.value.point);
58+ return Just(outgoing);
59+ } else {
60+ return Nothing();
5561 }
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−}
62+ },
63+ })
64+ )
65+ .getOrElse([]);
66+};
7067
7168export const isLocked = details =>
7269 details.owner === '0x86cd9cd0992f04231751e3761de45cecea5d1801' ||