diff --git a/lib/providers/duniter_indexer.dart b/lib/providers/duniter_indexer.dart index 0d95b9b..8224c02 100644 --- a/lib/providers/duniter_indexer.dart +++ b/lib/providers/duniter_indexer.dart @@ -250,6 +250,58 @@ class DuniterIndexer with ChangeNotifier { ); } + Widget balance(BuildContext context, String address, double size, + [Color color = Colors.black, + Color loadingColor = const Color(0xffd07316)]) { + return Column(children: [ + Consumer(builder: (context, sdk, _) { + return FutureBuilder( + future: sdk.getBalance(address), + builder: (BuildContext context, + AsyncSnapshot> globalBalance) { + if (globalBalance.connectionState != ConnectionState.done || + globalBalance.hasError) { + if (balanceCache[address] != null && + balanceCache[address] != -1) { + return Row(children: [ + Text(balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, color: color)), + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); + } else { + return SizedBox( + height: 15, + width: 15, + child: CircularProgressIndicator( + color: loadingColor, + strokeWidth: 2, + ), + ); + } + } + balanceCache[address] = globalBalance.data!['transferableBalance']!; + if (balanceCache[address] != -1) { + return Row(children: [ + Text( + balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, + color: color, + ), + ), + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); + } else { + return const Text(''); + } + }); + }), + ]); +} + Widget searchIdentity(BuildContext context, String name) { // WalletOptionsProvider _walletOptions = // Provider.of(context, listen: false); diff --git a/lib/providers/wallet_options.dart b/lib/providers/wallet_options.dart index ae03268..eeb4bb6 100644 --- a/lib/providers/wallet_options.dart +++ b/lib/providers/wallet_options.dart @@ -507,57 +507,7 @@ class WalletOptionsProvider with ChangeNotifier { Map balanceCache = {}; -Widget balance(BuildContext context, String address, double size, - [Color color = Colors.black, - Color loadingColor = const Color(0xffd07316)]) { - return Column(children: [ - Consumer(builder: (context, sdk, _) { - return FutureBuilder( - future: sdk.getBalance(address), - builder: (BuildContext context, - AsyncSnapshot> globalBalance) { - if (globalBalance.connectionState != ConnectionState.done || - globalBalance.hasError) { - if (balanceCache[address] != null && - balanceCache[address] != -1) { - return Row(children: [ - Text(balanceCache[address]!.toString(), - style: TextStyle( - fontSize: isTall ? size : size * 0.9, color: color)), - const SizedBox(width: 5), - udUnitDisplay(size, color), - ]); - } else { - return SizedBox( - height: 15, - width: 15, - child: CircularProgressIndicator( - color: loadingColor, - strokeWidth: 2, - ), - ); - } - } - balanceCache[address] = globalBalance.data!['transferableBalance']!; - if (balanceCache[address] != -1) { - return Row(children: [ - Text( - balanceCache[address]!.toString(), - style: TextStyle( - fontSize: isTall ? size : size * 0.9, - color: color, - ), - ), - const SizedBox(width: 5), - udUnitDisplay(size, color), - ]); - } else { - return const Text(''); - } - }); - }), - ]); -} + Widget getCerts(BuildContext context, String address, double size, [Color color = Colors.black]) { diff --git a/lib/providers/wallets_profiles.dart b/lib/providers/wallets_profiles.dart index 2d3a71c..f774741 100644 --- a/lib/providers/wallets_profiles.dart +++ b/lib/providers/wallets_profiles.dart @@ -129,6 +129,58 @@ class WalletsProfilesProvider with ChangeNotifier { return _balance; } + Widget balance(BuildContext context, String address, double size, + [Color color = Colors.black, + Color loadingColor = const Color(0xffd07316)]) { + return Column(children: [ + Consumer(builder: (context, sdk, _) { + return FutureBuilder( + future: sdk.getBalance(address), + builder: (BuildContext context, + AsyncSnapshot> globalBalance) { + if (globalBalance.connectionState != ConnectionState.done || + globalBalance.hasError) { + if (balanceCache[address] != null && + balanceCache[address] != -1) { + return Row(children: [ + Text(balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, color: color)), + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); + } else { + return SizedBox( + height: 15, + width: 15, + child: CircularProgressIndicator( + color: loadingColor, + strokeWidth: 2, + ), + ); + } + } + balanceCache[address] = globalBalance.data!['transferableBalance']!; + if (balanceCache[address] != -1) { + return Row(children: [ + Text( + balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, + color: color, + ), + ), + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); + } else { + return const Text(''); + } + }); + }), + ]); +} + Widget headerProfileView( BuildContext context, String address, String? username) { const double avatarSize = 140; diff --git a/lib/screens/myWallets/choose_wallet.dart b/lib/screens/myWallets/choose_wallet.dart index 44a0698..8941ef1 100644 --- a/lib/screens/myWallets/choose_wallet.dart +++ b/lib/screens/myWallets/choose_wallet.dart @@ -211,6 +211,58 @@ class ChooseWalletScreen extends StatelessWidget { ]); } + Widget balance(BuildContext context, String address, double size, + [Color color = Colors.black, + Color loadingColor = const Color(0xffd07316)]) { + return Column(children: [ + Consumer(builder: (context, sdk, _) { + return FutureBuilder( + future: sdk.getBalance(address), + builder: (BuildContext context, + AsyncSnapshot> globalBalance) { + if (globalBalance.connectionState != ConnectionState.done || + globalBalance.hasError) { + if (balanceCache[address] != null && + balanceCache[address] != -1) { + return Row(children: [ + Text(balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, color: color)), + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); + } else { + return SizedBox( + height: 15, + width: 15, + child: CircularProgressIndicator( + color: loadingColor, + strokeWidth: 2, + ), + ); + } + } + balanceCache[address] = globalBalance.data!['transferableBalance']!; + if (balanceCache[address] != -1) { + return Row(children: [ + Text( + balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, + color: color, + ), + ), + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); + } else { + return const Text(''); + } + }); + }), + ]); +} + Widget balanceBuilder(context, String address, bool isDefault) { return Container( width: double.infinity, diff --git a/lib/screens/myWallets/wallet_options.dart b/lib/screens/myWallets/wallet_options.dart index 74dd524..7f1f6a5 100644 --- a/lib/screens/myWallets/wallet_options.dart +++ b/lib/screens/myWallets/wallet_options.dart @@ -574,4 +574,58 @@ class WalletOptions extends StatelessWidget { ); }); } + +Widget balance(BuildContext context, String address, double size, + [Color color = Colors.black, + Color loadingColor = const Color(0xffd07316)]) { + return Column(children: [ + Consumer(builder: (context, sdk, _) { + return FutureBuilder( + future: sdk.getBalance(address), + builder: (BuildContext context, + AsyncSnapshot> globalBalance) { + if (globalBalance.connectionState != ConnectionState.done || + globalBalance.hasError) { + if (balanceCache[address] != null && + balanceCache[address] != -1) { + return Row(children: [ + Text(balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, color: color)), + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); + } else { + return SizedBox( + height: 15, + width: 15, + child: CircularProgressIndicator( + color: loadingColor, + strokeWidth: 2, + ), + ); + } + } + balanceCache[address] = globalBalance.data!['transferableBalance']!; + if (balanceCache[address] != -1) { + return Row(children: [ + Text( + balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, + color: color, + ), + ), + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); + } else { + return const Text(''); + } + }); + }), + ]); +} + + } diff --git a/lib/screens/myWallets/wallets_home.dart b/lib/screens/myWallets/wallets_home.dart index 6c0fa86..7766e1f 100644 --- a/lib/screens/myWallets/wallets_home.dart +++ b/lib/screens/myWallets/wallets_home.dart @@ -373,6 +373,58 @@ class WalletsHome extends StatelessWidget { ]); } +Widget balance(BuildContext context, String address, double size, + [Color color = Colors.black, + Color loadingColor = const Color(0xffd07316)]) { + return Column(children: [ + Consumer(builder: (context, sdk, _) { + return FutureBuilder( + future: sdk.getBalance(address), + builder: (BuildContext context, + AsyncSnapshot> globalBalance) { + if (globalBalance.connectionState != ConnectionState.done || + globalBalance.hasError) { + if (balanceCache[address] != null && + balanceCache[address] != -1) { + return Row(children: [ + Text(balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, color: color)), + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); + } else { + return SizedBox( + height: 15, + width: 15, + child: CircularProgressIndicator( + color: loadingColor, + strokeWidth: 2, + ), + ); + } + } + balanceCache[address] = globalBalance.data!['transferableBalance']!; + if (balanceCache[address] != -1) { + return Row(children: [ + Text( + balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, + color: color, + ), + ), + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); + } else { + return const Text(''); + } + }); + }), + ]); +} + Widget balanceBuilder(context, String address, bool isDefault) { return Container( width: double.infinity, diff --git a/lib/screens/my_contacts.dart b/lib/screens/my_contacts.dart index 1ec6e09..d2625b8 100644 --- a/lib/screens/my_contacts.dart +++ b/lib/screens/my_contacts.dart @@ -40,6 +40,58 @@ class ContactsScreen extends StatelessWidget { p2.username?.toLowerCase() ?? 'zz'); }); + Widget balance(BuildContext context, String address, double size, + [Color color = Colors.black, + Color loadingColor = const Color(0xffd07316)]) { + return Column(children: [ + Consumer(builder: (context, sdk, _) { + return FutureBuilder( + future: sdk.getBalance(address), + builder: (BuildContext context, + AsyncSnapshot> globalBalance) { + if (globalBalance.connectionState != ConnectionState.done || + globalBalance.hasError) { + if (balanceCache[address] != null && + balanceCache[address] != -1) { + return Row(children: [ + Text(balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, color: color)), + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); + } else { + return SizedBox( + height: 15, + width: 15, + child: CircularProgressIndicator( + color: loadingColor, + strokeWidth: 2, + ), + ); + } + } + balanceCache[address] = globalBalance.data!['transferableBalance']!; + if (balanceCache[address] != -1) { + return Row(children: [ + Text( + balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, + color: color, + ), + ), + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); + } else { + return const Text(''); + } + }); + }), + ]); +} + return Scaffold( backgroundColor: backgroundColor, appBar: AppBar( diff --git a/lib/screens/search_result.dart b/lib/screens/search_result.dart index 44b47ce..5ac9a68 100644 --- a/lib/screens/search_result.dart +++ b/lib/screens/search_result.dart @@ -18,6 +18,58 @@ import 'package:provider/provider.dart'; class SearchResultScreen extends StatelessWidget { const SearchResultScreen({Key? key}) : super(key: key); +Widget balance(BuildContext context, String address, double size, + [Color color = Colors.black, + Color loadingColor = const Color(0xffd07316)]) { + return Column(children: [ + Consumer(builder: (context, sdk, _) { + return FutureBuilder( + future: sdk.getBalance(address), + builder: (BuildContext context, + AsyncSnapshot> globalBalance) { + if (globalBalance.connectionState != ConnectionState.done || + globalBalance.hasError) { + if (balanceCache[address] != null && + balanceCache[address] != -1) { + return Row(children: [ + Text(balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, color: color)), + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); + } else { + return SizedBox( + height: 15, + width: 15, + child: CircularProgressIndicator( + color: loadingColor, + strokeWidth: 2, + ), + ); + } + } + balanceCache[address] = globalBalance.data!['transferableBalance']!; + if (balanceCache[address] != -1) { + return Row(children: [ + Text( + balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, + color: color, + ), + ), + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); + } else { + return const Text(''); + } + }); + }), + ]); +} + @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); diff --git a/lib/screens/wallet_view.dart b/lib/screens/wallet_view.dart index 9171b58..4c4efcf 100644 --- a/lib/screens/wallet_view.dart +++ b/lib/screens/wallet_view.dart @@ -360,6 +360,8 @@ class WalletViewScreen extends StatelessWidget { )); } + + Widget waitToCert(String status, String duration) { return Column(children: [ SizedBox( @@ -440,6 +442,58 @@ void paymentPopup(BuildContext context, String toAddress) { } } + Widget balance(BuildContext context, String address, double size, + [Color color = Colors.black, + Color loadingColor = const Color(0xffd07316)]) { + return Column(children: [ + Consumer(builder: (context, sdk, _) { + return FutureBuilder( + future: sdk.getBalance(address), + builder: (BuildContext context, + AsyncSnapshot> globalBalance) { + if (globalBalance.connectionState != ConnectionState.done || + globalBalance.hasError) { + if (balanceCache[address] != null && + balanceCache[address] != -1) { + return Row(children: [ + Text(balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, color: color)), + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); + } else { + return SizedBox( + height: 15, + width: 15, + child: CircularProgressIndicator( + color: loadingColor, + strokeWidth: 2, + ), + ); + } + } + balanceCache[address] = globalBalance.data!['transferableBalance']!; + if (balanceCache[address] != -1) { + return Row(children: [ + Text( + balanceCache[address]!.toString(), + style: TextStyle( + fontSize: isTall ? size : size * 0.9, + color: color, + ), + ), + const SizedBox(width: 5), + udUnitDisplay(size, color), + ]); + } else { + return const Text(''); + } + }); + }), + ]); +} + showModalBottomSheet( shape: const RoundedRectangleBorder( borderRadius: BorderRadius.only( @@ -684,4 +738,6 @@ void paymentPopup(BuildContext context, String toAddress) { ); }); }).then((value) => walletViewProvider.payAmount.text = ''); + + }