Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(newAddress: Address) => {
if (newAddress && checkMetaMask()) {
console.log(`new address: ${newAddress}`);
this.props.setCurrentAccount(newAddress);
this.props.cookies.set("currentAddress", newAddress, { path: "/"});
// TODO: we reload on setting a new account,
// but it would be more elegant if we did not need to
window.location.reload();
}
});
}
console.log(`using address from web3 connection: ${currentAddress}`);
this.props.cookies.set("currentAddress", currentAddress, { path: "/"});
this.props.setCurrentAccount(currentAddress);
} else {
const currentAddressFromCookie = this.props.cookies.get("currentAddress");
if (currentAddressFromCookie) {
console.log(`using address from cookie: ${currentAddressFromCookie}`);
this.props.setCurrentAccount(currentAddressFromCookie);
} else {
this.props.cookies.set("currentAddress", "", { path: "/"});
this.props.setCurrentAccount(undefined);
}
}
try {
metamask = await checkMetaMask();
} catch (err) {
console.log("MM not available or not set correctly: using default web3 provider: ", err.message);
}
if (metamask) {
pollForAccountChanges(currentAddress).subscribe(
(newAddress: Address) => {
if (newAddress && checkMetaMask()) {
console.log(`new address: ${newAddress}`);
this.props.setCurrentAccount(newAddress);
this.props.cookies.set("currentAddress", newAddress, { path: "/"});
// TODO: we reload on setting a new account,
// but it would be more elegant if we did not need to
window.location.reload();
}
});