2022-06-18 00:48:07 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-05-26 02:19:29 +02:00
|
|
|
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 {
|
2022-05-27 08:54:29 +02:00
|
|
|
const TransactionInProgress({Key? key, this.transType = 'pay'})
|
2022-05-26 02:19:29 +02:00
|
|
|
: super(key: key);
|
2022-05-27 08:54:29 +02:00
|
|
|
final String transType;
|
2022-05-26 02:19:29 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
2022-08-06 02:22:41 +02:00
|
|
|
SubstrateSdk sub = Provider.of<SubstrateSdk>(context, listen: true);
|
|
|
|
WalletsProfilesProvider walletViewProvider =
|
2022-05-26 02:19:29 +02:00
|
|
|
Provider.of<WalletsProfilesProvider>(context, listen: false);
|
2022-08-06 02:22:41 +02:00
|
|
|
MyWalletsProvider myWalletProvider =
|
2022-05-26 02:19:29 +02:00
|
|
|
Provider.of<MyWalletsProvider>(context, listen: false);
|
2022-06-08 02:30:19 +02:00
|
|
|
bool isValid = false;
|
2022-05-26 02:19:29 +02:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
String resultText;
|
2022-05-26 02:19:29 +02:00
|
|
|
bool isLoading = true;
|
|
|
|
// Map jsonResult;
|
2022-08-06 02:22:41 +02:00
|
|
|
final result = sub.transactionStatus;
|
2022-05-26 02:19:29 +02:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
log.d(walletViewProvider.address!);
|
2022-05-27 08:54:29 +02:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
final from = myWalletProvider.getDefaultWallet().name!;
|
|
|
|
final to = getShortPubkey(walletViewProvider.address!);
|
|
|
|
final amount = walletViewProvider.payAmount.text;
|
|
|
|
String actionName = '';
|
2022-05-27 08:54:29 +02:00
|
|
|
|
|
|
|
switch (transType) {
|
|
|
|
case 'pay':
|
|
|
|
{
|
2022-08-06 02:22:41 +02:00
|
|
|
actionName = 'transaction'.tr();
|
2022-05-27 08:54:29 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'cert':
|
|
|
|
{
|
2022-08-06 02:22:41 +02:00
|
|
|
actionName = 'certification'.tr();
|
2022-05-27 08:54:29 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-06-04 23:32:44 +02:00
|
|
|
case 'comfirmIdty':
|
|
|
|
{
|
2022-08-06 02:22:41 +02:00
|
|
|
actionName = "identityConfirm".tr();
|
2022-06-04 23:32:44 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-06-05 19:58:04 +02:00
|
|
|
case 'revokeIdty':
|
|
|
|
{
|
2022-08-06 02:22:41 +02:00
|
|
|
actionName = "revokeAdhesion".tr();
|
2022-06-05 19:58:04 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-05-27 08:54:29 +02:00
|
|
|
default:
|
|
|
|
{
|
2022-08-06 02:22:41 +02:00
|
|
|
actionName = 'strangeTransaction'.tr();
|
2022-05-27 08:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
2022-05-26 02:19:29 +02:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
switch (result) {
|
2022-05-26 02:19:29 +02:00
|
|
|
case '':
|
|
|
|
{
|
2022-08-06 02:22:41 +02:00
|
|
|
resultText = 'sending'.tr();
|
2022-05-26 02:19:29 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-05-30 14:48:12 +02:00
|
|
|
case 'Ready':
|
|
|
|
{
|
2022-08-06 02:22:41 +02:00
|
|
|
resultText = 'propagating'.tr();
|
2022-05-30 14:48:12 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'Broadcast':
|
2022-05-26 02:19:29 +02:00
|
|
|
{
|
2022-08-06 02:22:41 +02:00
|
|
|
resultText = 'validating'.tr();
|
2022-05-26 02:19:29 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
isLoading = false;
|
|
|
|
// jsonResult = json.decode(_result);
|
2022-08-06 02:22:41 +02:00
|
|
|
log.d(result);
|
|
|
|
if (result.contains('blockHash: ')) {
|
2022-06-08 02:30:19 +02:00
|
|
|
isValid = true;
|
2022-08-06 02:22:41 +02:00
|
|
|
resultText = 'extrinsicValidated'.tr(args: [actionName]);
|
2022-05-26 02:19:29 +02:00
|
|
|
} else {
|
2022-06-08 02:30:19 +02:00
|
|
|
isValid = false;
|
2022-08-06 02:22:41 +02:00
|
|
|
resultText = "${"anErrorOccured".tr()}:\n";
|
|
|
|
final List exceptionSplit = result.split('Exception: ');
|
|
|
|
String exception;
|
|
|
|
if (exceptionSplit.length > 1) {
|
|
|
|
exception = exceptionSplit[1];
|
2022-06-04 23:32:44 +02:00
|
|
|
} else {
|
2022-08-06 02:22:41 +02:00
|
|
|
exception = exceptionSplit[0];
|
2022-06-04 23:32:44 +02:00
|
|
|
}
|
2022-06-08 02:30:19 +02:00
|
|
|
// log.d('expection: $_exception');
|
2022-08-06 02:22:41 +02:00
|
|
|
switch (exception) {
|
2022-06-04 17:24:33 +02:00
|
|
|
case 'cert.NotRespectCertPeriod':
|
|
|
|
case 'identity.CreatorNotAllowedToCreateIdty':
|
|
|
|
{
|
2022-08-06 02:22:41 +02:00
|
|
|
resultText = "24hbetweenCerts".tr();
|
2022-06-04 17:24:33 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'cert.CannotCertifySelf':
|
|
|
|
{
|
2022-08-06 02:22:41 +02:00
|
|
|
resultText = "canNotCertifySelf".tr();
|
2022-06-04 17:24:33 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-06-04 23:32:44 +02:00
|
|
|
case 'identity.IdtyNameAlreadyExist':
|
|
|
|
{
|
2022-08-06 02:22:41 +02:00
|
|
|
resultText = "nameAlreadyExist".tr();
|
2022-06-04 23:32:44 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-06-08 02:30:19 +02:00
|
|
|
case 'balances.KeepAlive':
|
|
|
|
{
|
2022-08-06 02:22:41 +02:00
|
|
|
resultText = "2GDtoKeepAlive".tr();
|
2022-06-08 02:30:19 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '1010: Invalid Transaction: Inability to pay some fees , e.g. account balance too low':
|
|
|
|
{
|
2022-08-06 02:22:41 +02:00
|
|
|
resultText = "youHaveToFeedThisAccountBeforeUsing".tr();
|
2022-06-08 02:30:19 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-06-08 03:14:08 +02:00
|
|
|
|
2022-06-08 02:30:19 +02:00
|
|
|
case 'timeout':
|
|
|
|
{
|
2022-08-06 02:22:41 +02:00
|
|
|
resultText += "execTimeoutOver".tr();
|
2022-06-08 02:30:19 +02:00
|
|
|
}
|
|
|
|
break;
|
2022-06-04 17:24:33 +02:00
|
|
|
default:
|
|
|
|
{
|
2022-08-06 02:22:41 +02:00
|
|
|
resultText += "\n$exception";
|
2022-06-04 17:24:33 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-05-26 02:19:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return WillPopScope(
|
|
|
|
onWillPop: () {
|
2022-08-06 02:22:41 +02:00
|
|
|
sub.transactionStatus = '';
|
2022-05-26 02:19:29 +02:00
|
|
|
Navigator.pop(context);
|
2022-06-02 13:19:32 +02:00
|
|
|
if (transType == 'pay') Navigator.pop(context);
|
2022-05-26 02:19:29 +02:00
|
|
|
return Future<bool>.value(true);
|
|
|
|
},
|
|
|
|
child: Scaffold(
|
2022-05-29 00:00:57 +02:00
|
|
|
backgroundColor: backgroundColor,
|
2022-05-26 02:19:29 +02:00
|
|
|
appBar: AppBar(
|
|
|
|
toolbarHeight: 60 * ratio,
|
|
|
|
elevation: 0,
|
|
|
|
automaticallyImplyLeading: false,
|
|
|
|
title: SizedBox(
|
|
|
|
height: 22,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
2022-06-18 03:01:22 +02:00
|
|
|
children: <Widget>[
|
2022-08-06 02:22:41 +02:00
|
|
|
Text('extrinsicInProgress'.tr(args: [actionName]))
|
2022-06-18 03:01:22 +02:00
|
|
|
]),
|
2022-05-26 02:19:29 +02:00
|
|
|
)),
|
|
|
|
body: SafeArea(
|
|
|
|
child: Align(
|
|
|
|
alignment: FractionalOffset.bottomCenter,
|
|
|
|
child: Column(children: <Widget>[
|
|
|
|
Container(
|
|
|
|
width: double.infinity,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
gradient: LinearGradient(
|
|
|
|
begin: Alignment.topCenter,
|
|
|
|
end: Alignment.bottomCenter,
|
|
|
|
colors: [
|
|
|
|
yellowC,
|
2022-06-08 02:30:19 +02:00
|
|
|
backgroundColor,
|
2022-05-26 02:19:29 +02:00
|
|
|
],
|
|
|
|
)),
|
|
|
|
child: Column(children: <Widget>[
|
|
|
|
const SizedBox(height: 10),
|
2022-05-27 08:54:29 +02:00
|
|
|
if (transType == 'pay')
|
|
|
|
Text(
|
|
|
|
'$amount $currencyName',
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 18, fontWeight: FontWeight.w600),
|
|
|
|
),
|
|
|
|
if (transType == 'pay') const SizedBox(height: 10),
|
2022-06-18 03:01:22 +02:00
|
|
|
Text(
|
|
|
|
'fromMinus'.tr(),
|
2022-05-26 02:19:29 +02:00
|
|
|
textAlign: TextAlign.center,
|
2022-06-18 03:01:22 +02:00
|
|
|
style: const TextStyle(fontSize: 18),
|
2022-05-26 02:19:29 +02:00
|
|
|
),
|
|
|
|
Text(
|
|
|
|
from,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 18, fontWeight: FontWeight.w600),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
2022-06-18 03:01:22 +02:00
|
|
|
Text(
|
|
|
|
'toMinus'.tr(),
|
2022-05-26 02:19:29 +02:00
|
|
|
textAlign: TextAlign.center,
|
2022-06-18 03:01:22 +02:00
|
|
|
style: const TextStyle(fontSize: 18),
|
2022-05-26 02:19:29 +02:00
|
|
|
),
|
|
|
|
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(),
|
2022-05-27 08:54:29 +02:00
|
|
|
Column(children: [
|
2022-05-26 02:19:29 +02:00
|
|
|
Visibility(
|
|
|
|
visible: isLoading,
|
|
|
|
child: SizedBox(
|
2022-05-27 08:54:29 +02:00
|
|
|
height: 18,
|
|
|
|
width: 18,
|
2022-05-26 02:19:29 +02:00
|
|
|
child: CircularProgressIndicator(
|
|
|
|
color: orangeC,
|
|
|
|
strokeWidth: 2,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-06-08 02:30:19 +02:00
|
|
|
Visibility(
|
|
|
|
visible: !isLoading,
|
|
|
|
child: Icon(
|
|
|
|
isValid ? Icons.done_all : Icons.close,
|
|
|
|
size: 35,
|
|
|
|
color: isValid ? Colors.greenAccent : Colors.redAccent,
|
|
|
|
),
|
|
|
|
),
|
2022-05-27 08:54:29 +02:00
|
|
|
const SizedBox(height: 10),
|
|
|
|
Text(
|
2022-08-06 02:22:41 +02:00
|
|
|
resultText,
|
2022-05-27 08:54:29 +02:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(fontSize: 19 * ratio),
|
|
|
|
),
|
2022-05-26 02:19:29 +02:00
|
|
|
]),
|
|
|
|
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);
|
2022-08-06 02:22:41 +02:00
|
|
|
sub.transactionStatus = '';
|
2022-06-02 13:19:32 +02:00
|
|
|
if (transType == 'pay') Navigator.pop(context);
|
2022-05-26 02:19:29 +02:00
|
|
|
},
|
|
|
|
child: Text(
|
2022-06-18 00:48:07 +02:00
|
|
|
'close'.tr(),
|
2022-05-26 02:19:29 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 23 * ratio,
|
|
|
|
fontWeight: FontWeight.w600),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(height: isTall ? 80 : 20)
|
|
|
|
])),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|