Commit 590d363c authored by Kegan's avatar Kegan
Browse files

more state handling

parent af412dbf
......@@ -28,7 +28,11 @@ const IsWalletConnected = async () => {
};
const OnConnectClicked = async () => {
// 1. determine if we can connect a wallet?
if(!is_web3) return; // infura -> do nothing
if(!is_web3)
{
alert('No web3 found! Try the Metamask app or install the Metamask browser extension!');
return; // infura -> do nothing
}
if(await IsWalletConnected()) return; // wallet already connected
try {
......@@ -88,57 +92,78 @@ connect_btn.onclick = OnConnectClicked; //on btn click call onConnectClicked
if(!await IsOnArbitrum())
{
//--- handle non-arbitrum provider found (web3 but connected to maybe mainnet?)
ShowErrorBanner("You are not connected to the <a href=\"https://arbitrum.io/\" target=\"_blank\">Arbitrum</a> Network!");
// handle displaying page when not on arbitrum
Hide(steamid_unlink_div);
steamid_link_form.onsubmit = () => {
alert('You are on the wrong network!');
return false;
};
}
else
{
//--- handle arbitrum provider found (testnet and mainnet both run through here)
HideErrorBanner();
Hide(steamid_link_div);
Hide(steamid_unlink_div);
let network = await provider.getNetwork(); //get our network id
if(network.chainId == 421611)
{
ShowErrorBanner("You are connected to the <a href=\"https://arbitrum.io/\" target=\"_blank\">Arbitrum</a> Test Network!");
}
let address = await provider.getSigner().getAddress();
//--- steam to ethereum setup
let ste_artifact = await GetABI("SteamIDToEthereum");
let ste_contracts = await GetContracts("SteamIDToEthereum");
console.log(ste_artifact);
console.log(ste_contracts);
const ste = new ethers.Contract(ste_contracts[`${network.chainId}`], ste_artifact.abi, provider);
if(await ste.hasLink(address))
if(is_web3)
{
//show unlink
Show(steamid_unlink_div);
steamid_unlink_btn.onclick = () => {
alert('unlink clicked');
};
//--- handle connected via Metamask/Web3
let address = await provider.getSigner().getAddress();
//--- steam to ethereum setup
let ste_artifact = await GetABI("SteamIDToEthereum");
let ste_contracts = await GetContracts("SteamIDToEthereum");
console.log(ste_artifact);
console.log(ste_contracts);
const ste = new ethers.Contract(ste_contracts[`${network.chainId}`], ste_artifact.abi, provider);
if(await ste.hasLink(address))
{
//show unlink
Show(steamid_unlink_div);
steamid_unlink_btn.onclick = () => {
alert('unlink clicked');
};
}
else
{
//show link
Show(steamid_link_div);
steamid_link_form.onsubmit = () => {
alert('form submission!');
return false;
};
}
// handle display page when on arbitrum
}
else
{
//show link
//--- handle connected via Infura (no web3)
Show(steamid_link_div);
steamid_link_form.onsubmit = () => {
alert('form submission!');
alert('No web3 found! Try the Metamask app or install the Metamask browser extension!');
return false;
};
}
// handle display page when on arbitrum
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment