2021-12-20 21:33:03 +01:00
|
|
|
import 'dart:io';
|
2022-06-17 01:13:14 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2021-01-23 16:38:03 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2021-01-30 19:00:31 +01:00
|
|
|
import 'package:gecko/globals.dart';
|
2022-08-14 20:02:02 +02:00
|
|
|
import 'package:gecko/models/g1_wallets_list.dart';
|
2021-11-29 04:05:08 +01:00
|
|
|
import 'package:gecko/screens/wallet_view.dart';
|
2021-03-21 00:35:32 +01:00
|
|
|
import 'package:jdenticon_dart/jdenticon_dart.dart';
|
2021-01-23 16:38:03 +01:00
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
2022-06-01 23:59:56 +02:00
|
|
|
// import 'package:qrscan/qrscan.dart' as scanner;
|
|
|
|
import 'package:barcode_scan2/barcode_scan2.dart';
|
2021-01-23 16:38:03 +01:00
|
|
|
|
2021-11-30 01:25:48 +01:00
|
|
|
class WalletsProfilesProvider with ChangeNotifier {
|
2022-05-30 15:32:00 +02:00
|
|
|
WalletsProfilesProvider(this.address);
|
2021-11-30 01:25:48 +01:00
|
|
|
|
2022-09-12 11:22:26 +02:00
|
|
|
String address = '';
|
2021-02-16 03:55:01 +01:00
|
|
|
String pubkeyShort = '';
|
2022-06-16 19:45:34 +02:00
|
|
|
|
2021-02-17 00:15:08 +01:00
|
|
|
bool isHistoryScreen = false;
|
|
|
|
String historySwitchButtun = "Voir l'historique";
|
2021-12-23 12:36:09 +01:00
|
|
|
String? rawSvg;
|
2021-04-03 00:07:03 +02:00
|
|
|
TextEditingController payAmount = TextEditingController();
|
|
|
|
TextEditingController payComment = TextEditingController();
|
2022-06-16 20:09:35 +02:00
|
|
|
num? _balance;
|
2021-01-30 15:48:27 +01:00
|
|
|
|
2022-05-30 14:48:12 +02:00
|
|
|
Future<String> scan(context) async {
|
2021-12-20 21:33:03 +01:00
|
|
|
if (Platform.isAndroid || Platform.isIOS) {
|
|
|
|
await Permission.camera.request();
|
|
|
|
}
|
2022-06-01 23:59:56 +02:00
|
|
|
ScanResult? barcode;
|
2021-01-23 16:38:03 +01:00
|
|
|
try {
|
2022-06-01 23:59:56 +02:00
|
|
|
barcode = await BarcodeScanner.scan();
|
2021-02-18 04:42:57 +01:00
|
|
|
} catch (e) {
|
2023-02-26 02:23:28 +01:00
|
|
|
log.e("BarcodeScanner ERR: $e");
|
2021-01-23 16:38:03 +01:00
|
|
|
return 'false';
|
|
|
|
}
|
2022-06-01 23:59:56 +02:00
|
|
|
if (isAddress(barcode.rawContent)) {
|
2021-11-30 01:25:48 +01:00
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
2022-12-05 04:03:53 +01:00
|
|
|
return WalletViewScreen(
|
|
|
|
address: barcode!.rawContent,
|
|
|
|
username: '',
|
|
|
|
);
|
2021-11-30 01:25:48 +01:00
|
|
|
}),
|
|
|
|
);
|
2021-01-23 16:38:03 +01:00
|
|
|
} else {
|
|
|
|
return 'false';
|
|
|
|
}
|
2022-06-01 23:59:56 +02:00
|
|
|
return barcode.rawContent;
|
2021-01-23 16:38:03 +01:00
|
|
|
}
|
|
|
|
|
2022-05-19 13:44:22 +02:00
|
|
|
// Future<String> pay(BuildContext context, {int? derivation}) async {
|
|
|
|
// MyWalletsProvider _myWalletProvider =
|
|
|
|
// Provider.of<MyWalletsProvider>(context, listen: false);
|
|
|
|
// int? currentChest = configBox.get('currentChest');
|
|
|
|
// String result;
|
2021-12-03 10:25:36 +01:00
|
|
|
|
2022-05-19 13:44:22 +02:00
|
|
|
// derivation ??=
|
|
|
|
// _myWalletProvider.getDefaultWallet(currentChest)!.derivation!;
|
|
|
|
// result = await Gva(node: endPointGVA).pay(
|
|
|
|
// recipient: pubkey!,
|
|
|
|
// amount: double.parse(payAmount.text),
|
|
|
|
// mnemonic: _myWalletProvider.mnemonic,
|
|
|
|
// comment: payComment.text,
|
|
|
|
// derivation: derivation,
|
|
|
|
// lang: appLang);
|
2021-11-14 03:12:07 +01:00
|
|
|
|
2022-05-19 13:44:22 +02:00
|
|
|
// return result;
|
|
|
|
// }
|
2021-03-29 22:12:38 +02:00
|
|
|
|
2022-05-30 15:32:00 +02:00
|
|
|
bool isAddress(address) {
|
2021-11-14 19:21:20 +01:00
|
|
|
final RegExp regExp = RegExp(
|
2021-01-23 16:38:03 +01:00
|
|
|
r'^[a-zA-Z0-9]+$',
|
|
|
|
caseSensitive: false,
|
|
|
|
multiLine: false,
|
|
|
|
);
|
|
|
|
|
2022-05-30 15:32:00 +02:00
|
|
|
if (regExp.hasMatch(address) == true &&
|
2022-05-30 20:30:06 +02:00
|
|
|
address.length > 45 &&
|
|
|
|
address.length < 52) {
|
2022-05-30 15:32:00 +02:00
|
|
|
log.d("C'est une adresse !");
|
2021-01-23 16:38:03 +01:00
|
|
|
|
2022-05-30 15:32:00 +02:00
|
|
|
this.address = address;
|
2021-03-21 00:35:32 +01:00
|
|
|
|
2021-11-30 01:25:48 +01:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
2021-01-23 16:38:03 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-29 02:20:15 +01:00
|
|
|
|
2021-04-03 12:50:34 +02:00
|
|
|
// poka: Do99s6wQR2JLfhirPdpAERSjNbmjjECzGxHNJMiNKT3P
|
2021-02-06 08:31:14 +01:00
|
|
|
// Pi: D2meevcAHFTS2gQMvmRW5Hzi25jDdikk4nC4u1FkwRaU // For debug
|
2021-02-03 18:45:08 +01:00
|
|
|
// Boris: JE6mkuzSpT3ePciCPRTpuMT9fqPUVVLJz2618d33p7tn
|
2021-02-06 08:31:14 +01:00
|
|
|
// Matograine portefeuille: 9p5nHsES6xujFR7pw2yGy4PLKKHgWsMvsDHaHF64Uj25.
|
|
|
|
// Lion simone: 78jhpprYkMNF6i5kQPXfkAVBpd2aqcpieNsXTSW4c21f
|
2021-02-03 18:45:08 +01:00
|
|
|
|
2021-01-30 15:24:08 +01:00
|
|
|
void resetdHistory() {
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
String generateIdenticon(String pubkey) {
|
|
|
|
return Jdenticon.toSvg(pubkey);
|
2021-03-21 00:35:32 +01:00
|
|
|
}
|
2021-11-30 10:28:13 +01:00
|
|
|
|
2021-12-01 08:14:07 +01:00
|
|
|
// Future<num> getBalance(String _pubkey) async {
|
|
|
|
// final url = Uri.parse(
|
|
|
|
// '$endPointGVA?query={%20balance(script:%20%22$_pubkey%22)%20{%20amount%20base%20}%20}');
|
|
|
|
// final response = await http.get(url);
|
|
|
|
// final result = json.decode(response.body);
|
|
|
|
|
|
|
|
// if (result['data']['balance'] == null) {
|
|
|
|
// balance = 0.0;
|
|
|
|
// } else {
|
|
|
|
// balance = removeDecimalZero(result['data']['balance']['amount'] / 100);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return balance;
|
|
|
|
// }
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
Future<num?> getBalance(String? pubkey) async {
|
2022-06-16 20:09:35 +02:00
|
|
|
while (_balance == null) {
|
2021-12-01 08:14:07 +01:00
|
|
|
await Future.delayed(const Duration(milliseconds: 50));
|
2021-11-30 10:28:13 +01:00
|
|
|
}
|
|
|
|
|
2022-06-16 20:09:35 +02:00
|
|
|
return _balance;
|
2021-11-30 10:28:13 +01:00
|
|
|
}
|
2022-05-25 20:40:55 +02:00
|
|
|
|
2022-08-14 20:02:02 +02:00
|
|
|
bool isContact(String address) {
|
|
|
|
return contactsBox.containsKey(address);
|
|
|
|
}
|
|
|
|
|
2022-08-14 22:16:46 +02:00
|
|
|
Future addContact(G1WalletsList profile) async {
|
|
|
|
// log.d(profile.username);
|
2022-09-12 11:22:26 +02:00
|
|
|
if (isContact(profile.address)) {
|
|
|
|
await contactsBox.delete(profile.address);
|
2022-08-14 20:02:02 +02:00
|
|
|
} else {
|
2022-09-12 11:22:26 +02:00
|
|
|
await contactsBox.put(profile.address, profile);
|
2022-08-14 20:02:02 +02:00
|
|
|
}
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
2022-05-25 20:40:55 +02:00
|
|
|
void reload() {
|
|
|
|
notifyListeners();
|
|
|
|
}
|
2021-01-23 16:38:03 +01:00
|
|
|
}
|
2022-05-21 06:47:26 +02:00
|
|
|
|
2023-02-02 20:10:00 +01:00
|
|
|
snackMessage(context,
|
|
|
|
{required String message, int duration = 2, double fontSize = 16}) {
|
|
|
|
final snackBar = SnackBar(
|
|
|
|
padding: const EdgeInsets.all(20),
|
|
|
|
content: Text(message, style: TextStyle(fontSize: fontSize)),
|
|
|
|
duration: Duration(seconds: duration));
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
|
|
|
}
|
|
|
|
|
2022-05-21 06:47:26 +02:00
|
|
|
snackCopyKey(context) {
|
2022-06-17 01:13:14 +02:00
|
|
|
final snackBar = SnackBar(
|
|
|
|
padding: const EdgeInsets.all(20),
|
|
|
|
content: Text("thisAddressHasBeenCopiedToClipboard".tr(),
|
|
|
|
style: const TextStyle(fontSize: 16)),
|
2022-06-17 20:18:54 +02:00
|
|
|
duration: const Duration(seconds: 2));
|
2022-05-21 06:47:26 +02:00
|
|
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
|
|
|
}
|
2022-12-03 10:44:48 +01:00
|
|
|
|
|
|
|
snackCopySeed(context) {
|
|
|
|
final snackBar = SnackBar(
|
|
|
|
padding: const EdgeInsets.all(20),
|
|
|
|
content: Text("thisMnemonicHasBeenCopiedToClipboard".tr(),
|
|
|
|
style: const TextStyle(fontSize: 17)),
|
|
|
|
duration: const Duration(seconds: 4));
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
|
|
|
}
|