-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #644 from onflow:643-feature-correct-all-exception…
…s-thrown-during-registration-process 643-feature-correct-all-exceptions-thrown-during-registration-process
- Loading branch information
Showing
12 changed files
with
151 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
export const retryOperation = async ( | ||
operation: () => Promise<any>, | ||
export const retryOperation = async <T>( | ||
operation: () => Promise<T>, | ||
maxAttempts = 3, | ||
delay = 1000 | ||
) => { | ||
): Promise<T> => { | ||
for (let attempt = 1; attempt <= maxAttempts; attempt++) { | ||
try { | ||
return await operation(); | ||
} catch (error) { | ||
if (attempt === maxAttempts) throw error; | ||
// eslint-disable-next-line no-console | ||
console.log(`Attempt ${attempt} failed, retrying in ${delay}ms...`); | ||
await new Promise((resolve) => setTimeout(resolve, delay)); | ||
} | ||
} | ||
// Show never get here... | ||
throw new Error('Operation failed after all attempts'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
import { useCallback } from 'react'; | ||
|
||
import { useWalletLoaded } from '../utils/WalletContext'; | ||
|
||
import { useCoins } from './useCoinHook'; | ||
import { useNetworks } from './useNetworkHook'; | ||
import { useProfiles } from './useProfileHook'; | ||
|
||
export const useInitHook = () => { | ||
const walletLoaded = useWalletLoaded(); | ||
const { fetchProfileData, freshUserWallet, fetchUserWallet } = useProfiles(); | ||
const { fetchNetwork } = useNetworks(); | ||
const { refreshCoinData } = useCoins(); | ||
|
||
const initializeStore = useCallback(async () => { | ||
if (!walletLoaded) { | ||
return; | ||
} | ||
|
||
await fetchNetwork(); | ||
await fetchProfileData(); | ||
await freshUserWallet(); | ||
await fetchUserWallet(); | ||
await refreshCoinData(); | ||
}, [fetchNetwork, fetchProfileData, freshUserWallet, fetchUserWallet, refreshCoinData]); | ||
}, [ | ||
fetchNetwork, | ||
fetchProfileData, | ||
freshUserWallet, | ||
fetchUserWallet, | ||
refreshCoinData, | ||
walletLoaded, | ||
]); | ||
|
||
return { initializeStore }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.