From e131815681a905568efb535c324230ecd237d329 Mon Sep 17 00:00:00 2001 From: Petr Knetl Date: Fri, 9 Aug 2024 10:54:15 +0200 Subject: [PATCH] feat(suite-native): crypto to fiat amout formatter supports isBalance flag --- .../formatters/src/utils/convertCryptoToFiatAmount.ts | 6 ++++-- .../src/components/CryptoToFiatAmountFormatter.tsx | 5 ++++- .../formatters/src/hooks/useFiatFromCryptoValue.ts | 8 ++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/suite-common/formatters/src/utils/convertCryptoToFiatAmount.ts b/suite-common/formatters/src/utils/convertCryptoToFiatAmount.ts index b95a970333f..44914efddf0 100644 --- a/suite-common/formatters/src/utils/convertCryptoToFiatAmount.ts +++ b/suite-common/formatters/src/utils/convertCryptoToFiatAmount.ts @@ -7,14 +7,16 @@ export const convertCryptoToFiatAmount = ({ value, rate, network, + isBalance = false, }: { value: CryptoToFiatAmountValue; - rate?: number; network: NetworkSymbol; + rate?: number; + isBalance?: boolean; }): string | null => { if (!value) return null; - const transactionAmount = formatNetworkAmount(value, network); + const transactionAmount = isBalance ? value : formatNetworkAmount(value, network); const fiatAmount = toFiatCurrency(transactionAmount, rate); return fiatAmount; diff --git a/suite-native/formatters/src/components/CryptoToFiatAmountFormatter.tsx b/suite-native/formatters/src/components/CryptoToFiatAmountFormatter.tsx index 89a7c19bc88..18b42a1536e 100644 --- a/suite-native/formatters/src/components/CryptoToFiatAmountFormatter.tsx +++ b/suite-native/formatters/src/components/CryptoToFiatAmountFormatter.tsx @@ -12,6 +12,7 @@ type CryptoToFiatAmountFormatterProps = FormatterProps & historicRate?: number; useHistoricRate?: boolean; isDiscreetText?: boolean; + isBalance?: boolean; }; export const CryptoToFiatAmountFormatter = ({ @@ -20,15 +21,17 @@ export const CryptoToFiatAmountFormatter = ({ historicRate, useHistoricRate, isDiscreetText = true, + isBalance = false, ...textProps }: CryptoToFiatAmountFormatterProps) => { const { FiatAmountFormatter } = useFormatters(); const fiatValue = useFiatFromCryptoValue({ - cryptoValue: value, network, historicRate, useHistoricRate, + isBalance, + cryptoValue: value, }); const formattedFiatValue = FiatAmountFormatter.format(fiatValue ?? '0'); diff --git a/suite-native/formatters/src/hooks/useFiatFromCryptoValue.ts b/suite-native/formatters/src/hooks/useFiatFromCryptoValue.ts index 007ff80674b..07831a5860f 100644 --- a/suite-native/formatters/src/hooks/useFiatFromCryptoValue.ts +++ b/suite-native/formatters/src/hooks/useFiatFromCryptoValue.ts @@ -16,15 +16,18 @@ type useFiatFromCryptoValueParams = { tokenDecimals?: number; historicRate?: number; useHistoricRate?: boolean; + isBalance?: boolean; }; export const useFiatFromCryptoValue = ({ + // TODO: is balance cryptoValue, network, tokenAddress, - tokenDecimals = 0, historicRate, useHistoricRate, + isBalance = false, + tokenDecimals = 0, }: useFiatFromCryptoValueParams) => { const fiatCurrencyCode = useSelector(selectFiatCurrencyCode); const fiatRateKey = getFiatRateKey(network, fiatCurrencyCode, tokenAddress); @@ -45,8 +48,9 @@ export const useFiatFromCryptoValue = ({ } return convertCryptoToFiatAmount({ - value: cryptoValue, rate, network, + isBalance, + value: cryptoValue, }); };