diff --git a/src/config/gravityBridgeTokens.ts b/src/config/gravityBridgeTokens.ts index 6601a61..f567eab 100644 --- a/src/config/gravityBridgeTokens.ts +++ b/src/config/gravityBridgeTokens.ts @@ -24,4 +24,8 @@ export const CantoGravityTokens = [ nativeName : 'ibc/DC186CA7A8C009B43774EBDC825C935CABA9743504CE6037507E6E5CCE12858A',} ] +export const ATOMGravityToken = [ + {...TOKENS.cantoMainnet.ATOM, + nativeName: "ibc/9117A26BA81E29FA4F78F57DC2BD90CD3D26848101BA880445F119B22A1E254E"} +] diff --git a/src/global/components/cantoNav.tsx b/src/global/components/cantoNav.tsx index b818af2..6ea4d65 100644 --- a/src/global/components/cantoNav.tsx +++ b/src/global/components/cantoNav.tsx @@ -1,6 +1,7 @@ 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"; @@ -8,19 +9,13 @@ 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) { @@ -28,11 +23,6 @@ export const CantoNav = () => { window.ethereum.on("accountsChanged", () => { window.location.reload(); }); - - // //@ts-ignore - // window.ethereum.on("networkChanged", () => { - // window.location.reload(); - // }); } async function getBalance() { @@ -41,26 +31,29 @@ export const CantoNav = () => { } } useEffect(() => { - if (!netWorkInfo.isConnected) { + if (!netWorkInfo.hasPubKey) { + alert.show("Failure", ) + } else if (!netWorkInfo.account) { + alert.show("Failure",

