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

[FIXED] Issue 34: Listener added to wallet provider in order to detect account changed #61

Merged
merged 2 commits into from
Oct 2, 2023

Conversation

leirbag95
Copy link
Contributor

@leirbag95 leirbag95 commented Sep 21, 2023

This pull request fixes the issue mentioned in #34 . The issue was related to detecting and reloading when the Ethereum account changes from the wallet provider.

Changes Made:

  • Added an event listener to window.ethereum to detect changes in Ethereum accounts.
  • When the accountsChanged event is triggered, it reloads the interface with the updated Ethereum account.
window.ethereum.on('accountsChanged', function (accounts) {
  // Time to reload interface with accounts[0]!
})

Test Plan:

  • Tested the code changes locally to ensure they function as expected.
  • Checked for any potential side effects.

Screenshots:

Adapts to the entire application, here is an example after changing account the requirements are updated and the button becomes active

Screenshot 2023-09-21 à 11 11 05 Screenshot 2023-09-21 à 11 11 58

Copy link
Member

@BjrInt BjrInt left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! 👌

Changing accounts does indeed updates the address and balance in the store and dispatches the informations on the view.
However it does not fetches and refresh the different products (functions, volumes, instances, ... ) of the user, can you take care of this as well ?

@leirbag95
Copy link
Contributor Author

Thanks for the PR! 👌

Changing accounts does indeed updates the address and balance in the store and dispatches the informations on the view. However it does not fetches and refresh the different products (functions, volumes, instances, ... ) of the user, can you take care of this as well ?

It's done :)

I changed the useRequest.ts by adding a triggerDeps param which allows to listen account change from all of account entities

  • useAccountFunctions()
  • useAccountVolumes()
  • useAccountInstances()
  • useAccountSSHKeys()
  • useAccountDomains()
export function useRequest<T>({
  doRequest,
  triggerOnMount,
  triggerDeps = [],
  ...rest
}: UseRequestProps<T>): UseRequestReturn<T> {
...
useEffect(() => {
    if (!triggerOnMount) return
    request()
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, triggerDeps)

@amalcaraz
Copy link
Collaborator

LGTM!

@BjrInt BjrInt merged commit 3af847b into main Oct 2, 2023
1 check passed
@BjrInt BjrInt deleted the issue/34-switching-wallet branch October 2, 2023 08:40
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.

Switching wallet account in browser wallet should trigger a change in the frontend
3 participants