|
| 1 | +import React from "react"; |
| 2 | +import { Trans } from "react-i18next"; |
| 3 | +import { SpaceProps } from "styled-system"; |
| 4 | + |
| 5 | +import { |
| 6 | + SolanaTokenAccount, |
| 7 | + SolanaTokenAccountExtensions, |
| 8 | +} from "@ledgerhq/live-common/families/solana/types"; |
| 9 | +import { bpsToPercent } from "@ledgerhq/live-common/families/solana/token"; |
| 10 | +import Box from "~/renderer/components/Box"; |
| 11 | +import Alert from "~/renderer/components/Alert"; |
| 12 | +import Text from "~/renderer/components/Text"; |
| 13 | +import LabelInfoTooltip from "~/renderer/components/LabelInfoTooltip"; |
| 14 | +import Button from "~/renderer/components/Button"; |
| 15 | +import TokenExtensionsInfoDrawer from "./TokenExtensionsInfoDrawer"; |
| 16 | + |
| 17 | +type Props = SpaceProps & { |
| 18 | + tokenAccount: SolanaTokenAccount; |
| 19 | + extensions: SolanaTokenAccountExtensions; |
| 20 | +}; |
| 21 | + |
| 22 | +export default function TokenExtensionsInfoBox({ tokenAccount, extensions, ...boxProps }: Props) { |
| 23 | + const extensionsSize = Object.values(extensions); |
| 24 | + const [isDrawerOpen, setIsDrawerOpen] = React.useState(false); |
| 25 | + if (!extensionsSize.length) return null; |
| 26 | + |
| 27 | + const onLearnMoreClick = () => { |
| 28 | + openDrawer(); |
| 29 | + }; |
| 30 | + |
| 31 | + const openDrawer = () => { |
| 32 | + setIsDrawerOpen(true); |
| 33 | + }; |
| 34 | + const closeDrawer = () => { |
| 35 | + setIsDrawerOpen(false); |
| 36 | + }; |
| 37 | + |
| 38 | + return ( |
| 39 | + <Box {...boxProps}> |
| 40 | + <Alert |
| 41 | + type="hint" |
| 42 | + right={ |
| 43 | + <Button small lighterPrimary onClick={onLearnMoreClick}> |
| 44 | + <Trans i18nKey="common.learnMore" /> |
| 45 | + </Button> |
| 46 | + } |
| 47 | + > |
| 48 | + <Box flexDirection="column"> |
| 49 | + {!!extensions.nonTransferable && ( |
| 50 | + <Text> |
| 51 | + <Trans i18nKey="solana.token.nonTransferable.notice" /> |
| 52 | + </Text> |
| 53 | + )} |
| 54 | + |
| 55 | + {!!extensions.interestRate && ( |
| 56 | + <LabelInfoTooltip text={<Trans i18nKey="solana.token.interestRate.tooltipHint" />}> |
| 57 | + <Text> |
| 58 | + <Trans |
| 59 | + i18nKey="solana.token.interestRate.notice" |
| 60 | + values={{ rate: bpsToPercent(extensions.interestRate.rateBps) }} |
| 61 | + /> |
| 62 | + </Text> |
| 63 | + </LabelInfoTooltip> |
| 64 | + )} |
| 65 | + |
| 66 | + {extensions.permanentDelegate ? ( |
| 67 | + <LabelInfoTooltip text={<Trans i18nKey="solana.token.permanentDelegate.tooltipHint" />}> |
| 68 | + <Text> |
| 69 | + {extensions.permanentDelegate.delegateAddress ? ( |
| 70 | + <Trans i18nKey="solana.token.permanentDelegate.notice" /> |
| 71 | + ) : ( |
| 72 | + <Trans i18nKey="solana.token.permanentDelegate.initializationNotice" /> |
| 73 | + )} |
| 74 | + </Text> |
| 75 | + </LabelInfoTooltip> |
| 76 | + ) : null} |
| 77 | + |
| 78 | + {!!extensions.transferFee && ( |
| 79 | + <LabelInfoTooltip text={<Trans i18nKey="solana.token.transferFees.tooltipHint" />}> |
| 80 | + <Text> |
| 81 | + <Trans |
| 82 | + i18nKey="solana.token.transferFees.notice" |
| 83 | + values={{ fee: bpsToPercent(extensions.transferFee.feeBps) }} |
| 84 | + /> |
| 85 | + </Text> |
| 86 | + </LabelInfoTooltip> |
| 87 | + )} |
| 88 | + |
| 89 | + {extensions.transferHook ? ( |
| 90 | + extensions.transferHook.programAddress ? ( |
| 91 | + <LabelInfoTooltip |
| 92 | + text={ |
| 93 | + <Trans |
| 94 | + i18nKey="solana.token.transferHook.tooltipHint" |
| 95 | + values={{ programAddress: extensions.transferHook.programAddress }} |
| 96 | + /> |
| 97 | + } |
| 98 | + > |
| 99 | + <Text> |
| 100 | + <Trans i18nKey="solana.token.transferHook.notice" /> |
| 101 | + </Text> |
| 102 | + </LabelInfoTooltip> |
| 103 | + ) : ( |
| 104 | + <Text> |
| 105 | + <Trans i18nKey="solana.token.transferHook.initializationNotice" /> |
| 106 | + </Text> |
| 107 | + ) |
| 108 | + ) : null} |
| 109 | + |
| 110 | + {!!extensions.requiredMemoOnTransfer && ( |
| 111 | + <LabelInfoTooltip |
| 112 | + text={<Trans i18nKey="solana.token.requiredMemoOnTransfer.tooltipHint" />} |
| 113 | + > |
| 114 | + <Text> |
| 115 | + <Trans i18nKey="solana.token.requiredMemoOnTransfer.notice" /> |
| 116 | + </Text> |
| 117 | + </LabelInfoTooltip> |
| 118 | + )} |
| 119 | + </Box> |
| 120 | + <TokenExtensionsInfoDrawer |
| 121 | + extensions={extensions} |
| 122 | + tokenAccount={tokenAccount} |
| 123 | + isOpen={isDrawerOpen} |
| 124 | + closeDrawer={closeDrawer} |
| 125 | + /> |
| 126 | + </Alert> |
| 127 | + </Box> |
| 128 | + ); |
| 129 | +} |
0 commit comments