on master help sign in
WIP: migration working
commitac1828fd5326e2515cd6dc2a77d4eba44fddc041 authorWill Galebach <willbach@gmail.com> dateThu 9 Sep 2021, 19:13 (5 years ago) parent70004bb
12 files changed+151−52
src/components/L2/Dropdowns/AccountsDropdown.scss+1−1 src/components/L2/Dropdowns/AccountsDropdown.tsx+1−6 src/components/L2/Dropdowns/Dropdown.scss+1−1 src/components/L2/Dropdowns/Dropdown.tsx+4−4 src/types/Invite.ts → src/lib/types/Invite.ts src/types/L1Point.ts → src/lib/types/L1Point.ts src/lib/types/PointLayer.ts+4 src/lib/useRoller.ts+14−17 src/store/lib/useControlledPointsStore.js+18−19 src/views/Point/MigrateL2.scss+44 src/views/Point/MigrateL2.tsx+60−4 src/views/Point/Point.js+4
src/components/L2/Dropdowns/AccountsDropdown.scss+1−1
@@ -5,7 +5,7 @@
55 position: relative;
66
77 .content-border {
8− .content {
8+ .dropdown-content {
99 .entry, .current-address {
1010 display: flex;
1111 flex-direction: row;
src/components/L2/Dropdowns/AccountsDropdown.tsx+1−6
@@ -15,11 +15,7 @@ import Dropdown from './Dropdown';
1515
1616import './AccountsDropdown.scss';
1717import { abbreviateAddress } from 'lib/utils/address';
18−
19−interface PointLayer {
20− point: number;
21− layer: 1 | 2;
22−}
18+import { PointLayer } from 'lib/types/PointLayer';
2319
2420const AccountsDropdown = () => {
2521 const [open, setOpen] = useState<boolean>(false);
@@ -30,7 +26,6 @@ const AccountsDropdown = () => {
3026
3127 const canBitcoin = Just.hasInstance(walletInfo.urbitWallet);
3228
33− console.log('WHAT', controlledPoints)
3429 const points = controlledPoints?.value?.value?.pointsWithLayers || [];
3530
3631 const currentAddress = walletInfo?.wallet?.value?.address || '';
src/components/L2/Dropdowns/Dropdown.scss+1−1
@@ -33,7 +33,7 @@
3333 border-radius: $medium-border-radius;
3434 z-index: 1;
3535
36− .content {
36+ .dropdown-content {
3737 border-radius: $medium-border-radius;
3838 background-color: white;
3939 border: 1px solid $light-gray;
src/components/L2/Dropdowns/Dropdown.tsx+4−4
@@ -4,9 +4,9 @@ import { Box, Icon } from '@tlon/indigo-react';
44import './Dropdown.scss';
55
66export interface DropdownProps {
7− className: string;
7+ className?: string;
88 children: React.ReactNode;
9− value: string;
9+ value: string | React.ReactNode;
1010 open: boolean;
1111 toggleOpen: () => void;
1212}
@@ -16,7 +16,7 @@ const Dropdown = ({
1616 value,
1717 open,
1818 toggleOpen,
19− className,
19+ className = '',
2020}: DropdownProps) => {
2121 return (
2222 <Box className={`dropdown ${className}`}>
@@ -26,7 +26,7 @@ const Dropdown = ({
2626 </Box>
2727 {open && (
2828 <Box className="content-border">
29− <Box className="content">{children}</Box>
29+ <Box className="dropdown-content">{children}</Box>
3030 </Box>
3131 )}
3232 </Box>
src/types/Invite.ts → src/lib/types/Invite.tsrenamed

The content is the same.

src/types/L1Point.ts → src/lib/types/L1Point.tsrenamed

The content is the same.

src/lib/types/PointLayer.tsnew file+4
@@ -0,0 +1,4 @@
1+export interface PointLayer {
2+ point: number;
3+ layer: 1 | 2;
4+}
src/lib/useRoller.ts+14−17
@@ -269,24 +269,26 @@ export default function useRoller() {
269269 azimuth.azimuth.getPointSize(p) ===
270270 azimuth.azimuth.PointSize.Planet
271271 );
272− } else {
273− const outgoingPoints = getOutgoingPoints(
274− controlledPoints,
275− getDetails
276− );
272+ }
277273
278− const availablePoints = await azimuth.azimuth.getUnspawnedChildren(
279− _contracts,
280− curPoint
281− );
274+ const outgoingPoints = getOutgoingPoints(
275+ controlledPoints,
276+ getDetails
277+ );
278+
279+ const availablePoints = await azimuth.azimuth.getUnspawnedChildren(
280+ _contracts,
281+ curPoint
282+ );
282283
283− possibleMissingInvites = outgoingPoints.filter(
284+ possibleMissingInvites = possibleMissingInvites.concat(
285+ outgoingPoints.filter(
284286 (p: number) =>
285287 azimuth.azimuth.getPointSize(p) ===
286288 azimuth.azimuth.PointSize.Planet &&
287289 availablePoints.includes(p)
288− );
289− }
290+ )
291+ );
290292
291293 // Iterate over all spawned and controlled planets
292294 // If the planet is not in available invites, generate the ticket and add it
@@ -344,10 +346,6 @@ export default function useRoller() {
344346 ]
345347 );
346348
347− const migratePoint = useCallback(async () => {
348− console.log('MIGRATING')
349− }, []);
350−
351349 // On load, get initial config
352350 useEffect(() => {
353351 if (config) {
@@ -381,6 +379,5 @@ export default function useRoller() {
381379 getInvites,
382380 getPendingTransactions,
383381 generateInviteCodes,
384− migratePoint,
385382 };
386383}
src/store/lib/useControlledPointsStore.js+18−19
@@ -53,25 +53,24 @@ export default function useControlledPointsStore() {
5353 azimuth.azimuth.getSpawningFor(_contracts, address),
5454 ]);
5555
56− console.log(1)
57− const pointsWithLayers = await Promise.all(
58− ownedPoints.map(async ship => {
59− console.log(2)
60− try {
61− const pointInfo = await api.getPoint(Number(ship));
62− console.log(3, pointInfo)
63− return {
64− point: Number(ship),
65− layer: isL2(pointInfo?.dominion) ? 1 : 2,
66− };
67− } catch (error) {
68− console.warn(error)
69− return { point: ship, layer: 1 };
70− }
71− })
72− );
73−
74− console.log(4, pointsWithLayers)
56+ // const pointsWithLayers = await Promise.all(
57+ // ownedPoints.map(async ship => {
58+ // try {
59+ // const pointInfo = await api.getPoint(Number(ship));
60+ // return {
61+ // point: Number(ship),
62+ // layer: isL2(pointInfo?.dominion) ? 1 : 2,
63+ // };
64+ // } catch (error) {
65+ // console.warn(error);
66+ // return { point: ship, layer: 1 };
67+ // }
68+ // })
69+ // );
70+ const pointsWithLayers = ownedPoints.map(point => ({
71+ point: Number(point),
72+ layer: 1,
73+ }));
7574
7675 if (
7776 ownedPoints === null &&
src/views/Point/MigrateL2.scss+44
@@ -109,6 +109,50 @@
109109 .select-ship {
110110 color: $mid-gray;
111111 }
112+
113+ .entry {
114+ display: flex;
115+ flex-direction: row;
116+ align-items: center;
117+ cursor: pointer;
118+
119+ padding: 8px 0 8px 6px;
120+
121+ &:hover {
122+ opacity: 0.8;
123+ }
124+
125+ svg {
126+ height: 16px;
127+ width: 16px;
128+ }
129+
130+ .sigil {
131+ margin-right: 8px;
132+ width: 24px;
133+ height: 24px;
134+ border-radius: $small-border-radius;
135+ }
136+
137+ .layer-migration {
138+ svg {
139+ width: 12px;
140+ height: 12px;
141+ margin: 4px 2px;
142+ }
143+ }
144+ }
145+
146+ .dropdown {
147+ margin-top: 4px;
148+ &.migrate-selector .dropdown-content {
149+ max-height: 200px;
150+ }
151+
152+ .selector .entry {
153+ padding: 0;
154+ }
155+ }
112156 }
113157 }
114158}
src/views/Point/MigrateL2.tsx+60−4
@@ -1,6 +1,7 @@
11import React, { useState, useEffect, useCallback } from 'react';
22import { Grid } from 'indigo-react';
33import * as azimuth from 'azimuth-js';
4+import * as ob from 'urbit-ob';
45
56import View from 'components/View';
67import L2BackHeader from 'components/L2/Headers/L2BackHeader';
@@ -25,9 +26,31 @@ import { useNetwork } from 'store/network';
2526import { usePointCache } from 'store/pointCache';
2627import useEthereumTransaction from 'lib/useEthereumTransaction';
2728import { GAS_LIMITS } from 'lib/constants';
29+import Dropdown from 'components/L2/Dropdowns/Dropdown';
30+import { PointLayer } from 'lib/types/PointLayer';
31+import Sigil from 'components/Sigil';
2832
2933const DUMMY_L2_ADDRESS = '0x1111111111111111111111111111111111111111';
3034
35+const PointEntry = ({
36+ point,
37+ select,
38+}: {
39+ point: number;
40+ select?: () => void;
41+}) => {
42+ const patp = ob.patp(point);
43+
44+ return (
45+ <Row className="entry" onClick={select}>
46+ <Box className="sigil">
47+ <Sigil patp={patp} size={1} colors={['#000000', '#FFFFFF']} />
48+ </Box>
49+ <Box>{patp}</Box>
50+ </Row>
51+ );
52+};
53+
3154const useMigrate = () => {
3255 const { contracts }: any = useNetwork();
3356 const { syncDates }: any = usePointCache();
@@ -55,13 +78,25 @@ const useMigrate = () => {
5578
5679export default function MigrateL2() {
5780 const { pop }: any = useLocalRouter();
81+ const { pointCursor }: any = usePointCursor();
82+ const point = need.point(pointCursor);
83+ const { controlledPoints }: any = usePointCache();
5884
5985 const [proceed, setProceed] = useState(false);
6086 const [hideMessage, setHideMessage] = useState(false);
61− const hideInfo = getHideMigrationMessage();
87+ const [selectedPoint, setSelectedPoint] = useState(point);
88+ const [showDropdown, setShowDropdown] = useState(false);
89+
90+ const points = controlledPoints?.value?.value?.pointsWithLayers || [
91+ { point, layer: 1 },
92+ ];
93+ const l1Points = points.filter(
94+ ({ point, layer }: PointLayer) =>
95+ layer === 1 &&
96+ azimuth.azimuth.getPointSize(point) === azimuth.azimuth.PointSize.Star
97+ );
6298
63− const { pointCursor }: any = usePointCursor();
64− const point = need.point(pointCursor);
99+ const hideInfo = getHideMigrationMessage();
65100
66101 const { construct, unconstruct, completed, bind } = useMigrate();
67102
@@ -95,6 +130,15 @@ export default function MigrateL2() {
95130 setProceed(true);
96131 }, [hideMessage]);
97132
133+ const selectPoint = useCallback(
134+ (point: number) => {
135+ setSelectedPoint(point);
136+ setShowDropdown(false);
137+ construct(point);
138+ },
139+ [setSelectedPoint, setShowDropdown, construct]
140+ );
141+
98142 const getContent = () => {
99143 if (proceed) {
100144 return (
@@ -102,7 +146,19 @@ export default function MigrateL2() {
102146 <Box className="ship-selector">
103147 <Box>Ship</Box>
104148 <Box className="select-ship">Select one of your ships</Box>
105−
149+ <Dropdown
150+ open={showDropdown}
151+ toggleOpen={() => setShowDropdown(!showDropdown)}
152+ value={<PointEntry point={selectedPoint} />} // change this to include the sigil
153+ className="migrate-selector">
154+ {l1Points.map(({ point }: PointLayer) => (
155+ <PointEntry
156+ point={point}
157+ key={point}
158+ select={() => selectPoint(point)}
159+ />
160+ ))}
161+ </Dropdown>
106162 </Box>
107163 <Grid.Item
108164 full
src/views/Point/Point.js+4
@@ -31,6 +31,7 @@ import useRoller from 'lib/useRoller';
3131
3232import './Point.scss';
3333import { isL2 } from 'lib/utils/roller';
34+import { isDevelopment } from 'lib/flags';
3435
3536function InviteForm({
3637 showInviteForm,
@@ -138,6 +139,9 @@ export default function Point() {
138139 const loadL2Info = async () => {
139140 const getTransactions = async () => {
140141 const pointInfo = await api.getPoint(Number(point));
142+ if (isDevelopment) {
143+ console.log('POINT INFO', pointInfo);
144+ }
141145 setCurrentPoint(pointInfo);
142146
143147 getInvites(isL2(pointInfo.dominion));