gecko/lib/screens/transaction_in_progress.dart

185 lines
6.6 KiB
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, required this.chest, required this.pin})
: super(key: key);
final int chest;
final String pin;
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: true);
WalletsProfilesProvider _walletViewProvider =
Provider.of<WalletsProfilesProvider>(context, listen: false);
MyWalletsProvider _myWalletProvider =
Provider.of<MyWalletsProvider>(context, listen: false);
String _resultText;
bool isLoading = true;
// Map jsonResult;
final _result = _sub.transactionStatus;
final from = _myWalletProvider.getDefaultWallet()!.name!;
final to = _walletViewProvider
.getShortPubkey(_walletViewProvider.outputPubkey.text);
final amount = _walletViewProvider.payAmount.text;
switch (_result) {
case '':
{
_resultText = 'Envoi en cours ...';
}
break;
case 'sent':
{
_resultText = 'En cours de validation ...';
}
break;
default:
{
isLoading = false;
// jsonResult = json.decode(_result);
log.d(_result);
if (_result.contains('blockHash: ')) {
_resultText = 'Transcation validé !';
} else {
_resultText = "Une erreur s'est produite:\n\n$_result";
}
}
}
return WillPopScope(
onWillPop: () {
_sub.transactionStatus = '';
Navigator.pop(context);
Navigator.pop(context);
Navigator.pop(context);
return Future<bool>.value(true);
},
child: Scaffold(
appBar: AppBar(
toolbarHeight: 60 * ratio,
elevation: 0,
automaticallyImplyLeading: false,
title: SizedBox(
height: 22,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const <Widget>[Text('Transaction en cours')]),
)),
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,
const Color(0xfffafafa),
],
)),
child: Column(children: <Widget>[
const SizedBox(height: 10),
Text(
'$amount $currencyName',
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 18, fontWeight: FontWeight.w600),
),
const SizedBox(height: 10),
const Text(
'de',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 18),
),
Text(
from,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 18, fontWeight: FontWeight.w600),
),
const SizedBox(height: 10),
const Text(
'vers',
textAlign: TextAlign.center,
style: 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(),
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Text(
_resultText,
textAlign: TextAlign.center,
style: TextStyle(fontSize: 19 * ratio),
),
Visibility(
visible: isLoading,
child: SizedBox(
height: 15,
width: 15,
child: CircularProgressIndicator(
color: orangeC,
strokeWidth: 2,
),
),
),
]),
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);
Navigator.pop(context);
Navigator.pop(context);
},
child: Text(
'Fermer',
style: TextStyle(
fontSize: 23 * ratio,
fontWeight: FontWeight.w600),
),
),
),
),
),
SizedBox(height: isTall ? 80 : 20)
])),
),
));
}
}