import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/services.dart'; import 'package:gecko/globals.dart'; import 'package:flutter/material.dart'; import 'package:gecko/providers/my_wallets.dart'; import 'package:gecko/providers/substrate_sdk.dart'; import 'package:gecko/providers/wallets_profiles.dart'; import 'package:provider/provider.dart'; // import 'package:gecko/models/home.dart'; // import 'package:provider/provider.dart'; // ignore: must_be_immutable class TransactionInProgress extends StatelessWidget { const TransactionInProgress({Key? key, this.transType = 'pay'}) : super(key: key); final String transType; @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); SubstrateSdk _sub = Provider.of(context, listen: true); WalletsProfilesProvider _walletViewProvider = Provider.of(context, listen: false); MyWalletsProvider _myWalletProvider = Provider.of(context, listen: false); bool isValid = false; String _resultText; bool isLoading = true; // Map jsonResult; final _result = _sub.transactionStatus; log.d(_walletViewProvider.address!); final from = _myWalletProvider.getDefaultWallet().name!; final to = getShortPubkey(_walletViewProvider.address!); final amount = _walletViewProvider.payAmount.text; String _actionName = ''; switch (transType) { case 'pay': { _actionName = 'transaction'.tr(); } break; case 'cert': { _actionName = 'certification'.tr(); } break; case 'comfirmIdty': { _actionName = "identityConfirm".tr(); } break; case 'revokeIdty': { _actionName = "revokeAdhesion".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); log.d(_result); if (_result.contains('blockHash: ')) { isValid = true; _resultText = 'extrinsicValidated'.tr(args: [_actionName]); } else { isValid = false; _resultText = "anErrorOccured".tr() + ":\n"; final List _exceptionSplit = _result.split('Exception: '); String _exception; if (_exceptionSplit.length > 1) { _exception = _exceptionSplit[1]; } else { _exception = _exceptionSplit[0]; } // log.d('expection: $_exception'); 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( onWillPop: () { _sub.transactionStatus = ''; Navigator.pop(context); if (transType == 'pay') Navigator.pop(context); return Future.value(true); }, child: Scaffold( backgroundColor: backgroundColor, appBar: AppBar( toolbarHeight: 60 * ratio, elevation: 0, automaticallyImplyLeading: false, title: SizedBox( height: 22, child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Text('extrinsicInProgress'.tr(args: [_actionName])) ]), )), body: SafeArea( child: Align( alignment: FractionalOffset.bottomCenter, child: Column(children: [ Container( width: double.infinity, decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [ yellowC, backgroundColor, ], )), child: Column(children: [ const SizedBox(height: 10), if (transType == 'pay') Text( '$amount $currencyName', textAlign: TextAlign.center, style: const TextStyle( fontSize: 18, fontWeight: FontWeight.w600), ), if (transType == 'pay') const SizedBox(height: 10), Text( 'fromMinus'.tr(), textAlign: TextAlign.center, style: const TextStyle(fontSize: 18), ), Text( from, textAlign: TextAlign.center, style: const TextStyle( fontSize: 18, fontWeight: FontWeight.w600), ), const SizedBox(height: 10), Text( 'toMinus'.tr(), textAlign: TextAlign.center, style: const TextStyle(fontSize: 18), ), Text( to, textAlign: TextAlign.center, style: const TextStyle( fontSize: 18, fontWeight: FontWeight.w600), ), const SizedBox(height: 20), ]), ), // const SizedBox(height: 20, width: double.infinity), const Spacer(), Column(children: [ Visibility( visible: isLoading, child: SizedBox( height: 18, width: 18, child: CircularProgressIndicator( color: orangeC, strokeWidth: 2, ), ), ), Visibility( visible: !isLoading, child: Icon( isValid ? Icons.done_all : Icons.close, size: 35, color: isValid ? Colors.greenAccent : Colors.redAccent, ), ), const SizedBox(height: 10), Text( _resultText, textAlign: TextAlign.center, style: TextStyle(fontSize: 19 * ratio), ), ]), const Spacer(), Expanded( child: Align( alignment: Alignment.bottomCenter, child: SizedBox( width: 380 * ratio, height: 60 * ratio, child: ElevatedButton( style: ElevatedButton.styleFrom( elevation: 4, primary: orangeC, // background onPrimary: Colors.white, // foreground ), onPressed: () { Navigator.pop(context); _sub.transactionStatus = ''; if (transType == 'pay') Navigator.pop(context); }, child: Text( 'close'.tr(), style: TextStyle( fontSize: 23 * ratio, fontWeight: FontWeight.w600), ), ), ), ), ), SizedBox(height: isTall ? 80 : 20) ])), ), )); } }