Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
24 changes: 5 additions & 19 deletions lib/shared/widgets/coin_balance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,15 @@ import 'package:web_dex/shared/widgets/coin_fiat_balance.dart';
// TODO! Integrate this widget directly to the SDK and make it subscribe to
// the balance changes of the coin.
class CoinBalance extends StatelessWidget {
const CoinBalance({
super.key,
required this.coin,
this.isVertical = false,
});
const CoinBalance({super.key, required this.coin, this.isVertical = false});

final Coin coin;
final bool isVertical;

@override
Widget build(BuildContext context) {
final baseFont = Theme.of(context).textTheme.bodySmall;
final balanceStyle = baseFont?.copyWith(
fontWeight: FontWeight.w500,
);
final balanceStyle = baseFont?.copyWith(fontWeight: FontWeight.w500);

final balance =
context.sdk.balances.lastKnown(coin.id)?.spendable.toDouble() ?? 0.0;
Expand All @@ -38,23 +32,15 @@ class CoinBalance extends StatelessWidget {
textAlign: TextAlign.right,
),
),
Text(
' ${Coin.normalizeAbbr(coin.abbr)}',
style: balanceStyle,
),
Text(' ${Coin.normalizeAbbr(coin.abbr)}', style: balanceStyle),
],
),
ConstrainedBox(
constraints: const BoxConstraints(
maxWidth: 100,
),
constraints: const BoxConstraints(maxWidth: 100),
child: Row(
children: [
Text(' (', style: balanceStyle),
CoinFiatBalance(
coin,
isAutoScrollEnabled: true,
),
CoinFiatBalance(coin, isAutoScrollEnabled: true),
Text(')', style: balanceStyle),
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import 'package:web_dex/common/screen.dart';
import 'package:web_dex/generated/codegen_loader.g.dart';
import 'package:web_dex/model/coin.dart';
import 'package:web_dex/shared/utils/utils.dart';
import 'package:web_dex/shared/utils/formatters.dart';
import 'package:web_dex/shared/utils/extensions/legacy_coin_migration_extensions.dart';
import 'package:web_dex/shared/widgets/coin_type_tag.dart';
import 'package:web_dex/shared/widgets/truncate_middle_text.dart';
import 'package:web_dex/views/wallet/coin_details/coin_page_type.dart';
Expand Down Expand Up @@ -243,7 +245,6 @@ class AddressCard extends StatelessWidget {
),
const SizedBox(height: 12),
_Balance(address: address, coin: coin),
const SizedBox(height: 4),
],
)
: SizedBox(
Expand Down Expand Up @@ -286,9 +287,13 @@ class _Balance extends StatelessWidget {

@override
Widget build(BuildContext context) {
final balance = address.balance.total.toDouble();
final price = coin.lastKnownUsdPrice(context.sdk);
final usdValue = price == null ? null : price * balance;
final fiat = formatUsdValue(usdValue);
Comment on lines +289 to +292

@CharlVS CharlVS Aug 5, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Consider using a stream-based approach so that we're resilient to edge cases where the user is on the page before the prices are loaded or if they have a momentary dip in their connection.

I generally avoid using stream builders because they clutter up the UI and suggest that the state is modelled correctly incorrectly, but all fiat-display UI code is going to be overhauled in the near future when we add the UX enhancement for multiple fiat currency options.

EDIT: strike out and replace a word which changes the meaning of the entire comment (@smk762 @takenagain)


return Text(
'${doubleToString(address.balance.total.toDouble())} '
'${abbr2Ticker(coin.abbr)} (${address.balance.total.toDouble()})',
'${doubleToString(balance)} ${abbr2Ticker(coin.abbr)} ($fiat)',
style: TextStyle(fontSize: isMobile ? 12 : 14),
);
}
Expand Down
Loading