please connect your wallet to use the bridge

) + }else if (!netWorkInfo.isConnected) { alert.show("Failure",

this network is not supported on gravity bridge, please switch networks

) } else { alert.close(); } getBalance(); - },[netWorkInfo.account, netWorkInfo.chainId]) + },[netWorkInfo.account, netWorkInfo.chainId, netWorkInfo.hasPubKey]) return ( { 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" /> diff --git a/src/hooks/useCosmosTokens.ts b/src/hooks/useCosmosTokens.ts index af582ae..94d5870 100644 --- a/src/hooks/useCosmosTokens.ts +++ b/src/hooks/useCosmosTokens.ts @@ -2,6 +2,7 @@ import { useCalls } from "@usedapp/core"; import { Contract } from "ethers"; import { GravityTestnet } from "config/networks"; import { + ATOMGravityToken, CantoGravityTokens, gravityTokenBase, mainnetGravityTokensBase, @@ -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"; @@ -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 } diff --git a/src/pages/ImageButton.tsx b/src/pages/ImageButton.tsx index 0bfc313..e61cb68 100644 --- a/src/pages/ImageButton.tsx +++ b/src/pages/ImageButton.tsx @@ -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"; @@ -12,16 +11,13 @@ interface IWallet { export const ImageButton = ({ image, name, networkSwitch }: IWallet) => { - const { activateBrowserWallet, switchNetwork } = useEthers(); const networkInfo = useNetworkInfo(); - return (
{ //1 for ethereum mainnet, 15 for gravity bridge testnet - activateBrowserWallet(); networkSwitch == 1 ? addEthMainToWallet() : addNetwork(); } } @@ -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 ? {name} : null} @@ -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"} + }
); diff --git a/src/pages/ReactiveButton.tsx b/src/pages/ReactiveButton.tsx index 7a621e4..ccbccce 100644 --- a/src/pages/ReactiveButton.tsx +++ b/src/pages/ReactiveButton.tsx @@ -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 - // return please generate public key; + return please generate public key; } //if the token hasn't been approved if (token?.allowance == -1) { @@ -91,7 +90,7 @@ export const ReactiveButton = ({ return enter amount; } if (disabled) { - return enter gravity address; + return enter cosmos address; } return ( diff --git a/src/pages/TokenSelect.tsx b/src/pages/TokenSelect.tsx index a1e2381..2d16278 100644 --- a/src/pages/TokenSelect.tsx +++ b/src/pages/TokenSelect.tsx @@ -46,9 +46,9 @@ export const TokenWallet = ({ onSelect, tokens }: ITokenSelect) => { `; return ( { - setOpen(true); - }} + // onClick={() => { + // setOpen(true); + // }} > { const [gravReceiver, setGravReceiver] = useState(""); @@ -28,93 +23,21 @@ const BridgePage = () => { const activeToken = useTokenStore().selectedToken; const [amount, setAmount] = useState(""); - const [bridgeOut, setBridgeOut] = useState(false); - const alert = useAlert(); - - //get tokens from the contract call - const { gravityTokens, gravityAddress } = useGravityTokens( - networkInfo.account, - Number(networkInfo.chainId) - ); - const [cantoTokens, setCantoTokens] = useState([]); - //contracts for transactions - const { - state: stateApprove, - send: sendApprove, - resetState: resetApprove, - } = useApprove(tokenStore.selectedToken.data.address); - const { - state: stateCosmos, - send: sendCosmos, - resetState: resetCosmos, - } = useCosmos(gravityAddress ?? ADDRESSES.ETHMainnet.GravityBridge); - function copyAddress(value : string | undefined) { + function copyAddress(value: string | undefined) { navigator.clipboard.writeText(value ?? ""); toast("copied address", { - autoClose: 300 - }) + autoClose: 300, + }); } - -const [tempPubKeyMsg, setTempPubKeyMsg] = useState("") - - //event tracker - useEffect(() => { - tokenStore.setApproveStatus(stateApprove.status); - if (stateApprove.status == "Success") { - // tokenStore.setSelectedToken(gravityTokens?.find(item => item.data.address == tokenStore.selectedToken.data.address)) - tokenStore.setSelectedToken({ - ...tokenStore.selectedToken, - allowance: Number.MAX_VALUE, - }); - setTimeout(() => { - resetApprove(); - }, 1000); - } - }, [stateApprove.status]); - - useEffect(() => { - tokenStore.setCosmosStatus(stateCosmos.status); - }, [stateCosmos.status]); - useEffect(() => { if (networkInfo.cantoAddress) { getBalances(); } }, [networkInfo.cantoAddress]); - useEffect(()=>{ - if (!networkInfo.hasPubKey) { - alert.show("Failure", ); - } else { - // alert.close(); - } - },[networkInfo.hasPubKey]) - //send function - const send = () => { - //Checking if amount enter is greater than balance available in wallet and token has been approved. - if (!networkInfo.cantoAddress) return; - if ( - (Number(amount) >= activeToken.allowance || activeToken.allowance <= 0) && - stateApprove.status == "None" - ) { - sendApprove( - gravityAddress, - BigNumber.from( - "115792089237316195423570985008687907853269984665640564039457584007913129639935" - ) - ); - } else if (Number(amount) > 0 && stateCosmos.status == "None") { - sendCosmos( - activeToken.data.address, - networkInfo.cantoAddress, - ethers.utils.parseUnits(amount, activeToken.data.decimals) - ); - } - }; - Mixpanel.events.pageOpened("Bridge", activeToken.wallet); async function getBalances() { @@ -123,8 +46,8 @@ const [tempPubKeyMsg, setTempPubKeyMsg] = useState("") networkInfo.cantoAddress ); setCantoTokens(tokensWithBalances); + tokenStore.setSelectedToken(tokensWithBalances[0]) } - // ========================= return ( @@ -133,7 +56,7 @@ const [tempPubKeyMsg, setTempPubKeyMsg] = useState("") margin: "2rem", }} > - send funds {bridgeOut ? "from" : "to"} canto + send ATOM from canto to cosmos hub
-

{bridgeOut ? "to:" : "from:"}

+

{"to:"}

- eth -

{bridgeOut ? "gravity bridge" : "ethereum"}

+ atom +

{"cosmos hub"}

-

copyAddress(networkInfo.account)}> - {bridgeOut - ? "" - : networkInfo.account?.slice(0, 6) + - "..." + - networkInfo.account?.slice(-6, -1)} -

