on master help sign in
invites: fix missing planet invites
commit2c72275d13f0351b9b72e46679758d73489c8eae authoryosoyubik <yosoyubik@gmail.com> dateTue 21 Sep 2021, 11:46 (5 years ago) parent40b752c
1 file changed+24−25
src/lib/useRoller.ts+24−25
src/lib/useRoller.ts+24−25
@@ -4,11 +4,13 @@ import * as need from 'lib/need';
44import * as ob from 'urbit-ob';
55import * as wg from 'lib/walletgen';
66
7+import { Invite } from 'lib/types/Invite';
78import { convertToInt } from './convertToInt';
89import { ensureHexPrefix } from 'form/formatters';
9−import { getOutgoingPoints, maybeGetResult } from 'views/Points';
10+import { getOutgoingPoints } from 'views/Points';
1011import { isDevelopment, isRopsten } from './flags';
1112import { isPlanet } from './utils/point';
13+import { hasPoint } from './utils/roller';
1214import { ROLLER_HOSTS } from './constants';
1315import { signTransactionHash } from './authToken';
1416import { useNetwork } from 'store/network';
@@ -143,9 +145,16 @@ export default function useRoller() {
143145 const planets: UnspawnedPoints = await api.getUnspawned(_point);
144146 const starInfo = await api.getPoint(_point);
145147
146− const tickets: { ticket: string; planet: number; owner: string }[] = [];
148+ const tickets: {
149+ ticket: string;
150+ planet: number;
151+ owner: string;
152+ }[] = [];
147153 const requests: Promise<string>[] = [];
148154
155+ // TODO: replace with "currentNonce" from store, that would reflect the latest nonce
156+ // Bridge has used for the star _wallet.address
157+ //
149158 const { proxy, nonce } = getProxyAndNonce(starInfo, _wallet.address);
150159
151160 if (!(proxy === 'own' || proxy === 'spawn') || nonce === undefined)
@@ -174,7 +183,7 @@ export default function useRoller() {
174183 _wallet,
175184 planet,
176185 proxy,
177− 0, //nonceInc + 1,
186+ 0,
178187 _details,
179188 authToken,
180189 authMnemonic,
@@ -187,7 +196,7 @@ export default function useRoller() {
187196 _wallet,
188197 planet,
189198 proxy,
190− 1, //nonceInc + 2,
199+ 1,
191200 owner.keys.address
192201 );
193202
@@ -201,7 +210,7 @@ export default function useRoller() {
201210
202211 const hashes = await Promise.all(requests);
203212
204− const pendingInvites = tickets.map((ticket, ind) => ({
213+ const pendingInvites: Invite[] = tickets.map((ticket, ind) => ({
205214 ...ticket,
206215 hash: hashes[ind * 3 + 2],
207216 status: 'pending',
@@ -262,7 +271,6 @@ export default function useRoller() {
262271 const curPoint: number = Number(need.point(pointCursor));
263272 const invites = getStoredInvites(curPoint);
264273 const availableInvites = invites.available;
265−
266274 const pendingTransactions = await api.getPendingByShip(curPoint);
267275 if (isDevelopment) {
268276 console.log('PENDING', pendingTransactions);
@@ -276,7 +284,7 @@ export default function useRoller() {
276284
277285 if (
278286 completed &&
279− !availableInvites.find(({ ship }) => invite.ship === ship)
287+ !availableInvites.find(({ planet }) => invite.planet === planet)
280288 ) {
281289 availableInvites.push({ ...invite, status: 'available' });
282290 }
@@ -295,15 +303,15 @@ export default function useRoller() {
295303
296304 if (_authToken && _contracts) {
297305 let possibleMissingInvites: number[] = [];
306+ let availablePoints: number[] = [];
298307 if (isL2) {
299− const allSpawned = await api.getSpawned(curPoint);
300− const ownedPoints = maybeGetResult(
301− controlledPoints,
302− 'ownedPoints',
303− []
304− );
305− possibleMissingInvites = allSpawned.filter(
306− (p: number) => ownedPoints.includes(p) && isPlanet(p)
308+ possibleMissingInvites = await api.getSpawned(curPoint);
309+ availablePoints = await api.getUnspawned(curPoint);
310+ } else {
311+ // TODO: should it be removed?
312+ availablePoints = await azimuth.azimuth.getUnspawnedChildren(
313+ _contracts,
314+ curPoint
307315 );
308316 }
309317
@@ -312,11 +320,6 @@ export default function useRoller() {
312320 getDetails
313321 );
314322
315− const availablePoints = await azimuth.azimuth.getUnspawnedChildren(
316− _contracts,
317− curPoint
318− );
319−
320323 possibleMissingInvites = possibleMissingInvites.concat(
321324 outgoingPoints.filter(
322325 (p: number) => isPlanet(p) && availablePoints.includes(p)
@@ -331,11 +334,7 @@ export default function useRoller() {
331334
332335 for (let i = 0; i < possibleMissingInvites.length; i++) {
333336 const planet = possibleMissingInvites[i];
334−
335− if (
336− !availableInvites.find(hasPoint(planet)) &&
337− !(await azimuth.azimuth.isActive(_contracts, planet))
338− ) {
337+ if (!availableInvites.find(hasPoint(planet))) {
339338 console.log('MISSING IN AVAILABLE', planet);
340339 const {
341340 ticket,