-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,777 additions
and
49 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,97 @@ | ||
import React, { memo } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import DropdownMenu from 'components/DropdownMenu'; | ||
import { Asset } from 'types/Bridge'; | ||
import { optimism } from 'wagmi/chains'; | ||
import { Box, Skeleton, Typography } from '@mui/material'; | ||
import Image from 'next/image'; | ||
import useBalance from 'hooks/useBalance'; | ||
import formatNumber from 'utils/formatNumber'; | ||
import { useGetEXA } from 'contexts/GetEXAContext'; | ||
import useSocketAssets from 'hooks/useSocketAssets'; | ||
|
||
type AssetOptionProps = { | ||
asset?: Asset; | ||
option?: boolean; | ||
optionSize?: number; | ||
selectedSize?: number; | ||
chainId: number; | ||
}; | ||
|
||
function AssetOption({ asset, option = false, optionSize = 17, selectedSize = 14, chainId }: AssetOptionProps) { | ||
const size = option ? optionSize : selectedSize; | ||
const balance = useBalance(asset?.symbol, asset?.address as `0x${string}`, true, chainId); | ||
|
||
if (!asset) { | ||
return <Skeleton width={80} />; | ||
} | ||
|
||
return ( | ||
<Box | ||
display="flex" | ||
gap={1} | ||
my={0.5} | ||
mx={option ? 0.5 : 0} | ||
alignContent="center" | ||
alignItems="center" | ||
justifyContent="center" | ||
> | ||
{asset.logoURI && ( | ||
<Image | ||
src={asset.logoURI} | ||
alt={asset.symbol} | ||
width={size} | ||
height={size} | ||
style={{ | ||
borderRadius: '100%', | ||
}} | ||
/> | ||
)} | ||
<> | ||
{option ? ( | ||
<> | ||
<Box display="flex" alignItems="center"> | ||
<Box> | ||
<Typography fontWeight={600} fontSize={14} color="grey.900"> | ||
{asset.name} | ||
</Typography> | ||
<Typography fontSize={10} color="grey.900"> | ||
{asset.symbol} | ||
</Typography> | ||
</Box> | ||
</Box> | ||
<Box ml="auto"> | ||
<Typography fontSize={8}>{balance && Number(balance) ? formatNumber(balance) : ''}</Typography> | ||
</Box> | ||
</> | ||
) : ( | ||
<Typography fontWeight={600} fontSize={14} color="grey.900"> | ||
{asset.symbol} | ||
</Typography> | ||
)} | ||
</> | ||
</Box> | ||
); | ||
} | ||
|
||
function AssetSelector() { | ||
const { t } = useTranslation(); | ||
const { setAsset, asset, chain } = useGetEXA(); | ||
const assets = useSocketAssets(); | ||
|
||
if (!assets) return null; | ||
|
||
return ( | ||
<DropdownMenu | ||
label={t('Asset')} | ||
options={assets} | ||
onChange={setAsset} | ||
renderValue={<AssetOption asset={asset} chainId={chain?.chainId || optimism.id} />} | ||
renderOption={(o: Asset) => <AssetOption option asset={o} chainId={chain?.chainId || optimism.id} />} | ||
data-testid="modal-asset-selector" | ||
/> | ||
); | ||
} | ||
|
||
export default memo(AssetSelector); |
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,79 @@ | ||
import React, { memo, useCallback } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { Box, Skeleton, Typography } from '@mui/material'; | ||
import DropdownMenu from 'components/DropdownMenu'; | ||
import { useGetEXA } from 'contexts/GetEXAContext'; | ||
import Image from 'next/image'; | ||
import { Chain } from 'types/Bridge'; | ||
type AssetOptionProps = { | ||
chain?: Chain; | ||
option?: boolean; | ||
optionSize?: number; | ||
selectedSize?: number; | ||
}; | ||
|
||
function ChainOption({ chain, option = false, optionSize = 17, selectedSize = 14 }: AssetOptionProps) { | ||
const size = option ? optionSize : selectedSize; | ||
|
||
if (!chain) { | ||
return <Skeleton width={80} />; | ||
} | ||
|
||
return ( | ||
<Box | ||
display="flex" | ||
gap={0.5} | ||
my={0.5} | ||
mx={option ? 0.5 : 0} | ||
alignContent="center" | ||
alignItems="center" | ||
justifyContent="center" | ||
> | ||
{chain.icon && ( | ||
<Image | ||
src={chain.icon} | ||
alt={chain.name} | ||
width={size} | ||
height={size} | ||
style={{ | ||
borderRadius: '100%', | ||
}} | ||
/> | ||
)} | ||
<Typography fontWeight={600} fontSize={size} color="grey.900"> | ||
{chain.name} | ||
</Typography> | ||
</Box> | ||
); | ||
} | ||
|
||
const ChainSelector = ({ disabled }: { disabled?: boolean }) => { | ||
const { t } = useTranslation(); | ||
|
||
const { setChain: onChainChange, chains, chain } = useGetEXA(); | ||
|
||
const handleChainChange = useCallback( | ||
(value: string) => { | ||
const c = chains?.find(({ name }) => value === name); | ||
if (c) onChainChange(c); | ||
}, | ||
[chains, onChainChange], | ||
); | ||
|
||
if (!chains) return <Skeleton width={100} />; | ||
|
||
return ( | ||
<DropdownMenu | ||
label={t('Asset')} | ||
options={chains.map(({ name }) => name)} | ||
onChange={handleChainChange} | ||
renderValue={<ChainOption chain={chain} />} | ||
renderOption={(o: string) => <ChainOption option chain={chains.find(({ name }) => o === name)} />} | ||
data-testid="modal-asset-selector" | ||
disabled={disabled} | ||
/> | ||
); | ||
}; | ||
|
||
export default memo(ChainSelector); |
Oops, something went wrong.