Compare commits
1 Commits
master
...
subscribes
Author | SHA1 | Date |
---|---|---|
poka | 3096b8f0ed |
|
@ -24,6 +24,7 @@ import 'package:gecko/models/chest_data.dart';
|
|||
import 'package:gecko/providers/chest_provider.dart';
|
||||
import 'package:gecko/models/g1_wallets_list.dart';
|
||||
import 'package:gecko/providers/generate_wallets.dart';
|
||||
import 'package:gecko/providers/subscribe_balances.dart';
|
||||
import 'package:gecko/providers/substrate_sdk.dart';
|
||||
import 'package:gecko/providers/wallets_profiles.dart';
|
||||
import 'package:gecko/providers/home.dart';
|
||||
|
@ -134,7 +135,8 @@ class Gecko extends StatelessWidget {
|
|||
ChangeNotifierProvider(create: (_) => WalletOptionsProvider()),
|
||||
ChangeNotifierProvider(create: (_) => SearchProvider()),
|
||||
ChangeNotifierProvider(create: (_) => CesiumPlusProvider()),
|
||||
ChangeNotifierProvider(create: (_) => SubstrateSdk())
|
||||
ChangeNotifierProvider(create: (_) => SubstrateSdk()),
|
||||
ChangeNotifierProvider(create: (_) => SubscribeBalances())
|
||||
],
|
||||
child: MaterialApp(
|
||||
builder: (context, widget) => ResponsiveWrapper.builder(
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
// ignore_for_file: avoid_print
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/providers/substrate_sdk.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class SubscribeBalances with ChangeNotifier {
|
||||
Map<String, double> balances = {};
|
||||
|
||||
Future<Map<String, double>> getBalance(
|
||||
BuildContext context, String address) async {
|
||||
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
|
||||
// double balance = 0;
|
||||
|
||||
if (_sub.nodeConnected) {
|
||||
await _sub.sdk.api.account.subscribeBalance(
|
||||
address,
|
||||
(p0) {
|
||||
balances.clear();
|
||||
// balances[address] = int.parse(p0.freeBalance) / 100;
|
||||
balances.putIfAbsent(address, () => int.parse(p0.freeBalance) / 100);
|
||||
// balances.update(address, (_) => int.parse(p0.freeBalance) / 100);
|
||||
log.d('tatatatataata : ' + balances.toString());
|
||||
|
||||
notifyListeners();
|
||||
// return balance;
|
||||
},
|
||||
);
|
||||
}
|
||||
log.d(balances);
|
||||
return balances;
|
||||
}
|
||||
|
||||
void reload() {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import 'dart:async';
|
|||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/providers/my_wallets.dart';
|
||||
import 'package:gecko/models/wallet_data.dart';
|
||||
import 'package:gecko/providers/subscribe_balances.dart';
|
||||
import 'package:gecko/providers/substrate_sdk.dart';
|
||||
import 'package:gecko/screens/animated_text.dart';
|
||||
import 'package:gecko/screens/common_elements.dart';
|
||||
|
@ -301,42 +302,55 @@ class WalletOptionsProvider with ChangeNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
Map<String, String> balanceCache = {};
|
||||
Map<String, double> balanceCache = {};
|
||||
|
||||
Widget balance(BuildContext context, String address, double size,
|
||||
[Color _color = Colors.black]) {
|
||||
SubscribeBalances _subBalances =
|
||||
Provider.of<SubscribeBalances>(context, listen: false);
|
||||
|
||||
log.d('Start balance widget: $address');
|
||||
|
||||
return Column(children: <Widget>[
|
||||
Consumer<SubstrateSdk>(builder: (context, _sdk, _) {
|
||||
return FutureBuilder(
|
||||
future: _sdk.getBalance(address),
|
||||
builder: (BuildContext context, AsyncSnapshot<num?> _balance) {
|
||||
if (_balance.connectionState != ConnectionState.done ||
|
||||
_balance.hasError) {
|
||||
if (balanceCache[address] != null) {
|
||||
return Text(balanceCache[address]!,
|
||||
style: TextStyle(
|
||||
fontSize: isTall ? size : size * 0.9, color: _color));
|
||||
} else {
|
||||
return SizedBox(
|
||||
height: 15,
|
||||
width: 15,
|
||||
child: CircularProgressIndicator(
|
||||
color: orangeC,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
);
|
||||
}
|
||||
FutureBuilder(
|
||||
future: _subBalances.getBalance(context, address),
|
||||
builder: (BuildContext context,
|
||||
AsyncSnapshot<Map<String, double>> _balance) {
|
||||
if (_balance.connectionState != ConnectionState.done ||
|
||||
_balance.hasError) {
|
||||
if (balanceCache[address] != null) {
|
||||
log.d('BALANCES: ' + balanceCache[address].toString());
|
||||
return Text(balanceCache[address].toString(),
|
||||
style: TextStyle(
|
||||
fontSize: isTall ? size : size * 0.9, color: _color));
|
||||
} else {
|
||||
return SizedBox(
|
||||
height: 15,
|
||||
width: 15,
|
||||
child: CircularProgressIndicator(
|
||||
color: orangeC,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
balanceCache[address] = _subBalances.balances[address] ?? 0;
|
||||
|
||||
_subBalances.balances.forEach((key, value) {
|
||||
if (key == address) {
|
||||
balanceCache[address] = value;
|
||||
}
|
||||
balanceCache[address] = "${_balance.data.toString()} $currencyName";
|
||||
return Text(
|
||||
balanceCache[address]!,
|
||||
style: TextStyle(
|
||||
fontSize: isTall ? size : size * 0.9,
|
||||
color: _color,
|
||||
),
|
||||
);
|
||||
});
|
||||
}),
|
||||
|
||||
log.d('balanceCache: $balanceCache');
|
||||
return Text(
|
||||
balanceCache[address].toString(),
|
||||
style: TextStyle(
|
||||
fontSize: isTall ? size : size * 0.9,
|
||||
color: _color,
|
||||
),
|
||||
);
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -424,8 +424,7 @@ class WalletViewScreen extends StatelessWidget {
|
|||
builder: (BuildContext context, StateSetter setState) {
|
||||
if (_walletViewProvider.payAmount.text != '' &&
|
||||
double.parse(_walletViewProvider.payAmount.text) <=
|
||||
double.parse(
|
||||
balanceCache[defaultWallet.address]!.split(' ')[0]) &&
|
||||
balanceCache[defaultWallet.address]! &&
|
||||
_walletViewProvider.address != defaultWallet.address) {
|
||||
canValidate = true;
|
||||
} else {
|
||||
|
@ -520,7 +519,7 @@ class WalletViewScreen extends StatelessWidget {
|
|||
future:
|
||||
_sub.getBalance(defaultWallet.address!),
|
||||
builder: (BuildContext context,
|
||||
AsyncSnapshot<num?> _balance) {
|
||||
AsyncSnapshot<double> _balance) {
|
||||
if (_balance.connectionState !=
|
||||
ConnectionState.done ||
|
||||
_balance.hasError) {
|
||||
|
@ -529,7 +528,8 @@ class WalletViewScreen extends StatelessWidget {
|
|||
null) {
|
||||
return Text(
|
||||
balanceCache[
|
||||
defaultWallet.address!]!,
|
||||
defaultWallet.address!]
|
||||
.toString(),
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
));
|
||||
|
@ -545,9 +545,10 @@ class WalletViewScreen extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
balanceCache[defaultWallet.address!] =
|
||||
"${_balance.data.toString()} $currencyName";
|
||||
_balance.data!;
|
||||
return Text(
|
||||
balanceCache[defaultWallet.address!]!,
|
||||
balanceCache[defaultWallet.address]
|
||||
.toString(),
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
),
|
||||
|
@ -689,7 +690,7 @@ class WalletViewScreen extends StatelessWidget {
|
|||
Provider.of<WalletOptionsProvider>(context, listen: false);
|
||||
// SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
|
||||
|
||||
bool isAccountExist = balanceCache[pubkey] != '0.0 $currencyName';
|
||||
bool isAccountExist = balanceCache[pubkey] != 0;
|
||||
|
||||
return Stack(children: <Widget>[
|
||||
Consumer<SubstrateSdk>(builder: (context, _sub, _) {
|
||||
|
@ -736,7 +737,8 @@ class WalletViewScreen extends StatelessWidget {
|
|||
|
||||
balance(context, pubkey!, 22),
|
||||
const SizedBox(height: 10),
|
||||
_walletOptions.idtyStatus(context, pubkey!, isOwner: false, color: Colors.black),
|
||||
_walletOptions.idtyStatus(context, pubkey!,
|
||||
isOwner: false, color: Colors.black),
|
||||
getCerts(context, pubkey!, 14),
|
||||
|
||||
// if (username == null &&
|
||||
|
|
Loading…
Reference in New Issue