2022-12-15 10:06:44 +00:00
|
|
|
import { ChainItemType, WidthHeightProps } from "../../types";
|
|
|
|
import { FunctionComponent, useEffect, useState } from "react";
|
2022-12-09 11:59:52 +00:00
|
|
|
|
|
|
|
import color from "../../styles/color";
|
2022-12-12 06:51:25 +00:00
|
|
|
import { Flex1 } from "../../styles/flex-1";
|
2022-12-09 11:59:52 +00:00
|
|
|
import styled from "styled-components";
|
2022-12-12 13:45:24 +00:00
|
|
|
import { ChainImage } from "./chain-image";
|
2022-12-09 11:59:52 +00:00
|
|
|
|
|
|
|
interface Props {
|
2022-12-12 13:45:24 +00:00
|
|
|
chainItem: ChainItemType;
|
|
|
|
checkedItemHandler: (chainItem: ChainItemType, isChecked: boolean) => void;
|
2022-12-13 12:21:16 +00:00
|
|
|
checkedItems: Set<unknown>;
|
2022-12-15 10:06:44 +00:00
|
|
|
disabled?: boolean;
|
2022-12-09 11:59:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const ChainItem: FunctionComponent<Props> = (props) => {
|
2022-12-15 10:06:44 +00:00
|
|
|
const { chainItem, checkedItemHandler, checkedItems, disabled } = props;
|
|
|
|
const [checked, setChecked] = useState(disabled);
|
2022-12-12 13:45:24 +00:00
|
|
|
|
2022-12-13 12:21:16 +00:00
|
|
|
const checkHandler = () => {
|
2022-12-15 10:06:44 +00:00
|
|
|
if (!disabled) {
|
|
|
|
setChecked(!checked);
|
|
|
|
checkedItemHandler(chainItem, !checked);
|
|
|
|
}
|
2022-12-12 13:45:24 +00:00
|
|
|
};
|
2022-12-13 12:21:16 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2022-12-15 10:06:44 +00:00
|
|
|
if (!disabled) {
|
|
|
|
setChecked(checkedItems.has(chainItem));
|
|
|
|
}
|
2022-12-13 12:21:16 +00:00
|
|
|
}, [checkedItems]);
|
|
|
|
|
2022-12-09 11:59:52 +00:00
|
|
|
return (
|
2022-12-13 12:21:16 +00:00
|
|
|
<ChainItemContainer
|
|
|
|
key={chainItem.prefix}
|
|
|
|
isLoading={false}
|
2022-12-15 10:06:44 +00:00
|
|
|
disabled={disabled}
|
2022-12-13 12:21:16 +00:00
|
|
|
onClick={checkHandler}
|
|
|
|
>
|
2022-12-09 11:59:52 +00:00
|
|
|
<ChainImageContainer width="3rem" height="3rem">
|
2022-12-12 13:45:24 +00:00
|
|
|
<ChainImage
|
|
|
|
src={chainItem.chainImageUrl}
|
2022-12-09 11:59:52 +00:00
|
|
|
fill={true}
|
2022-12-12 13:45:24 +00:00
|
|
|
alt={`${chainItem.prefix} chain image`}
|
2022-12-09 11:59:52 +00:00
|
|
|
/>
|
|
|
|
</ChainImageContainer>
|
|
|
|
<ChainInfoContainer>
|
2022-12-12 13:45:24 +00:00
|
|
|
<ChainName>{`.${chainItem.prefix}`}</ChainName>
|
|
|
|
<WalletAddress>{chainItem.address}</WalletAddress>
|
2022-12-09 11:59:52 +00:00
|
|
|
</ChainInfoContainer>
|
|
|
|
|
|
|
|
<Flex1 />
|
|
|
|
|
2022-12-13 14:46:32 +00:00
|
|
|
<ChainCheckBox checked={checked} readOnly />
|
2022-12-09 11:59:52 +00:00
|
|
|
</ChainItemContainer>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-12-15 10:06:44 +00:00
|
|
|
export const ChainItemContainer = styled.div<{
|
|
|
|
isLoading: boolean;
|
|
|
|
checked?: boolean;
|
|
|
|
disabled?: boolean;
|
|
|
|
}>`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
gap: 1rem;
|
|
|
|
|
|
|
|
padding: 1.5rem;
|
|
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
opacity: ${(props) => (props.disabled ? "0.3" : "1")};
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: ${(props) => (props.isLoading ? null : color.grey["600"])};
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export const ChainImageContainer = styled.div<WidthHeightProps>`
|
|
|
|
width: ${(props) => props.width};
|
|
|
|
height: ${(props) => props.height};
|
|
|
|
|
|
|
|
position: relative;
|
|
|
|
`;
|
|
|
|
|
|
|
|
export const ChainInfoContainer = styled.div`
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
gap: 0.5rem;
|
|
|
|
`;
|
|
|
|
|
2022-12-13 12:21:16 +00:00
|
|
|
export const ChainName = styled.div`
|
2022-12-09 11:59:52 +00:00
|
|
|
font-weight: 600;
|
|
|
|
font-size: 0.8rem;
|
|
|
|
line-height: 1rem;
|
|
|
|
|
2022-12-13 12:21:16 +00:00
|
|
|
color: ${color.white};
|
2022-12-09 11:59:52 +00:00
|
|
|
`;
|
|
|
|
|
2022-12-13 12:21:16 +00:00
|
|
|
export const WalletAddress = styled.div`
|
2022-12-09 11:59:52 +00:00
|
|
|
font-weight: 500;
|
|
|
|
font-size: 0.8rem;
|
|
|
|
line-height: 1rem;
|
|
|
|
|
2022-12-13 12:21:16 +00:00
|
|
|
max-height: 2rem;
|
|
|
|
max-width: 27rem;
|
|
|
|
display: -webkit-box;
|
|
|
|
-webkit-line-clamp: 2;
|
|
|
|
-webkit-box-orient: vertical;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
2022-12-09 11:59:52 +00:00
|
|
|
color: ${color.grey["400"]};
|
|
|
|
`;
|
|
|
|
|
2022-12-13 12:21:16 +00:00
|
|
|
export const ChainCheckBox = styled.input.attrs({ type: "checkbox" })`
|
2022-12-09 11:59:52 +00:00
|
|
|
width: 1.5rem;
|
|
|
|
height: 1.5rem;
|
|
|
|
`;
|