-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(multichainSelector): worked on multichain selector
- Loading branch information
1 parent
87cb180
commit 5695da8
Showing
5 changed files
with
149 additions
and
34 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
20 changes: 20 additions & 0 deletions
20
src/components/MultichainSelector/MultiChainSelectorTypes.ts
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,20 @@ | ||
export type NetworksDataType = { | ||
logo: any; | ||
name: string; | ||
rpcUrl: string; | ||
chainId: number; | ||
explorerUrl: string; | ||
baseTokenAddress: string; | ||
currency: "MATIC" | "ETH"; | ||
collateralAddress: string; | ||
poolContractAddress: string; | ||
}; | ||
|
||
export type IMultiChainSelector = { | ||
networksAssets: any; | ||
textFieldLabel: string; | ||
onClick: (event: any) => void; | ||
networksList: Array<NetworksDataType>; | ||
networkSelected: Array<NetworksDataType>; | ||
onChange: (_: any, selectedValue: any) => void; | ||
}; |
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,78 @@ | ||
import React from "react"; | ||
import { | ||
Box, | ||
Checkbox, | ||
TextField, | ||
Typography, | ||
Autocomplete, | ||
} from "@mui/material"; | ||
import CheckBoxIcon from "@mui/icons-material/CheckBox"; | ||
import CheckBoxOutlineBlankIcon from "@mui/icons-material/CheckBoxOutlineBlank"; | ||
|
||
import { IMultiChainSelector } from "./MultiChainSelectorTypes"; | ||
|
||
export const MultichainSelector = ({ | ||
networkSelected, | ||
networksAssets, | ||
textFieldLabel, | ||
networksList, | ||
onChange, | ||
onClick, | ||
}: IMultiChainSelector) => ( | ||
<Autocomplete | ||
multiple | ||
id="chain-selector" | ||
onChange={onChange} | ||
disableCloseOnSelect | ||
options={networksList} | ||
sx={{ width: "200px" }} | ||
getOptionLabel={(option) => option?.name} | ||
renderOption={(_props, state, { selected }) => ( | ||
<Box display="flex" alignItems="center" onClick={onClick}> | ||
<Checkbox | ||
checked={selected} | ||
icon={<CheckBoxOutlineBlankIcon />} | ||
checkedIcon={<CheckBoxIcon color="secondary" />} | ||
/> | ||
<Box mr={1} display="flex" alignItems="center"> | ||
<img | ||
width={24} | ||
height={24} | ||
alt="Network icon" | ||
src={networksAssets[state.chainId].logo} | ||
/> | ||
</Box> | ||
<Typography variant="body1">{state.name}</Typography> | ||
</Box> | ||
)} | ||
renderInput={(params) => ( | ||
<Box display="flex" alignItems="center"> | ||
<TextField | ||
{...params} | ||
variant="outlined" | ||
label={textFieldLabel} | ||
InputProps={{ | ||
...params.InputProps, | ||
startAdornment: networkSelected.map((chain) => ( | ||
<Box | ||
mr={1} | ||
display="flex" | ||
alignItems="center" | ||
key={chain.chainId} | ||
> | ||
<img | ||
width={24} | ||
height={24} | ||
alt="Networ icon" | ||
src={networksAssets[chain.chainId]?.logo || ""} | ||
/> | ||
</Box> | ||
)), | ||
disableUnderline: true, | ||
}} | ||
/> | ||
</Box> | ||
)} | ||
value={networkSelected} | ||
/> | ||
); |
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