|
| 1 | +import React from "react"; |
| 2 | +import { View } from "react-native"; |
| 3 | +import BigNumber from "bignumber.js"; |
| 4 | +import { Trans } from "react-i18next"; |
| 5 | +import { Flex, Text, Alert, Box } from "@ledgerhq/native-ui"; |
| 6 | +import { |
| 7 | + SolanaTokenAccount, |
| 8 | + SolanaTokenAccountExtensions, |
| 9 | +} from "@ledgerhq/live-common/families/solana/types"; |
| 10 | +import { bpsToPercent } from "@ledgerhq/live-common/families/solana/token"; |
| 11 | +import TooltipLabel from "~/components/TooltipLabel"; |
| 12 | +import TokenExtensionsInfoDrawer from "./TokenExtensionsInfoDrawer"; |
| 13 | +import { InfoMedium } from "@ledgerhq/native-ui/assets/icons"; |
| 14 | +import CopyButton from "../shared/CopyButton"; |
| 15 | +import Button from "~/components/Button"; |
| 16 | + |
| 17 | +export default function TokenExtensionsInfoBox({ |
| 18 | + tokenAccount, |
| 19 | + extensions, |
| 20 | +}: { |
| 21 | + tokenAccount: SolanaTokenAccount; |
| 22 | + extensions: SolanaTokenAccountExtensions; |
| 23 | +}) { |
| 24 | + const [isDrawerOpen, setIsDrawerOpen] = React.useState(false); |
| 25 | + |
| 26 | + const extensionsSize = Object.values(extensions); |
| 27 | + if (!extensionsSize.length) return null; |
| 28 | + |
| 29 | + function openDrawer() { |
| 30 | + setIsDrawerOpen(true); |
| 31 | + } |
| 32 | + |
| 33 | + function closeDrawer() { |
| 34 | + setIsDrawerOpen(false); |
| 35 | + } |
| 36 | + |
| 37 | + return ( |
| 38 | + <View> |
| 39 | + <Alert showIcon={extensionsSize.length === 1} type="info"> |
| 40 | + <Flex width="100%" flexDirection="column" columnGap={4} alignItems="flex-start"> |
| 41 | + {!!extensions.nonTransferable && ( |
| 42 | + <Text> |
| 43 | + <Trans i18nKey="solana.token.nonTransferable.notice" /> |
| 44 | + </Text> |
| 45 | + )} |
| 46 | + |
| 47 | + {!!extensions.interestRate && ( |
| 48 | + <TooltipLabel |
| 49 | + label={ |
| 50 | + <Text> |
| 51 | + <Trans |
| 52 | + i18nKey="solana.token.interestRate.notice" |
| 53 | + values={{ |
| 54 | + rate: BigNumber(extensions.interestRate.rateBps).div(100).toNumber(), |
| 55 | + }} |
| 56 | + /> |
| 57 | + </Text> |
| 58 | + } |
| 59 | + tooltip={<Trans i18nKey="solana.token.interestRate.tooltipHint" />} |
| 60 | + /> |
| 61 | + )} |
| 62 | + |
| 63 | + {extensions.permanentDelegate ? ( |
| 64 | + extensions.permanentDelegate.delegateAddress ? ( |
| 65 | + <TooltipLabel |
| 66 | + label={ |
| 67 | + <Text> |
| 68 | + <Trans i18nKey="solana.token.permanentDelegate.notice" /> |
| 69 | + </Text> |
| 70 | + } |
| 71 | + tooltip={ |
| 72 | + <Trans |
| 73 | + i18nKey="solana.token.permanentDelegate.tooltipHint" |
| 74 | + values={{ delegateAddress: extensions.permanentDelegate.delegateAddress }} |
| 75 | + components={[ |
| 76 | + <CopyButton |
| 77 | + key="SolanaCopyDelegateAddress" |
| 78 | + copyString={extensions.permanentDelegate.delegateAddress} |
| 79 | + />, |
| 80 | + ]} |
| 81 | + /> |
| 82 | + } |
| 83 | + /> |
| 84 | + ) : ( |
| 85 | + <TooltipLabel |
| 86 | + label={ |
| 87 | + <Text> |
| 88 | + <Trans i18nKey="solana.token.permanentDelegate.initializationNotice" /> |
| 89 | + </Text> |
| 90 | + } |
| 91 | + tooltip={ |
| 92 | + <Trans i18nKey="solana.token.permanentDelegate.initializationNoticeTooltipHint" /> |
| 93 | + } |
| 94 | + /> |
| 95 | + ) |
| 96 | + ) : null} |
| 97 | + |
| 98 | + {!!extensions.transferFee && ( |
| 99 | + <TooltipLabel |
| 100 | + label={ |
| 101 | + <Text> |
| 102 | + <Trans |
| 103 | + i18nKey="solana.token.transferFees.notice" |
| 104 | + values={{ fee: bpsToPercent(extensions.transferFee.feeBps) }} |
| 105 | + /> |
| 106 | + </Text> |
| 107 | + } |
| 108 | + tooltip={<Trans i18nKey="solana.token.transferFees.tooltipHint" />} |
| 109 | + /> |
| 110 | + )} |
| 111 | + |
| 112 | + {extensions.transferHook ? ( |
| 113 | + extensions.transferHook.programAddress ? ( |
| 114 | + <TooltipLabel |
| 115 | + label={ |
| 116 | + <Text> |
| 117 | + <Trans i18nKey="solana.token.transferHook.notice" /> |
| 118 | + </Text> |
| 119 | + } |
| 120 | + tooltip={ |
| 121 | + <Trans |
| 122 | + i18nKey="solana.token.transferHook.tooltipHint" |
| 123 | + values={{ programAddress: extensions.transferHook.programAddress }} |
| 124 | + components={[ |
| 125 | + <CopyButton |
| 126 | + key="SolanaCopyHookAddress" |
| 127 | + copyString={extensions.transferHook.programAddress} |
| 128 | + />, |
| 129 | + ]} |
| 130 | + /> |
| 131 | + } |
| 132 | + /> |
| 133 | + ) : ( |
| 134 | + <Text> |
| 135 | + <Trans i18nKey="solana.token.transferHook.initializationNotice" /> |
| 136 | + </Text> |
| 137 | + ) |
| 138 | + ) : null} |
| 139 | + |
| 140 | + {!!extensions.requiredMemoOnTransfer && ( |
| 141 | + <TooltipLabel |
| 142 | + label={ |
| 143 | + <Text> |
| 144 | + <Trans i18nKey="solana.token.requiredMemoOnTransfer.notice" /> |
| 145 | + </Text> |
| 146 | + } |
| 147 | + tooltip={<Trans i18nKey="solana.token.requiredMemoOnTransfer.tooltipHint" />} |
| 148 | + /> |
| 149 | + )} |
| 150 | + <Box width="100%" mt={4}> |
| 151 | + {/* <Link type="color" size="medium" Icon={InfoMedium} onPress={openDrawer}> |
| 152 | + <Trans i18nKey="common.moreInfo" /> |
| 153 | + </Link> */} |
| 154 | + <Button |
| 155 | + type="color" |
| 156 | + size="small" |
| 157 | + maxWidth={150} |
| 158 | + alignSelf="center" |
| 159 | + outline |
| 160 | + Icon={InfoMedium} |
| 161 | + onPress={openDrawer} |
| 162 | + > |
| 163 | + <Trans i18nKey="common.moreInfo" /> |
| 164 | + </Button> |
| 165 | + </Box> |
| 166 | + </Flex> |
| 167 | + </Alert> |
| 168 | + <TokenExtensionsInfoDrawer |
| 169 | + extensions={extensions} |
| 170 | + tokenAccount={tokenAccount} |
| 171 | + isOpen={isDrawerOpen} |
| 172 | + closeDrawer={closeDrawer} |
| 173 | + /> |
| 174 | + </View> |
| 175 | + ); |
| 176 | +} |
0 commit comments