Skip to content

Instantly share code, notes, and snippets.

@alexytiger
Last active January 29, 2020 01:40
Show Gist options
  • Save alexytiger/ed3f93c73cba8d37cb7e2c3e1ec2359b to your computer and use it in GitHub Desktop.
Save alexytiger/ed3f93c73cba8d37cb7e2c3e1ec2359b to your computer and use it in GitHub Desktop.
e-book
accountChanged$ = createEffect(
() =>
fromEvent(this.web3Token, 'accountsChanged').pipe(
withLatestFrom(this.store$.pipe(select(fromStore.getAccount))),
filter(([accounts, currentAccount]) => !!currentAccount && (currentAccount !== accounts[0])),
map(([accounts, currentAccount]) => {
console.log('new account', accounts[0]);
// to reload browser
// based onhttps://medium.com/metamask/no-longer-reloading-pages-on-network-change-fbf041942b44
this.document.location.reload();
})
),
{ dispatch: false }
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment