@@ -1,14 +1,15 @@
6 Button as IndigoButton,
5 Button as IndigoButton,
8} from '@tlon/indigo-react';
8} from '@tlon/indigo-react';
9import { Button } from 'indigo-react';
9import { Button } from 'indigo-react';
10import Modal from './Modal';
10import Modal from './Modal';
11import { useCallback, useEffect, useState } from 'react';
11import { useCallback, useEffect, useState } from 'react';
12+import { ReactComponent as InviteIcon } from 'assets/invite.svg';
12import Point from 'lib/types/Point';
13import Point from 'lib/types/Point';
13import useRoller from 'lib/useRoller';
14import useRoller from 'lib/useRoller';
14import BodyPane from './Window/BodyPane';
15import BodyPane from './Window/BodyPane';
@@ -17,8 +18,8 @@ import {
17 useInvites,
18 useInvites,
18 useInviteStore,
19 useInviteStore,
19} from 'views/Invite/useInvites';
20} from 'views/Invite/useInvites';
20−import { GeneratingModal } from 'views/Invite/GeneratingModal';
21import { usePointCache } from 'store/pointCache';
21import { usePointCache } from 'store/pointCache';
22+import { CreatingInvitesModal } from './CreatingInvitesModal';
23interface StarMap {
24interface StarMap {
24 [key: string]: {
25 [key: string]: {
@@ -60,8 +61,11 @@ export const InviteConverter = ({ points }: InviteConverterProps) => {
60 const [generatingStatus, setGeneratingStatus] = useState<
61 const [generatingStatus, setGeneratingStatus] = useState<
61 InviteGeneratingStatus
62 InviteGeneratingStatus
62 >('initial');
63 >('initial');
64+ const [error, setError] = useState('');
65+ const [created, setCreated] = useState(0);
63 const [currentPoint, setCurrentPoint] = useState<Point>();
66 const [currentPoint, setCurrentPoint] = useState<Point>();
64 const currentJob = inviteJobs[currentPoint?.value || 0];
67 const currentJob = inviteJobs[currentPoint?.value || 0];
68+ const signatureCount = selected.length * 3;
66 useEffect(() => {
70 useEffect(() => {
67 if (!points) {
71 if (!points) {
@@ -70,11 +74,13 @@ export const InviteConverter = ({ points }: InviteConverterProps) => {
71 async function collect() {
75 async function collect() {
72 const pointMap: StarMap = {};
76 const pointMap: StarMap = {};
73− const stars = points.filter(point => point.isStar);
77+ const stars = points.filter(point => point.isStar && point.isL2Spawn);
75 for (const star of stars) {
79 for (const star of stars) {
76 const spawns = await api.getSpawned(star.value);
80 const spawns = await api.getSpawned(star.value);
77− const filteredPoints = points.filter(p => spawns.includes(p.value));
81+ const filteredPoints = points.filter(
82+ p => spawns.includes(p.value) && p.isL2Spawn
79 if (filteredPoints.length !== 0) {
85 if (filteredPoints.length !== 0) {
80 pointMap[star.patp] = {
86 pointMap[star.patp] = {
@@ -126,56 +132,65 @@ export const InviteConverter = ({ points }: InviteConverterProps) => {
127 setGeneratingStatus('generating');
133 setGeneratingStatus('generating');
129− for (const { point, children } of Object.values(starMap)) {
136+ for (const { point, children } of Object.values(starMap)) {
130− debugger;
137+ debugger;
131− const filtered = children
138+ const filtered = children
132− .filter(p => selected.includes(p.patp))
139+ .filter(p => selected.includes(p.patp))
133− .map(p => p.value);
140+ .map(p => p.value);
135− if (filtered.length <= 0) {
142+ if (filtered.length <= 0) {
136− continue;
143+ continue;
146+ setCurrentPoint(point);
147+ await generateInviteCodes(point, filtered, false);
148+ await getAndUpdatePoint(point.value);
149+ setCreated(children.length);
139− setCurrentPoint(point);
152+ setGeneratingStatus('finished');
140− await generateInviteCodes(point, filtered, false);
153+ } catch (error) {
141− await getAndUpdatePoint(point.value);
154+ if (typeof error === 'object' && (error as Error)?.message) {
155+ setError((error as Error).message);
156+ } else if (typeof error === 'string') {
159+ setError('Creating invites failed');
161+ setGeneratingStatus('errored');
144− getPendingTransactions();
145− syncControlledPoints();
146− setGeneratingStatus('finished');
148 generatingStatus,
164 generatingStatus,
149 selected,
165 selected,
151 generateInviteCodes,
167 generateInviteCodes,
152 getAndUpdatePoint,
168 getAndUpdatePoint,
153− getPendingTransactions,
154− syncControlledPoints,
172+ Object.entries(starMap).reduce((sum, [, star]) => {
173+ return (sum += star.children.length);
157 if (generatingStatus !== 'initial') {
180 if (generatingStatus !== 'initial') {
159− <GeneratingModal
182+ <CreatingInvitesModal
160 status={generatingStatus}
183 status={generatingStatus}
161− current={currentJob?.generatingNum}
184+ current={created + currentJob?.generatingNum}
163− generatingStatus === 'finished'
165− : selected.filter(p => {
166− const children = starMap[currentPoint?.patp || '']?.children;
167− return children.map(c => c.patp).includes(p);
168− }).length
185+ total={selected.length}
170− fromStar={currentPoint?.patp}
172 hide={() => {
187 hide={() => {
173 setGeneratingStatus('initial');
188 setGeneratingStatus('initial');
174 setSelected([]);
189 setSelected([]);
175 setShow(false);
190 setShow(false);
176− if (generatingStatus !== 'errored') {
191+ setCreated(0);
177− //pop();
192+ getPendingTransactions();
178− }
193+ syncControlledPoints();
@@ -185,51 +200,57 @@ export const InviteConverter = ({ points }: InviteConverterProps) => {
187 @ts-ignore */}
202 @ts-ignore */}
188− <Button solid center onClick={() => setShow(true)}>
203+ <Button className="create-invites" center onClick={() => setShow(true)}>
189− Convert to Invites
204+ Create Invites from Planets
190 </Button>
205 </Button>
191− <Modal show={show} hide={() => setShow(false)}>
206+ <Modal small show={show} hide={() => setShow(false)}>
192 <BodyPane p={0}>
207 <BodyPane p={0}>
193− <Col width="420px">
208+ <Col width="368px">
194− <H3 mb={2}>Convert Planet Spawns to Invites</H3>
209+ <Row alignItems="center" mb={3}>
212+ Create Invites for Existing Planets
195− <Text>
215+ <Text mb={5}>
196− This allows you to convert a spawned planets into invites. After
216+ Select L2 planets you own to convert them back into invite links
197− this operation, invites will show up under the point they were
217+ under each star.{' '}
198− spawned from.
218+ <Text color="red" lineHeight="24px">
219+ Note: this will re-ticket the planets and render their existing
223+ <Text bold className={!!signatureCount ? '' : 'hidden'}>
224+ {signatureCount} manual signatures will be required.
201 bg="washedGray"
227 bg="washedGray"
202 height="300px"
228 height="300px"
205 borderRadius={2}
231 borderRadius={2}
206 overflowY="auto">
232 overflowY="auto">
207 {Object.entries(starMap).map(([patp, { children }]) => (
233 {Object.entries(starMap).map(([patp, { children }]) => (
208 <Col mb={4}>
234 <Col mb={4}>
210− <Text mb={2} fontSize={2}>
236+ <Text bold mb={2}>
212− <Text bold fontSize={2}>
213− {patp}
237+ Owned by {patp}
216− <IndigoButton
239+ <Action
217− height="18px"
240+ backgroundColor="transparent"
220 ml="auto"
241 ml="auto"
221 onClick={() => selectChildren(children)}>
242 onClick={() => selectChildren(children)}>
222 {selectText(selected, children)}
243 {selectText(selected, children)}
223− </IndigoButton>
244+ </Action>
225− {children.map(point => (
246+ {children.map((point, index) => (
227 alignItems="center"
248 alignItems="center"
228 justifyContent="space-between"
249 justifyContent="space-between"
232− borderBottomWidth="1px"
251+ borderBottomWidth={
252+ index === children.length - 1 ? '0px' : '1px'
233 borderBottomStyle="solid"
254 borderBottomStyle="solid"
234 borderBottomColor="washedGray">
255 borderBottomColor="washedGray">
235 <Text>{point.patp}</Text>
256 <Text>{point.patp}</Text>
@@ -241,8 +262,9 @@ export const InviteConverter = ({ points }: InviteConverterProps) => {
245− <Row mt={4} justifyContent="end">
267+ <Row mt={3} justifyContent="end">
246 <IndigoButton
268 <IndigoButton
247 className="secondary"
269 className="secondary"
248 onClick={() => setShow(false)}>
270 onClick={() => setShow(false)}>
@@ -255,7 +277,7 @@ export const InviteConverter = ({ points }: InviteConverterProps) => {
256 onClick={convert}
278 onClick={convert}
257 disabled={selected.length === 0}>
279 disabled={selected.length === 0}>
258− Convert
280+ Convert Selected
259 </IndigoButton>
281 </IndigoButton>