on master help sign in
useRoller: make updates check immediately and then repeat every 10s
2a60cdbHunter Miller
src/lib/useRoller.ts+12−3
@@ -268,7 +268,8 @@ export default function useRoller() {
268 }: UpdateParams) => {
268 }: UpdateParams) => {
269 if (l1Txn) storePendingL1Txn(l1Txn);
269 if (l1Txn) storePendingL1Txn(l1Txn);
270
270
271− const interval = setInterval(async () => {
271+ let interval: any;
272+ const check = async () => {
272 const updatedPoint = await initPoint(point);
273 const updatedPoint = await initPoint(point);
273 const changedField = !points[point]
274 const changedField = !points[point]
274 ? 'newPoint'
275 ? 'newPoint'
@@ -280,7 +281,10 @@ export default function useRoller() {
280
281
281 if (!updatedPoint.isPlaceholder && changedField) {
282 if (!updatedPoint.isPlaceholder && changedField) {
282 updatePoint(updatedPoint);
283 updatePoint(updatedPoint);
284+ if (interval) {
283− clearInterval(interval);
285+ clearInterval(interval);
286+ }
287+
284 if (l1Txn) deletePendingL1Txn(l1Txn);
288 if (l1Txn) deletePendingL1Txn(l1Txn);
285 if (notify) {
289 if (notify) {
286 showNotification(
290 showNotification(
@@ -288,7 +292,10 @@ export default function useRoller() {
288 );
292 );
289 }
293 }
290 }
294 }
295+ };
296+
291− }, intervalTime);
297+ interval = setInterval(check, intervalTime);
298+ check();
292 },
299 },
293 [points, initPoint, updatePoint, storePendingL1Txn, deletePendingL1Txn]
300 [points, initPoint, updatePoint, storePendingL1Txn, deletePendingL1Txn]
294 );
301 );
@@ -1001,6 +1008,7 @@ export default function useRoller() {
1001 spawningPoints: number[]
1008 spawningPoints: number[]
1002 ) => {
1009 ) => {
1003 try {
1010 try {
1011+ debugger;
1004 const allPoints = [
1012 const allPoints = [
1005 await Promise.all(ownedPoints.map(initPoint)),
1013 await Promise.all(ownedPoints.map(initPoint)),
1006 await Promise.all(incomingPoints.map(initPoint)),
1014 await Promise.all(incomingPoints.map(initPoint)),
@@ -1009,6 +1017,7 @@ export default function useRoller() {
1009 await Promise.all(spawningPoints.map(initPoint)),
1017 await Promise.all(spawningPoints.map(initPoint)),
1010 ];
1018 ];
1011
1019
1020+ debugger;
1012 setPoints(
1021 setPoints(
1013 allPoints.reduce((acc: Points, cur: (Point | undefined)[]) => {
1022 allPoints.reduce((acc: Points, cur: (Point | undefined)[]) => {
1014 cur.forEach(p => {
1023 cur.forEach(p => {