From 2aa11d7a0797b6064d2688c01bebcb79eb572953 Mon Sep 17 00:00:00 2001 From: KraXen72 Date: Mon, 10 Jun 2024 21:16:57 +0200 Subject: [PATCH] work on LimitsCard --- src/i18n_messages/en.json | 1 + src/screens/MintInfoScreen.tsx | 57 +++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/i18n_messages/en.json b/src/i18n_messages/en.json index 1e5a8d16..94914999 100644 --- a/src/i18n_messages/en.json +++ b/src/i18n_messages/en.json @@ -620,6 +620,7 @@ "motd": "Important notice", "contactsHeading": "Contacts", "nutsHeading": "NUTs", + "mintMeltHeading": "Limits", "keyValueInfoCardHeading": "More Info" } } \ No newline at end of file diff --git a/src/screens/MintInfoScreen.tsx b/src/screens/MintInfoScreen.tsx index a8ee8ed1..550c2ea3 100644 --- a/src/screens/MintInfoScreen.tsx +++ b/src/screens/MintInfoScreen.tsx @@ -56,7 +56,7 @@ const contactIconMap: Record = { 'discord': 'faDiscord', 'github': 'faGithub', 'reddit': 'faReddit', - 'nostr': 'faBolt' + 'nostr': 'faCircleNodes' } function MOTDCard(props: {info: GetInfoResponse}) { @@ -77,12 +77,25 @@ function MOTDCard(props: {info: GetInfoResponse}) { ) } +function MintLimtsCard(props: {info: GetInfoResponse}) { + const textDim = useThemeColor('textDim') + return ( + } + />) +} + function DescriptionCard(props: {info: GetInfoResponse}) { const textDim = useThemeColor('textDim') return () } +/** one-line item for NUT specifications and adjacent things like limits */ function NutItem(props: { enabled: boolean, nutNameNumber: string, display: 'row' | 'small', width?: DimensionValue nutInfo?: DetailedNutInfo + customIcon?: IconTypes, + customIconColor?: string, }) { const textDim = useThemeColor('textDim') const $nutIcon: ViewStyle = { paddingHorizontal: 0 } @@ -115,8 +131,8 @@ function NutItem(props: { return ( @@ -277,6 +293,26 @@ function MintInfoDetails(props: { info: GetInfoResponse, popupMessage: (msg: str return <>{items} } +/** returns true if mint has atleast one limit for the given type */ +function mintHasLimits(info: GetInfoResponse) { + const mint = info.nuts['4'].methods.some( + (method) => + typeof method.min_amount !== 'undefined' || + typeof method.max_amount !== 'undefined' + ) + const melt = info.nuts['5'].methods.some( + (method) => + typeof method.min_amount !== 'undefined' || + typeof method.max_amount !== 'undefined' + ) + return { + any: mint || melt, + mint, + melt, + both: mint && melt, + } +} + export const MintInfoScreen: FC> = observer(function MintInfoScreen(_props) { const { navigation, route } = _props useHeader({ @@ -388,8 +424,10 @@ export const MintInfoScreen: FC> = observer {mintInfo?.motd && } + {mintInfo && mintHasLimits(mintInfo).any && } {mintInfo && <> + } > = observer HeadingTextProps={{style: [$sizeStyles.sm, {color: textDim}]}} ContentComponent={ <> - {mintInfo && ( - - )} + {mintInfo && } {isLoading && ( > = observer )} } - style={$card} /> - {mintInfo && }