Skip to content
Snippets Groups Projects
Commit db5358ac authored by poka's avatar poka
Browse files

refacto: replace huge switch cases by 2 maps in screen transaction_in_proggress

parent 4614f81d
No related branches found
No related tags found
No related merge requests found
Pipeline #34430 waiting for manual action
...@@ -226,5 +226,6 @@ ...@@ -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"
} }
\ No newline at end of file
...@@ -227,5 +227,6 @@ ...@@ -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"
} }
\ No newline at end of file
...@@ -226,5 +226,6 @@ ...@@ -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"
} }
\ No newline at end of file
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'; ...@@ -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 { ...@@ -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,69 +42,39 @@ class TransactionInProgress extends StatelessWidget { ...@@ -48,69 +42,39 @@ 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(),
switch (transType) { 'cert': 'certification'.tr(),
case 'pay': 'comfirmIdty': 'identityConfirm'.tr(),
{ 'revokeIdty': 'revokeAdhesion'.tr(),
actionName = 'transaction'.tr(); 'identityMigration': 'identityMigration'.tr(),
} };
break; String resultText = '';
case 'cert': final Map<String, String> resultMap = {
{ '': 'sending'.tr(),
actionName = 'certification'.tr(); 'Ready': 'propagating'.tr(),
} 'Broadcast': 'validating'.tr(),
break; 'cert.NotRespectCertPeriod': '24hbetweenCerts'.tr(),
case 'comfirmIdty': 'identity.CreatorNotAllowedToCreateIdty': '24hbetweenCerts'.tr(),
{ 'cert.CannotCertifySelf': 'canNotCertifySelf'.tr(),
actionName = "identityConfirm".tr(); 'identity.IdtyNameAlreadyExist': 'nameAlreadyExist'.tr(),
} 'balances.KeepAlive': '2GDtoKeepAlive'.tr(),
break; '1010: Invalid Transaction: Inability to pay some fees , e.g. account balance too low':
case 'revokeIdty': 'youHaveToFeedThisAccountBeforeUsing'.tr(),
{ 'Token.FundsUnavailable': 'fundsUnavailable'.tr(),
actionName = "revokeAdhesion".tr(); 'timeout': 'execTimeoutOver'.tr(),
} };
break;
case 'identityMigration':
{
actionName = "identityMigration".tr();
}
break;
default:
{
actionName = 'strangeTransaction'.tr();
}
}
switch (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: ')) { if (result.contains('blockHash: ')) {
isLoading = false;
isValid = true; isValid = true;
resultText = 'extrinsicValidated'.tr(args: [actionName]); resultText = 'extrinsicValidated'
log.i( .tr(args: [actionMap[transType] ?? 'strangeTransaction'.tr()]);
'g1migration Bloc of last transaction: ${sub.blocNumber} --- $result'); log.i('Bloc of last transaction: ${sub.blocNumber} --- $result');
} else { } else if (result.contains('Exception: ')) {
isLoading = false;
isValid = false; isValid = false;
resultText = "${"anErrorOccurred".tr()}:\n"; resultText = "${"anErrorOccurred".tr()}:\n";
final List exceptionSplit = result.split('Exception: '); final List exceptionSplit = result.split('Exception: ');
...@@ -120,49 +84,13 @@ class TransactionInProgress extends StatelessWidget { ...@@ -120,49 +84,13 @@ class TransactionInProgress extends StatelessWidget {
} else { } else {
exception = exceptionSplit[0]; exception = exceptionSplit[0];
} }
resultText = resultMap[exception] ?? "$resultText\n$exception";
log.d('expection: $exceptionSplit'); log.d('expection: $exceptionSplit');
switch (exception) { } else {
case 'cert.NotRespectCertPeriod': resultText = resultMap[result] ?? 'unknown status...';
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': log.d("$transType :: ${actionMap[transType]} :: $result");
{
resultText += "execTimeoutOver".tr();
}
break;
default:
{
resultText += "\n$exception";
}
break;
}
}
}
}
return WillPopScope( return WillPopScope(
onWillPop: () { onWillPop: () {
...@@ -184,7 +112,9 @@ class TransactionInProgress extends StatelessWidget { ...@@ -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(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment