Skip to content

Commit

Permalink
Added a retry mechanism to getRegisteredStealthKeys (#655)
Browse files Browse the repository at this point in the history
* Added a retry mechanism to getRegisteredStealthKeys

* Added a delay to the retry mechanism in getRegisteredStealthKeys
  • Loading branch information
jferas authored Apr 8, 2024
1 parent 1a64de8 commit 1dfa693
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions frontend/src/store/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,11 +631,19 @@ const hasSetPublicKeysLegacy = async (name: string, provider: Provider) => {

// Helper method to check if user has registered public keys in the StealthKeyRegistry
async function getRegisteredStealthKeys(account: string, provider: Provider) {
try {
const stealthPubKeys = await utils.lookupRecipient(account, provider); // throws if no keys found
return stealthPubKeys;
} catch (err) {
window.logger.warn(err);
return null;
let retryCounter = 0;
while (retryCounter < 3) {
try {
console.log(`getting stealth keys for ${account}, try ${retryCounter + 1} of 3`);
const stealthPubKeys = await utils.lookupRecipient(account, provider); // throws if no keys found
return stealthPubKeys;
} catch (err) {
window.logger.warn(err);
retryCounter++;
if (retryCounter < 3) {
await new Promise((resolve) => setTimeout(resolve, 2000)); // Wait for 2 seconds
}
}
}
return null;
}

0 comments on commit 1dfa693

Please sign in to comment.