@@ -222,132 +222,134 @@ export default function useRoller() {
222222 }
223223 }, [api, setPendingTransactions, pointCursor]);
224224
225− const getInvites = useCallback(async () => {
226− try {
227− const curPoint: string = need.point(pointCursor);
228− const invites = getStoredInvites(curPoint);
229− const availableInvites = invites.available;
230−
231− const pendingTransactions = await api.getPendingByShip(curPoint);
232− console.log('PENDING', pendingTransactions);
233− setPendingTransactions(pendingTransactions);
234−
235− const stillPending = invites.pending.filter(invite => {
236− const completed = !pendingTransactions.find(
237− p => p?.rawTx?.tx?.tx?.data?.ship === invite.planet
238− );
239−
240− if (completed) {
241− availableInvites.push({ ...invite, status: 'available' });
242− }
225+ const getInvites = useCallback(
226+ async (isL2: boolean) => {
227+ try {
228+ const curPoint: string = need.point(pointCursor);
229+ const invites = getStoredInvites(curPoint);
230+ const availableInvites = invites.available;
231+
232+ const pendingTransactions = await api.getPendingByShip(curPoint);
233+ console.log('PENDING', pendingTransactions);
234+ setPendingTransactions(pendingTransactions);
235+
236+ const stillPending = invites.pending.filter(invite => {
237+ const completed = !pendingTransactions.find(
238+ p => p?.rawTx?.tx?.tx?.data?.ship === invite.planet
239+ );
243240
244− return !completed;
245− });
241+ if (completed) {
242+ availableInvites.push({ ...invite, status: 'available' });
243+ }
246244
247− setStoredInvites(curPoint, {
248− available: availableInvites,
249− pending: stillPending,
250− claimed: invites.claimed,
251− });
252− setInvites(availableInvites);
245+ return !completed;
246+ });
253247
254− let possibleMissingInvites: number[] = [];
248+ setStoredInvites(curPoint, {
249+ available: availableInvites,
250+ pending: stillPending,
251+ claimed: invites.claimed,
252+ });
253+ setInvites(availableInvites);
255254
256− if (currentL2) {
257− const allSpawned = await api.getSpawned(Number(curPoint));
258− const ownedPoints = maybeGetResult(controlledPoints, 'ownedPoints', []);
259− possibleMissingInvites = ownedPoints.filter(
260− (p: number) =>
261− allSpawned.includes(p) &&
262− azimuth.azimuth.getPointSize(p) === azimuth.azimuth.PointSize.Planet
263− );
264− } else {
265− const maybeOutgoingPoints = controlledPoints.chain((points: any) =>
266− points.matchWith({
267− Error: () => Nothing(),
268− Ok: (c: any) => {
269− const points = c.value.ownedPoints.map((point: number) =>
270− getDetails(point).chain((details: any) =>
271− Just({ point: point, has: hasTransferProxy(details) })
272− )
273− );
274− if (points.every((p: any) => Just.hasInstance(p))) {
275− const outgoing = points
276− .filter((p: any) => p.value.has)
277− .map((p: any) => p.value.point);
278− return Just(outgoing);
279− } else {
280− return Nothing();
281− }
282− },
283− })
284− );
255+ let possibleMissingInvites: number[] = [];
285256
286− possibleMissingInvites = maybeOutgoingPoints
287− .getOrElse([])
288− .filter(
257+ if (isL2) {
258+ const allSpawned = await api.getSpawned(Number(curPoint));
259+ const ownedPoints = maybeGetResult(controlledPoints, 'ownedPoints', []);
260+ possibleMissingInvites = allSpawned.filter(
289261 (p: number) =>
290− azimuth.azimuth.getPointSize(p) ===
291− azimuth.azimuth.PointSize.Planet
262+ ownedPoints.includes(p) &&
263+ azimuth.azimuth.getPointSize(p) === azimuth.azimuth.PointSize.Planet
264+ );
265+ } else {
266+ const maybeOutgoingPoints = controlledPoints.chain((points: any) =>
267+ points.matchWith({
268+ Error: () => Nothing(),
269+ Ok: (c: any) => {
270+ const points = c.value.ownedPoints.map((point: number) =>
271+ getDetails(point).chain((details: any) =>
272+ Just({ point: point, has: hasTransferProxy(details) })
273+ )
274+ );
275+ if (points.every((p: any) => Just.hasInstance(p))) {
276+ const outgoing = points
277+ .filter((p: any) => p.value.has)
278+ .map((p: any) => p.value.point);
279+ return Just(outgoing);
280+ } else {
281+ return Nothing();
282+ }
283+ },
284+ })
292285 );
293− }
294286
295− // Iterate over all spawned and controlled planets
296− // If the planet is not in available invites, generate the ticket and add it
297− const _authToken = authToken.getOrElse(null);
298− const _contracts = contracts.getOrElse(null);
287+ possibleMissingInvites = maybeOutgoingPoints
288+ .getOrElse([])
289+ .filter(
290+ (p: number) =>
291+ azimuth.azimuth.getPointSize(p) ===
292+ azimuth.azimuth.PointSize.Planet
293+ );
294+ }
299295
300− const newClaimed = availableInvites.filter(
301− ({ planet }) => !possibleMissingInvites.includes(planet)
302− );
296+ // Iterate over all spawned and controlled planets
297+ // If the planet is not in available invites, generate the ticket and add it
298+ const _authToken = authToken.getOrElse(null);
299+ const _contracts = contracts.getOrElse(null);
303300
304− if (_authToken && _contracts) {
305− for (let i = 0; i < possibleMissingInvites.length; i++) {
306− const planet = possibleMissingInvites[i];
307−
308− if (!availableInvites.find(hasPoint(planet))) {
309− console.log('MISSING IN AVAILABLE', planet);
310− const {
311− ticket,
312− owner,
313− } = await wg.generateTemporaryDeterministicWallet(
314− planet,
315− _authToken
316− );
301+ const newClaimed = availableInvites.filter(
302+ ({ planet }) => !possibleMissingInvites.includes(planet)
303+ );
304+
305+ if (_authToken && _contracts) {
306+ for (let i = 0; i < possibleMissingInvites.length; i++) {
307+ const planet = possibleMissingInvites[i];
308+
309+ if (!availableInvites.find(hasPoint(planet))) {
310+ console.log('MISSING IN AVAILABLE', planet);
311+ const {
312+ ticket,
313+ owner,
314+ } = await wg.generateTemporaryDeterministicWallet(
315+ planet,
316+ _authToken
317+ );
317318
318− availableInvites.push({
319− ticket,
320− status: 'available',
321− planet,
322− hash: '',
323− owner: owner.keys.address,
324− });
319+ availableInvites.push({
320+ ticket,
321+ status: 'available',
322+ planet,
323+ hash: '',
324+ owner: owner.keys.address,
325+ });
326+ }
325327 }
326− }
327328
328− setStoredInvites(curPoint, {
329− available: availableInvites.filter(({ planet }) =>
330− possibleMissingInvites.includes(planet)
331− ),
332− pending: stillPending,
333− claimed: invites.claimed.concat(newClaimed),
334− });
335− setInvites(availableInvites);
329+ setStoredInvites(curPoint, {
330+ available: availableInvites.filter(({ planet }) =>
331+ possibleMissingInvites.includes(planet)
332+ ),
333+ pending: stillPending,
334+ claimed: invites.claimed.concat(newClaimed),
335+ });
336+ setInvites(availableInvites);
337+ }
338+ } catch (error) {
339+ console.warn('ERROR GETTING INVITES', error);
336340 }
337− } catch (error) {
338− console.warn('ERROR GETTING INVITES', error);
339− }
340− }, [
341− api,
342− pointCursor,
343− setInvites,
344− setPendingTransactions,
345− authToken,
346− contracts,
347− controlledPoints,
348− currentL2,
349− getDetails,
350− ]);
341+ },
342+ [
343+ api,
344+ pointCursor,
345+ setInvites,
346+ setPendingTransactions,
347+ authToken,
348+ contracts,
349+ controlledPoints,
350+ getDetails,
351+ ]
352+ );
351353
352354 // On load, get initial config
353355 useEffect(() => {