Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async componentDidMount (): Promise {
/**
* Heads up that there is a chance this cached account may differ from an account
* that the user has already selected in a provider but have
* not yet made available to the app.
*/
const currentAddress = getCachedAccount();
let accountWasCached = false;
if (currentAddress) {
accountWasCached = true;
// eslint-disable-next-line no-console
console.log(`using account from local storage: ${currentAddress}`);
}
this.props.setCurrentAccount(currentAddress);
/**
* Only supply currentAddress if it was obtained from a provider. The poll
* is only comparing changes with respect to the provider state. Passing it a cached state
* will only cause it to get the wrong impression and misbehave.
*/
pollForAccountChanges(accountWasCached ? null : currentAddress).subscribe(
(newAddress: Address | null): void => {
// eslint-disable-next-line no-console