From 67fb40db1ef35cf2bdae67e564c0d5c8e8da99dc Mon Sep 17 00:00:00 2001 From: jesse snyder Date: Wed, 4 Sep 2024 17:49:51 -0600 Subject: [PATCH] Refactor/chain config (#16) * use first ibc chain as default selection * use correct denom envar * use selectedIbcChain not envar * only need memo in msgIBCTransfer * cleanup before change * put defaults in ts files. can override with envar --- web/.env.example | 27 +-- web/config-overrides.js | 1 + .../components/DepositCard/DepositCard.tsx | 7 +- web/src/components/Dropdown/Dropdown.tsx | 13 +- .../components/WithdrawCard/WithdrawCard.tsx | 3 +- web/src/config/chainConfigs/dev/.gitkeep | 0 web/src/config/chainConfigs/dusk.ts | 85 +++++++++ web/src/config/chainConfigs/local.ts | 86 ++++++++++ web/src/config/chains.ts | 161 ++++-------------- web/src/config/index.ts | 17 +- .../hooks/useIbcChainSelection.ts | 7 +- web/src/services/ibc.ts | 17 +- web/src/utils/index.test.ts | 23 +-- web/src/utils/index.ts | 17 +- 14 files changed, 261 insertions(+), 203 deletions(-) delete mode 100644 web/src/config/chainConfigs/dev/.gitkeep create mode 100644 web/src/config/chainConfigs/dusk.ts create mode 100644 web/src/config/chainConfigs/local.ts diff --git a/web/.env.example b/web/.env.example index b01183c..a79d20c 100644 --- a/web/.env.example +++ b/web/.env.example @@ -3,30 +3,7 @@ REACT_APP_VERSION=$npm_package_version # bech32m address for the sequencer bridge account REACT_APP_SEQUENCER_BRIDGE_ACCOUNT=astria1d7zjjljc0dsmxa545xkpwxym86g8uvvwhtezcr -REACT_APP_SEQUENCER_BRIDGE_DENOM=utia REACT_APP_EVM_WITHDRAWER_CONTRACT_ADDRESS=0xA58639fB5458e65E4fA917FF951C390292C24A15 -# list of ibc chains -REACT_APP_IBC_CHAINS="CELESTIA" - -# celestia config for local development -REACT_APP_CELESTIA_CHAIN_ID="celestia-local-0" -REACT_APP_CELESTIA_CHAIN_NAME="celestia-local-0" -REACT_APP_CELESTIA_RPC_ENDPOINT="http://rpc.app.celestia.localdev.me" -REACT_APP_CELESTIA_REST_ENDPOINT="http://rest.app.celestia.localdev.me" -REACT_APP_CELESTIA_STAKE_CURRENCY_COIN_DENOM="TIA" -REACT_APP_CELESTIA_STAKE_CURRENCY_COIN_MINIMAL_DENOM="utia" -REACT_APP_CELESTIA_STAKE_CURRENCY_COIN_DECIMALS=6 -REACT_APP_CELESTIA_BIP_44_COIN_TYPE=118 -REACT_APP_CELESTIA_BECH32_PREFIX=celestia -REACT_APP_CELESTIA_CURRENCIES_COIN_DENOM="TIA" -REACT_APP_CELESTIA_CURRENCIES_COIN_MINIMAL_DENOM="utia" -REACT_APP_CELESTIA_CURRENCIES_COIN_DECIMALS=6 -REACT_APP_CELESTIA_FEE_CURRENCIES_COIN_DENOM="TIA" -REACT_APP_CELESTIA_FEE_CURRENCIES_COIN_MINIMAL_DENOM="utia" -REACT_APP_CELESTIA_FEE_CURRENCIES_COIN_DECIMALS=6 -REACT_APP_CELESTIA_FEE_CURRENCIES_GAS_PRICE_STEP_LOW=0.01 -REACT_APP_CELESTIA_FEE_CURRENCIES_GAS_PRICE_STEP_AVERAGE=0.02 -REACT_APP_CELESTIA_FEE_CURRENCIES_GAS_PRICE_STEP_HIGH=0.1 -REACT_APP_CELESTIA_IBC_CHANNEL="channel-110" -REACT_APP_CELESTIA_ICON_SOURCE_URL="https://placehold.co/60x60/EEE/31343C" +# can set custom ibc chains via json string +REACT_APP_IBC_CHAINS= diff --git a/web/config-overrides.js b/web/config-overrides.js index 30b25f7..0c94ebe 100644 --- a/web/config-overrides.js +++ b/web/config-overrides.js @@ -2,6 +2,7 @@ const webpack = require("webpack"); // This file is used by react-app-rewired. // Needed to browserify crypto for some cosmos key stuff I believe. +// FIXME - is this still needed? module.exports = function override(config) { const fallback = config.resolve.fallback || {}; Object.assign(fallback, { diff --git a/web/src/components/DepositCard/DepositCard.tsx b/web/src/components/DepositCard/DepositCard.tsx index c55ab74..3855af1 100644 --- a/web/src/components/DepositCard/DepositCard.tsx +++ b/web/src/components/DepositCard/DepositCard.tsx @@ -9,7 +9,7 @@ import { useEthWallet } from "features/EthWallet/hooks/useEthWallet"; import { getBalance, sendIbcTransfer } from "services/ibc"; import { getKeplrFromWindow } from "services/keplr"; import { useIbcChainSelection } from "features/IbcChainSelector/hooks/useIbcChainSelection"; -import Dropdown from "../Dropdown/Dropdown"; +import Dropdown from "components/Dropdown/Dropdown"; export default function DepositCard(): React.ReactElement { const { addNotification } = useContext(NotificationsContext); @@ -211,6 +211,7 @@ export default function DepositCard(): React.ReactElement { selectIbcChain(selected)} /> {!isRecipientAddressValid && hasTouchedForm && (

Must be a valid EVM address

diff --git a/web/src/components/Dropdown/Dropdown.tsx b/web/src/components/Dropdown/Dropdown.tsx index 27c89f9..3eac10c 100644 --- a/web/src/components/Dropdown/Dropdown.tsx +++ b/web/src/components/Dropdown/Dropdown.tsx @@ -1,5 +1,5 @@ import type React from "react"; -import { useState } from "react"; +import { useState, useEffect } from "react"; export interface DropdownOption { label: string; @@ -10,16 +10,25 @@ interface DropdownProps { options: DropdownOption[]; onSelect: (value: T) => void; placeholder?: string; + defaultOption?: DropdownOption; } function Dropdown({ options, onSelect, placeholder = "Select an option", + defaultOption, }: DropdownProps) { const [isActive, setIsActive] = useState(false); const [selectedOption, setSelectedOption] = - useState | null>(null); + useState | null>(defaultOption || null); + + useEffect(() => { + if (defaultOption) { + setSelectedOption(defaultOption); + onSelect(defaultOption.value); + } + }, [defaultOption, onSelect]); const handleSelect = (option: DropdownOption) => { setSelectedOption(option); diff --git a/web/src/components/WithdrawCard/WithdrawCard.tsx b/web/src/components/WithdrawCard/WithdrawCard.tsx index e5688be..1a95fc0 100644 --- a/web/src/components/WithdrawCard/WithdrawCard.tsx +++ b/web/src/components/WithdrawCard/WithdrawCard.tsx @@ -10,7 +10,7 @@ import { getAstriaWithdrawerService, } from "features/EthWallet"; import { useIbcChainSelection } from "features/IbcChainSelector"; -import Dropdown from "../Dropdown/Dropdown"; +import Dropdown from "components/Dropdown/Dropdown"; export default function WithdrawCard(): React.ReactElement { const { addNotification } = useContext(NotificationsContext); @@ -256,6 +256,7 @@ export default function WithdrawCard(): React.ReactElement { placeholder="Select a chain" options={ibcChainsOptions} onSelect={(selected) => selectIbcChain(selected)} + defaultOption={ibcChainsOptions[0]} />