Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove namespace from storage on auto connect failure #988

Open
wants to merge 2 commits into
base: fix/rf-2098-update-connected-namespaces-in-storage-on-switch-account
Choose a base branch
from

Conversation

RyukTheCoder
Copy link
Collaborator

Summary

Remove namespace from storage on auto connect failure.

Fixes # (RF-2118)

How did you test this change?

Tested this change by changin phantom account to an account containg only Solana address and setting {"phantom":[{"namespace":"Solana"},{"namespace":"EVM"}]} value for hub-v1-last-connected-wallets in localStorage and refreshing the app. Observed that Solana namespace connected successfully and also EVM namespace removed from localstorage.

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • Implemented a user interface (UI) change, referencing our Figma design to ensure pixel-perfect precision.

@RyukTheCoder RyukTheCoder changed the base branch from next to fix/rf-2098-update-connected-namespaces-in-storage-on-switch-account January 13, 2025 07:36
@RyukTheCoder RyukTheCoder changed the title Fix/rf 2118 remove namespace from storage on autoconnect failure !WIP fix: remove namespace from storage on auto connect failure Jan 13, 2025

return async () => await namespace.connect(chain);
});
return async () => await namespace.connect(chain);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you are making a list of failed promises using instanceof Error, ensure you will throw an error in any cases by having something like this:

.catch(e => {
if(e instanceof Error){
throw e;
}
throw new Error(e)
})

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write this assumption as a comment on top of it also.

);
}

const atLeastOneNamespaceConnectedSuccessfully = successNamespaces.length > 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove successNamespaces and consoder it as:

Suggested change
const atLeastOneNamespaceConnectedSuccessfully = successNamespaces.length > 0;
const atLeastOneNamespaceConnectedSuccessfully = connectNamespacesResult.length - failedNamespaces.length > 0;

I'm suggesting this since you only need the length, and not the input itselt.

throw new Error(`No namespace connected for ${type}`);
}

return connectNamespacesResult.filter((result) => !(result instanceof Error));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return connectNamespacesResult.filter((result) => !(result instanceof Error));
const successfulResult = connectNamespacesResult.filter((result) => !(result instanceof Error));
return successfulResult

@@ -161,26 +190,15 @@ export async function autoConnect(deps: {
providerName,
}).catch((e) => {
walletsToRemoveFromPersistance.push(providerName);
throw e;
console.warn(e);
})
);
});

await Promise.allSettled(eagerConnectQueue);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with your change on remving throw, the promise never fails, so you can change this to Promise.all i guess


return [...previousResults, taskResult];
return [...previousResults, taskResult];
} catch (error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you've change the behavior and it doesn't reflect in the name. you can create a new function called sequentiollyRunWithoutFailing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants