diff --git a/src/app/components/ActionsBackground.tsx b/src/app/components/ActionsBackground.tsx index ad25ceed5..99815d07e 100644 --- a/src/app/components/ActionsBackground.tsx +++ b/src/app/components/ActionsBackground.tsx @@ -4,11 +4,11 @@ import styles from "./ActionsBackground.module.scss" const ActionsBackground = () => { const { name } = useTheme() - if (name === "light" || name === "whale") { - return <> + if (name === "moon") { + return
} - return
+ return <> } export default ActionsBackground diff --git a/src/app/sections/DisplayChainsSetting.tsx b/src/app/sections/DisplayChainsSetting.tsx index a7e2aeb58..81bbdae83 100644 --- a/src/app/sections/DisplayChainsSetting.tsx +++ b/src/app/sections/DisplayChainsSetting.tsx @@ -14,9 +14,9 @@ const DisplayChainsSetting = () => { const onChange = (value: string) => { if (isTerraChain(value)) return - const newDisplayChains = displayChains.includes(value) - ? displayChains.filter((chainID) => chainID !== value) - : [...displayChains, value] + const newDisplayChains = displayChains?.includes(value) + ? displayChains?.filter((chainID) => chainID !== value) + : [...(displayChains || []), value] changeDisplayChains(newDisplayChains) if (value === selectedDisplayChain) { changeSelectedDisplayChain(undefined) @@ -42,7 +42,7 @@ const DisplayChainsSetting = () => { ) .map((chainID) => ({ value: chainID, - selected: displayChains.includes(chainID), + selected: displayChains?.includes(chainID), label: network[chainID].name, icon: network[chainID].icon, })) diff --git a/src/app/sections/LCDSetting.tsx b/src/app/sections/LCDSetting.tsx index caad30c6a..cf9c24a85 100644 --- a/src/app/sections/LCDSetting.tsx +++ b/src/app/sections/LCDSetting.tsx @@ -3,7 +3,7 @@ import { useForm } from "react-hook-form" import { Form, FormItem, Input } from "components/form" import { useTranslation } from "react-i18next" import { useNetworks } from "app/InitNetworks" -import ChainSelector from "components/form/ChainSelector" +import ChainSelector from "components/form/Selectors/ChainSelector/ChainSelector" import { useEffect, useMemo, useState } from "react" import { Button } from "components/general" import styles from "./LCDSetting.module.scss" diff --git a/src/components/form/Selectors/AssetSelector/AssetList.tsx b/src/components/form/Selectors/AssetSelector/AssetList.tsx new file mode 100644 index 000000000..c798330b7 --- /dev/null +++ b/src/components/form/Selectors/AssetSelector/AssetList.tsx @@ -0,0 +1,60 @@ +import styles from "../../ChainSelector.module.scss" +import WithSearchInput from "pages/custom/WithSearchInput" +import classNames from "classnames" + +interface AssetType { + denom: string + balance: string + icon: string + symbol: string + price: number + chains: string[] +} + +interface Props { + list: AssetType[] + onChange: (symbol: string, index: number) => void + value: string + small?: boolean + noSearch?: boolean +} + +const ChainList = ({ list, onChange, value, small, noSearch }: Props) => { + return ( +
+ + {(search) => ( +
+ {list + .filter( + ({ denom, symbol }) => + denom.toLowerCase().includes(search.toLowerCase()) || + symbol.toLowerCase().includes(search.toLowerCase()) + ) + .map(({ denom, symbol, icon }, index) => ( + + ))} +
+ )} +
+
+ ) +} + +export default ChainList diff --git a/src/components/form/Selectors/AssetSelector/AssetSelector.tsx b/src/components/form/Selectors/AssetSelector/AssetSelector.tsx new file mode 100644 index 000000000..375b99a58 --- /dev/null +++ b/src/components/form/Selectors/AssetSelector/AssetSelector.tsx @@ -0,0 +1,74 @@ +import { useState, useRef, useEffect } from "react" +import styles from "../../ChainSelector.module.scss" +import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown" +import AssetList from "./AssetList" + +interface AssetType { + denom: string + balance: string + icon: string + symbol: string + price: number + chains: string[] +} + +interface Props { + assetList: AssetType[] + onChange: (chain: string) => void + value: string + assetsByDenom: Record +} + +const AssetSelector = ({ + assetList, + onChange, + value, + assetsByDenom, +}: Props) => { + const [open, setOpen] = useState(false) + const ref = useRef(null) + + const handleClickOutside = (event: MouseEvent) => { + if (ref.current && !ref.current.contains(event.target as Node)) { + setOpen(false) + } + } + useEffect(() => { + document.addEventListener("mousedown", handleClickOutside) + return () => { + document.removeEventListener("mousedown", handleClickOutside) + } + }, []) + + const handleSelection = (denom: string) => { + onChange(denom) + setOpen(false) + } + + return ( +
+ + {open && ( + + )} +
+ ) +} + +export default AssetSelector diff --git a/src/components/form/ChainList.tsx b/src/components/form/Selectors/ChainSelector/ChainList.tsx similarity index 96% rename from src/components/form/ChainList.tsx rename to src/components/form/Selectors/ChainSelector/ChainList.tsx index ea33dff35..630877200 100644 --- a/src/components/form/ChainList.tsx +++ b/src/components/form/Selectors/ChainSelector/ChainList.tsx @@ -1,4 +1,4 @@ -import styles from "./ChainSelector.module.scss" +import styles from "../../ChainSelector.module.scss" import WithSearchInput from "pages/custom/WithSearchInput" import classNames from "classnames" diff --git a/src/components/form/ChainSelector.tsx b/src/components/form/Selectors/ChainSelector/ChainSelector.tsx similarity index 97% rename from src/components/form/ChainSelector.tsx rename to src/components/form/Selectors/ChainSelector/ChainSelector.tsx index 1ec70ec97..58fa69e02 100644 --- a/src/components/form/ChainSelector.tsx +++ b/src/components/form/Selectors/ChainSelector/ChainSelector.tsx @@ -1,5 +1,5 @@ import { useMemo, useState, useRef, useEffect } from "react" -import styles from "./ChainSelector.module.scss" +import styles from "../../ChainSelector.module.scss" import ArrowDropDownIcon from "@mui/icons-material/ArrowDropDown" import { useNetworks } from "app/InitNetworks" import ChainList from "./ChainList" diff --git a/src/components/form/TokenList.tsx b/src/components/form/Selectors/TokenSelector/TokenList.tsx similarity index 100% rename from src/components/form/TokenList.tsx rename to src/components/form/Selectors/TokenSelector/TokenList.tsx diff --git a/src/components/form/TokenSelector.module.scss b/src/components/form/Selectors/TokenSelector/TokenSelector.module.scss similarity index 100% rename from src/components/form/TokenSelector.module.scss rename to src/components/form/Selectors/TokenSelector/TokenSelector.module.scss diff --git a/src/components/form/TokenSelector.tsx b/src/components/form/Selectors/TokenSelector/TokenSelector.tsx similarity index 100% rename from src/components/form/TokenSelector.tsx rename to src/components/form/Selectors/TokenSelector/TokenSelector.tsx diff --git a/src/components/form/index.ts b/src/components/form/index.ts index c653971d5..c37c007e3 100644 --- a/src/components/form/index.ts +++ b/src/components/form/index.ts @@ -14,7 +14,7 @@ export { default as Checkbox } from "./Checkbox" export * from "./Checkbox" export { default as Toggle } from "./Toggle" export { default as Upload } from "./Upload" -export { default as ChainSelector } from "./ChainSelector" +export { default as ChainSelector } from "./Selectors/ChainSelector/ChainSelector" /* modules */ export { default as Paste } from "./Paste" diff --git a/src/components/layout/ChainFilter.tsx b/src/components/layout/ChainFilter.tsx index 78024c4e5..a5d3b347c 100644 --- a/src/components/layout/ChainFilter.tsx +++ b/src/components/layout/ChainFilter.tsx @@ -51,7 +51,7 @@ const ChainFilter = ({ () => sortedDisplayChains .map((id) => network[id]) - .filter((n) => displayChains.includes(n?.chainID)), + .filter((n) => displayChains?.includes(n?.chainID)), [network, sortedDisplayChains, displayChains] ) diff --git a/src/components/layout/OtherChainsButton.tsx b/src/components/layout/OtherChainsButton.tsx index 4b875333b..bde337a2b 100644 --- a/src/components/layout/OtherChainsButton.tsx +++ b/src/components/layout/OtherChainsButton.tsx @@ -21,7 +21,7 @@ const OtherChainsButton = ({ list, handleSetChain }: Props) => { const closePopover = () => setKey((key) => key + 1) const onClick = (chainID: string) => { - if (displayChains.includes(chainID)) { + if (displayChains?.includes(chainID)) { changeSelectedDisplayChain(chainID) handleSetChain(chainID) } else { diff --git a/src/components/layout/SimpleChainList.tsx b/src/components/layout/SimpleChainList.tsx index 62e715965..a38755f38 100644 --- a/src/components/layout/SimpleChainList.tsx +++ b/src/components/layout/SimpleChainList.tsx @@ -12,9 +12,10 @@ const cx = classNames.bind(styles) const SimpleChainList = ({ list, onClick }: Props) => { const { displayChains } = useDisplayChains() const sortedList = list.sort((a, b) => - displayChains.includes(a.chainID) && !displayChains.includes(b.chainID) + displayChains?.includes(a.chainID) && !displayChains?.includes(b.chainID) ? -1 - : !displayChains.includes(a.chainID) && displayChains.includes(b.chainID) + : !displayChains?.includes(a.chainID) && + displayChains?.includes(b.chainID) ? 1 : 0 ) @@ -25,7 +26,7 @@ const SimpleChainList = ({ list, onClick }: Props) => {