Skip to content

Commit 9a2e215

Browse files
committed
add balance with wallet name in dropdown
1 parent a1d3ca2 commit 9a2e215

2 files changed

Lines changed: 35 additions & 8 deletions

File tree

app/lib/services/tfchain_service.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Future<Map<String, List<Proposal>>> getProposals() async {
107107
return proposals;
108108
} catch (e) {
109109
throw Exception('Failed to get DAO proposals due to $e');
110-
} finally{
110+
} finally {
111111
if (proposals != null) {
112112
await client.disconnect();
113113
}
@@ -324,3 +324,16 @@ Future<Votes> getCouncilProposalVotes(String chainUrl, String hash) async {
324324
await client.disconnect();
325325
}
326326
}
327+
328+
Future<int> getTFTPrice(String chainUrl) async {
329+
final client = TFChain.QueryClient(chainUrl);
330+
try {
331+
await client.connect();
332+
final price = await client.price.get();
333+
return price;
334+
} catch (e) {
335+
throw Exception('Failed to get TFT price due to $e');
336+
} finally {
337+
await client.disconnect();
338+
}
339+
}

app/lib/widgets/wallets/activate_wallet.dart

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:threebotlogin/models/wallet.dart';
77
import 'package:threebotlogin/providers/wallets_provider.dart';
88
import 'package:threebotlogin/services/stellar_service.dart' as StellarService;
99
import 'package:threebotlogin/widgets/custom_dialog.dart';
10+
import 'package:threebotlogin/services/tfchain_service.dart' as TFChainService;
1011

1112
class ActivateWalletWidget extends ConsumerStatefulWidget {
1213
const ActivateWalletWidget({super.key, required this.wallet});
@@ -50,9 +51,10 @@ class _ActivateWalletWidgetState extends ConsumerState<ActivateWalletWidget> {
5051
}
5152
} catch (e) {
5253
logger.e('Failed to load TFT price: $e');
54+
final price = await TFChainService.getTFTPrice(Globals().chainUrl) * 0.5;
5355
if (mounted) {
5456
setState(() {
55-
tftPrice = 0;
57+
tftPrice = price.ceil();
5658
isLoadingPrice = false;
5759
});
5860
}
@@ -67,11 +69,24 @@ class _ActivateWalletWidgetState extends ConsumerState<ActivateWalletWidget> {
6769
.map((wallet) {
6870
return DropdownMenuEntry<Wallet>(
6971
value: wallet,
70-
label: wallet.name,
71-
labelWidget: Text(wallet.name,
72-
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
73-
color: Theme.of(context).colorScheme.onSurface,
74-
)),
72+
label: "${wallet.name} (${wallet.stellarBalance} TFT)",
73+
labelWidget: Row(
74+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
75+
children: [
76+
Text(
77+
wallet.name,
78+
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
79+
color: Theme.of(context).colorScheme.onSurface,
80+
),
81+
),
82+
Text(
83+
"${wallet.stellarBalance} TFT",
84+
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
85+
color: Theme.of(context).colorScheme.onSurfaceVariant,
86+
),
87+
),
88+
],
89+
),
7590
);
7691
}).toList();
7792
}
@@ -133,7 +148,6 @@ class _ActivateWalletWidgetState extends ConsumerState<ActivateWalletWidget> {
133148
),
134149
);
135150
walletRef.reloadBalances();
136-
widget.wallet.stellarBalance = '0';
137151
Navigator.pop(context);
138152
} else {
139153
logger.e('Failed to activate wallet');

0 commit comments

Comments
 (0)