Skip to content

Commit

Permalink
feat(suite-native): crypto to fiat amout formatter supports isBalance…
Browse files Browse the repository at this point in the history
… flag
  • Loading branch information
PeKne committed Aug 14, 2024
1 parent 655b9d3 commit e131815
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type CryptoToFiatAmountFormatterProps = FormatterProps<string | null> &
historicRate?: number;
useHistoricRate?: boolean;
isDiscreetText?: boolean;
isBalance?: boolean;
};

export const CryptoToFiatAmountFormatter = ({
Expand All @@ -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');
Expand Down
8 changes: 6 additions & 2 deletions suite-native/formatters/src/hooks/useFiatFromCryptoValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -45,8 +48,9 @@ export const useFiatFromCryptoValue = ({
}

return convertCryptoToFiatAmount({
value: cryptoValue,
rate,
network,
isBalance,
value: cryptoValue,
});
};

0 comments on commit e131815

Please sign in to comment.