+

copyAddress(networkInfo.account)} + >

@@ -174,206 +87,160 @@ const [tempPubKeyMsg, setTempPubKeyMsg] = useState("") src={sendImg} height={40} style={{ - // transform: bridgeOut ? "rotate(90deg)" : "rotate(90deg)", transition: "transform .3s", }} - onClick={() => { - setBridgeOut(!bridgeOut); - tokenStore.setSelectedToken(selectedEmptyToken) - } - } />

-

{bridgeOut ? "from:" : "to:"}

+

from:

canto

canto

-

copyAddress(networkInfo.cantoAddress)}> +

copyAddress(networkInfo.cantoAddress)} + > {networkInfo.cantoAddress ? networkInfo.cantoAddress.slice(0, 10) + "..." + networkInfo.cantoAddress.slice(-5) : "retrieving wallet"}

- {/* copyAddress(networkInfo.cantoAddress)}/> */}
- {networkInfo.hasPubKey ? "" :
{tempPubKeyMsg}
} - - {((bridgeOut && (Number(networkInfo.chainId) != CantoMainnet.chainId)) || (!bridgeOut && (networkInfo.chainId != "1"))) ?
: -
- - { - tokenStore.setSelectedToken(value); - resetCosmos(); - resetApprove(); - }} - /> -
- { - if ( - !( - stateApprove.status == "PendingSignature" || - stateCosmos.status == "PendingSignature" || - stateApprove.status == "Mining" || - stateCosmos.status == "Mining" - ) - ) { - const val = Number(e.target.value); - if (!isNaN(val)) { - setAmount(e.target.value); - } - resetCosmos(); - resetApprove(); - } - }} - /> -
{setAmount((tokenStore.selectedToken.balanceOf))}}> - {Number(tokenStore.selectedToken.balanceOf) < 0 ? "" : "max " + tokenStore.selectedToken.balanceOf} -
-
-
-
- - - { - setGravReceiver(e.target.value); - }} - style={{ width: "120%" }} - /> -
- - - { - const response = await txIBCTransfer( - gravReceiver, - "channel-0", - ethers.utils - .parseUnits(amount, tokenStore.selectedToken.data.decimals) - .toString(), - tokenStore.selectedToken.data.nativeName, - CantoMainnet.cosmosAPIEndpoint, - "https://gravitychain.io:1317", - fee, - chain, - memo - ); - if (response.tx_response?.txhash) { - toast("bridge out successful", { - position: "top-right", - autoClose: 5000, - hideProgressBar: false, - closeOnClick: true, - pauseOnHover: true, - draggable: true, - progressStyle: { - color: "var(--primary-color)", - }, - style: { - border: "1px solid var(--primary-color)", - borderRadius: "0px", - paddingBottom: "3px", - background: "black", - color: "var(--primary-color)", - height: "100px", - fontSize: "20px", - }, - }); - } else { - //TODO: Show an error - } - } - : send - } - /> -
-} -

- {bridgeOut ? ( -
- in order to bridge out of canto, you must convert all of your ERC20 - assets - {" (Metamask)"} to native canto tokens{" "} - - here. - {" "} - the balances in your Metamask will not reflect your bridgeable assets -
+ + {Number(networkInfo.chainId) != CantoMainnet.chainId ? ( +
) : ( -
- it takes several minutes for your bridged assets to arrive on the - canto network. go to the{" "} - - convert coin - {" "} - page to view your bridged assets and convert them into canto ERC20 - tokens to view your assets in Metamask. for more details, please read{" "} - - here - - . +
+ + { + tokenStore.setSelectedToken(value); + }} + /> +
+ { + const val = Number(e.target.value); + if (!isNaN(val)) { + setAmount(e.target.value); + } + }} + /> +
{ + setAmount(tokenStore.selectedToken.balanceOf); + }} + > + {Number(tokenStore.selectedToken.balanceOf) < 0 + ? "" + : "max " + tokenStore.selectedToken.balanceOf} +
+
+
+
+ + + { + setGravReceiver(e.target.value); + }} + style={{ width: "120%" }} + /> +
+ + { + const response = await txIBCTransfer( + gravReceiver, + "channel-2", + ethers.utils + .parseUnits(amount, tokenStore.selectedToken.data.decimals) + .toString(), + tokenStore.selectedToken.data.nativeName, + CantoMainnet.cosmosAPIEndpoint, + "https://api-cosmoshub-ia.cosmosia.notional.ventures/", + fee, + chain, + memo + ); + if (response.tx_response?.txhash) { + toast("bridge out successful", { + position: "top-right", + autoClose: 5000, + hideProgressBar: false, + closeOnClick: true, + pauseOnHover: true, + draggable: true, + progressStyle: { + color: "var(--primary-color)", + }, + style: { + border: "1px solid var(--primary-color)", + borderRadius: "0px", + paddingBottom: "3px", + background: "black", + color: "var(--primary-color)", + height: "100px", + fontSize: "20px", + }, + }); + } else { + //TODO: Show an error + } + }} + />
)} -
-

to learn how to bridge ATOM into canto, please read - here

-
- -
- powered by Gravity Bridge +

+
+ this page is only for bridging ATOM from canto to the cosmos hub
+
+

+ to learn how to bridge ATOM into canto, please read{" "} + + here + {" "} +

+
); }; diff --git a/src/pages/genPubKey.tsx b/src/pages/genPubKey.tsx index ad6263c..9705277 100644 --- a/src/pages/genPubKey.tsx +++ b/src/pages/genPubKey.tsx @@ -1,40 +1,59 @@ +import { useEthers } from "@usedapp/core"; import { CantoMainnet } from "cantoui"; -import { useState } from "react" +import { useEffect, useState } from "react"; import { useNetworkInfo } from "stores/networkInfo"; import { addNetwork } from "utils/addCantoToWallet"; import { generatePubKey } from "utils/nodeTransactions"; export const GenPubKey = () => { - - const [pubKeySuccess, setPubKeySuccess] = useState(""); - const networkInfo = useNetworkInfo(); - - return ( - + ); +}; diff --git a/src/providers/index.tsx b/src/providers/index.tsx index b2f6633..626ed39 100644 --- a/src/providers/index.tsx +++ b/src/providers/index.tsx @@ -15,18 +15,18 @@ export const getAddressLink = (explorerUrl: string) => (address: string) => `${e export const getTransactionLink = (explorerUrl: string) => (txnId: string) => `${explorerUrl}/tx/${txnId}` -export const Gravity: Chain = { - chainId: GravityTestnet.chainId, - chainName: GravityTestnet.name, - isTestChain: GravityTestnet.isTestChain, - isLocalChain: false, - multicallAddress: '0x86C885e7D824F0278323f7CF4529d330BEA6f87C', - multicall2Address: '0xaC14870809392C5181c9869046619b2A86386C80', - blockExplorerUrl: GravityTestnet.blockExplorerUrl, - getExplorerAddressLink: getAddressLink("kovanEtherscanUrl"), - getExplorerTransactionLink: getTransactionLink("kovanEtherscanUrl"), - rpcUrl: GravityTestnet.rpcUrl -} +// export const Gravity: Chain = { +// chainId: GravityTestnet.chainId, +// chainName: GravityTestnet.name, +// isTestChain: GravityTestnet.isTestChain, +// isLocalChain: false, +// multicallAddress: '0x86C885e7D824F0278323f7CF4529d330BEA6f87C', +// multicall2Address: '0xaC14870809392C5181c9869046619b2A86386C80', +// blockExplorerUrl: GravityTestnet.blockExplorerUrl, +// getExplorerAddressLink: getAddressLink("kovanEtherscanUrl"), +// getExplorerTransactionLink: getTransactionLink("kovanEtherscanUrl"), +// rpcUrl: GravityTestnet.rpcUrl +// } export const CantoMainnet: Chain = { chainId: CantoMain.chainId, chainName: CantoMain.name, @@ -44,9 +44,8 @@ export const CantoMainnet: Chain = { const config: Config = { - networks: [Gravity, ETHMain, CantoMainnet], + networks: [ETHMain, CantoMainnet], readOnlyUrls: { - [Gravity.chainId]: GravityTestnet.rpcUrl, [ETHMain.chainId]: ETHMainnet.rpcUrl, [CantoMainnet.chainId]: CantoMain.rpcUrl }, diff --git a/src/stores/networkInfo.tsx b/src/stores/networkInfo.tsx index c99ec90..a652770 100644 --- a/src/stores/networkInfo.tsx +++ b/src/stores/networkInfo.tsx @@ -1,6 +1,9 @@ import { CantoMainnet } from "cantoui"; import { GravityTestnet, ETHMainnet } from "config/networks"; -import { checkPubKey, getCantoAddressFromMetaMask } from "utils/nodeTransactions"; +import { + checkPubKey, + getCantoAddressFromMetaMask, +} from "utils/nodeTransactions"; import create from "zustand"; import { devtools } from "zustand/middleware"; @@ -35,14 +38,16 @@ export const useNetworkInfo = create()( } }, account: undefined, - cantoAddress : "", + cantoAddress: "", hasPubKey: true, setAccount: async (account) => { - set({ account: account }); - let cantoAddress = await getCantoAddressFromMetaMask(account); - let hasPubKey = await checkPubKey(cantoAddress); - set({cantoAddress : cantoAddress}); - set({hasPubKey : hasPubKey}); + if (account) { + set({ account: account }); + let cantoAddress = await getCantoAddressFromMetaMask(account); + let hasPubKey = await checkPubKey(cantoAddress); + set({ cantoAddress: cantoAddress }); + set({ hasPubKey: hasPubKey }); + } }, balance: "0", setBalance: (balance) => set({ balance: balance }), diff --git a/src/utils/IBC/signAndBroadcast.ts b/src/utils/IBC/signAndBroadcast.ts index b44e125..a2805a8 100644 --- a/src/utils/IBC/signAndBroadcast.ts +++ b/src/utils/IBC/signAndBroadcast.ts @@ -26,8 +26,6 @@ import {Buffer} from 'buffer' headers: { 'Content-Type': 'application/json' }, body: generatePostBodyBroadcast(raw), }; - console.log( nodeAddress + generateEndpointBroadcast(), - postOptions) const broadcastPost = await fetch( nodeAddress + generateEndpointBroadcast(), postOptions diff --git a/src/utils/IBC/signTransaction.js b/src/utils/IBC/signTransaction.js index b443a5c..63ecabf 100644 --- a/src/utils/IBC/signTransaction.js +++ b/src/utils/IBC/signTransaction.js @@ -15,14 +15,11 @@ export async function signAndBroadcastTxMsg(msg, senderObj, chain, nodeAddress, body: generatePostBodyBroadcast(raw), }; - console.log("POST OPTIONS: ", postOptions); - const broadcastPost = await fetch( nodeAddress + generateEndpointBroadcast(), postOptions ); const response = await broadcastPost.json(); - console.log("🚀 ~ file: signTransaction.js ~ line 25 ~ signAndBroadcastTxMsg ~ response", response) } function generateRawTx(chain, senderObj, signature, msg) { @@ -68,7 +65,6 @@ async function ethToCanto(address, nodeAddress) { } function reformatSender(addressData) { - console.log(addressData); return { accountNumber : addressData['account_number'], pubkey : addressData['pub_key']['key'],