-
Notifications
You must be signed in to change notification settings - Fork 250
fix(withdraw): add USD fiat values alongside amounts #3274
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
Changes from all commits
19537e0
89e62fc
257e0af
9f2afdb
fc2f907
0f4bc96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import 'package:decimal/decimal.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:komodo_defi_types/komodo_defi_types.dart'; | ||
| import 'package:komodo_ui_kit/komodo_ui_kit.dart'; | ||
| import 'package:web_dex/shared/utils/formatters.dart'; | ||
| import 'package:web_dex/shared/utils/utils.dart'; | ||
|
|
||
| /// A widget that displays an asset amount with its fiat value in parentheses. | ||
| /// | ||
| /// Example output: "0.5 BTC ($15,234.50)" | ||
| /// | ||
| /// The fiat value is only shown if pricing data is available from the SDK. | ||
| class AssetAmountWithFiat extends StatelessWidget { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: prefer a name that better aligns with Flutter's naming conventions, making it clear that it is a widget. I assumed e.g. |
||
| const AssetAmountWithFiat({ | ||
| required this.assetId, | ||
| required this.amount, | ||
| super.key, | ||
| this.style, | ||
| this.isSelectable = true, | ||
| this.isAutoScrollEnabled = true, | ||
| this.showCoinSymbol = true, | ||
| }); | ||
|
|
||
| /// The asset ID to fetch pricing for | ||
| final AssetId assetId; | ||
|
|
||
| /// The crypto amount to display | ||
| final Decimal amount; | ||
|
|
||
| /// Text style for the main amount | ||
| final TextStyle? style; | ||
|
|
||
| /// Whether the text should be selectable | ||
| final bool isSelectable; | ||
|
|
||
| /// Whether to enable auto-scrolling for long text | ||
| final bool isAutoScrollEnabled; | ||
|
|
||
| /// Whether to append the coin symbol to the amount | ||
| final bool showCoinSymbol; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| final sdk = context.sdk; | ||
| final price = sdk.marketData.priceIfKnown(assetId); | ||
|
|
||
| String displayText = amount.toString(); | ||
| if (showCoinSymbol) { | ||
| displayText = '$displayText ${assetId.id}'; | ||
| } | ||
|
|
||
| // If no price available, just show the amount | ||
| final formattedFiat = price != null | ||
| ? ' (${formatUsdValue((price * amount).toDouble())})' | ||
| : ''; | ||
|
|
||
| final fullText = '$displayText$formattedFiat'; | ||
|
|
||
| if (isAutoScrollEnabled) { | ||
| return AutoScrollText( | ||
| text: fullText, | ||
| style: style, | ||
| isSelectable: isSelectable, | ||
| textAlign: TextAlign.right, | ||
| ); | ||
| } | ||
|
|
||
| return isSelectable | ||
| ? SelectableText(fullText, style: style, textAlign: TextAlign.right) | ||
| : Text(fullText, style: style, textAlign: TextAlign.right); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: make it clear that the fiat value isn't passable and is automatically calculated from the SDK.