Skip to content

Commit 364ad1f

Browse files
fix: wrap-set-stake-refetch-in-retriable-function
1 parent d2581e5 commit 364ad1f

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

web/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,6 @@
118118
"react-use": "^17.5.1",
119119
"styled-components": "^5.3.3",
120120
"viem": "^2.21.54",
121-
"wagmi": "^2.13.4"
121+
"wagmi": "^2.13.5"
122122
}
123123
}

web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawButton.tsx

+31-6
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, ac
104104
error: allowanceError,
105105
} = useSimulatePnkIncreaseAllowance({
106106
query: {
107-
enabled:
108-
isAllowance && !isUndefined(targetStake) && !isUndefined(allowance) && !isUndefined(balance) && !isPopupOpen,
107+
enabled: isAllowance && !isUndefined(targetStake) && !isUndefined(allowance) && !isUndefined(balance),
109108
},
110109
args: [klerosCoreAddress[DEFAULT_CHAIN], BigInt(targetStake ?? 0) - BigInt(allowance ?? 0)],
111110
});
@@ -214,10 +213,10 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, ac
214213
const status = res.status === "success";
215214
if (status) {
216215
await refetchAllowance();
217-
const refetchData = await refetchSetStake();
216+
const refetchData = await refetchWithRetry(refetchSetStake);
218217
// check for a relatively new error with react/tanstack-query:
219218
// https://github.com/TanStack/query/issues/8209
220-
if (!refetchData.data)
219+
if (!refetchData?.data)
221220
setPopupStepsState(
222221
getStakeSteps(
223222
StakeSteps.ApproveFailed,
@@ -228,8 +227,9 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, ac
228227
new Error("Something went wrong. Please restart the process.")
229228
)
230229
);
231-
232-
handleStake(refetchData.data, hash);
230+
else {
231+
handleStake(refetchData.data, hash);
232+
}
233233
} else setPopupStepsState(getStakeSteps(StakeSteps.ApproveFailed, amount, theme, hash));
234234
});
235235
})
@@ -308,4 +308,29 @@ const StakeWithdrawButton: React.FC<IActionButton> = ({ amount, parsedAmount, ac
308308
);
309309
};
310310

311+
async function refetchWithRetry<T>(fn: () => Promise<T>, retryCount = 5, retryDelay = 2000) {
312+
let attempts = 0;
313+
314+
while (attempts < retryCount) {
315+
try {
316+
const returnData = await fn();
317+
318+
//@ts-expect-error data does exist
319+
if (returnData && returnData?.data !== undefined) {
320+
return returnData;
321+
}
322+
} catch (error) {
323+
console.error(`Attempt ${attempts + 1} failed with error:`, error);
324+
}
325+
326+
attempts++;
327+
328+
if (attempts >= retryCount) {
329+
return;
330+
}
331+
332+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
333+
}
334+
return;
335+
}
311336
export default StakeWithdrawButton;

web/src/pages/Courts/CourtDetails/StakePanel/StakeWithdrawPopup/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const InnerContainer = styled.div`
7373
flex-direction: column;
7474
align-self: center;
7575
gap: 24px;
76-
padding: 24px;
76+
padding: 0 24px 24px;
7777
`;
7878

7979
const StyledButton = styled(LightButton)`

yarn.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -5259,7 +5259,7 @@ __metadata:
52595259
vite-plugin-node-polyfills: "npm:^0.21.0"
52605260
vite-plugin-svgr: "npm:^4.3.0"
52615261
vite-tsconfig-paths: "npm:^4.3.2"
5262-
wagmi: "npm:^2.13.4"
5262+
wagmi: "npm:^2.13.5"
52635263
languageName: unknown
52645264
linkType: soft
52655265

@@ -35085,9 +35085,9 @@ __metadata:
3508535085
languageName: node
3508635086
linkType: hard
3508735087

35088-
"wagmi@npm:^2.13.4":
35089-
version: 2.13.4
35090-
resolution: "wagmi@npm:2.13.4"
35088+
"wagmi@npm:^2.13.5":
35089+
version: 2.13.5
35090+
resolution: "wagmi@npm:2.13.5"
3509135091
dependencies:
3509235092
"@wagmi/connectors": "npm:5.5.3"
3509335093
"@wagmi/core": "npm:2.15.2"
@@ -35100,7 +35100,7 @@ __metadata:
3510035100
peerDependenciesMeta:
3510135101
typescript:
3510235102
optional: true
35103-
checksum: 10/e2ef7d7c822d65ea8a851dc8d22a2f707c98df5d63bb401d7e018d03eab008cc9e2c2bf13e04e383abe2822097430cd20cb08be2d7394989def4ec408eda3c6c
35103+
checksum: 10/e37a79d8413abbebc10935956a8ec6696f02894501b235ec580e8855735fe04fd392ada964616aff0bbbc30190d5cb1f5319a70b99000f6061a05a78f458edbb
3510435104
languageName: node
3510535105
linkType: hard
3510635106

0 commit comments

Comments
 (0)