Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Expose purser-metamask account change hook #191

Closed
rdig opened this issue Jan 14, 2019 · 1 comment
Closed

Expose purser-metamask account change hook #191

rdig opened this issue Jan 14, 2019 · 1 comment
Assignees
Labels
Milestone

Comments

@rdig
Copy link
Member

rdig commented Jan 14, 2019

While the Metamask account change hook exists and it's used inside purser-metamask (to always keep the wallet instance in sync with the UI), it's not exposed outside of the package.

This could be useful for dApps who want to act on the account being changed (Eg: log out the user, update the interface with the new instance, etc)

For this, a safer (eg: properly validated) version of the setStateEventObserver should be exposed:

/**
* Add a new observer method to Metamask's state update events
*
* @method setStateEventObserver
*
* @param {Function} observer Function to add the state events update array
*
* @return {number} the length of the state events update array
*/
export const setStateEventObserver = (
observer: MetamaskStateEventsObserverType,
): void => {
const {
publicConfigStore: { _events: stateEvents },
}: () => MetamaskInpageProviderType =
/*
* We need this little go-around trick to mock just one export of
* the module, while leaving the rest of the module intact so we can test it
*
* See: https://github.com/facebook/jest/issues/936
*/
/* eslint-disable-next-line no-use-before-define */
metamaskHelpers.getInpageProvider();
return stateEvents.update.push(observer);
};

This issue is here to track implementation of the above.

@rdig rdig added the feature label Jan 14, 2019
@rdig
Copy link
Member Author

rdig commented Jan 17, 2019

Note that this will need an accompanying docs.colony.io entry in order to:

  • explain the reasoning behind exposing this API
  • show examples on how to use in your dApp

@rdig rdig self-assigned this Feb 27, 2019
@rdig rdig added this to the Sprint 20 milestone Feb 27, 2019
@rdig rdig closed this as completed in #207 Mar 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant