refacto: replace huge switch cases by 2 maps in screen transaction_in_proggress
This commit is contained in:
parent
4614f81dac
commit
db5358ace8
|
@ -226,5 +226,6 @@
|
||||||
"feesExplanationDetails": "These fees are transferred to the common treasury account.",
|
"feesExplanationDetails": "These fees are transferred to the common treasury account.",
|
||||||
"gotit": "Got it",
|
"gotit": "Got it",
|
||||||
"moreInfo": "More information",
|
"moreInfo": "More information",
|
||||||
"keepThisPaperSafe": "Keep this sheet safe from prying lizards.\nIt will allow you to restore all your wallets at any time."
|
"keepThisPaperSafe": "Keep this sheet safe from prying lizards.\nIt will allow you to restore all your wallets at any time.",
|
||||||
|
"fundsUnavailable": "Insufficient funds"
|
||||||
}
|
}
|
|
@ -227,5 +227,6 @@
|
||||||
"feesExplanationDetails": "These fees are transferred to the common treasury account.",
|
"feesExplanationDetails": "These fees are transferred to the common treasury account.",
|
||||||
"gotit": "Got it",
|
"gotit": "Got it",
|
||||||
"moreInfo": "More information",
|
"moreInfo": "More information",
|
||||||
"keepThisPaperSafe": "Keep this sheet safe from prying lizards.\nIt will allow you to restore all your wallets at any time."
|
"keepThisPaperSafe": "Keep this sheet safe from prying lizards.\nIt will allow you to restore all your wallets at any time.",
|
||||||
|
"fundsUnavailable": "Insufficient funds"
|
||||||
}
|
}
|
|
@ -226,5 +226,6 @@
|
||||||
"feesExplanationDetails": "Ces frais sont transférés vers le compte de trésorerie commune.",
|
"feesExplanationDetails": "Ces frais sont transférés vers le compte de trésorerie commune.",
|
||||||
"gotit": "J'ai compris",
|
"gotit": "J'ai compris",
|
||||||
"moreInfo": "Plus d'info",
|
"moreInfo": "Plus d'info",
|
||||||
"keepThisPaperSafe": "Gardez cette feuille précieusement, à l’abri des lézards indiscrets.\nElle vous permettra de restaurer tous vos portefeuilles à tout moment."
|
"keepThisPaperSafe": "Gardez cette feuille précieusement, à l’abri des lézards indiscrets.\nElle vous permettra de restaurer tous vos portefeuilles à tout moment.",
|
||||||
|
"fundsUnavailable": "Fonds insuffisants"
|
||||||
}
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
|
||||||
import 'package:gecko/globals.dart';
|
import 'package:gecko/globals.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:gecko/models/widgets_keys.dart';
|
import 'package:gecko/models/widgets_keys.dart';
|
||||||
|
@ -7,8 +6,6 @@ import 'package:gecko/providers/my_wallets.dart';
|
||||||
import 'package:gecko/providers/substrate_sdk.dart';
|
import 'package:gecko/providers/substrate_sdk.dart';
|
||||||
import 'package:gecko/providers/wallets_profiles.dart';
|
import 'package:gecko/providers/wallets_profiles.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
// import 'package:gecko/models/home.dart';
|
|
||||||
// import 'package:provider/provider.dart';
|
|
||||||
|
|
||||||
class TransactionInProgress extends StatelessWidget {
|
class TransactionInProgress extends StatelessWidget {
|
||||||
const TransactionInProgress(
|
const TransactionInProgress(
|
||||||
|
@ -32,12 +29,9 @@ class TransactionInProgress extends StatelessWidget {
|
||||||
Provider.of<MyWalletsProvider>(context, listen: false);
|
Provider.of<MyWalletsProvider>(context, listen: false);
|
||||||
bool isValid = false;
|
bool isValid = false;
|
||||||
|
|
||||||
String resultText;
|
|
||||||
bool isLoading = true;
|
bool isLoading = true;
|
||||||
final result = sub.transactionStatus;
|
final result = sub.transactionStatus;
|
||||||
|
|
||||||
log.d(walletProfiles.address);
|
|
||||||
|
|
||||||
final from = fromAddress ??
|
final from = fromAddress ??
|
||||||
g1WalletsBox
|
g1WalletsBox
|
||||||
.get(myWalletProvider.getDefaultWallet().address)
|
.get(myWalletProvider.getDefaultWallet().address)
|
||||||
|
@ -48,121 +42,55 @@ class TransactionInProgress extends StatelessWidget {
|
||||||
myWalletProvider.getWalletDataByAddress(to)?.name ?? getShortPubkey(to);
|
myWalletProvider.getWalletDataByAddress(to)?.name ?? getShortPubkey(to);
|
||||||
|
|
||||||
final amount = walletProfiles.payAmount.text;
|
final amount = walletProfiles.payAmount.text;
|
||||||
String actionName = '';
|
|
||||||
final bool isUdUnit = configBox.get('isUdUnit') ?? false;
|
final bool isUdUnit = configBox.get('isUdUnit') ?? false;
|
||||||
|
|
||||||
log.d("$transType :: $actionName :: $result");
|
final Map<String, String> actionMap = {
|
||||||
|
'pay': 'transaction'.tr(),
|
||||||
|
'cert': 'certification'.tr(),
|
||||||
|
'comfirmIdty': 'identityConfirm'.tr(),
|
||||||
|
'revokeIdty': 'revokeAdhesion'.tr(),
|
||||||
|
'identityMigration': 'identityMigration'.tr(),
|
||||||
|
};
|
||||||
|
String resultText = '';
|
||||||
|
final Map<String, String> resultMap = {
|
||||||
|
'': 'sending'.tr(),
|
||||||
|
'Ready': 'propagating'.tr(),
|
||||||
|
'Broadcast': 'validating'.tr(),
|
||||||
|
'cert.NotRespectCertPeriod': '24hbetweenCerts'.tr(),
|
||||||
|
'identity.CreatorNotAllowedToCreateIdty': '24hbetweenCerts'.tr(),
|
||||||
|
'cert.CannotCertifySelf': 'canNotCertifySelf'.tr(),
|
||||||
|
'identity.IdtyNameAlreadyExist': 'nameAlreadyExist'.tr(),
|
||||||
|
'balances.KeepAlive': '2GDtoKeepAlive'.tr(),
|
||||||
|
'1010: Invalid Transaction: Inability to pay some fees , e.g. account balance too low':
|
||||||
|
'youHaveToFeedThisAccountBeforeUsing'.tr(),
|
||||||
|
'Token.FundsUnavailable': 'fundsUnavailable'.tr(),
|
||||||
|
'timeout': 'execTimeoutOver'.tr(),
|
||||||
|
};
|
||||||
|
|
||||||
switch (transType) {
|
if (result.contains('blockHash: ')) {
|
||||||
case 'pay':
|
isLoading = false;
|
||||||
{
|
isValid = true;
|
||||||
actionName = 'transaction'.tr();
|
resultText = 'extrinsicValidated'
|
||||||
}
|
.tr(args: [actionMap[transType] ?? 'strangeTransaction'.tr()]);
|
||||||
break;
|
log.i('Bloc of last transaction: ${sub.blocNumber} --- $result');
|
||||||
case 'cert':
|
} else if (result.contains('Exception: ')) {
|
||||||
{
|
isLoading = false;
|
||||||
actionName = 'certification'.tr();
|
isValid = false;
|
||||||
}
|
resultText = "${"anErrorOccurred".tr()}:\n";
|
||||||
break;
|
final List exceptionSplit = result.split('Exception: ');
|
||||||
case 'comfirmIdty':
|
String exception;
|
||||||
{
|
if (exceptionSplit.length > 1) {
|
||||||
actionName = "identityConfirm".tr();
|
exception = exceptionSplit[1];
|
||||||
}
|
} else {
|
||||||
break;
|
exception = exceptionSplit[0];
|
||||||
case 'revokeIdty':
|
}
|
||||||
{
|
resultText = resultMap[exception] ?? "$resultText\n$exception";
|
||||||
actionName = "revokeAdhesion".tr();
|
log.d('expection: $exceptionSplit');
|
||||||
}
|
} else {
|
||||||
break;
|
resultText = resultMap[result] ?? 'unknown status...';
|
||||||
case 'identityMigration':
|
|
||||||
{
|
|
||||||
actionName = "identityMigration".tr();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
actionName = 'strangeTransaction'.tr();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (result) {
|
log.d("$transType :: ${actionMap[transType]} :: $result");
|
||||||
case '':
|
|
||||||
{
|
|
||||||
resultText = 'sending'.tr();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'Ready':
|
|
||||||
{
|
|
||||||
resultText = 'propagating'.tr();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'Broadcast':
|
|
||||||
{
|
|
||||||
resultText = 'validating'.tr();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
isLoading = false;
|
|
||||||
// jsonResult = json.decode(_result);
|
|
||||||
if (result.contains('blockHash: ')) {
|
|
||||||
isValid = true;
|
|
||||||
resultText = 'extrinsicValidated'.tr(args: [actionName]);
|
|
||||||
log.i(
|
|
||||||
'g1migration Bloc of last transaction: ${sub.blocNumber} --- $result');
|
|
||||||
} else {
|
|
||||||
isValid = false;
|
|
||||||
resultText = "${"anErrorOccurred".tr()}:\n";
|
|
||||||
final List exceptionSplit = result.split('Exception: ');
|
|
||||||
String exception;
|
|
||||||
if (exceptionSplit.length > 1) {
|
|
||||||
exception = exceptionSplit[1];
|
|
||||||
} else {
|
|
||||||
exception = exceptionSplit[0];
|
|
||||||
}
|
|
||||||
log.d('expection: $exceptionSplit');
|
|
||||||
switch (exception) {
|
|
||||||
case 'cert.NotRespectCertPeriod':
|
|
||||||
case 'identity.CreatorNotAllowedToCreateIdty':
|
|
||||||
{
|
|
||||||
resultText = "24hbetweenCerts".tr();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'cert.CannotCertifySelf':
|
|
||||||
{
|
|
||||||
resultText = "canNotCertifySelf".tr();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'identity.IdtyNameAlreadyExist':
|
|
||||||
{
|
|
||||||
resultText = "nameAlreadyExist".tr();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'balances.KeepAlive':
|
|
||||||
{
|
|
||||||
resultText = "2GDtoKeepAlive".tr();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case '1010: Invalid Transaction: Inability to pay some fees , e.g. account balance too low':
|
|
||||||
{
|
|
||||||
resultText = "youHaveToFeedThisAccountBeforeUsing".tr();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'timeout':
|
|
||||||
{
|
|
||||||
resultText += "execTimeoutOver".tr();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
resultText += "\n$exception";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return WillPopScope(
|
return WillPopScope(
|
||||||
onWillPop: () {
|
onWillPop: () {
|
||||||
|
@ -184,7 +112,9 @@ class TransactionInProgress extends StatelessWidget {
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text('extrinsicInProgress'.tr(args: [actionName]))
|
Text('extrinsicInProgress'.tr(args: [
|
||||||
|
actionMap[transType] ?? 'strangeTransaction'.tr()
|
||||||
|
]))
|
||||||
]),
|
]),
|
||||||
)),
|
)),
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
|
|
Loading…
Reference in New Issue