on master help sign in
useRoller: make updates check immediately and then repeat every 10s
commit2a60cdb45f2f5c13750f7b5badd9a808135ea1a3 authorHunter Miller <hunter@thisdot.co> dateTue 8 Feb 2022, 15:04 (5 years ago) parentc93b2b8
1 file changed+12−3
src/lib/useRoller.ts+12−3
src/lib/useRoller.ts+12−3
@@ -268,7 +268,8 @@ export default function useRoller() {
268268 }: UpdateParams) => {
269269 if (l1Txn) storePendingL1Txn(l1Txn);
270270
271− const interval = setInterval(async () => {
271+ let interval: any;
272+ const check = async () => {
272273 const updatedPoint = await initPoint(point);
273274 const changedField = !points[point]
274275 ? 'newPoint'
@@ -280,7 +281,10 @@ export default function useRoller() {
280281
281282 if (!updatedPoint.isPlaceholder && changedField) {
282283 updatePoint(updatedPoint);
283− clearInterval(interval);
284+ if (interval) {
285+ clearInterval(interval);
286+ }
287+
284288 if (l1Txn) deletePendingL1Txn(l1Txn);
285289 if (notify) {
286290 showNotification(
@@ -288,7 +292,10 @@ export default function useRoller() {
288292 );
289293 }
290294 }
291− }, intervalTime);
295+ };
296+
297+ interval = setInterval(check, intervalTime);
298+ check();
292299 },
293300 [points, initPoint, updatePoint, storePendingL1Txn, deletePendingL1Txn]
294301 );
@@ -1001,6 +1008,7 @@ export default function useRoller() {
10011008 spawningPoints: number[]
10021009 ) => {
10031010 try {
1011+ debugger;
10041012 const allPoints = [
10051013 await Promise.all(ownedPoints.map(initPoint)),
10061014 await Promise.all(incomingPoints.map(initPoint)),
@@ -1009,6 +1017,7 @@ export default function useRoller() {
10091017 await Promise.all(spawningPoints.map(initPoint)),
10101018 ];
10111019
1020+ debugger;
10121021 setPoints(
10131022 allPoints.reduce((acc: Points, cur: (Point | undefined)[]) => {
10141023 cur.forEach(p => {