diff --git a/.github/workflows/test-and-lint.yaml b/.github/workflows/test-and-lint.yaml index 7419fff..d650ff3 100644 --- a/.github/workflows/test-and-lint.yaml +++ b/.github/workflows/test-and-lint.yaml @@ -26,8 +26,6 @@ jobs: - name: Install Dependencies if: steps.cache-node-modules.outputs.cache-hit != 'true' run: npm install - - name: Copy env file - run: cp .env.example .env - name: Lint run: npm run lint - name: Test diff --git a/.gitignore b/.gitignore index fe1d564..d4cab0f 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ web/build # envs .env +.env.local # local secrets .secret.local diff --git a/web/.env.test b/web/.env.test new file mode 100644 index 0000000..bd3b375 --- /dev/null +++ b/web/.env.test @@ -0,0 +1,9 @@ +# NOTE - REACT_APP_VERSION is commented out on purpose to test getEnvVariable +#REACT_APP_VERSION=$npm_package_version + +REACT_APP_ENV=test + +REACT_APP_SEQUENCER_BRIDGE_ACCOUNT=astria1d7zjjljc0dsmxa545xkpwxym86g8uvvwhtezcr +REACT_APP_EVM_WITHDRAWER_CONTRACT_ADDRESS=0xA58639fB5458e65E4fA917FF951C390292C24A15 + +REACT_APP_IBC_CHAINS='{"Celestia Mocha-4":{"chainId":"mocha-4","chainName":"Celestia Mocha-4","rpc":"wss://rpc-mocha.pops.one","rest":"https://api-mocha.pops.one","stakeCurrency":{"coinDenom":"TIA","coinMinimalDenom":"utia","coinDecimals":6},"bip44":{"coinType":118},"bech32Config":{"bech32PrefixAccAddr":"celestia","bech32PrefixAccPub":"celestiapub","bech32PrefixConsAddr":"celestiavalcons","bech32PrefixConsPub":"celestiavalconspub","bech32PrefixValAddr":"celestiavaloper","bech32PrefixValPub":"celestiavaloperpub"},"currencies":[{"coinDenom":"TIA","coinMinimalDenom":"utia","coinDecimals":6}],"feeCurrencies":[{"coinDenom":"TIA","coinMinimalDenom":"utia","coinDecimals":6,"gasPriceStep":{"low":0.01,"average":0.02,"high":0.1}}],"ibcChannel":"channel-110","iconSourceUrl":"https://placehold.co/60x60/EEE/31343C"}}' diff --git a/web/justfile b/web/justfile index 2a9b45d..1551d05 100644 --- a/web/justfile +++ b/web/justfile @@ -1,9 +1,9 @@ _default: @just --list -# copies web/.env.example to web/.env +# copies web/.env.example to web/.env.local init-env: - cp .env.example .env + cp .env.example .env.local # installs npm deps for web install: diff --git a/web/src/App.tsx b/web/src/App.tsx index 6a87ae5..6e2290c 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -3,21 +3,24 @@ import { Route, Routes } from "react-router-dom"; import { EthWalletContextProvider } from "features/EthWallet/contexts/EthWalletContext"; import BridgePage from "pages/BridgePage/BridgePage"; import Layout from "pages/Layout"; -import { NotificationsProvider } from "features/Notifications/contexts/NotificationsContext"; +import { NotificationsContextProvider } from "features/Notifications/contexts/NotificationsContext"; +import { ConfigContextProvider } from "config/contexts/ConfigContext"; /** * App component with routes. */ export default function App(): React.ReactElement { return ( - - - - }> - } /> - - - - + + + + + }> + } /> + + + + + ); } diff --git a/web/src/chainInfos/index.ts b/web/src/chainInfos/index.ts deleted file mode 100644 index 255d09f..0000000 --- a/web/src/chainInfos/index.ts +++ /dev/null @@ -1,170 +0,0 @@ -import type { ChainInfo } from "@keplr-wallet/types"; - -export const CelestiaChainInfo: ChainInfo = { - // Chain-id of the celestia chain. - chainId: "celestia-local-0", - // The name of the chain to be displayed to the user. - chainName: "celestia-local-0", - // RPC endpoint of the chain - // TODO - use envar - rpc: "http://rpc.app.celestia.localdev.me", - // REST endpoint of the chain. - // TODO - use envar - rest: "http://rest.app.celestia.localdev.me", - // Staking coin information - stakeCurrency: { - // Coin denomination to be displayed to the user. - coinDenom: "TIA", - // Actual denom (i.e. uatom, uscrt) used by the blockchain. - coinMinimalDenom: "utia", - // # of decimal points to convert minimal denomination to user-facing denomination. - coinDecimals: 6, - // (Optional) Keplr can show the fiat value of the coin if a coingecko id is provided. - // You can get id from https://api.coingecko.com/api/v3/coins/list if it is listed. - // coinGeckoId: "" - }, - // (Optional) If you have a wallet webpage used to stake the coin then provide the url to the website in `walletUrlForStaking`. - // The 'stake' button in Keplr extension will link to the webpage. - // walletUrlForStaking: "", - // The BIP44 path. - bip44: { - // You can only set the coin type of BIP44. - // 'Purpose' is fixed to 44. - coinType: 118, - }, - - bech32Config: { - bech32PrefixAccAddr: "celestia", - bech32PrefixAccPub: "celestiapub", - bech32PrefixConsAddr: "celestiavalcons", - bech32PrefixConsPub: "celestiavalconspub", - bech32PrefixValAddr: "celestiavaloper", - bech32PrefixValPub: "celestiavaloperpub", - }, - // List of all coin/tokens used in this chain. - currencies: [ - { - // Coin denomination to be displayed to the user. - coinDenom: "TIA", - // Actual denom (i.e. uatom, uscrt) used by the blockchain. - coinMinimalDenom: "utia", - // # of decimal points to convert minimal denomination to user-facing denomination. - coinDecimals: 6, - // (Optional) Keplr can show the fiat value of the coin if a coingecko id is provided. - // You can get id from https://api.coingecko.com/api/v3/coins/list if it is listed. - // coinGeckoId: "" - }, - ], - // List of coin/tokens used as a fee token in this chain. - feeCurrencies: [ - { - // Coin denomination to be displayed to the user. - coinDenom: "TIA", - // Actual denom (i.e. nria, uscrt) used by the blockchain. - coinMinimalDenom: "utia", - // # of decimal points to convert minimal denomination to user-facing denomination. - coinDecimals: 6, - // (Optional) Keplr can show the fiat value of the coin if a coingecko id is provided. - // You can get id from https://api.coingecko.com/api/v3/coins/list if it is listed. - // coinGeckoId: "" - // (Optional) This is used to set the fee of the transaction. - // If this field is not provided and suggesting chain is not natively integrated, Keplr extension will set the Keplr default gas price (low: 0.01, average: 0.025, high: 0.04). - // Currently, Keplr doesn't support dynamic calculation of the gas prices based on on-chain data. - // Make sure that the gas prices are higher than the minimum gas prices accepted by chain validators and RPC/REST endpoint. - gasPriceStep: { - low: 0.01, - average: 0.02, - high: 0.1, - }, - }, - ], -}; - -export const AstriaChainInfo: ChainInfo = { - // Chain-id of the Astria chain. - chainId: "sequencer-test-chain-0", - // The name of the chain to be displayed to the user. - chainName: "sequencer-test-chain-0", - // RPC endpoint of the chain. In this case we are using blockapsis, as it's accepts connections from any host currently. No Cors limitations. - // TODO - use envar - rpc: "http://rpc.sequencer.localdev.me", - // REST endpoint of the chain. - // TODO - use envar - rest: "http://rpc.sequencer.localdev.me", - // Staking coin information - stakeCurrency: { - // Coin denomination to be displayed to the user. - coinDenom: "RIA", - // Actual denom (i.e. uatom, uscrt) used by the blockchain. - coinMinimalDenom: "nria", - // # of decimal points to convert minimal denomination to user-facing denomination. - coinDecimals: 9, - // (Optional) Keplr can show the fiat value of the coin if a coingecko id is provided. - // You can get id from https://api.coingecko.com/api/v3/coins/list if it is listed. - // coinGeckoId: "" - }, - // (Optional) If you have a wallet webpage used to stake the coin then provide the url to the website in `walletUrlForStaking`. - // The 'stake' button in Keplr extension will link to the webpage. - // walletUrlForStaking: "", - // The BIP44 path. - bip44: { - // You can only set the coin type of BIP44. - // 'Purpose' is fixed to 44. - coinType: 118, - }, - // Bech32 configuration to show the address to user. - // This field is the interface of - // { - // bech32PrefixAccAddr: string; - // bech32PrefixAccPub: string; - // bech32PrefixValAddr: string; - // bech32PrefixValPub: string; - // bech32PrefixConsAddr: string; - // bech32PrefixConsPub: string; - // } - bech32Config: { - bech32PrefixAccAddr: "astria", - bech32PrefixAccPub: "astriapub", - bech32PrefixConsAddr: "astriavalcons", - bech32PrefixConsPub: "astriavalconspub", - bech32PrefixValAddr: "astriavaloper", - bech32PrefixValPub: "astriavaloperpub", - }, - // List of all coin/tokens used in this chain. - currencies: [ - { - // Coin denomination to be displayed to the user. - coinDenom: "RIA", - // Actual denom (i.e. uatom, uscrt) used by the blockchain. - coinMinimalDenom: "nria", - // # of decimal points to convert minimal denomination to user-facing denomination. - coinDecimals: 9, - // (Optional) Keplr can show the fiat value of the coin if a coingecko id is provided. - // You can get id from https://api.coingecko.com/api/v3/coins/list if it is listed. - // coinGeckoId: "" - }, - ], - // List of coin/tokens used as a fee token in this chain. - feeCurrencies: [ - { - // Coin denomination to be displayed to the user. - coinDenom: "RIA", - // Actual denom (i.e. nria, uscrt) used by the blockchain. - coinMinimalDenom: "nria", - // # of decimal points to convert minimal denomination to user-facing denomination. - coinDecimals: 9, - // (Optional) Keplr can show the fiat value of the coin if a coingecko id is provided. - // You can get id from https://api.coingecko.com/api/v3/coins/list if it is listed. - // coinGeckoId: "" - // (Optional) This is used to set the fee of the transaction. - // If this field is not provided and suggesting chain is not natively integrated, Keplr extension will set the Keplr default gas price (low: 0.01, average: 0.025, high: 0.04). - // Currently, Keplr doesn't support dynamic calculation of the gas prices based on on-chain data. - // Make sure that the gas prices are higher than the minimum gas prices accepted by chain validators and RPC/REST endpoint. - gasPriceStep: { - low: 0.01, - average: 0.02, - high: 0.1, - }, - }, - ], -}; diff --git a/web/src/components/DepositCard/DepositCard.tsx b/web/src/components/DepositCard/DepositCard.tsx index 703fda1..90d911b 100644 --- a/web/src/components/DepositCard/DepositCard.tsx +++ b/web/src/components/DepositCard/DepositCard.tsx @@ -1,4 +1,5 @@ import type React from "react"; +import { useMemo } from "react"; import { useContext, useEffect, useState } from "react"; import { Dec, DecUtils } from "@keplr-wallet/unit"; import { NotificationType } from "features/Notifications/components/Notification/types"; @@ -10,13 +11,27 @@ import { getBalance, sendIbcTransfer } from "services/ibc"; import { getKeplrFromWindow } from "services/keplr"; import { useIbcChainSelection } from "features/IbcChainSelector/hooks/useIbcChainSelection"; import Dropdown from "components/Dropdown/Dropdown"; +import { useConfig } from "config/hooks/useConfig"; export default function DepositCard(): React.ReactElement { const { addNotification } = useContext(NotificationsContext); const { userAccount } = useEthWallet(); + const { ibcChains } = useConfig(); - const { selectedIbcChain, selectIbcChain, ibcChainsOptions } = - useIbcChainSelection(); + const { + selectIbcChain, + ibcChainsOptions, + selectedIbcChain, + selectIbcCurrency, + ibcCurrencyOptions, + selectedIbcCurrency, + } = useIbcChainSelection(ibcChains); + const defaultIbcChainOption = useMemo(() => { + return ibcChainsOptions[0] || null; + }, [ibcChainsOptions]); + const defaultIbcCurrencyOption = useMemo(() => { + return ibcCurrencyOptions[0] || null; + }, [ibcCurrencyOptions]); const [balance, setBalance] = useState("0 TIA"); const [fromAddress, setFromAddress] = useState(""); @@ -48,12 +63,13 @@ export default function DepositCard(): React.ReactElement { }, [recipientAddress, amount]); const getAndSetBalance = async () => { - if (!selectedIbcChain) { + if (!selectedIbcChain || !selectedIbcCurrency) { return; } try { setIsLoadingBalance(true); - const balance = await getBalance(selectedIbcChain); + // TODO - should update balance if user selects different token + const balance = await getBalance(selectedIbcChain, selectedIbcCurrency); setBalance(balance); } catch (e) { console.error(e); @@ -64,11 +80,11 @@ export default function DepositCard(): React.ReactElement { }; const sendBalance = async () => { - if (!selectedIbcChain) { + if (!selectedIbcChain || !selectedIbcCurrency) { addNotification({ toastOpts: { toastType: NotificationType.WARNING, - message: "Please select a chain first.", + message: "Please select a chain and token first.", onAcknowledge: () => {}, }, }); @@ -83,6 +99,7 @@ export default function DepositCard(): React.ReactElement { fromAddress, recipientAddress, DecUtils.getTenExponentN(6).mul(new Dec(amount)).truncate().toString(), + selectedIbcCurrency, ); } catch (e) { if (e instanceof Error) { @@ -211,8 +228,8 @@ export default function DepositCard(): React.ReactElement { selectIbcChain(selected)} + defaultOption={defaultIbcChainOption} + onSelect={selectIbcChain} />