on master help sign in
integrate #1143 to fix #1141
7b82fc8~sarlev-sarsen
src/lib/useRoller.ts+65−46
@@ -145,16 +145,17 @@ export default function useRoller() {
145 }
145 }
146
146
147 const pointNum = Number(point);
147 const pointNum = Number(point);
148− const rawDetails = await api.getPoint(pointNum);
149− const isL2 = isL2Spawn(rawDetails?.dominion);
150−
151− const details = toL1Details(rawDetails);
152
148
153 try {
149 try {
154− if (isL2) {
150+ // Try fetching from the roller
155− const l2Quota = isL2 ? await api.getRemainingQuota(pointNum) : 0;
151+ const rawDetails = await api.getPoint(pointNum); // this fails for newly spawned L1 point until roller updates
156− const l2Allowance = isL2 ? await api.getAllowance(pointNum) : 0;
152+ const details = toL1Details(rawDetails);
153+ const isL2 = isL2Spawn(rawDetails?.dominion);
157
154
155+ if (isL2) {
156+ // Scenario 1: L2 point exists in roller state - use roller data
157+ const l2Quota = await api.getRemainingQuota(pointNum);
158+ const l2Allowance = await api.getAllowance(pointNum);
158 return new Point({
159 return new Point({
159 value: pointNum,
160 value: pointNum,
160 details,
161 details,
@@ -162,30 +163,48 @@ export default function useRoller() {
162 l2Quota,
163 l2Quota,
163 l2Allowance,
164 l2Allowance,
164 });
165 });
166+ } else {
167+ // Scenario 2: L1 point exists in roller state - use combination of chain and roller data
168+ const _contracts = need.contracts(contracts);
169+ const l1Details = await azimuth.azimuth.getPoint(
170+ _contracts,
171+ pointNum
172+ );
173+ // Override with roller data for accuracy, L1 data here could be stale
174+ l1Details.sponsor = details.sponsor;
175+ l1Details.escapeRequested = details.escapeRequested;
176+ l1Details.escapeRequestedTo = details.escapeRequestedTo;
177+ return new Point({
178+ value: pointNum,
179+ details: l1Details,
180+ address: _wallet.address,
181+ });
165 }
182 }
166−
167− const _contracts = need.contracts(contracts);
168− const l1Details = await azimuth.azimuth.getPoint(_contracts, point);
169−
170− l1Details.sponsor = details.sponsor;
171− l1Details.escapeRequested = details.escapeRequested;
172− l1Details.escapeRequestedTo = details.escapeRequestedTo;
173−
174− return new Point({
175− value: pointNum,
176− details: l1Details,
177− address: _wallet.address,
178− });
179 } catch (e) {
183 } catch (e) {
180− console.warn(e);
184+ // roller failed to fetch point
181− // Just return a placeholder Point
185+ try {
186+ // Scenario 3: Newly spawned L1 point - not in roller state yet, use chain data only
187+ const _contracts = need.contracts(contracts);
188+ const l1Details = await azimuth.azimuth.getPoint(
189+ _contracts,
190+ pointNum
191+ );
192+ return new Point({
193+ value: pointNum,
194+ details: l1Details,
195+ address: _wallet.address,
196+ });
197+ } catch (e2) {
198+ // Scenario 4: Some other issue, point doesn’t exist on chain or in roller state. Just return placeholder.
199+ console.warn('Failed to fetch point data:', e2);
182− const details: L1Point = toL1Details();
200+ const details: L1Point = toL1Details();
183− return new Point({
201+ return new Point({
184− value: pointNum,
202+ value: pointNum,
185− details,
203+ details,
186− address: _wallet.address,
204+ address: _wallet.address,
187− isPlaceholder: true,
205+ isPlaceholder: true,
188− });
206+ });
207+ }
189 }
208 }
190 },
209 },
191 [api, wallet, contracts]
210 [api, wallet, contracts]
@@ -309,14 +328,14 @@ export default function useRoller() {
309 proxy === 'own'
328 proxy === 'own'
310 ? await api.getOwnedPoints(address)
329 ? await api.getOwnedPoints(address)
311 : proxy === 'manage'
330 : proxy === 'manage'
312− ? await api.getManagerFor(address)
331+ ? await api.getManagerFor(address)
313− : proxy === 'vote'
332+ : proxy === 'vote'
314− ? await api.getVotingFor(address)
333+ ? await api.getVotingFor(address)
315− : proxy === 'transfer'
334+ : proxy === 'transfer'
316− ? await api.getTransferringFor(address)
335+ ? await api.getTransferringFor(address)
317− : proxy === 'spawn'
336+ : proxy === 'spawn'
318− ? await api.getSpawningFor(address)
337+ ? await api.getSpawningFor(address)
319− : [];
338+ : [];
320
339
321 return points;
340 return points;
322 },
341 },
@@ -365,14 +384,14 @@ export default function useRoller() {
365 const networkSeed = customNetworkSeed
384 const networkSeed = customNetworkSeed
366 ? customNetworkSeed
385 ? customNetworkSeed
367 : await attemptNetworkSeedDerivation({
386 : await attemptNetworkSeedDerivation({
368− urbitWallet,
387+ urbitWallet,
369− wallet,
388+ wallet,
370− authMnemonic,
389+ authMnemonic,
371− details: point,
390+ details: point,
372− authToken,
391+ authToken,
373− point: point.value,
392+ point: point.value,
374− revision: nextRevision,
393+ revision: nextRevision,
375− });
394+ });
376 const txHash = await submitL2Transaction({
395 const txHash = await submitL2Transaction({
377 api,
396 api,
378 wallet: _wallet,
397 wallet: _wallet,
@@ -422,7 +441,7 @@ export default function useRoller() {
422 let nonce = await api.getNonce({ ship: point, proxy });
441 let nonce = await api.getNonce({ ship: point, proxy });
423 const progress = onUpdate
442 const progress = onUpdate
424 ? (state: number) => onUpdate({ type: 'progress', state })
443 ? (state: number) => onUpdate({ type: 'progress', state })
425− : () => {};
444+ : () => { };
426
445
427 let requests = [];
446 let requests = [];
428
447