-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #416 from terra-money/staging
7.2.8
- Loading branch information
Showing
34 changed files
with
311 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<div className={styles.options}> | ||
<WithSearchInput disabled={noSearch} inline gap={4}> | ||
{(search) => ( | ||
<div | ||
className={classNames( | ||
styles.options__container, | ||
small && styles.options__container__small | ||
)} | ||
> | ||
{list | ||
.filter( | ||
({ denom, symbol }) => | ||
denom.toLowerCase().includes(search.toLowerCase()) || | ||
symbol.toLowerCase().includes(search.toLowerCase()) | ||
) | ||
.map(({ denom, symbol, icon }, index) => ( | ||
<button | ||
className={symbol === value ? styles.active : ""} | ||
key={denom} | ||
onClick={(e) => { | ||
e.preventDefault() | ||
e.stopPropagation() | ||
onChange(denom, index) | ||
}} | ||
> | ||
<img src={icon} alt={denom} /> | ||
{symbol} | ||
</button> | ||
))} | ||
</div> | ||
)} | ||
</WithSearchInput> | ||
</div> | ||
) | ||
} | ||
|
||
export default ChainList |
74 changes: 74 additions & 0 deletions
74
src/components/form/Selectors/AssetSelector/AssetSelector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string, AssetType> | ||
} | ||
|
||
const AssetSelector = ({ | ||
assetList, | ||
onChange, | ||
value, | ||
assetsByDenom, | ||
}: Props) => { | ||
const [open, setOpen] = useState(false) | ||
const ref = useRef<HTMLDivElement>(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 ( | ||
<div className={styles.container} ref={ref}> | ||
<button | ||
type="button" | ||
className={styles.selector} | ||
onClick={(e) => { | ||
e.stopPropagation() | ||
if (e.screenX && e.screenY) setOpen((o) => !o) // negate onClick triggered by enter key press | ||
}} | ||
> | ||
<span> | ||
<img | ||
src={assetsByDenom[value]?.icon} | ||
alt={assetsByDenom[value]?.denom} | ||
/>{" "} | ||
{assetsByDenom[value]?.symbol} | ||
</span>{" "} | ||
<ArrowDropDownIcon style={{ fontSize: 20 }} className={styles.caret} /> | ||
</button> | ||
{open && ( | ||
<AssetList list={assetList} onChange={handleSelection} value={value} /> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default AssetSelector |
2 changes: 1 addition & 1 deletion
2
src/components/form/ChainList.tsx → ...orm/Selectors/ChainSelector/ChainList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/components/form/ChainSelector.tsx → ...Selectors/ChainSelector/ChainSelector.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.