Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/config/gravityBridgeTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ export const CantoGravityTokens = [
nativeName : 'ibc/DC186CA7A8C009B43774EBDC825C935CABA9743504CE6037507E6E5CCE12858A',}
]

export const ATOMGravityToken = [
{...TOKENS.cantoMainnet.ATOM,
nativeName: "ibc/9117A26BA81E29FA4F78F57DC2BD90CD3D26848101BA880445F119B22A1E254E"}
]

35 changes: 14 additions & 21 deletions src/global/components/cantoNav.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
import { useEthers } from "@usedapp/core";
import { NavBar, useAlert } from "cantoui";
import { CantoMainnet, useAlert, NavBar } from "cantoui";
import { getAccountBalance, getChainIdandAccount } from "global/utils/walletConnect/addCantoToWallet";
import { GenPubKey } from "pages/genPubKey";
import { useEffect } from "react";
import { useNetworkInfo } from "stores/networkInfo";
import { addNetwork } from "utils/addCantoToWallet";
import logo from "./../../assets/logo.svg"

export const CantoNav = () => {
const netWorkInfo = useNetworkInfo();
const { activateBrowserWallet, account, switchNetwork } = useEthers();
const { activateBrowserWallet, account, chainId } = useEthers();
const alert = useAlert();

async function setChainInfo() {
const [chainId, account] = await getChainIdandAccount();
netWorkInfo.setChainId(chainId);
netWorkInfo.setAccount(account);
}

useEffect(() => {
setChainInfo();
//@ts-ignore
}, [window.ethereum?.networkVersion]);
netWorkInfo.setChainId(chainId?.toString());
netWorkInfo.setAccount(account);
}, [account, chainId]);

//@ts-ignore
if (window.ethereum) {
//@ts-ignore
window.ethereum.on("accountsChanged", () => {
window.location.reload();
});

// //@ts-ignore
// window.ethereum.on("networkChanged", () => {
// window.location.reload();
// });
}

async function getBalance() {
Expand All @@ -41,26 +31,29 @@ export const CantoNav = () => {
}
}
useEffect(() => {
if (!netWorkInfo.isConnected) {
if (!netWorkInfo.hasPubKey) {
alert.show("Failure", <GenPubKey />)
} else if (!netWorkInfo.account) {
alert.show("Failure", <p> please connect your wallet to use the bridge</p>)
}else if (!netWorkInfo.isConnected) {
alert.show("Failure", <p>this network is not supported on gravity bridge, please <a onClick={addNetwork} style={{cursor: "pointer", textDecoration: "underline"}}>switch networks</a></p>)
} else {
alert.close();
}
getBalance();
},[netWorkInfo.account, netWorkInfo.chainId])
},[netWorkInfo.account, netWorkInfo.chainId, netWorkInfo.hasPubKey])

return (
<NavBar
title="bridge"
onClick={() => {
activateBrowserWallet();
switchNetwork(1);
}}
chainId={Number(netWorkInfo.chainId)}
account={netWorkInfo.account ?? ""}
isConnected={netWorkInfo.isConnected && account ? true : false}
isConnected={account ? true : false}
balance={netWorkInfo.balance}
currency={netWorkInfo.chainId == "1" ? "ETH" : "CANTO"}
currency={Number(netWorkInfo.chainId) == CantoMainnet.chainId ? "CANTO" : "ETH"}
logo={logo}
currentPage="bridge"
/>
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useCosmosTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useCalls } from "@usedapp/core";
import { Contract } from "ethers";
import { GravityTestnet } from "config/networks";
import {
ATOMGravityToken,
CantoGravityTokens,
gravityTokenBase,
mainnetGravityTokensBase,
Expand Down Expand Up @@ -94,7 +95,7 @@ export async function getCantoBalance(
console.log(err);
});

let processedTokens = CantoGravityTokens.map((token) => {
let processedTokens = ATOMGravityToken.map((token) => {
let allowance = Number.MAX_SAFE_INTEGER;
let balanceOf = result.find((data : any) => data.denom == token.nativeName)?.amount ?? "0";

Expand Down Expand Up @@ -125,7 +126,6 @@ export async function getGravityTokenBalance (gravityAddress: string) {
.catch((err) => {
console.log(err);
});
console.log("🚀 ~ file: useCosmosTokens.ts ~ line 130 ~ getGravityTokenBalance ~ result", result)
return result
}

Expand Down
14 changes: 6 additions & 8 deletions src/pages/ImageButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEthers } from "@usedapp/core";
import { ETHMainnet } from "config/networks";
import { useNetworkInfo } from "stores/networkInfo";
import { addEthMainToWallet, addNetwork } from "utils/addCantoToWallet";

Expand All @@ -12,16 +11,13 @@ interface IWallet {

export const ImageButton = ({ image, name, networkSwitch }: IWallet) => {

const { activateBrowserWallet, switchNetwork } = useEthers();
const networkInfo = useNetworkInfo();

return (

<div
className="image-button button"
onClick={async () => {
//1 for ethereum mainnet, 15 for gravity bridge testnet
activateBrowserWallet();
networkSwitch == 1 ? addEthMainToWallet() : addNetwork();
}
}
Expand All @@ -35,6 +31,8 @@ interface IWallet {
gap: "1rem",
width: "20rem",
cursor: "pointer",
// border: Number(networkInfo.chainId) == networkSwitch ? "" : "1px solid yellow",
// boxShadow:" 0 1px 0 #000000, 0 5px 0 #000000, 0 6px 6px #ff0000"
}}
>
{image ? <img src={image} alt={name} height={24} width={24} /> : null}
Expand All @@ -44,13 +42,13 @@ interface IWallet {
textAlign: "center",
}}
>
{networkInfo.account
? Number(networkInfo.chainId) != networkSwitch ? networkSwitch == 1
? "switch to ethereum network" : "switch to canto network"
{Number(networkInfo.chainId) != networkSwitch ? networkSwitch == 1
? "switch to ethereum network" : "switch to canto network" :
!networkInfo.account ? ""
: networkInfo.account.substring(0, 10) +
"..." +
networkInfo.account.substring(networkInfo.account.length - 10, networkInfo.account.length)
: "connect"}
}
</span>
</div>
);
Expand Down
5 changes: 2 additions & 3 deletions src/pages/ReactiveButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ export const ReactiveButton = ({
//? refactor this into a single component
//if the account doesn't have a public key
if (!hasPubKey) {
return <Button onClick={() => generatePubKey(account, () => {})}>generate public key</Button>
// return <DisabledButton>please generate public key</DisabledButton>;
return <DisabledButton>please generate public key</DisabledButton>;
}
//if the token hasn't been approved
if (token?.allowance == -1) {
Expand All @@ -91,7 +90,7 @@ export const ReactiveButton = ({
return <DisabledButton>enter amount</DisabledButton>;
}
if (disabled) {
return <DisabledButton>enter gravity address</DisabledButton>;
return <DisabledButton>enter cosmos address</DisabledButton>;
}

return (
Expand Down
6 changes: 3 additions & 3 deletions src/pages/TokenSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export const TokenWallet = ({ onSelect, tokens }: ITokenSelect) => {
`;
return (
<Box
onClick={() => {
setOpen(true);
}}
// onClick={() => {
// setOpen(true);
// }}
>
<img
src={activeToken.data.icon}
Expand Down
Loading