2022-08-06 02:22:41 +02:00
|
|
|
// ignore_for_file: use_build_context_synchronously
|
|
|
|
|
2021-01-28 15:10:09 +01:00
|
|
|
import 'dart:io';
|
2022-06-17 01:13:14 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2021-01-28 15:10:09 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2022-08-21 01:30:26 +02:00
|
|
|
import 'package:flutter/services.dart';
|
2022-11-30 05:22:37 +01:00
|
|
|
|
2021-01-28 15:10:09 +01:00
|
|
|
import 'dart:async';
|
|
|
|
import 'package:gecko/globals.dart';
|
2022-08-23 00:25:16 +02:00
|
|
|
import 'package:gecko/models/widgets_keys.dart';
|
2022-06-14 21:55:33 +02:00
|
|
|
import 'package:gecko/providers/duniter_indexer.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';
|
2022-05-21 06:47:26 +02:00
|
|
|
import 'package:gecko/providers/substrate_sdk.dart';
|
2022-06-06 17:52:42 +02:00
|
|
|
import 'package:gecko/screens/animated_text.dart';
|
2022-05-28 19:13:30 +02:00
|
|
|
import 'package:gecko/screens/common_elements.dart';
|
2022-06-04 23:32:44 +02:00
|
|
|
import 'package:gecko/screens/myWallets/unlocking_wallet.dart';
|
|
|
|
import 'package:gecko/screens/transaction_in_progress.dart';
|
2021-03-21 23:04:11 +01:00
|
|
|
import 'package:image_picker/image_picker.dart';
|
2022-05-21 06:47:26 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2022-06-12 22:12:00 +02:00
|
|
|
import 'package:image_cropper/image_cropper.dart';
|
2022-07-22 22:08:41 +02:00
|
|
|
import 'package:truncate/truncate.dart';
|
2021-01-28 15:10:09 +01:00
|
|
|
|
|
|
|
class WalletOptionsProvider with ChangeNotifier {
|
2022-05-19 07:00:25 +02:00
|
|
|
TextEditingController address = TextEditingController();
|
2021-11-14 19:21:20 +01:00
|
|
|
final TextEditingController _newWalletName = TextEditingController();
|
2021-01-28 15:10:09 +01:00
|
|
|
bool isWalletUnlock = false;
|
|
|
|
bool ischangedPin = false;
|
2021-11-14 19:21:20 +01:00
|
|
|
TextEditingController newPin = TextEditingController();
|
2021-03-21 00:35:32 +01:00
|
|
|
bool isEditing = false;
|
2022-05-19 09:07:26 +02:00
|
|
|
bool isBalanceBlur = false;
|
2021-03-21 00:35:32 +01:00
|
|
|
FocusNode walletNameFocus = FocusNode();
|
|
|
|
TextEditingController nameController = TextEditingController();
|
2021-12-23 12:36:09 +01:00
|
|
|
late bool isDefaultWallet;
|
2022-06-12 21:19:05 +02:00
|
|
|
bool canValidateNameBool = false;
|
2022-08-18 14:26:12 +02:00
|
|
|
Map<String, String> idtyStatusCache = {};
|
2021-12-23 12:36:09 +01:00
|
|
|
Future<NewWallet>? get badWallet => null;
|
2021-01-28 15:10:09 +01:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
int getPinLenght(walletNbr) {
|
2021-12-23 15:13:58 +01:00
|
|
|
return pinLength;
|
2021-02-09 22:11:57 +01:00
|
|
|
}
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
void _renameWallet(List<int?> walletID, String newName,
|
2021-12-23 15:13:58 +01:00
|
|
|
{required bool isCesium}) async {
|
2022-05-21 06:47:26 +02:00
|
|
|
MyWalletsProvider myWalletClass = MyWalletsProvider();
|
2021-11-07 04:23:05 +01:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
WalletData walletTarget = myWalletClass.getWalletDataById(walletID)!;
|
|
|
|
walletTarget.name = newName;
|
|
|
|
await walletBox.put(walletTarget.key, walletTarget);
|
2021-02-15 01:44:25 +01:00
|
|
|
|
|
|
|
_newWalletName.text = '';
|
2021-01-28 15:10:09 +01:00
|
|
|
}
|
|
|
|
|
2021-11-07 04:23:05 +01:00
|
|
|
Future<int> deleteWallet(context, WalletData wallet) async {
|
2022-11-30 05:42:08 +01:00
|
|
|
final sub = Provider.of<SubstrateSdk>(context, listen: false);
|
2022-08-06 02:22:41 +02:00
|
|
|
final bool? answer = await (confirmPopup(
|
2022-06-18 00:48:07 +02:00
|
|
|
context, 'areYouSureToForgetWallet'.tr(args: [wallet.name!])));
|
2021-01-28 15:10:09 +01:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
if (answer ?? false) {
|
2022-06-08 02:30:19 +02:00
|
|
|
//Check if balance is null
|
2022-08-06 02:22:41 +02:00
|
|
|
final balance = await sub.getBalance(wallet.address!);
|
2022-08-11 19:19:50 +02:00
|
|
|
if (balance != {}) {
|
2022-11-30 05:42:08 +01:00
|
|
|
final myWalletProvider =
|
2022-06-08 02:30:19 +02:00
|
|
|
Provider.of<MyWalletsProvider>(context, listen: false);
|
2022-08-06 02:22:41 +02:00
|
|
|
final defaultWallet = myWalletProvider.getDefaultWallet();
|
|
|
|
log.d(defaultWallet.address);
|
|
|
|
sub.pay(
|
2022-06-08 02:30:19 +02:00
|
|
|
fromAddress: wallet.address!,
|
2022-08-06 02:22:41 +02:00
|
|
|
destAddress: defaultWallet.address!,
|
2022-06-08 02:30:19 +02:00
|
|
|
amount: -1,
|
2022-08-06 02:22:41 +02:00
|
|
|
password: myWalletProvider.pinCode);
|
2022-06-08 02:30:19 +02:00
|
|
|
}
|
|
|
|
|
2022-05-20 15:15:29 +02:00
|
|
|
await walletBox.delete(wallet.key);
|
2022-08-06 02:22:41 +02:00
|
|
|
await sub.deleteAccounts([wallet.address!]);
|
2021-02-15 01:44:25 +01:00
|
|
|
|
2022-05-20 15:15:29 +02:00
|
|
|
Navigator.pop(context);
|
2021-01-28 15:10:09 +01:00
|
|
|
}
|
2021-02-15 01:44:25 +01:00
|
|
|
return 0;
|
2021-01-28 15:10:09 +01:00
|
|
|
}
|
|
|
|
|
2021-03-21 00:35:32 +01:00
|
|
|
void bluringBalance() {
|
|
|
|
isBalanceBlur = !isBalanceBlur;
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
2022-05-28 19:13:30 +02:00
|
|
|
Future<String> changeAvatar() async {
|
|
|
|
// File _image;
|
2021-03-21 23:04:11 +01:00
|
|
|
final picker = ImagePicker();
|
|
|
|
|
2021-12-23 12:36:09 +01:00
|
|
|
XFile? pickedFile = await picker.pickImage(source: ImageSource.gallery);
|
2021-03-21 23:04:11 +01:00
|
|
|
|
|
|
|
if (pickedFile != null) {
|
2022-05-28 19:13:30 +02:00
|
|
|
File imageFile = File(pickedFile.path);
|
|
|
|
if (!await imageDirectory.exists()) {
|
|
|
|
log.e("Image folder doesn't exist");
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2022-06-12 22:12:00 +02:00
|
|
|
CroppedFile? croppedFile = await ImageCropper().cropImage(
|
|
|
|
sourcePath: imageFile.path,
|
|
|
|
aspectRatioPresets: [CropAspectRatioPreset.square],
|
|
|
|
cropStyle: CropStyle.circle,
|
|
|
|
uiSettings: [
|
|
|
|
AndroidUiSettings(
|
|
|
|
hideBottomControls: true,
|
|
|
|
toolbarTitle: 'Personnalisation',
|
|
|
|
toolbarColor: Colors.deepOrange,
|
|
|
|
toolbarWidgetColor: Colors.white,
|
|
|
|
initAspectRatio: CropAspectRatioPreset.original,
|
|
|
|
lockAspectRatio: true),
|
|
|
|
IOSUiSettings(
|
|
|
|
title: 'Cropper',
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2022-05-28 19:13:30 +02:00
|
|
|
|
2022-06-12 22:12:00 +02:00
|
|
|
final newPath = "${imageDirectory.path}/${pickedFile.name}";
|
2022-05-28 19:13:30 +02:00
|
|
|
|
2022-06-12 22:12:00 +02:00
|
|
|
if (croppedFile != null) {
|
|
|
|
await File(croppedFile.path).rename(newPath);
|
|
|
|
} else {
|
|
|
|
log.w('No image selected.');
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
// await imageFile.copy(newPath);
|
2022-05-28 19:13:30 +02:00
|
|
|
|
|
|
|
log.i(newPath);
|
|
|
|
return newPath;
|
2021-03-21 23:04:11 +01:00
|
|
|
} else {
|
2021-04-02 12:05:37 +02:00
|
|
|
log.w('No image selected.');
|
2022-05-28 19:13:30 +02:00
|
|
|
return '';
|
2021-03-21 23:04:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-24 16:51:40 +02:00
|
|
|
Widget idtyStatus(BuildContext context, String address,
|
2022-06-06 17:52:42 +02:00
|
|
|
{bool isOwner = false, Color color = Colors.black}) {
|
2022-11-30 05:42:08 +01:00
|
|
|
final duniterIndexer = Provider.of<DuniterIndexer>(context, listen: false);
|
2022-06-14 22:10:35 +02:00
|
|
|
|
2022-09-05 04:15:27 +02:00
|
|
|
showText(String text,
|
2022-08-06 02:22:41 +02:00
|
|
|
[double size = 18, bool bold = false, bool smooth = true]) {
|
2022-12-02 19:45:46 +01:00
|
|
|
// log.d('$address $text');
|
2022-06-06 17:52:42 +02:00
|
|
|
return AnimatedFadeOutIn<String>(
|
|
|
|
data: text,
|
|
|
|
duration: Duration(milliseconds: smooth ? 200 : 0),
|
|
|
|
builder: (value) => Text(
|
|
|
|
value,
|
2022-06-03 18:15:45 +02:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: size,
|
2022-08-06 02:22:41 +02:00
|
|
|
color: bold ? color : Colors.black,
|
|
|
|
fontWeight: bold ? FontWeight.w500 : FontWeight.w400),
|
2022-06-06 17:52:42 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-06-03 18:15:45 +02:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
return Consumer<SubstrateSdk>(builder: (context, sub, _) {
|
2022-05-24 16:51:40 +02:00
|
|
|
return FutureBuilder(
|
2022-08-06 02:22:41 +02:00
|
|
|
future: sub.idtyStatus(address),
|
2022-06-06 17:52:42 +02:00
|
|
|
initialData: '',
|
2022-05-24 16:51:40 +02:00
|
|
|
builder: (context, snapshot) {
|
2022-08-18 14:26:12 +02:00
|
|
|
idtyStatusCache[address] = snapshot.data.toString();
|
2022-05-24 16:51:40 +02:00
|
|
|
switch (snapshot.data.toString()) {
|
|
|
|
case 'noid':
|
|
|
|
{
|
2022-09-05 04:15:27 +02:00
|
|
|
return showText('noIdentity'.tr());
|
2022-05-24 16:51:40 +02:00
|
|
|
}
|
|
|
|
case 'Created':
|
|
|
|
{
|
2022-09-05 04:15:27 +02:00
|
|
|
return showText('identityCreated'.tr());
|
2022-05-24 16:51:40 +02:00
|
|
|
}
|
|
|
|
case 'ConfirmedByOwner':
|
|
|
|
{
|
2022-06-13 21:58:57 +02:00
|
|
|
return isOwner
|
2022-09-05 04:15:27 +02:00
|
|
|
? showText('identityConfirmed'.tr())
|
2022-08-06 02:22:41 +02:00
|
|
|
: duniterIndexer.getNameByAddress(
|
2022-06-14 22:10:35 +02:00
|
|
|
context,
|
|
|
|
address,
|
|
|
|
null,
|
|
|
|
20,
|
|
|
|
true,
|
|
|
|
Colors.grey[700]!,
|
|
|
|
FontWeight.w500,
|
|
|
|
FontStyle.italic);
|
2022-05-24 16:51:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case 'Validated':
|
|
|
|
{
|
2022-06-13 21:58:57 +02:00
|
|
|
return isOwner
|
2022-09-05 04:15:27 +02:00
|
|
|
? showText('memberValidated'.tr(), 18, true)
|
2022-08-06 02:22:41 +02:00
|
|
|
: duniterIndexer.getNameByAddress(
|
2022-06-14 22:10:35 +02:00
|
|
|
context,
|
|
|
|
address,
|
|
|
|
null,
|
|
|
|
20,
|
|
|
|
true,
|
|
|
|
Colors.black,
|
|
|
|
FontWeight.w600,
|
|
|
|
FontStyle.normal);
|
2022-05-24 16:51:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case 'expired':
|
|
|
|
{
|
2022-09-05 04:15:27 +02:00
|
|
|
return showText('identityExpired'.tr());
|
2022-05-24 16:51:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return SizedBox(
|
2022-09-05 04:15:27 +02:00
|
|
|
child: showText('', 18, false, false),
|
2022-05-24 16:51:40 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-06-06 17:52:42 +02:00
|
|
|
Future<bool> isMember(BuildContext context, String address) async {
|
2022-11-30 05:42:08 +01:00
|
|
|
final sub = Provider.of<SubstrateSdk>(context, listen: false);
|
2022-08-06 02:22:41 +02:00
|
|
|
return await sub.idtyStatus(address) == 'Validated';
|
2022-06-05 02:22:22 +02:00
|
|
|
}
|
|
|
|
|
2022-08-21 01:30:26 +02:00
|
|
|
Future<String?> confirmIdentityPopup(BuildContext context) async {
|
2022-05-24 16:51:40 +02:00
|
|
|
TextEditingController idtyName = TextEditingController();
|
2022-11-30 05:42:08 +01:00
|
|
|
final sub = Provider.of<SubstrateSdk>(context, listen: false);
|
|
|
|
final walletOptions =
|
2022-05-24 16:51:40 +02:00
|
|
|
Provider.of<WalletOptionsProvider>(context, listen: false);
|
2022-11-30 05:42:08 +01:00
|
|
|
final myWalletProvider =
|
2022-05-24 16:51:40 +02:00
|
|
|
Provider.of<MyWalletsProvider>(context, listen: false);
|
|
|
|
|
2022-12-02 21:18:28 +01:00
|
|
|
bool canValidate = false;
|
|
|
|
bool idtyExist = false;
|
|
|
|
|
2022-05-24 16:51:40 +02:00
|
|
|
return showDialog<String>(
|
|
|
|
context: context,
|
|
|
|
barrierDismissible: true, // user must tap button!
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertDialog(
|
2022-06-18 00:48:07 +02:00
|
|
|
title: Text(
|
|
|
|
'confirmYourIdentity'.tr(),
|
2022-06-03 18:15:45 +02:00
|
|
|
textAlign: TextAlign.center,
|
2022-06-18 00:48:07 +02:00
|
|
|
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
|
2022-06-03 18:15:45 +02:00
|
|
|
),
|
2022-05-24 16:51:40 +02:00
|
|
|
content: SizedBox(
|
|
|
|
height: 100,
|
|
|
|
child: Column(children: [
|
2022-06-03 18:15:45 +02:00
|
|
|
const SizedBox(height: 20),
|
2022-08-24 23:59:51 +02:00
|
|
|
TextField(
|
|
|
|
key: keyEnterIdentityUsername,
|
2022-12-02 21:18:28 +01:00
|
|
|
onChanged: (_) async {
|
|
|
|
idtyExist = await isIdtyExist(idtyName.text);
|
|
|
|
canValidate = !idtyExist &&
|
|
|
|
!await isIdtyExist(idtyName.text) &&
|
|
|
|
idtyName.text.length >= 2 &&
|
|
|
|
idtyName.text.length <= 32;
|
|
|
|
log.d('aaaaaaaaaa: $canValidate');
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
},
|
2022-08-21 01:30:26 +02:00
|
|
|
inputFormatters: <TextInputFormatter>[
|
|
|
|
// FilteringTextInputFormatter.allow(RegExp("[0-9a-zA-Z]")),
|
|
|
|
FilteringTextInputFormatter.deny(RegExp(r'^ ')),
|
|
|
|
// FilteringTextInputFormatter.deny(RegExp(r' $')),
|
|
|
|
],
|
2022-06-03 18:15:45 +02:00
|
|
|
textAlign: TextAlign.center,
|
2022-05-27 08:54:29 +02:00
|
|
|
autofocus: true,
|
2022-05-24 16:51:40 +02:00
|
|
|
controller: idtyName,
|
2022-06-03 18:15:45 +02:00
|
|
|
style: const TextStyle(fontSize: 19),
|
2022-12-02 21:18:28 +01:00
|
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
Consumer<WalletOptionsProvider>(builder: (context, wOptions, _) {
|
|
|
|
return Text(idtyExist ? 'Cette identité existe déjà' : '',
|
|
|
|
style: TextStyle(color: Colors.red[500]));
|
|
|
|
})
|
2022-05-24 16:51:40 +02:00
|
|
|
]),
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
2022-06-03 18:15:45 +02:00
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Consumer<WalletOptionsProvider>(
|
2022-08-06 02:22:41 +02:00
|
|
|
builder: (context, wOptions, _) {
|
2022-06-03 18:15:45 +02:00
|
|
|
return TextButton(
|
2022-08-24 21:53:16 +02:00
|
|
|
key: keyConfirm,
|
2022-12-02 21:18:28 +01:00
|
|
|
onPressed: canValidate
|
|
|
|
? () async {
|
|
|
|
idtyName.text =
|
|
|
|
idtyName.text.trim().replaceAll(' ', '');
|
|
|
|
|
|
|
|
if (idtyName.text.length.clamp(3, 32) ==
|
|
|
|
idtyName.text.length) {
|
|
|
|
WalletData? defaultWallet =
|
|
|
|
myWalletProvider.getDefaultWallet();
|
|
|
|
|
|
|
|
String? pin;
|
|
|
|
if (myWalletProvider.pinCode == '') {
|
|
|
|
pin = await Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (homeContext) {
|
|
|
|
return UnlockingWallet(
|
|
|
|
wallet: defaultWallet);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (pin != null ||
|
|
|
|
myWalletProvider.pinCode != '') {
|
|
|
|
final wallet = myWalletProvider
|
|
|
|
.getWalletDataByAddress(address.text);
|
|
|
|
await sub.setCurrentWallet(wallet!);
|
|
|
|
sub.confirmIdentity(walletOptions.address.text,
|
|
|
|
idtyName.text, myWalletProvider.pinCode);
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
|
|
|
return TransactionInProgress(
|
|
|
|
transType: 'comfirmIdty',
|
|
|
|
fromAddress:
|
|
|
|
getShortPubkey(wallet.address!),
|
|
|
|
toAddress:
|
|
|
|
getShortPubkey(wallet.address!),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
: null,
|
2022-06-03 18:15:45 +02:00
|
|
|
child: Text(
|
2022-06-17 01:13:14 +02:00
|
|
|
"validate".tr(),
|
2022-06-03 18:15:45 +02:00
|
|
|
style: TextStyle(
|
2022-12-02 21:18:28 +01:00
|
|
|
fontSize: 21,
|
|
|
|
color: canValidate
|
|
|
|
? const Color(0xffD80000)
|
|
|
|
: Colors.grey[500]),
|
2022-06-03 18:15:45 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
})
|
|
|
|
],
|
2022-05-24 16:51:40 +02:00
|
|
|
),
|
2022-12-02 21:18:28 +01:00
|
|
|
const SizedBox(height: 5)
|
2022-05-24 16:51:40 +02:00
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
Future<String?> editWalletName(BuildContext context, List<int?> wID) async {
|
2022-06-12 21:19:05 +02:00
|
|
|
TextEditingController walletName = TextEditingController();
|
|
|
|
canValidateNameBool = false;
|
|
|
|
|
|
|
|
return showDialog<String>(
|
|
|
|
context: context,
|
|
|
|
barrierDismissible: true,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return AlertDialog(
|
2022-06-17 01:13:14 +02:00
|
|
|
title: Text(
|
|
|
|
'chooseWalletName'.tr(),
|
2022-06-12 21:19:05 +02:00
|
|
|
textAlign: TextAlign.center,
|
2022-06-17 01:13:14 +02:00
|
|
|
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.w500),
|
2022-06-12 21:19:05 +02:00
|
|
|
),
|
|
|
|
content: SizedBox(
|
|
|
|
height: 100,
|
|
|
|
child: Column(children: [
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
TextField(
|
|
|
|
onChanged: (_) => canValidateName(context, walletName),
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
autofocus: true,
|
|
|
|
controller: walletName,
|
|
|
|
style: const TextStyle(fontSize: 19),
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Consumer<WalletOptionsProvider>(
|
2022-08-06 02:22:41 +02:00
|
|
|
builder: (context, wOptions, _) {
|
2022-06-12 21:19:05 +02:00
|
|
|
return TextButton(
|
2022-08-23 00:25:16 +02:00
|
|
|
key: keyInfoPopup,
|
2022-06-12 21:19:05 +02:00
|
|
|
child: Text(
|
2022-06-17 01:13:14 +02:00
|
|
|
"validate".tr(),
|
2022-06-12 21:19:05 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 21,
|
|
|
|
color: canValidateNameBool
|
|
|
|
? const Color(0xffD80000)
|
|
|
|
: Colors.grey,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onPressed: () async {
|
|
|
|
if (canValidateNameBool) {
|
|
|
|
nameController.text = walletName.text;
|
2022-08-06 02:22:41 +02:00
|
|
|
_renameWallet(wID, walletName.text, isCesium: false);
|
2022-06-12 21:19:05 +02:00
|
|
|
// notifyListeners();
|
|
|
|
Navigator.pop(context);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
})
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
TextButton(
|
2022-08-23 00:25:16 +02:00
|
|
|
key: keyCancel,
|
2022-06-12 21:19:05 +02:00
|
|
|
child: Text(
|
2022-06-18 03:01:22 +02:00
|
|
|
"cancel".tr(),
|
2022-06-12 21:19:05 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 18,
|
|
|
|
color: Colors.grey[800],
|
|
|
|
fontWeight: FontWeight.w300),
|
|
|
|
),
|
|
|
|
onPressed: () async {
|
|
|
|
Navigator.pop(context);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(height: 20)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool canValidateName(BuildContext context, TextEditingController walletName) {
|
2022-11-30 05:42:08 +01:00
|
|
|
final myWalletProvider =
|
2022-06-12 21:19:05 +02:00
|
|
|
Provider.of<MyWalletsProvider>(context, listen: false);
|
|
|
|
|
|
|
|
bool isNameValid = walletName.text.length >= 2 &&
|
|
|
|
!walletName.text.contains(':') &&
|
|
|
|
walletName.text.length <= 39;
|
|
|
|
|
|
|
|
if (isNameValid) {
|
2022-08-06 02:22:41 +02:00
|
|
|
for (var wallet in myWalletProvider.listWallets) {
|
2022-06-12 21:19:05 +02:00
|
|
|
if (walletName.text == wallet.name!) {
|
|
|
|
canValidateNameBool = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
canValidateNameBool = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
canValidateNameBool = false;
|
|
|
|
}
|
|
|
|
notifyListeners();
|
|
|
|
return canValidateNameBool;
|
|
|
|
}
|
|
|
|
|
2022-09-09 01:12:17 +02:00
|
|
|
void reload() {
|
2021-03-02 08:19:20 +01:00
|
|
|
notifyListeners();
|
|
|
|
}
|
2022-05-19 07:00:25 +02:00
|
|
|
|
2022-05-31 18:23:56 +02:00
|
|
|
Future changePinCacheChoice() async {
|
2022-06-01 07:33:56 +02:00
|
|
|
bool isCacheChecked = configBox.get('isCacheChecked') ?? false;
|
2022-05-31 18:23:56 +02:00
|
|
|
await configBox.put('isCacheChecked', !isCacheChecked);
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
2022-05-19 07:00:25 +02:00
|
|
|
String? getAddress(int chest, int derivation) {
|
2022-08-06 02:22:41 +02:00
|
|
|
String? addressGet;
|
2022-05-19 07:00:25 +02:00
|
|
|
walletBox.toMap().forEach((key, value) {
|
2022-05-19 09:07:26 +02:00
|
|
|
if (value.chest == chest && value.derivation == derivation) {
|
2022-08-06 02:22:41 +02:00
|
|
|
addressGet = value.address!;
|
2022-05-19 07:00:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
address.text = addressGet ?? '';
|
2022-05-19 07:00:25 +02:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
return addressGet;
|
2022-05-19 07:00:25 +02:00
|
|
|
}
|
2022-06-13 21:58:57 +02:00
|
|
|
|
|
|
|
Widget walletNameController(BuildContext context, WalletData wallet,
|
|
|
|
[double size = 20]) {
|
|
|
|
nameController.text = wallet.name!;
|
|
|
|
|
|
|
|
return SizedBox(
|
|
|
|
width: 260,
|
|
|
|
child: Stack(children: <Widget>[
|
|
|
|
TextField(
|
2022-08-23 00:25:16 +02:00
|
|
|
key: keyWalletName,
|
2022-06-13 21:58:57 +02:00
|
|
|
autofocus: false,
|
|
|
|
focusNode: walletNameFocus,
|
|
|
|
enabled: isEditing,
|
|
|
|
controller: nameController,
|
|
|
|
minLines: 1,
|
|
|
|
maxLines: 3,
|
|
|
|
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(
|
|
|
|
fontSize: isTall ? size : size * 0.9,
|
|
|
|
color: Colors.black,
|
|
|
|
fontWeight: FontWeight.w400,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Positioned(
|
|
|
|
right: 0,
|
|
|
|
child: InkWell(
|
2022-08-23 00:25:16 +02:00
|
|
|
key: keyRenameWallet,
|
2022-06-13 21:58:57 +02:00
|
|
|
onTap: () async {
|
|
|
|
// _isNewNameValid =
|
|
|
|
// walletProvider.editWalletName(wallet.id(), isCesium: false);
|
|
|
|
await editWalletName(context, wallet.id());
|
|
|
|
await Future.delayed(const Duration(milliseconds: 30));
|
|
|
|
walletNameFocus.requestFocus();
|
|
|
|
},
|
|
|
|
child: ClipRRect(
|
|
|
|
child: Image.asset(
|
|
|
|
isEditing
|
|
|
|
? 'assets/walletOptions/android-checkmark.png'
|
|
|
|
: 'assets/walletOptions/edit.png',
|
|
|
|
width: 25,
|
|
|
|
height: 25),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget walletName(BuildContext context, WalletData wallet,
|
|
|
|
[double size = 20, Color color = Colors.black]) {
|
2022-07-22 22:08:41 +02:00
|
|
|
double newSize = wallet.name!.length <= 15 ? size : size - 2;
|
|
|
|
|
|
|
|
return Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
|
|
|
|
Text(
|
|
|
|
truncate(wallet.name!, 20),
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: isTall ? newSize : newSize * 0.9,
|
|
|
|
color: color,
|
|
|
|
fontWeight: FontWeight.w400,
|
|
|
|
fontStyle: FontStyle.italic,
|
2022-06-13 21:58:57 +02:00
|
|
|
),
|
2022-07-22 22:08:41 +02:00
|
|
|
softWrap: false,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
]);
|
2022-06-13 21:58:57 +02:00
|
|
|
}
|
2021-01-28 15:10:09 +01:00
|
|
|
}
|
2022-05-21 06:47:26 +02:00
|
|
|
|
2022-06-09 23:08:28 +02:00
|
|
|
Map<String, double> balanceCache = {};
|
2022-05-21 06:47:26 +02:00
|
|
|
|
2022-05-28 19:13:30 +02:00
|
|
|
Widget balance(BuildContext context, String address, double size,
|
2022-08-06 02:22:41 +02:00
|
|
|
[Color color = Colors.black,
|
|
|
|
Color loadingColor = const Color(0xffd07316)]) {
|
2022-05-21 06:47:26 +02:00
|
|
|
return Column(children: <Widget>[
|
2022-08-06 02:22:41 +02:00
|
|
|
Consumer<SubstrateSdk>(builder: (context, sdk, _) {
|
2022-05-21 06:47:26 +02:00
|
|
|
return FutureBuilder(
|
2022-08-06 02:22:41 +02:00
|
|
|
future: sdk.getBalance(address),
|
2022-08-11 19:19:50 +02:00
|
|
|
builder: (BuildContext context,
|
|
|
|
AsyncSnapshot<Map<String, double>> globalBalance) {
|
|
|
|
if (globalBalance.connectionState != ConnectionState.done ||
|
|
|
|
globalBalance.hasError) {
|
2022-06-12 18:03:17 +02:00
|
|
|
if (balanceCache[address] != null &&
|
|
|
|
balanceCache[address] != -1) {
|
2022-09-11 13:14:52 +02:00
|
|
|
return Row(children: [
|
|
|
|
Text(balanceCache[address]!.toString(),
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: isTall ? size : size * 0.9, color: color)),
|
|
|
|
const SizedBox(width: 5),
|
|
|
|
udUnitDisplay(size, color),
|
|
|
|
]);
|
2022-05-24 18:31:41 +02:00
|
|
|
} else {
|
|
|
|
return SizedBox(
|
|
|
|
height: 15,
|
|
|
|
width: 15,
|
|
|
|
child: CircularProgressIndicator(
|
2022-08-06 02:22:41 +02:00
|
|
|
color: loadingColor,
|
2022-05-24 18:31:41 +02:00
|
|
|
strokeWidth: 2,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-05-21 06:47:26 +02:00
|
|
|
}
|
2022-08-11 19:19:50 +02:00
|
|
|
balanceCache[address] = globalBalance.data!['transferableBalance']!;
|
2022-06-12 18:03:17 +02:00
|
|
|
if (balanceCache[address] != -1) {
|
2022-09-11 13:14:52 +02:00
|
|
|
return Row(children: [
|
|
|
|
Text(
|
|
|
|
balanceCache[address]!.toString(),
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: isTall ? size : size * 0.9,
|
|
|
|
color: color,
|
|
|
|
),
|
2022-06-12 18:03:17 +02:00
|
|
|
),
|
2022-09-11 13:14:52 +02:00
|
|
|
const SizedBox(width: 5),
|
|
|
|
udUnitDisplay(size, color),
|
|
|
|
]);
|
2022-06-12 18:03:17 +02:00
|
|
|
} else {
|
|
|
|
return const Text('');
|
|
|
|
}
|
2022-05-21 06:47:26 +02:00
|
|
|
});
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
}
|
2022-06-02 19:58:23 +02:00
|
|
|
|
|
|
|
Widget getCerts(BuildContext context, String address, double size,
|
2022-08-06 02:22:41 +02:00
|
|
|
[Color color = Colors.black]) {
|
2022-06-02 19:58:23 +02:00
|
|
|
return Column(children: <Widget>[
|
2022-08-06 02:22:41 +02:00
|
|
|
Consumer<SubstrateSdk>(builder: (context, sdk, _) {
|
2022-06-02 19:58:23 +02:00
|
|
|
return FutureBuilder(
|
2022-12-04 03:03:08 +01:00
|
|
|
future: sdk.getCertsCounter(address),
|
2022-08-06 02:22:41 +02:00
|
|
|
builder: (BuildContext context, AsyncSnapshot<List<int>> certs) {
|
2022-06-16 19:45:34 +02:00
|
|
|
// log.d(_certs.data);
|
2022-06-03 18:15:45 +02:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
return certs.data?[0] != 0 && certs.data != null
|
2022-06-03 18:15:45 +02:00
|
|
|
? Row(
|
|
|
|
children: [
|
2022-06-04 15:08:22 +02:00
|
|
|
Image.asset('assets/medal.png', height: 20),
|
|
|
|
const SizedBox(width: 1),
|
2022-08-06 02:22:41 +02:00
|
|
|
Text(certs.data?[0].toString() ?? '0',
|
2022-06-04 15:08:22 +02:00
|
|
|
style: const TextStyle(fontSize: 20)),
|
|
|
|
const SizedBox(width: 5),
|
|
|
|
Text(
|
2022-08-06 02:22:41 +02:00
|
|
|
"(${certs.data?[1].toString() ?? '0'})",
|
2022-06-04 15:08:22 +02:00
|
|
|
style: const TextStyle(fontSize: 14),
|
|
|
|
)
|
2022-06-03 18:15:45 +02:00
|
|
|
],
|
|
|
|
)
|
|
|
|
: const Text('');
|
2022-06-02 19:58:23 +02:00
|
|
|
});
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
}
|
2022-09-11 13:14:52 +02:00
|
|
|
|
|
|
|
Widget udUnitDisplay(double size, [Color color = Colors.black]) {
|
|
|
|
final bool isUdUnit = configBox.get('isUdUnit') ?? false;
|
|
|
|
return isUdUnit
|
|
|
|
? Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
Text(
|
2022-09-11 14:04:52 +02:00
|
|
|
'ud'.tr(args: ['']),
|
2022-09-11 13:14:52 +02:00
|
|
|
style:
|
|
|
|
TextStyle(fontSize: isTall ? size : size * 0.9, color: color),
|
|
|
|
),
|
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
currencyName,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: (isTall ? size : size * 0.9) * 0.7,
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
color: color),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 15)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
: Text(currencyName,
|
|
|
|
style: TextStyle(fontSize: isTall ? size : size * 0.9, color: color));
|
|
|
|
}
|