fix: don't freeze after screen lock on walletOptions screen, and refactor stuff
This commit is contained in:
parent
b1f9067c36
commit
bfce822b17
|
@ -203,7 +203,7 @@ class DuniterIndexer with ChangeNotifier {
|
|||
'name': name,
|
||||
};
|
||||
final result = await _execQuery(isIdtyExistQ, variables);
|
||||
return result.data!['identity']?.isNotEmpty ?? false;
|
||||
return result.data?['identity']?.isNotEmpty ?? false;
|
||||
}
|
||||
|
||||
Future<DateTime> getBlockStart() async {
|
||||
|
|
|
@ -209,26 +209,27 @@ class SubstrateSdk with ChangeNotifier {
|
|||
await _getStorage('identity.identityIndexOf.multi($jsonString)'));
|
||||
}
|
||||
|
||||
Future<List<int>?> getCertsCounter(String address) async {
|
||||
Future<List<int>> getCertsCounter(String address) async {
|
||||
final idtyIndex = await _getIdentityIndexOf(address);
|
||||
if (idtyIndex == null) {
|
||||
return null;
|
||||
return [];
|
||||
}
|
||||
final certsReceiver =
|
||||
await _getStorage('cert.storageIdtyCertMeta($idtyIndex)') ?? [];
|
||||
|
||||
if (certsCounterCache[address] == null) {
|
||||
certsCounterCache.putIfAbsent(address, () => []);
|
||||
}
|
||||
try {
|
||||
certsCounterCache.update(
|
||||
address,
|
||||
(value) => [
|
||||
certsReceiver['receivedCount'] as int,
|
||||
certsReceiver['issuedCount'] as int
|
||||
],
|
||||
ifAbsent: () => [
|
||||
certsReceiver['receivedCount'] as int,
|
||||
certsReceiver['issuedCount'] as int
|
||||
]);
|
||||
} catch (e) {
|
||||
// catching String to int error .. network error?
|
||||
log.e(e);
|
||||
}
|
||||
return certsCounterCache[address]!;
|
||||
}
|
||||
|
@ -1059,7 +1060,7 @@ class SubstrateSdk with ChangeNotifier {
|
|||
final toCerts = await getCertsCounter(destAddress);
|
||||
|
||||
log.d(
|
||||
"debug toCert: ${toCerts?[0]} --- ${currencyParameters['minCertForMembership']!} --- $toIdtyStatus");
|
||||
"debug toCert: ${toCerts[0]} --- ${currencyParameters['minCertForMembership']!} --- $toIdtyStatus");
|
||||
|
||||
if (toIdtyStatus == IdtyStatus.none) {
|
||||
txInfo = TxInfoData(
|
||||
|
@ -1070,7 +1071,7 @@ class SubstrateSdk with ChangeNotifier {
|
|||
txOptions = [destAddress];
|
||||
} else if (toIdtyStatus == IdtyStatus.validated ||
|
||||
toIdtyStatus == IdtyStatus.confirmed) {
|
||||
if (toCerts![0] >= currencyParameters['minCertForMembership']! - 1 &&
|
||||
if (toCerts[0] >= currencyParameters['minCertForMembership']! - 1 &&
|
||||
toIdtyStatus != IdtyStatus.validated) {
|
||||
log.d('Batch cert and membership validation');
|
||||
txInfo = TxInfoData(
|
||||
|
|
|
@ -327,6 +327,9 @@ class WalletOptions extends StatelessWidget {
|
|||
initialData: const [IdtyStatus.unknown],
|
||||
builder:
|
||||
(BuildContext context, AsyncSnapshot<List<IdtyStatus>> snapshot) {
|
||||
if (!snapshot.hasData || snapshot.hasError) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
if (snapshot.data!.first == IdtyStatus.created) {
|
||||
return Column(children: [
|
||||
ScaledSizedBox(
|
||||
|
@ -526,7 +529,8 @@ class WalletOptions extends StatelessWidget {
|
|||
future: sub.hasAccountConsumers(wallet.address),
|
||||
builder: (BuildContext context, AsyncSnapshot<bool> hasConsumers) {
|
||||
if (hasConsumers.connectionState != ConnectionState.done ||
|
||||
hasConsumers.hasError) {
|
||||
hasConsumers.hasError ||
|
||||
!hasConsumers.hasData) {
|
||||
return const Text('');
|
||||
}
|
||||
final double balance =
|
||||
|
|
|
@ -18,8 +18,6 @@ import 'package:gecko/widgets/commons/offline_info.dart';
|
|||
import 'package:gecko/widgets/commons/top_appbar.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
AsyncSnapshot<List>? mnemoList;
|
||||
|
||||
class OnboardingStepFive extends StatefulWidget {
|
||||
const OnboardingStepFive({Key? key, this.skipIntro = false})
|
||||
: super(key: key);
|
||||
|
@ -155,35 +153,35 @@ Widget sentanceArray(BuildContext context) {
|
|||
padding: EdgeInsets.all(scaleSize(11)),
|
||||
child: FutureBuilder(
|
||||
future: generateWalletProvider.generateWordList(context),
|
||||
builder: (BuildContext context, AsyncSnapshot<List> data) {
|
||||
if (!data.hasData) {
|
||||
builder: (BuildContext context, AsyncSnapshot<List> mnemoListData) {
|
||||
if (!mnemoListData.hasData) {
|
||||
return const Text('');
|
||||
} else {
|
||||
mnemoList = data;
|
||||
final mnemoList = mnemoListData.data!;
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Row(children: <Widget>[
|
||||
arrayCell(data.data![0]),
|
||||
arrayCell(data.data![1]),
|
||||
arrayCell(data.data![2]),
|
||||
arrayCell(data.data![3]),
|
||||
arrayCell(mnemoList[0]),
|
||||
arrayCell(mnemoList[1]),
|
||||
arrayCell(mnemoList[2]),
|
||||
arrayCell(mnemoList[3]),
|
||||
]),
|
||||
ScaledSizedBox(height: 12),
|
||||
Row(children: <Widget>[
|
||||
arrayCell(data.data![4]),
|
||||
arrayCell(data.data![5]),
|
||||
arrayCell(data.data![6]),
|
||||
arrayCell(data.data![7]),
|
||||
arrayCell(mnemoList[4]),
|
||||
arrayCell(mnemoList[5]),
|
||||
arrayCell(mnemoList[6]),
|
||||
arrayCell(mnemoList[7]),
|
||||
]),
|
||||
ScaledSizedBox(height: 12),
|
||||
Row(children: <Widget>[
|
||||
arrayCell(data.data![8]),
|
||||
arrayCell(data.data![9]),
|
||||
arrayCell(data.data![10]),
|
||||
arrayCell(data.data![11]),
|
||||
arrayCell(mnemoList[8]),
|
||||
arrayCell(mnemoList[9]),
|
||||
arrayCell(mnemoList[10]),
|
||||
arrayCell(mnemoList[11]),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class _SearchScreenState extends State<SearchScreen> {
|
|||
|
||||
// Function to check clipboard and update if necessary
|
||||
Future<void> checkAndUpdateClipboard() async {
|
||||
var clipboardData = await Clipboard.getData(Clipboard.kTextPlain);
|
||||
final clipboardData = await Clipboard.getData(Clipboard.kTextPlain);
|
||||
if (clipboardData?.text != null && clipboardData!.text != pastedAddress) {
|
||||
pastedAddress = clipboardData.text ?? '';
|
||||
canPasteAddress = await isAddress(pastedAddress);
|
||||
|
|
|
@ -152,13 +152,14 @@ class WalletViewScreen extends StatelessWidget {
|
|||
future: sub.certState(defaultWallet.address, address),
|
||||
builder: (context, AsyncSnapshot<Map<String, int>> snapshot) {
|
||||
if (snapshot.data == null) return const SizedBox.shrink();
|
||||
final certStateData = snapshot.data!;
|
||||
String duration = '';
|
||||
|
||||
if (snapshot.data!['certDelay'] != null ||
|
||||
snapshot.data!['certRenewable'] != null) {
|
||||
if (certStateData['certDelay'] != null ||
|
||||
certStateData['certRenewable'] != null) {
|
||||
final Duration durationSeconds = Duration(
|
||||
seconds: snapshot.data!['certDelay'] ??
|
||||
snapshot.data!['certRenewable']!);
|
||||
seconds: certStateData['certDelay'] ??
|
||||
certStateData['certRenewable']!);
|
||||
final seconds = durationSeconds.inSeconds;
|
||||
final minutes = durationSeconds.inMinutes;
|
||||
|
||||
|
@ -186,12 +187,12 @@ class WalletViewScreen extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
final toStatus = snapshot.data!['toStatus'];
|
||||
final toStatus = certStateData['toStatus'];
|
||||
|
||||
return Visibility(
|
||||
visible: (snapshot.data != {}),
|
||||
child: Column(children: <Widget>[
|
||||
if (snapshot.data!['canCert'] != null ||
|
||||
if (certStateData['canCert'] != null ||
|
||||
duration == 'seconds'.tr(args: ['0']))
|
||||
Column(children: <Widget>[
|
||||
ScaledSizedBox(
|
||||
|
@ -273,10 +274,10 @@ class WalletViewScreen extends StatelessWidget {
|
|||
])
|
||||
else if (toStatus == 1)
|
||||
waitToCert('mustConfirmHisIdentity', duration)
|
||||
else if (snapshot.data!['certRenewable'] != null &&
|
||||
else if (certStateData['certRenewable'] != null &&
|
||||
duration != 'seconds'.tr(args: ['0']))
|
||||
waitToCert('canRenewCertInX', duration)
|
||||
else if (snapshot.data!['certDelay'] != null)
|
||||
else if (certStateData['certDelay'] != null)
|
||||
waitToCert('mustWaitXBeforeCertify', duration)
|
||||
]),
|
||||
);
|
||||
|
|
|
@ -10,62 +10,57 @@ class Balance extends StatelessWidget {
|
|||
{Key? key,
|
||||
required this.address,
|
||||
required this.size,
|
||||
this.color = Colors.black,
|
||||
this.loadingColor = const Color(0xffd07316)})
|
||||
this.color = Colors.black})
|
||||
: super(key: key);
|
||||
final String address;
|
||||
final double size;
|
||||
final Color color;
|
||||
final Color loadingColor;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final walletOptions =
|
||||
Provider.of<WalletOptionsProvider>(context, listen: false);
|
||||
return Consumer<SubstrateSdk>(builder: (context, sdk, _) {
|
||||
return FutureBuilder(
|
||||
future: sdk.getBalance(address),
|
||||
builder: (BuildContext context,
|
||||
AsyncSnapshot<Map<String, double>> globalBalance) {
|
||||
if (globalBalance.connectionState != ConnectionState.done ||
|
||||
globalBalance.hasError) {
|
||||
if (walletOptions.balanceCache[address] != null &&
|
||||
walletOptions.balanceCache[address] != -1) {
|
||||
return ScaledSizedBox(
|
||||
height: size * 1.4,
|
||||
child: FutureBuilder(
|
||||
future: sdk.getBalance(address),
|
||||
builder: (BuildContext context,
|
||||
AsyncSnapshot<Map<String, double>> globalBalance) {
|
||||
if (globalBalance.connectionState != ConnectionState.done ||
|
||||
globalBalance.hasError ||
|
||||
!globalBalance.hasData) {
|
||||
if (walletOptions.balanceCache[address] != null &&
|
||||
walletOptions.balanceCache[address] != -1) {
|
||||
return Row(children: [
|
||||
Text(walletOptions.balanceCache[address]!.toString(),
|
||||
style: scaledTextStyle(fontSize: size, color: color)),
|
||||
ScaledSizedBox(width: 5),
|
||||
UdUnitDisplay(size: scaleSize(size), color: color),
|
||||
]);
|
||||
} else {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
}
|
||||
walletOptions.balanceCache[address] =
|
||||
globalBalance.data!['transferableBalance']!;
|
||||
if (walletOptions.balanceCache[address] != -1) {
|
||||
return Row(children: [
|
||||
Text(walletOptions.balanceCache[address]!.toString(),
|
||||
style: scaledTextStyle(fontSize: size, color: color)),
|
||||
Text(
|
||||
walletOptions.balanceCache[address]!.toString(),
|
||||
style: scaledTextStyle(
|
||||
fontSize: size,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
ScaledSizedBox(width: 5),
|
||||
UdUnitDisplay(size: scaleSize(size), color: color),
|
||||
]);
|
||||
} else {
|
||||
return ScaledSizedBox(
|
||||
height: 15,
|
||||
width: 15,
|
||||
child: CircularProgressIndicator(
|
||||
color: loadingColor,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
);
|
||||
return const Text('');
|
||||
}
|
||||
}
|
||||
walletOptions.balanceCache[address] =
|
||||
globalBalance.data!['transferableBalance']!;
|
||||
if (walletOptions.balanceCache[address] != -1) {
|
||||
return Row(children: [
|
||||
Text(
|
||||
walletOptions.balanceCache[address]!.toString(),
|
||||
style: scaledTextStyle(
|
||||
fontSize: size,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
ScaledSizedBox(width: 5),
|
||||
UdUnitDisplay(size: scaleSize(size), color: color),
|
||||
]);
|
||||
} else {
|
||||
return const Text('');
|
||||
}
|
||||
});
|
||||
}),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,31 +16,35 @@ class Certifications extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final sub = Provider.of<SubstrateSdk>(context);
|
||||
|
||||
return Column(children: <Widget>[
|
||||
Consumer<SubstrateSdk>(builder: (context, sdk, _) {
|
||||
return FutureBuilder(
|
||||
future: sdk.getCertsCounter(address),
|
||||
builder: (BuildContext context, AsyncSnapshot<List<int>?> certs) {
|
||||
return certs.data != null
|
||||
? Row(
|
||||
children: [
|
||||
Image.asset('assets/medal.png',
|
||||
color: color, height: scaleSize(18)),
|
||||
ScaledSizedBox(width: 1),
|
||||
Text(certs.data?[0].toString() ?? '0',
|
||||
style:
|
||||
scaledTextStyle(fontSize: size, color: color)),
|
||||
ScaledSizedBox(width: 5),
|
||||
Text(
|
||||
"(${certs.data?[1].toString() ?? '0'})",
|
||||
style: scaledTextStyle(
|
||||
fontSize: size * 0.7, color: color),
|
||||
)
|
||||
],
|
||||
)
|
||||
: const SizedBox();
|
||||
});
|
||||
}),
|
||||
FutureBuilder(
|
||||
future: sub.getCertsCounter(address),
|
||||
builder: (BuildContext context, AsyncSnapshot<List<int>?> certs) {
|
||||
if ((certs.data != null && certs.data!.isEmpty) ||
|
||||
sub.certsCounterCache[address] == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final receivedCount = sub.certsCounterCache[address]![0];
|
||||
final sentCount = sub.certsCounterCache[address]![1];
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
Image.asset('assets/medal.png',
|
||||
color: color, height: scaleSize(18)),
|
||||
ScaledSizedBox(width: 1),
|
||||
Text(receivedCount.toString(),
|
||||
style: scaledTextStyle(fontSize: size, color: color)),
|
||||
ScaledSizedBox(width: 5),
|
||||
Text(
|
||||
"($sentCount)",
|
||||
style: scaledTextStyle(fontSize: size * 0.7, color: color),
|
||||
)
|
||||
],
|
||||
);
|
||||
}),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,26 +28,25 @@ class IdentityStatus extends StatelessWidget {
|
|||
future: sub.idtyStatus([address]),
|
||||
initialData: [walletData.identityStatus],
|
||||
builder: (context, AsyncSnapshot<List<IdtyStatus>> snapshot) {
|
||||
if (snapshot.hasError || snapshot.data == null) {
|
||||
log.e(snapshot.error);
|
||||
return const Icon(Icons.close, color: Colors.red);
|
||||
if (snapshot.data != null && !snapshot.hasError) {
|
||||
final resStatus = snapshot.data!.first;
|
||||
walletData.identityStatus = resStatus;
|
||||
walletBox.put(address, walletData);
|
||||
}
|
||||
|
||||
final resStatus = snapshot.data!.first;
|
||||
walletData.identityStatus = resStatus;
|
||||
walletBox.put(address, walletData);
|
||||
final resStatus = walletData.identityStatus;
|
||||
|
||||
if (!isOwner) {
|
||||
if (resStatus == IdtyStatus.confirmed) {
|
||||
return NameByAddress(
|
||||
wallet: WalletData(address: address),
|
||||
wallet: walletData,
|
||||
size: 18,
|
||||
color: Colors.grey[700]!,
|
||||
fontWeight: FontWeight.w500,
|
||||
fontStyle: FontStyle.italic);
|
||||
} else if (resStatus == IdtyStatus.validated) {
|
||||
return NameByAddress(
|
||||
wallet: WalletData(address: address),
|
||||
wallet: walletData,
|
||||
size: 20,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w600,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/globals.dart';
|
||||
import 'package:gecko/models/g1_wallets_list.dart';
|
||||
import 'package:gecko/models/scale_functions.dart';
|
||||
import 'package:gecko/models/wallet_data.dart';
|
||||
|
@ -10,6 +9,7 @@ import 'package:gecko/providers/substrate_sdk.dart';
|
|||
import 'package:gecko/providers/wallets_profiles.dart';
|
||||
import 'package:gecko/screens/wallet_view.dart';
|
||||
import 'package:gecko/widgets/balance.dart';
|
||||
import 'package:gecko/widgets/commons/loading.dart';
|
||||
import 'package:gecko/widgets/datapod_avatar.dart';
|
||||
import 'package:gecko/widgets/name_by_address.dart';
|
||||
import 'package:gecko/widgets/search_identity_query.dart';
|
||||
|
@ -47,11 +47,9 @@ class SearchResult extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
return const Center(
|
||||
heightFactor: 5,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 3,
|
||||
backgroundColor: yellowC,
|
||||
color: orangeC,
|
||||
child: Loading(
|
||||
stroke: 3,
|
||||
size: 30,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
|
|
@ -151,7 +151,7 @@ class BalanceBuilder extends StatelessWidget {
|
|||
address: address,
|
||||
size: 14,
|
||||
color: isDefault ? Colors.white : Colors.black,
|
||||
loadingColor: isDefault ? yellowC : orangeC),
|
||||
),
|
||||
)
|
||||
],
|
||||
)),
|
||||
|
|
|
@ -171,10 +171,10 @@ class BalanceBuilder extends StatelessWidget {
|
|||
Opacity(
|
||||
opacity: 0.7,
|
||||
child: Balance(
|
||||
address: address,
|
||||
size: 15,
|
||||
color: isDefault ? Colors.white : Colors.black,
|
||||
loadingColor: isDefault ? yellowC : orangeC),
|
||||
address: address,
|
||||
size: 15,
|
||||
color: isDefault ? Colors.white : Colors.black,
|
||||
),
|
||||
)
|
||||
],
|
||||
)),
|
||||
|
|
|
@ -5,7 +5,7 @@ description: Pay with G1.
|
|||
# pub.dev using `pub publish`. This is preferred for private packages.
|
||||
publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
||||
|
||||
version: 0.1.4+68
|
||||
version: 0.1.4+71
|
||||
|
||||
environment:
|
||||
sdk: ">=2.12.0 <3.0.0"
|
||||
|
|
Loading…
Reference in New Issue