@chakra-ui/react#AvatarGroup TypeScript Examples
The following examples show how to use
@chakra-ui/react#AvatarGroup.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AvatarPreview.tsx From openchakra with MIT License | 6 votes |
AvatarGroupPreview = ({ component }: IPreviewProps) => {
const { props, ref } = useInteractive(component, true)
const { drop, isOver } = useDropComponent(component.id, ['Avatar'])
const components = useSelector(getComponents)
let boxProps: any = { display: 'inline' }
if (isOver) {
props.bg = 'teal.50'
}
return (
<Box ref={drop(ref)} {...boxProps}>
<AvatarGroup {...props}>
{component.children.map((key: string, i: number) => (
<AvatarPreview
key={key}
index={i + 1}
spacing={props.spacing}
component={components[key]}
/>
))}
</AvatarGroup>
</Box>
)
}
Example #2
Source File: OraclesTable.tsx From rari-dApp with GNU Affero General Public License v3.0 | 5 votes |
OracleRow = ({
oracle,
underlyings,
isDefault = false,
}: {
oracle: string;
underlyings: string[];
isDefault?: boolean;
}) => {
const oracleIdentity = useIdentifyOracle(oracle);
const displayedOracle = !!oracleIdentity
? oracleIdentity
: shortAddress(oracle);
return (
<>
<Tr>
<Td>
<Link
href={`https://etherscan.io/address/${oracle}`}
isExternal
_hover={{ pointer: "cursor", color: "#21C35E" }}
>
<Text fontWeight="bold">{displayedOracle}</Text>
</Link>
</Td>
<Td>
{isDefault ? (
<span style={{ fontWeight: "bold" }}>DEFAULT</span>
) : (
<AvatarGroup size="xs" max={30} mr={2}>
{underlyings.map((underlying) => {
return <CTokenIcon key={underlying} address={underlying} />;
})}
</AvatarGroup>
)}
</Td>
</Tr>
</>
);
}
Example #3
Source File: FusePoolInfoPage.tsx From rari-dApp with GNU Affero General Public License v3.0 | 4 votes |
OracleAndInterestRates = ({
assets,
name,
totalSuppliedUSD,
totalBorrowedUSD,
totalLiquidityUSD,
comptrollerAddress,
oracleAddress,
oracleModel,
}: {
assets: USDPricedFuseAsset[];
name: string;
totalSuppliedUSD: number;
totalBorrowedUSD: number;
totalLiquidityUSD: number;
comptrollerAddress: string;
oracleAddress: string;
oracleModel: string | undefined;
}) => {
let { poolId } = useParams();
const { t } = useTranslation();
const data = useExtraPoolInfo(comptrollerAddress, oracleAddress);
const defaultOracleIdentity = useIdentifyOracle(data?.defaultOracle);
console.log(data?.defaultOracle, { defaultOracleIdentity });
const { hasCopied, onCopy } = useClipboard(data?.admin ?? "");
return (
<Column
mainAxisAlignment="flex-start"
crossAxisAlignment="flex-start"
height="100%"
width="100%"
>
<Row
mainAxisAlignment="space-between"
crossAxisAlignment="center"
width="100%"
px={4}
height="60px"
flexShrink={0}
>
<Heading size="sm">
{t("Pool {{num}} Info", { num: poolId, name })}
</Heading>
<Link
className="no-underline"
isExternal
ml="auto"
href={`https://metrics.rari.capital/d/HChNahwGk/fuse-pool-details?orgId=1&refresh=10s&var-poolID=${poolId}`}
>
<DashboardBox height="35px">
<Center expand px={2} fontWeight="bold">
{t("Metrics")}
</Center>
</DashboardBox>
</Link>
{data?.isPowerfulAdmin ? (
<Link
/* @ts-ignore */
as={RouterLink}
className="no-underline"
to="../edit"
ml={2}
>
<DashboardBox height="35px">
<Center expand px={2} fontWeight="bold">
{t("Edit")}
</Center>
</DashboardBox>
</Link>
) : null}
</Row>
<ModalDivider />
<Column
mainAxisAlignment="center"
crossAxisAlignment="center"
width="100%"
my={4}
px={4}
>
{assets.length > 0 ? (
<>
<AvatarGroup mt={1} size="xs" max={30}>
{assets.map(({ underlyingToken, cToken }) => {
return <CTokenIcon key={cToken} address={underlyingToken} />;
})}
</AvatarGroup>
<Text mt={3} lineHeight={1} textAlign="center">
{name} (
{assets.map(({ underlyingSymbol }, index, array) => {
return (
underlyingSymbol + (index !== array.length - 1 ? " / " : "")
);
})}
)
</Text>
</>
) : (
<Text>{name}</Text>
)}
</Column>
<ModalDivider />
<Column
mainAxisAlignment="flex-start"
crossAxisAlignment="flex-start"
my={5}
px={4}
width="100%"
>
<StatRow
statATitle={t("Total Supplied")}
statA={shortUsdFormatter(totalSuppliedUSD)}
statBTitle={t("Total Borrowed")}
statB={shortUsdFormatter(totalBorrowedUSD)}
/>
<StatRow
statATitle={t("Available Liquidity")}
statA={shortUsdFormatter(totalLiquidityUSD)}
statBTitle={t("Pool Utilization")}
statB={
totalSuppliedUSD.toString() === "0"
? "0%"
: ((totalBorrowedUSD / totalSuppliedUSD) * 100).toFixed(2) + "%"
}
/>
<StatRow
statATitle={t("Upgradeable")}
statA={data ? (data.upgradeable ? "Yes" : "No") : "?"}
statBTitle={
hasCopied ? t("Admin (copied!)") : t("Admin (click to copy)")
}
statB={data?.admin ? shortAddress(data.admin) : "?"}
onClick={onCopy}
/>
<StatRow
statATitle={t("Platform Fee")}
statA={assets.length > 0 ? assets[0].fuseFee / 1e16 + "%" : "10%"}
statBTitle={t("Average Admin Fee")}
statB={
assets
.reduce(
(a, b, _, { length }) => a + b.adminFee / 1e16 / length,
0
)
.toFixed(1) + "%"
}
/>
<StatRow
statATitle={t("Close Factor")}
statA={
data?.closeFactor
? (data.closeFactor / 1e16).toFixed(2) + "%"
: "?%"
}
statBTitle={t("Liquidation Incentive")}
statB={
data?.liquidationIncentive
? data.liquidationIncentive / 1e16 - 100 + "%"
: "?%"
}
/>
<StatRow
statATitle={t("Oracle")}
statA={data ? oracleModel ?? t("Unrecognized Oracle") : "?"}
statBTitle={t("Whitelist")}
statB={data ? (data.enforceWhitelist ? "Yes" : "No") : "?"}
/>
</Column>
</Column>
);
}
Example #4
Source File: FusePoolPage.tsx From rari-dApp with GNU Affero General Public License v3.0 | 4 votes |
AssetSupplyRow = ({
assets,
index,
comptrollerAddress,
supplyIncentives,
rewardTokensData,
isPaused,
}: {
assets: USDPricedFuseAsset[];
index: number;
comptrollerAddress: string;
supplyIncentives: CTokenRewardsDistributorIncentivesWithRates[];
rewardTokensData: TokensDataMap;
isPaused: boolean;
}) => {
const {
isOpen: isModalOpen,
onOpen: openModal,
onClose: closeModal,
} = useDisclosure();
const authedOpenModal = useAuthedCallback(openModal);
const asset = assets[index];
const { fuse, address } = useRari();
const tokenData = useTokenData(asset.underlyingToken);
const supplyAPY = convertMantissaToAPY(asset.supplyRatePerBlock, 365);
const queryClient = useQueryClient();
const toast = useToast();
const onToggleCollateral = async () => {
const comptroller = createComptroller(comptrollerAddress, fuse);
let call;
if (asset.membership) {
call = comptroller.methods.exitMarket(asset.cToken);
} else {
call = comptroller.methods.enterMarkets([asset.cToken]);
}
let response = await call.call({ from: address });
// For some reason `response` will be `["0"]` if no error but otherwise it will return a string number.
if (response[0] !== "0") {
if (asset.membership) {
toast({
title: "Error! Code: " + response,
description:
"You cannot disable this asset as collateral as you would not have enough collateral posted to keep your borrow. Try adding more collateral of another type or paying back some of your debt.",
status: "error",
duration: 9000,
isClosable: true,
position: "top-right",
});
} else {
toast({
title: "Error! Code: " + response,
description:
"You cannot enable this asset as collateral at this time.",
status: "error",
duration: 9000,
isClosable: true,
position: "top-right",
});
}
return;
}
await call.send({ from: address });
LogRocket.track("Fuse-ToggleCollateral");
queryClient.refetchQueries();
};
const isStakedOHM =
asset.underlyingToken.toLowerCase() ===
"0x04F2694C8fcee23e8Fd0dfEA1d4f5Bb8c352111F".toLowerCase();
const { data: stakedOHMApyData } = useQuery("sOHM_APY", async () => {
const data = (
await fetch("https://api.rari.capital/fuse/pools/18/apy")
).json();
return data as Promise<{ supplyApy: number; supplyWpy: number }>;
});
const isMobile = useIsMobile();
const { t } = useTranslation();
const hasSupplyIncentives = !!supplyIncentives.length;
const totalSupplyAPR =
supplyIncentives?.reduce((prev, incentive) => {
const apr = incentive.supplyAPR;
return prev + apr;
}, 0) ?? 0;
const [hovered, setHovered] = useState<number>(-1);
const handleMouseEnter = (index: number) => setHovered(index);
const handleMouseLeave = () => setHovered(-1);
const displayedSupplyAPR =
hovered >= 0 ? supplyIncentives[hovered].supplyAPR : totalSupplyAPR;
const displayedSupplyAPRLabel =
hovered >= 0
? `${supplyIncentives[hovered].supplyAPR.toFixed(2)} % APR in ${
rewardTokensData[supplyIncentives[hovered].rewardToken].symbol
} distributions.`
: `${displayedSupplyAPR.toFixed(
2
)}% total APR distributed in ${supplyIncentives
.map((incentive) => rewardTokensData[incentive.rewardToken].symbol)
.join(", ")}
`;
const _hovered = hovered > 0 ? hovered : 0;
const color =
rewardTokensData[supplyIncentives?.[_hovered]?.rewardToken]?.color ??
"white";
const symbol = getSymbol(tokenData, asset);
return (
<>
<PoolModal
defaultMode={Mode.SUPPLY}
comptrollerAddress={comptrollerAddress}
assets={assets}
index={index}
isOpen={isModalOpen}
onClose={closeModal}
isBorrowPaused={asset.isPaused}
/>
<Row
mainAxisAlignment="flex-start"
crossAxisAlignment="flex-start"
width="100%"
px={4}
py={1.5}
className="hover-row"
>
{/* Underlying Token Data */}
<Column
mainAxisAlignment="flex-start"
crossAxisAlignment="flex-start"
width="27%"
>
<Row
mainAxisAlignment="flex-start"
crossAxisAlignment="center"
width="100%"
as="button"
onClick={authedOpenModal}
>
<Avatar
bg="#FFF"
boxSize="37px"
name={symbol}
src={
tokenData?.logoURL ??
"https://raw.githubusercontent.com/feathericons/feather/master/icons/help-circle.svg"
}
/>
<Text fontWeight="bold" fontSize="lg" ml={2} flexShrink={0}>
{symbol}
</Text>
</Row>
{/* <Row
mainAxisAlignment="flex-start"
crossAxisAlignment="center"
width="100%"
>
<Text fontSize="sm" ml={2} flexShrink={0}>
{shortUsdFormatter(asset.liquidityUSD)}
</Text>
</Row> */}
</Column>
{/* APY */}
{isMobile ? null : (
<Column
mainAxisAlignment="flex-start"
crossAxisAlignment="flex-end"
width="27%"
as="button"
onClick={authedOpenModal}
>
<Text
color={tokenData?.color ?? "#FF"}
fontWeight="bold"
fontSize="17px"
>
{isStakedOHM
? stakedOHMApyData
? (stakedOHMApyData.supplyApy * 100).toFixed(2)
: "?"
: supplyAPY.toFixed(2)}
%
</Text>
{/* Demo Supply Incentives */}
{hasSupplyIncentives && (
<Row
// ml={1}
// mb={.5}
crossAxisAlignment="center"
mainAxisAlignment="flex-end"
py={2}
>
<Text fontWeight="bold" mr={1}>
+
</Text>
<AvatarGroup size="xs" max={30} ml={2} mr={1} spacing={1}>
{supplyIncentives?.map((supplyIncentive, i) => {
return (
<SimpleTooltip label={displayedSupplyAPRLabel}>
<CTokenIcon
address={supplyIncentive.rewardToken}
boxSize="20px"
onMouseEnter={() => handleMouseEnter(i)}
onMouseLeave={() => handleMouseLeave()}
_hover={{
zIndex: 9,
border: ".5px solid white",
transform: "scale(1.3);",
}}
/>
</SimpleTooltip>
);
})}
</AvatarGroup>
<SimpleTooltip label={displayedSupplyAPRLabel}>
<Text color={color} fontWeight="bold" pl={1} fontSize="sm">
{/* {(supplyIncentive.supplySpeed / 1e18).toString()}% */}
{displayedSupplyAPR.toFixed(2)}% APR
</Text>
</SimpleTooltip>
</Row>
)}
{/* Incentives */}
{/* {hasSupplyIncentives && (
<Column
mainAxisAlignment="flex-start"
crossAxisAlignment="flex-end"
py={1}
>
{supplyIncentives?.map((supplyIncentive) => {
return (
<Row
ml={1}
py={0.5}
// mb={.5}
crossAxisAlignment="center"
mainAxisAlignment="flex-end"
>
<Text fontWeight="bold" mr={2}>
+
</Text>
<CTokenIcon
address={supplyIncentive.rewardToken}
boxSize="20px"
/>
<Text fontWeight="bold" mr={2}></Text>
<Text
color={
rewardTokensData[supplyIncentive.rewardToken].color ??
"white"
}
fontWeight="bold"
>
{(supplyIncentive.supplySpeed / 1e18).toString()}%
</Text>
</Row>
);
})}
</Column>
)} */}
<SimpleTooltip
label={t(
"The Collateral Factor (CF) ratio defines the maximum amount of tokens in the pool that can be borrowed with a specific collateral. It’s expressed in percentage: if in a pool ETH has 75% LTV, for every 1 ETH worth of collateral, borrowers will be able to borrow 0.75 ETH worth of other tokens in the pool."
)}
>
<Text fontSize="sm">{asset.collateralFactor / 1e16}% CF</Text>
</SimpleTooltip>
{/* Incentives under APY
<Column
mainAxisAlignment="flex-start"
crossAxisAlignment="flex-end"
my={1}
>
{supplyIncentives?.map((supplyIncentive) => {
return (
<Row
mainAxisAlignment="space-between"
crossAxisAlignment="center"
w="100%"
>
<Avatar
src={
rewardTokensData[supplyIncentive.rewardToken].logoURL ?? ""
}
boxSize="20px"
/>
<Text
ml={2}
fontWeight="bold"
color={
rewardTokensData[supplyIncentive.rewardToken].color ?? ""
}
>
{(supplyIncentive.supplySpeed / 1e18).toString()}%
</Text>
</Row>
);
})}
</Column>
*/}
</Column>
)}
{/* Incentives */}
{/* <Column mainAxisAlignment="flex-start" crossAxisAlignment="flex-start">
{supplyIncentives?.map((supplyIncentive) => {
return (
<Row mainAxisAlignment="flex-start" crossAxisAlignment="center">
<Avatar
src={rewardTokensData[supplyIncentive.rewardToken].logoURL}
boxSize="15px"
/>
<Box>
{(supplyIncentive.supplySpeed / 1e18).toString()}% APY
</Box>
</Row>
);
})}
</Column> */}
<Column
mainAxisAlignment="flex-start"
crossAxisAlignment="flex-end"
width={isMobile ? "40%" : "27%"}
as="button"
onClick={authedOpenModal}
>
<Text
color={tokenData?.color ?? "#FFF"}
fontWeight="bold"
fontSize="17px"
>
{smallUsdFormatter(asset.supplyBalanceUSD)}
</Text>
<Text fontSize="sm">
{smallUsdFormatter(
asset.supplyBalance / 10 ** asset.underlyingDecimals
).replace("$", "")}{" "}
{symbol}
</Text>
</Column>
{/* Set As Collateral */}
<Row
width={isMobile ? "34%" : "20%"}
mainAxisAlignment="flex-end"
crossAxisAlignment="center"
>
<SwitchCSS symbol={symbol} color={tokenData?.color} />
<Switch
isChecked={asset.membership}
className={symbol + "-switch"}
onChange={onToggleCollateral}
size="md"
mt={1}
mr={5}
/>
</Row>
</Row>
</>
);
}
Example #5
Source File: FusePoolPage.tsx From rari-dApp with GNU Affero General Public License v3.0 | 4 votes |
AssetBorrowRow = ({
assets,
index,
comptrollerAddress,
borrowIncentives,
rewardTokensData,
isPaused,
}: {
assets: USDPricedFuseAsset[];
index: number;
comptrollerAddress: string;
borrowIncentives: CTokenRewardsDistributorIncentives[];
rewardTokensData: TokensDataMap;
isPaused: boolean;
}) => {
const asset = assets[index];
const {
isOpen: isModalOpen,
onOpen: openModal,
onClose: closeModal,
} = useDisclosure();
const authedOpenModal = useAuthedCallback(openModal);
const tokenData = useTokenData(asset.underlyingToken);
const borrowAPY = convertMantissaToAPY(asset.borrowRatePerBlock, 365);
const { t } = useTranslation();
const isMobile = useIsMobile();
const hasBorrowIncentives = !!borrowIncentives.length;
const totalBorrowAPY =
borrowIncentives?.reduce((prev, incentive) => {
const apy = incentive.borrowSpeed / 1e18;
return prev + apy;
}, 0) ?? 0;
const [hovered, setHovered] = useState<number>(-1);
const handleMouseEnter = (index: number) => setHovered(index);
const handleMouseLeave = () => setHovered(-1);
const displayedBorrowAPY =
hovered >= 0
? borrowIncentives[hovered].borrowSpeed / 1e18
: totalBorrowAPY;
const symbol = getSymbol(tokenData, asset);
return (
<>
<PoolModal
comptrollerAddress={comptrollerAddress}
defaultMode={Mode.BORROW}
assets={assets}
index={index}
isOpen={isModalOpen}
onClose={closeModal}
isBorrowPaused={isPaused}
/>
<Row
mainAxisAlignment="flex-start"
crossAxisAlignment="center"
width="100%"
px={4}
py={1.5}
className="hover-row"
as="button"
onClick={authedOpenModal}
>
<Row
mainAxisAlignment="flex-start"
crossAxisAlignment="center"
width="27%"
>
<Avatar
bg="#FFF"
boxSize="37px"
name={symbol}
src={
tokenData?.logoURL ??
"https://raw.githubusercontent.com/feathericons/feather/master/icons/help-circle.svg"
}
/>
<Text fontWeight="bold" fontSize="lg" ml={2} flexShrink={0}>
{symbol}
</Text>
</Row>
{isMobile ? null : (
<Column
mainAxisAlignment="flex-start"
crossAxisAlignment="flex-end"
width="27%"
>
<Text
color={tokenData?.color ?? "#FF"}
fontWeight="bold"
fontSize="17px"
>
{borrowAPY.toFixed(2)}%
</Text>
{/* Demo Borrow Incentives */}
{hasBorrowIncentives && (
<Row
// ml={1}
// mb={.5}
crossAxisAlignment="center"
mainAxisAlignment="flex-end"
py={1}
>
<Text fontWeight="bold" mr={1}>
+
</Text>
<AvatarGroup size="xs" max={30} ml={2} mr={2} spacing={1}>
{borrowIncentives?.map((borrowIncentive, i) => {
return (
<CTokenIcon
address={borrowIncentive.rewardToken}
boxSize="20px"
_hover={{
zIndex: 9,
border: ".5px solid white",
transform: "scale(1.3);",
}}
onMouseEnter={() => handleMouseEnter(i)}
onMouseLeave={handleMouseLeave}
/>
);
})}
</AvatarGroup>
<Text
color={
rewardTokensData[borrowIncentives?.[hovered]?.rewardToken]
?.color ?? "white"
}
pl={1}
fontWeight="bold"
>
{/* {(supplyIncentive.supplySpeed / 1e18).toString()}% */}
{displayedBorrowAPY}%
</Text>
</Row>
)}
{/* Borrow Incentives */}
{/* {hasBorrowIncentives && (
<Column
mainAxisAlignment="flex-start"
crossAxisAlignment="flex-end"
py={1}
>
{borrowIncentives?.map((borrowIncentive) => {
return (
<Row
ml={1}
// mb={.5}
crossAxisAlignment="center"
mainAxisAlignment="flex-end"
>
<Text fontWeight="bold" mr={2}>
+
</Text>
<CTokenIcon
address={borrowIncentive.rewardToken}
boxSize="20px"
/>
<Text fontWeight="bold" mr={2}></Text>
<Text
color={
rewardTokensData[borrowIncentive.rewardToken].color ??
"white"
}
fontWeight="bold"
>
{(borrowIncentive.borrowSpeed / 1e18).toString()}%
</Text>
</Row>
);
})}
</Column>
)} */}
<SimpleTooltip
label={t(
"Total Value Lent (TVL) measures how much of this asset has been supplied in total. TVL does not account for how much of the lent assets have been borrowed, use 'liquidity' to determine the total unborrowed assets lent."
)}
>
<Text fontSize="sm">
{shortUsdFormatter(asset.totalSupplyUSD)} TVL
</Text>
</SimpleTooltip>
{/* Borrow Incentives under APY */}
{/* <Column
mainAxisAlignment="flex-start"
crossAxisAlignment="flex-end"
my={1}
>
{borrowIncentives?.map((borrowIncentive) => {
return (
<Row
mainAxisAlignment="space-between"
crossAxisAlignment="center"
w="100%"
>
<Avatar
src={
rewardTokensData[borrowIncentive.rewardToken].logoURL ??
""
}
boxSize="20px"
/>
<Text
ml={2}
fontWeight="bold"
color={
rewardTokensData[borrowIncentive.rewardToken].color ??
""
}
>
{(borrowIncentive.borrowSpeed / 1e18).toString()}%
</Text>
</Row>
);
})}
</Column> */}
</Column>
)}
<Column
mainAxisAlignment="flex-start"
crossAxisAlignment="flex-end"
width={isMobile ? "40%" : "27%"}
>
<Text
color={tokenData?.color ?? "#FFF"}
fontWeight="bold"
fontSize="17px"
>
{smallUsdFormatter(asset.borrowBalanceUSD)}
</Text>
<Text fontSize="sm">
{smallUsdFormatter(
asset.borrowBalance / 10 ** asset.underlyingDecimals
).replace("$", "")}{" "}
{symbol}
</Text>
</Column>
<SimpleTooltip
label={t(
"Liquidity is the amount of this asset that is available to borrow (unborrowed). To see how much has been supplied and borrowed in total, navigate to the Pool Info tab."
)}
placement="top-end"
>
<Box width={isMobile ? "34%" : "20%"}>
<Column
mainAxisAlignment="flex-start"
crossAxisAlignment="flex-end"
>
<Text
color={tokenData?.color ?? "#FFF"}
fontWeight="bold"
fontSize="17px"
>
{shortUsdFormatter(asset.liquidityUSD)}
</Text>
<Text fontSize="sm">
{shortUsdFormatter(
asset.liquidity / 10 ** asset.underlyingDecimals
).replace("$", "")}{" "}
{symbol}
</Text>
</Column>
</Box>
</SimpleTooltip>
</Row>
</>
);
}
Example #6
Source File: FusePoolsPage.tsx From rari-dApp with GNU Affero General Public License v3.0 | 4 votes |
PoolRow = ({
tokens,
poolNumber,
tvl,
borrowed,
name,
noBottomDivider,
isWhitelisted,
comptroller,
}: {
tokens: { symbol: string; address: string }[];
poolNumber: number;
tvl: number;
borrowed: number;
name: string;
noBottomDivider?: boolean;
isWhitelisted: boolean;
comptroller: string;
}) => {
const isEmpty = tokens.length === 0;
const rss = usePoolRSS(poolNumber);
const rssScore = rss ? letterScore(rss.totalScore) : "?";
const isMobile = useIsMobile();
const poolIncentives = usePoolIncentives(comptroller);
const { hasIncentives } = poolIncentives;
if (hasIncentives) {
console.log({ poolNumber, poolIncentives });
}
return (
<>
<Link
/* @ts-ignore */
as={RouterLink}
width="100%"
className="no-underline"
to={"/fuse/pool/" + poolNumber}
>
<Row
mainAxisAlignment="flex-start"
crossAxisAlignment="center"
width="100%"
height="90px"
className="hover-row"
pl={4}
pr={1}
>
<Column
pt={2}
width={isMobile ? "100%" : "40%"}
height="100%"
mainAxisAlignment="center"
crossAxisAlignment="flex-start"
>
{isEmpty ? null : (
<SimpleTooltip label={tokens.map((t) => t.symbol).join(" / ")}>
<AvatarGroup size="xs" max={30} mr={2}>
{tokens.map(({ address }) => {
return <CTokenIcon key={address} address={address} />;
})}
</AvatarGroup>
</SimpleTooltip>
)}
<Row
mainAxisAlignment="flex-start"
crossAxisAlignment="center"
mt={isEmpty ? 0 : 2}
>
<WhitelistedIcon
isWhitelisted={isWhitelisted}
mr={2}
boxSize={"15px"}
mb="2px"
/>
<Text>{name}</Text>
</Row>
</Column>
{isMobile ? null : (
<>
<Center height="100%" width="13%">
<b>{poolNumber}</b>
</Center>
<Center height="100%" width="16%">
<b>{smallUsdFormatter(tvl)}</b>
</Center>
<Center height="100%" width="16%">
<b>{smallUsdFormatter(borrowed)}</b>
</Center>
<Center height="100%" width="15%">
<SimpleTooltip
label={
"Underlying RSS: " +
(rss ? rss.totalScore.toFixed(2) : "?") +
"%"
}
>
<b>{rssScore}</b>
</SimpleTooltip>
</Center>
</>
)}
</Row>
</Link>
{noBottomDivider ? null : <ModalDivider />}
</>
);
}
Example #7
Source File: IconDetailOverlay.tsx From lucide with ISC License | 4 votes |
IconDetailOverlay = ({ open = true, close, icon }) => {
const toast = useToast();
const { colorMode } = useColorMode();
const { tags = [], name } = icon;
const {color, strokeWidth, size} = useContext(IconStyleContext);
const iconRef = useRef<SVGSVGElement>(null);
const [isMobile] = useMediaQuery("(max-width: 560px)")
const { isOpen, onOpen, onClose } = useDisclosure()
const handleClose = () => {
onClose();
close();
};
useEffect(() => {
if(open) {
onOpen()
}
}, [open])
const iconStyling = (isLight) => ({
height: "25vw",
width: "25vw",
minHeight: "160px",
minWidth: "160px",
maxHeight: "240px",
maxWidth: "240px",
color: color,
});
const downloadIcon = ({src, name} : IconDownload) => download(src, `${name}.svg`, 'image/svg+xml');
const copyIcon = ({src, name} : IconDownload) => {
copy(src);
toast({
title: "Copied!",
description: `Icon "${name}" copied to clipboard.`,
status: "success",
duration: 1500,
isClosable: true
});
}
const downloadPNG = ({src, name}: IconDownload) => {
const canvas = document.createElement('canvas');
canvas.width = size;
canvas.height = size;
const ctx = canvas.getContext("2d");
const image = new Image();
image.src = `data:image/svg+xml;base64,${btoa(src)}`;
image.onload = function() {
ctx.drawImage(image, 0, 0);
const link = document.createElement('a');
link.download = `${name}.png`;
link.href = canvas.toDataURL('image/png')
link.click();
}
}
return (
<Box
position="fixed"
bottom={0}
zIndex={2}
width="100%"
left={0}
height={0}
key={name}
>
<Slide direction="bottom" in={isOpen} style={{ zIndex: 10 }}>
<Flex
alignItems="center"
justifyContent="space-between"
pt={4}
pb={4}
maxW="850px"
margin="0 auto"
w="full"
px={8}
>
<Box
borderWidth="1px"
rounded="lg"
width="full"
boxShadow={theme.shadows.xl}
position="relative"
bg={
colorMode == "light"
? theme.colors.white
: theme.colors.gray[700]
}
padding={8}
>
<IconButton
size="sm"
aria-label="Close overlay"
variant="ghost"
color="current"
ml="3"
position="absolute"
top={4}
right={4}
onClick={handleClose}
icon={<Close />}
/>
<Flex direction={['column', 'row']} alignItems={['center', 'flex-start']}>
<Flex>
<Box
borderWidth="1px"
rounded="md"
position="relative"
bg={
colorMode == "light"
? theme.colors.whiteAlpha[800]
: theme.colors.blackAlpha[500]
}
padding={0}
>
<div
style={iconStyling(colorMode == "light")}
className="icon-large"
>
<IconWrapper
content={icon.content}
stroke={color}
strokeWidth={strokeWidth}
height={size}
width={size}
ref={iconRef}
/>
</div>
<svg className="icon-grid" width="24" height="24" viewBox={`0 0 ${size} ${size}`} fill="none" stroke={colorMode == "light" ? '#E2E8F0' : theme.colors.gray[600]} strokeWidth="0.1" xmlns="http://www.w3.org/2000/svg">
{ Array.from({ length:(size - 1) }, (_, i) => (
<g key={`grid-${i}`}>
<line key={`horizontal-${i}`} x1={0} y1={i + 1} x2={size} y2={i + 1} />
<line key={`vertical-${i}`} x1={i + 1} y1={0} x2={i + 1} y2={size} />
</g>
)) }
</svg>
</Box>
</Flex>
<Flex marginLeft={[0, 8]} w="100%">
<Box w="100%">
<Flex
justify={isMobile ? 'center' : 'flex-start'}
marginTop={isMobile ? 10 : 0}
>
<Box
position="relative"
mb={1}
display="inline-block"
style={{ cursor: "pointer" }}
pr={6}
>
<Text fontSize="3xl">
{icon.name}
</Text>
{ icon?.contributors?.length ? ( <ModifiedTooltip/> ) : null}
</Box>
</Flex>
<Box mb={4}>
{ tags?.length ? (
<Text
fontSize="xl"
fontWeight="bold"
color={
colorMode === "light"
? 'gray.600'
: 'gray.500'
}
>
{ tags.join(' • ') }
</Text>
) : ''}
{/* <Button size="sm" fontSize="md" variant="ghost" onClick={() => downloadIcon(icon)}>
Edit Tags
</Button> */}
</Box>
<Box overflowY="auto" w="100%" pt={1} pb={1}>
<ButtonGroup spacing={4}>
<Button variant="solid" onClick={() => downloadIcon({src: iconRef.current.outerHTML, name: icon.name})} mb={1}>
Download SVG
</Button>
<Button variant="solid" onClick={() => copyIcon({src: iconRef.current.outerHTML, name: icon.name})} mb={1}>
Copy SVG
</Button>
<Button variant="solid" onClick={() => downloadPNG({src: iconRef.current.outerHTML, name: icon.name})} mb={1}>
Download PNG
</Button>
</ButtonGroup>
</Box>
{ icon?.contributors?.length ? (
<>
<Heading as="h5" size="sm" marginTop={4} marginBottom={2}>
Contributors:
</Heading>
<AvatarGroup size="md">
{ icon.contributors.map((commit, index) => (
<Link href={`https://github.com/${commit.author}`} isExternal key={`${index}_${commit.sha}`}>
<Tooltip label={commit.author} key={commit.sha}>
<Avatar name={commit.author} src={`https://github.com/${commit.author}.png?size=88`} />
</Tooltip>
</Link>
)) }
</AvatarGroup>
</>
) : null }
</Box>
</Flex>
</Flex>
</Box>
</Flex>
</Slide>
</Box>
);
}