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 2 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.finalAmount;
} else {
return secondaryCurrency.amount;
return secondaryCurrency.finalAmount;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class CurrencyDetail {
bool get isStableCurrency =>
stableCurrencies.contains(currencyType.toUpperCase());

/// This will give the final amount to do processing based on what type of currency it is like fiat or crypto currency.
double get finalAmount => double.parse(formatter.format(amount));
Copy link
Contributor

Choose a reason for hiding this comment

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

@sagar-deriv Can we name it like formattedAmount?

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.

Please update the doc comments to reflect the updated name.


/// Amount that is used to display for user.
String get displayAmount {
if (amount == 0.0) {
Expand All @@ -54,9 +57,9 @@ class CurrencyDetail {
/// 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we update the getter name isStableCurrency and the list name stableCurrencies? Using crypto instead of stable would be more accurate, as our currency types are fiat and crypto.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, that's better. I will push the changes.

return NumberFormat.decimalPattern()..maximumFractionDigits = 2;
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