Skip to content

Commit

Permalink
Merge pull request #1502 from decentdao/fix/use-async-retry-typing
Browse files Browse the repository at this point in the history
Add better typing to `useAsyncRetry`
  • Loading branch information
adamgall authored Mar 29, 2024
2 parents 2a41563 + 19690dd commit 1bdf008
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/components/pages/DaoHierarchy/useFetchNodes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function useFetchNodes(address?: string) {
for await (const subDAO of nodes) {
try {
const safeInfo = await requestWithRetries(() => fetchDAOInfo(subDAO.address), 5, 5000);
if (safeInfo.guard) {
if (safeInfo && safeInfo.guard) {
if (safeInfo.guard === ethers.constants.AddressZero) {
subDAOs.push(safeInfo);
} else {
Expand Down
10 changes: 6 additions & 4 deletions src/hooks/DAO/loaders/governance/useAzoriusProposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,12 @@ export const useAzoriusProposals = () => {
);
};
const proposal = await requestWithRetries(func, 5, 7000);
action.dispatch({
type: FractalGovernanceAction.UPDATE_PROPOSALS_NEW,
payload: proposal,
});
if (proposal) {
action.dispatch({
type: FractalGovernanceAction.UPDATE_PROPOSALS_NEW,
payload: proposal,
});
}
},
[
baseContracts,
Expand Down
10 changes: 2 additions & 8 deletions src/hooks/utils/useAsyncRetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@ function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}

export type RequestWithRetries<FuncRes = any> = (
func: () => Promise<FuncRes>,
retries: number,
secondsToWait?: number,
) => Promise<FuncRes | {} | null | undefined>;

export function useAsyncRetry() {
const requestWithRetries: RequestWithRetries = useCallback(
async (func: () => Promise<any>, retries: number, secondsToWait: number = 2000) => {
const requestWithRetries = useCallback(
async <T>(func: () => Promise<T>, retries: number, secondsToWait: number = 2000) => {
let currentRetries = 0;
let result = null;

Expand Down

0 comments on commit 1bdf008

Please sign in to comment.