Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(deriv_ui): [DERG-3500] return inputted amount based on the formatter in numpad #624

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ class ExchangeController extends ChangeNotifier {
/// what user send by default in primaryCurrency when coming to numpad.)
double finalAmount() {
Copy link
Contributor

@aliakbar-deriv aliakbar-deriv Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we rename the double finalAmount() { .. method to formattedAmount()?

Copy link
Contributor Author

@sagar-deriv sagar-deriv Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case finalAmount is okay, because this is the final amount returned to the user. I will make the change and push for the other one in the CurrencyDetail class.

if (_exchangeRate.baseCurrency == primaryCurrency.currencyType) {
return primaryCurrency.amount;
return primaryCurrency.formattedAmount;
} else {
return secondaryCurrency.amount;
return secondaryCurrency.formattedAmount;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CurrencyDetail {
];

/// Available stable coin currency that Deriv supports.
static List<String> stableCurrencies = <String>[
static List<String> stableCryptoCurrencies = <String>[
'USDC',
'USDT',
'TUSDT',
Expand All @@ -37,26 +37,29 @@ class CurrencyDetail {
bool get isFiat => fiatCurrencies.contains(currencyType);

/// This will check if the currency is stable coin currency(USDC,tUSDT,eUSDT) or not.
bool get isStableCurrency =>
stableCurrencies.contains(currencyType.toUpperCase());
bool get isStableCryptoCurrency =>
stableCryptoCurrencies.contains(currencyType.toUpperCase());

/// This will give the formatted amount to do processing based on type of currency it is like fiat or crypto currency.
double get formattedAmount => double.parse(formatter.format(amount));

/// Amount that is used to display for user.
String get displayAmount {
if (amount == 0.0) {
return '';
}

return isFiat || isStableCurrency
return isFiat || isStableCryptoCurrency
? amount.toStringAsFixed(2)
: amount.toStringAsFixed(8);
}

/// This will give a specific currency formatter based on what type of currency it is like fiat or crypto currency.
NumberFormat get formatter {
if (isFiat || isStableCurrency) {
return NumberFormat.decimalPattern()..maximumFractionDigits = 2;
if (isFiat || isStableCryptoCurrency) {
return NumberFormat('#0.##', 'en_US');
} else {
return NumberFormat.decimalPattern()..maximumFractionDigits = 8;
return NumberFormat('#0.########', 'en_US');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ class _NumpadWithExchange extends NumberPad {
NumberPadCloseCallback? onClose,
}) : super(
numberPadType: NumberPadWidgetType.singleInput,
formatter: NumberFormat.decimalPattern()..maximumFractionDigits = 8,
formatter: primaryCurrency.formatter,
label: label,
firstInputTitle: title,
onClose: onClose,
Expand Down
Loading