on master help sign in
accept-transfer: fix infinite render leading to roller request spam
commit4025cc9f15b983587062a271d12e1af3946fd7c8 authorpkova <pyry.kovanen@gmail.com> dateSat 8 Oct 2022, 02:54 (4 years ago) parent8e289ff
10 files changed+27−23
src/lib/useRoller.ts+9−6 src/store/pointCache.js+2−1 src/views/AcceptTransfer.tsx+3−3 src/views/CancelTransfer.tsx+2−2 src/views/Point/IssueChild.tsx+2−2 src/views/Point/MigrateL2.tsx+1−1 src/views/UrbitID/SetProxy.js+2−2 src/views/UrbitID/Transfer.tsx+2−2 src/views/UrbitOS/ChangeSponsor.tsx+2−2 src/views/UrbitOS/NetworkKeys.tsx+2−2
src/lib/useRoller.ts+9−6
@@ -210,22 +210,25 @@ export default function useRoller() {
210210 field,
211211 l1Txn,
212212 intervalTime = TEN_SECONDS,
213+ pointValue,
213214 }: UpdateParams) => {
215+
216+ point = point === undefined ? await initPoint(pointValue) : point;
217+
214218 if (l1Txn) storePendingL1Txn(l1Txn);
215219
216220 let interval: any;
217221 const check = async () => {
218− const updatedPoint = await initPoint(point);
219222 const changedField = !points[point]
220223 ? 'newPoint'
221− : updatedPoint.getChangedField(points[point], field);
224+ : point.getChangedField(points[point], field);
222225
223226 if (isDevelopment) {
224− console.log(`CHECKING FOR ${changedField} UPDATES:`, updatedPoint);
227+ console.log(`CHECKING FOR ${changedField} UPDATES:`, point.patp);
225228 }
226229
227− if (!updatedPoint.isPlaceholder && changedField) {
228− updatePoint(updatedPoint);
230+ if (!point.isPlaceholder && changedField) {
231+ updatePoint(point);
229232 if (interval) {
230233 clearInterval(interval);
231234 }
@@ -233,7 +236,7 @@ export default function useRoller() {
233236 if (l1Txn) deletePendingL1Txn(l1Txn);
234237 if (notify) {
235238 showNotification(
236− `${message || getUpdatedPointMessage(updatedPoint, changedField)}`
239+ `${message || getUpdatedPointMessage(point, changedField)}`
237240 );
238241 }
239242 }
src/store/pointCache.js+2−1
@@ -1,5 +1,6 @@
11import React, { createContext, forwardRef, useContext } from 'react';
22
3+import useDeepEqualReference from 'lib/useDeepEqualReference';
34import usePointStore from './lib/usePointStore';
45
56export const PointCacheContext = createContext(null);
@@ -8,7 +9,7 @@ export function PointCacheProvider({ children }) {
89 const cache = usePointStore();
910
1011 return (
11− <PointCacheContext.Provider value={cache}>
12+ <PointCacheContext.Provider value={useDeepEqualReference(cache)}>
1213 {children}
1314 </PointCacheContext.Provider>
1415 );
src/views/AcceptTransfer.tsx+3−3
@@ -53,7 +53,7 @@ function useAcceptTransfer() {
5353 ),
5454 useCallback(
5555 () => Promise.all([syncExtras(_point), syncControlledPoints()]),
56− [_point, syncControlledPoints, syncExtras]
56+ [_point]
5757 ),
5858 GAS_LIMITS.TRANSFER
5959 );
@@ -89,7 +89,7 @@ export default function AcceptTransfer() {
8989 // Update this one
9090 if (completed) {
9191 checkForUpdates({
92− point: point.value,
92+ point: point,
9393 message: `${point.patp} has been transferred to you!`,
9494 l1Txn: {
9595 id: `accept-transfer-${point.value}`,
@@ -129,7 +129,7 @@ export default function AcceptTransfer() {
129129 transferring.current = true;
130130 await transferPoint(_address, reset);
131131 await checkForUpdates({
132− point: point.value,
132+ point: point,
133133 message: `${point.patp} has been transferred to you!`,
134134 });
135135
src/views/CancelTransfer.tsx+2−2
@@ -68,7 +68,7 @@ function AdminCancelTransfer() {
6868 useEffect(() => {
6969 if (completed) {
7070 checkForUpdates({
71− point: point.value,
71+ point: point,
7272 message: `${point.patp} transfer cancelled`,
7373 l1Txn: {
7474 id: `cancel-${point.value}`,
@@ -89,7 +89,7 @@ function AdminCancelTransfer() {
8989 const cancelTransfer = useCallback(async () => {
9090 await setProxyAddress('transfer', ETH_ZERO_ADDR);
9191 await checkForUpdates({
92− point: point.value,
92+ point: point,
9393 message: `${point.patp} transfer cancelled`,
9494 });
9595 goBack();
src/views/Point/IssueChild.tsx+2−2
@@ -119,7 +119,7 @@ export default function IssueChild() {
119119 if (pointToSpawn && destinationAddress) {
120120 setLoading(true);
121121 await spawnPoint(pointToSpawn, destinationAddress);
122− checkForUpdates({ point: pointToSpawn });
122+ checkForUpdates({ pointValue: pointToSpawn });
123123 setPointToSpawn(null);
124124 setDestinationAddress(null);
125125 setL2SpawnSent(true);
@@ -140,7 +140,7 @@ export default function IssueChild() {
140140 useEffect(() => {
141141 if (completed && pointToSpawn) {
142142 checkForUpdates({
143− point: pointToSpawn,
143+ pointValue: pointToSpawn,
144144 l1Txn: {
145145 id: `${pointToSpawn}`,
146146 point: point.value,
src/views/Point/MigrateL2.tsx+1−1
@@ -135,7 +135,7 @@ export default function MigrateL2() {
135135 : `${selectedPoint.patp}'s spawn proxy has been set to Layer 2!`;
136136
137137 checkForUpdates({
138− point: selectedPoint.value,
138+ point: selectedPoint,
139139 message,
140140 notify: true,
141141 field: PointField.layer,
src/views/UrbitID/SetProxy.js+2−2
@@ -165,7 +165,7 @@ export default function SetProxy() {
165165 await setProxyAddress(getL2ProxyName(data.proxyType), newAddress);
166166
167167 checkForUpdates({
168− point: point.value,
168+ point: point,
169169 message: `${point.patp}'s ${humanProxyType} proxy has been set!`,
170170 });
171171
@@ -191,7 +191,7 @@ export default function SetProxy() {
191191 useEffect(() => {
192192 if (completed) {
193193 checkForUpdates({
194− point: point.value,
194+ point: point,
195195 message: `${point.patp}'s ${humanProxyType} proxy has been set!`,
196196 l1Txn: {
197197 id: `${newAddress}-${point.value}`,
src/views/UrbitID/Transfer.tsx+2−2
@@ -80,7 +80,7 @@ export default function AdminTransfer() {
8080 // Update this one
8181 if (completed) {
8282 checkForUpdates({
83− point: point.value,
83+ point: point,
8484 message: `${point.patp}'s transfer proxy has been set!`,
8585 l1Txn: {
8686 id: `set-transfer-proxy-${point.value}`,
@@ -105,7 +105,7 @@ export default function AdminTransfer() {
105105 await setProxyAddress('transfer', owner);
106106 getPendingTransactions();
107107 checkForUpdates({
108− point: point.value,
108+ point: point,
109109 message: `${point.patp}'s transfer proxy has been set!`,
110110 });
111111 pop();
src/views/UrbitOS/ChangeSponsor.tsx+2−2
@@ -63,7 +63,7 @@ function ChangeSponsor({ onDone }: { onDone: Function }) {
6363 setLoading(true);
6464 await changeSponsor(newSponsor!);
6565 checkForUpdates({
66− point: point.value,
66+ point: point,
6767 message: `${point.patp} has requested ${ob.patp(
6868 newSponsor
6969 )} as a sponsor`,
@@ -210,7 +210,7 @@ function CurrentEscape({ onDone }: { onDone: Function }) {
210210 setLoading(true);
211211 await cancelEscape();
212212 checkForUpdates({
213− point: point.value,
213+ point: point,
214214 message: `${point.patp}'s sponsor change cancelled`,
215215 });
216216 setLoading(false);
src/views/UrbitOS/NetworkKeys.tsx+2−2
@@ -176,7 +176,7 @@ export default function UrbitOSNetworkKeys({
176176 useEffect(() => {
177177 if (completed) {
178178 checkForUpdates({
179− point: point.value,
179+ point: point,
180180 message: `${point.patp}'s Network Keys have been set!`,
181181 l1Txn: {
182182 id: `${point.keyRevisionNumber}-network-keys-${point.value}`,
@@ -252,7 +252,7 @@ export default function UrbitOSNetworkKeys({
252252 // we could inspect if there's a changeKeys in the local list of pending txs,...
253253 //
254254 checkForUpdates({
255− point: point.value,
255+ point: point,
256256 message: `${point.patp}'s Network Keys have been set!`,
257257 intervalTime: ONE_SECOND,
258258 });