2021-12-23 12:36:09 +01:00
|
|
|
import 'dart:async';
|
2021-11-17 06:20:23 +01:00
|
|
|
import 'dart:io';
|
2021-03-21 00:35:32 +01:00
|
|
|
import 'dart:ui';
|
2021-01-28 15:26:26 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2021-03-21 23:04:11 +01:00
|
|
|
import 'package:gecko/globals.dart';
|
2021-12-23 15:13:58 +01:00
|
|
|
import 'package:gecko/providers/my_wallets.dart';
|
2021-11-14 19:21:20 +01:00
|
|
|
import 'package:gecko/models/wallet_data.dart';
|
2021-12-23 15:13:58 +01:00
|
|
|
import 'package:gecko/providers/wallet_options.dart';
|
|
|
|
import 'package:gecko/providers/wallets_profiles.dart';
|
2021-12-01 08:14:07 +01:00
|
|
|
import 'package:gecko/screens/history.dart';
|
2021-01-28 15:26:26 +01:00
|
|
|
import 'package:provider/provider.dart';
|
2021-02-06 08:31:14 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2021-12-20 21:33:03 +01:00
|
|
|
import 'package:qr_flutter/qr_flutter.dart';
|
2021-01-28 15:26:26 +01:00
|
|
|
|
2021-03-28 21:37:12 +02:00
|
|
|
class WalletOptions extends StatelessWidget {
|
2021-12-23 21:44:24 +01:00
|
|
|
const WalletOptions({Key? keyMyWallets, required this.wallet})
|
2021-01-28 15:26:26 +01:00
|
|
|
: super(key: keyMyWallets);
|
2021-12-23 21:44:24 +01:00
|
|
|
final WalletData wallet;
|
2021-01-28 15:26:26 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-02-27 20:29:35 +01:00
|
|
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
2021-01-28 15:26:26 +01:00
|
|
|
WalletOptionsProvider _walletOptions =
|
2021-12-01 08:14:07 +01:00
|
|
|
Provider.of<WalletOptionsProvider>(context, listen: false);
|
2021-12-02 07:57:05 +01:00
|
|
|
WalletsProfilesProvider _historyProvider =
|
|
|
|
Provider.of<WalletsProfilesProvider>(context, listen: false);
|
2021-01-28 21:45:35 +01:00
|
|
|
MyWalletsProvider _myWalletProvider =
|
|
|
|
Provider.of<MyWalletsProvider>(context);
|
2021-03-08 02:20:48 +01:00
|
|
|
|
2021-12-20 21:33:03 +01:00
|
|
|
log.d(_walletOptions.pubkey.text);
|
|
|
|
|
2021-12-23 21:44:24 +01:00
|
|
|
final int _currentChest = _myWalletProvider.getCurrentChest()!;
|
2021-02-09 22:11:57 +01:00
|
|
|
|
2021-12-23 21:44:24 +01:00
|
|
|
log.d("Wallet options: $_currentChest:${wallet.number}");
|
2021-03-21 00:35:32 +01:00
|
|
|
|
2021-01-28 15:26:26 +01:00
|
|
|
return WillPopScope(
|
2021-11-29 04:05:08 +01:00
|
|
|
onWillPop: () {
|
|
|
|
_walletOptions.isEditing = false;
|
|
|
|
_walletOptions.isBalanceBlur = true;
|
2021-12-24 15:27:38 +01:00
|
|
|
Navigator.pop(context);
|
2021-11-29 04:05:08 +01:00
|
|
|
return Future<bool>.value(true);
|
|
|
|
},
|
|
|
|
child: Scaffold(
|
|
|
|
resizeToAvoidBottomInset: false,
|
|
|
|
appBar: AppBar(
|
2021-12-01 08:14:07 +01:00
|
|
|
toolbarHeight: 60 * ratio,
|
|
|
|
elevation: 0,
|
|
|
|
leading: IconButton(
|
|
|
|
icon: const Icon(Icons.arrow_back, color: Colors.black),
|
|
|
|
onPressed: () {
|
|
|
|
_walletOptions.isEditing = false;
|
|
|
|
_walletOptions.isBalanceBlur = true;
|
2021-12-24 15:27:38 +01:00
|
|
|
Navigator.pop(context);
|
2021-12-01 08:14:07 +01:00
|
|
|
}),
|
|
|
|
title: SizedBox(
|
|
|
|
height: 22,
|
|
|
|
child: Consumer<WalletOptionsProvider>(
|
|
|
|
builder: (context, walletProvider, _) {
|
|
|
|
return Text(_walletOptions.nameController.text);
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
),
|
2021-11-29 04:05:08 +01:00
|
|
|
body: Builder(
|
|
|
|
builder: (ctx) => SafeArea(
|
|
|
|
child: Column(children: <Widget>[
|
|
|
|
Container(
|
2021-12-01 08:14:07 +01:00
|
|
|
height: isTall ? 5 : 0,
|
2021-11-29 04:05:08 +01:00
|
|
|
color: yellowC,
|
|
|
|
),
|
2021-12-01 08:14:07 +01:00
|
|
|
Consumer<WalletOptionsProvider>(
|
|
|
|
builder: (context, walletProvider, _) {
|
|
|
|
return Container(
|
2021-11-29 04:05:08 +01:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
gradient: LinearGradient(
|
|
|
|
begin: Alignment.topCenter,
|
|
|
|
end: Alignment.bottomCenter,
|
|
|
|
colors: [
|
|
|
|
yellowC,
|
|
|
|
const Color(0xfffafafa),
|
|
|
|
],
|
|
|
|
)),
|
2021-12-23 21:44:24 +01:00
|
|
|
child: Row(
|
2021-12-24 15:27:38 +01:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2021-12-23 21:44:24 +01:00
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
|
|
children: <Widget>[
|
2021-12-30 00:51:04 +01:00
|
|
|
const Spacer(flex: 1),
|
2021-12-23 21:44:24 +01:00
|
|
|
avatar(walletProvider),
|
2021-12-30 00:51:04 +01:00
|
|
|
const Spacer(flex: 1),
|
2021-11-29 04:05:08 +01:00
|
|
|
Column(children: <Widget>[
|
2021-12-23 21:44:24 +01:00
|
|
|
walletName(walletProvider, _walletOptions),
|
2021-11-29 04:05:08 +01:00
|
|
|
SizedBox(height: isTall ? 5 : 0),
|
2021-12-23 21:44:24 +01:00
|
|
|
balance(walletProvider),
|
2021-03-21 01:22:52 +01:00
|
|
|
]),
|
2021-12-30 00:51:04 +01:00
|
|
|
const Spacer(flex: 3),
|
2021-03-21 01:22:52 +01:00
|
|
|
]),
|
2021-12-01 08:14:07 +01:00
|
|
|
);
|
|
|
|
}),
|
2021-11-29 04:05:08 +01:00
|
|
|
SizedBox(height: 4 * ratio),
|
2022-02-16 16:29:08 +01:00
|
|
|
QrImageWidget(
|
2021-12-20 21:33:03 +01:00
|
|
|
data: _walletOptions.pubkey.text,
|
|
|
|
version: QrVersions.auto,
|
|
|
|
size: isTall ? 300 : 270,
|
2021-11-30 01:25:48 +01:00
|
|
|
),
|
2021-11-29 04:05:08 +01:00
|
|
|
SizedBox(height: 15 * ratio),
|
2021-12-01 08:14:07 +01:00
|
|
|
Consumer<WalletOptionsProvider>(
|
|
|
|
builder: (context, walletProvider, _) {
|
|
|
|
return Column(children: [
|
2021-12-23 21:44:24 +01:00
|
|
|
pubkeyWidget(walletProvider, ctx),
|
2021-12-01 08:14:07 +01:00
|
|
|
SizedBox(height: 10 * ratio),
|
2021-12-23 21:44:24 +01:00
|
|
|
historyWidget(context, _historyProvider, walletProvider),
|
2021-12-01 08:14:07 +01:00
|
|
|
SizedBox(height: 12 * ratio),
|
2021-12-23 21:44:24 +01:00
|
|
|
setDefaultWallet(walletProvider, _myWalletProvider,
|
|
|
|
_walletOptions, _currentChest),
|
2021-12-01 08:14:07 +01:00
|
|
|
SizedBox(height: 17 * ratio),
|
|
|
|
if (!walletProvider.isDefaultWallet)
|
2021-12-23 21:44:24 +01:00
|
|
|
deleteWallet(context, walletProvider, _myWalletProvider,
|
|
|
|
_currentChest)
|
2021-12-01 08:14:07 +01:00
|
|
|
]);
|
|
|
|
}),
|
2021-11-29 04:05:08 +01:00
|
|
|
]),
|
2021-04-03 00:07:03 +02:00
|
|
|
),
|
2021-11-29 04:05:08 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2021-03-06 22:26:30 +01:00
|
|
|
}
|
2021-12-23 21:44:24 +01:00
|
|
|
|
|
|
|
Widget avatar(WalletOptionsProvider walletProvider) {
|
|
|
|
return Stack(
|
|
|
|
children: <Widget>[
|
|
|
|
InkWell(
|
|
|
|
onTap: () async {
|
2021-12-24 15:27:38 +01:00
|
|
|
File newAvatar = await (walletProvider.changeAvatar());
|
2021-12-23 21:44:24 +01:00
|
|
|
wallet.imageFile = newAvatar;
|
|
|
|
walletProvider.reloadBuild();
|
|
|
|
},
|
|
|
|
child: wallet.imageFile == null
|
|
|
|
? Image.asset(
|
|
|
|
'assets/avatars/${wallet.imageName}',
|
|
|
|
width: 110,
|
|
|
|
)
|
|
|
|
: Image.file(
|
|
|
|
wallet.imageFile!,
|
|
|
|
width: 110,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Positioned(
|
|
|
|
right: 0,
|
2021-12-24 15:27:38 +01:00
|
|
|
top: 0,
|
2021-12-23 21:44:24 +01:00
|
|
|
child: InkWell(
|
|
|
|
onTap: () async {
|
2021-12-24 15:27:38 +01:00
|
|
|
File newAvatar = await (walletProvider.changeAvatar());
|
2021-12-23 21:44:24 +01:00
|
|
|
wallet.imageFile = newAvatar;
|
|
|
|
walletProvider.reloadBuild();
|
|
|
|
},
|
|
|
|
child: Image.asset(
|
|
|
|
'assets/walletOptions/camera.png',
|
|
|
|
height: 40,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget walletName(WalletOptionsProvider walletProvider,
|
|
|
|
WalletOptionsProvider _walletOptions) {
|
|
|
|
bool _isNewNameValid = false;
|
|
|
|
if (_isNewNameValid == false) {
|
|
|
|
_walletOptions.nameController.text = wallet.name!;
|
|
|
|
} else {
|
|
|
|
wallet.name = _walletOptions.nameController.text;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SizedBox(
|
|
|
|
width: 260,
|
|
|
|
child: Stack(children: <Widget>[
|
|
|
|
TextField(
|
|
|
|
key: const Key('walletName'),
|
|
|
|
autofocus: false,
|
|
|
|
focusNode: walletProvider.walletNameFocus,
|
|
|
|
enabled: walletProvider.isEditing,
|
|
|
|
controller: walletProvider.nameController,
|
2021-12-24 15:27:38 +01:00
|
|
|
minLines: 1,
|
|
|
|
maxLines: 3,
|
2021-12-23 21:44:24 +01:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
border: InputBorder.none,
|
|
|
|
focusedBorder: InputBorder.none,
|
|
|
|
enabledBorder: InputBorder.none,
|
|
|
|
disabledBorder: InputBorder.none,
|
|
|
|
contentPadding: EdgeInsets.all(15.0),
|
|
|
|
),
|
|
|
|
style: TextStyle(
|
2021-12-24 15:27:38 +01:00
|
|
|
fontSize: isTall ? 27 : 23,
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.w400,
|
|
|
|
),
|
2021-12-23 21:44:24 +01:00
|
|
|
),
|
|
|
|
Positioned(
|
|
|
|
right: 0,
|
|
|
|
child: InkWell(
|
|
|
|
key: const Key('renameWallet'),
|
|
|
|
onTap: () async {
|
|
|
|
_isNewNameValid =
|
|
|
|
walletProvider.editWalletName(wallet.id(), isCesium: false);
|
|
|
|
await Future.delayed(const Duration(milliseconds: 30));
|
|
|
|
walletProvider.walletNameFocus.requestFocus();
|
|
|
|
},
|
|
|
|
child: ClipRRect(
|
|
|
|
child: Image.asset(
|
|
|
|
walletProvider.isEditing
|
|
|
|
? 'assets/walletOptions/android-checkmark.png'
|
|
|
|
: 'assets/walletOptions/edit.png',
|
|
|
|
width: 20,
|
|
|
|
height: 20),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget balance(WalletOptionsProvider walletProvider) {
|
|
|
|
return Column(children: <Widget>[
|
|
|
|
FutureBuilder(
|
|
|
|
future: walletProvider.getBalance(walletProvider.pubkey.text),
|
|
|
|
builder: (BuildContext context, AsyncSnapshot<num?> _balance) {
|
|
|
|
if (_balance.connectionState != ConnectionState.done ||
|
|
|
|
_balance.hasError) {
|
|
|
|
return Text('',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: isTall ? 20 : 18,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
return ImageFiltered(
|
|
|
|
imageFilter: ImageFilter.blur(
|
|
|
|
sigmaX: walletProvider.isBalanceBlur ? 6 : 0,
|
|
|
|
sigmaY: walletProvider.isBalanceBlur ? 5 : 0),
|
|
|
|
child: Text(
|
2021-12-24 15:27:38 +01:00
|
|
|
_balance.data.toString() + ' Ğ1',
|
2021-12-23 21:44:24 +01:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: isTall ? 20 : 18,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
const SizedBox(height: 5),
|
|
|
|
InkWell(
|
|
|
|
key: const Key('displayBalance'),
|
|
|
|
onTap: () {
|
|
|
|
walletProvider.bluringBalance();
|
|
|
|
},
|
|
|
|
child: Image.asset(
|
|
|
|
walletProvider.isBalanceBlur
|
|
|
|
? 'assets/walletOptions/icon_oeuil.png'
|
|
|
|
: 'assets/walletOptions/icon_oeuil_close.png',
|
|
|
|
height: 35,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget pubkeyWidget(WalletOptionsProvider walletProvider, BuildContext ctx) {
|
|
|
|
final String shortPubkey =
|
|
|
|
walletProvider.getShortPubkey(walletProvider.pubkey.text);
|
|
|
|
return GestureDetector(
|
|
|
|
key: const Key('copyPubkey'),
|
|
|
|
onTap: () {
|
|
|
|
Clipboard.setData(ClipboardData(text: walletProvider.pubkey.text));
|
|
|
|
walletProvider.snackCopyKey(ctx);
|
|
|
|
},
|
|
|
|
child: SizedBox(
|
|
|
|
height: 50,
|
|
|
|
child: Row(children: <Widget>[
|
|
|
|
const SizedBox(width: 30),
|
|
|
|
Image.asset(
|
|
|
|
'assets/walletOptions/key.png',
|
|
|
|
height: 45,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 20),
|
|
|
|
Text("${shortPubkey.split(':')[0]}:",
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 22,
|
|
|
|
fontWeight: FontWeight.w800,
|
|
|
|
fontFamily: 'Monospace',
|
|
|
|
color: Colors.black)),
|
|
|
|
Text(shortPubkey.split(':')[1],
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 22,
|
|
|
|
fontWeight: FontWeight.w800,
|
|
|
|
fontFamily: 'Monospace')),
|
|
|
|
const SizedBox(width: 15),
|
|
|
|
SizedBox(
|
|
|
|
height: 40,
|
|
|
|
child: ElevatedButton(
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
),
|
|
|
|
elevation: 1,
|
|
|
|
primary: orangeC, // background
|
|
|
|
onPrimary: Colors.black, // foreground
|
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
Clipboard.setData(
|
|
|
|
ClipboardData(text: walletProvider.pubkey.text));
|
|
|
|
walletProvider.snackCopyKey(ctx);
|
|
|
|
},
|
|
|
|
child: Row(children: <Widget>[
|
|
|
|
Image.asset(
|
|
|
|
'assets/walletOptions/copy-white.png',
|
|
|
|
height: 25,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 7),
|
|
|
|
Text(
|
|
|
|
'Copier',
|
|
|
|
style: TextStyle(fontSize: 15, color: Colors.grey[50]),
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget historyWidget(
|
|
|
|
BuildContext context,
|
|
|
|
WalletsProfilesProvider _historyProvider,
|
|
|
|
WalletOptionsProvider walletProvider) {
|
|
|
|
return InkWell(
|
|
|
|
key: const Key('displayHistory'),
|
|
|
|
onTap: () {
|
|
|
|
_historyProvider.nPage = 1;
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
|
|
|
return HistoryScreen(
|
|
|
|
pubkey: walletProvider.pubkey.text,
|
|
|
|
avatar: wallet.imageFile == null
|
|
|
|
? Image.asset(
|
|
|
|
'assets/avatars/${wallet.imageName}',
|
|
|
|
width: 110,
|
|
|
|
)
|
|
|
|
: Image.file(
|
|
|
|
wallet.imageFile!,
|
|
|
|
width: 110,
|
|
|
|
));
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
child: SizedBox(
|
|
|
|
height: 50,
|
|
|
|
child: Row(children: <Widget>[
|
|
|
|
const SizedBox(width: 30),
|
|
|
|
Image.asset(
|
|
|
|
'assets/walletOptions/clock.png',
|
|
|
|
height: 45,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 22),
|
|
|
|
const Text('Historique des transactions',
|
|
|
|
style: TextStyle(fontSize: 20, color: Colors.black)),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget setDefaultWallet(
|
|
|
|
WalletOptionsProvider walletProvider,
|
|
|
|
MyWalletsProvider _myWalletProvider,
|
|
|
|
WalletOptionsProvider _walletOptions,
|
|
|
|
int _currentChest) {
|
|
|
|
WalletData defaultWallet =
|
|
|
|
_myWalletProvider.getDefaultWallet(_currentChest)!;
|
|
|
|
|
|
|
|
_walletOptions.isDefaultWallet = (defaultWallet.number == wallet.id()[1]);
|
|
|
|
|
|
|
|
return InkWell(
|
|
|
|
key: const Key('setDefaultWallet'),
|
|
|
|
onTap: !walletProvider.isDefaultWallet
|
|
|
|
? () {
|
|
|
|
defaultWallet = wallet;
|
|
|
|
chestBox.get(_currentChest)!.defaultWallet = wallet.number;
|
|
|
|
_myWalletProvider.readAllWallets(_currentChest);
|
|
|
|
_myWalletProvider.rebuildWidget();
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
child: SizedBox(
|
|
|
|
height: 50,
|
|
|
|
child: Row(children: <Widget>[
|
|
|
|
const SizedBox(width: 31),
|
|
|
|
CircleAvatar(
|
|
|
|
backgroundColor:
|
|
|
|
Colors.grey[walletProvider.isDefaultWallet ? 300 : 500],
|
|
|
|
child: Image.asset(
|
|
|
|
'assets/walletOptions/android-checkmark.png',
|
|
|
|
height: 25,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(width: 22),
|
|
|
|
Text(
|
|
|
|
walletProvider.isDefaultWallet
|
|
|
|
? 'Ce portefeuille est celui par defaut'
|
|
|
|
: 'Définir comme portefeuille par défaut',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 20,
|
|
|
|
color: walletProvider.isDefaultWallet
|
|
|
|
? Colors.grey[500]
|
|
|
|
: Colors.black)),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget deleteWallet(
|
|
|
|
BuildContext context,
|
|
|
|
WalletOptionsProvider walletProvider,
|
|
|
|
MyWalletsProvider _myWalletProvider,
|
|
|
|
int _currentChest) {
|
|
|
|
return InkWell(
|
|
|
|
key: const Key('deleteWallet'),
|
|
|
|
onTap: !walletProvider.isDefaultWallet
|
|
|
|
? () async {
|
|
|
|
await walletProvider.deleteWallet(context, wallet);
|
|
|
|
WidgetsBinding.instance!.addPostFrameCallback((_) {
|
|
|
|
_myWalletProvider.listWallets =
|
|
|
|
_myWalletProvider.readAllWallets(_currentChest);
|
|
|
|
_myWalletProvider.rebuildWidget();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
child: Row(children: <Widget>[
|
|
|
|
const SizedBox(width: 30),
|
|
|
|
Image.asset(
|
|
|
|
'assets/walletOptions/trash.png',
|
|
|
|
height: 45,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 19),
|
|
|
|
const Text('Supprimer ce portefeuille',
|
|
|
|
style: TextStyle(fontSize: 20, color: Color(0xffD80000))),
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
}
|
2021-01-28 15:26:26 +01:00
|
|
|
}
|