Skip to content
Snippets Groups Projects
Commit b184f10d authored by poka's avatar poka
Browse files

can scan v1 pubkey

parent 08bc93d4
No related branches found
No related tags found
No related merge requests found
Pipeline #39847 failed
......@@ -284,5 +284,6 @@
"clearCacheExplanation": "Clear cached data (balances, certifications, etc.)",
"generalSettings": "General",
"clearCacheConfirmTitle": "Clear Cache Confirmation",
"clearCacheConfirmMessage": "Do you really want to clear the cache?\n\nThis includes:\n- Wallet balances\n- Certifications\n- Identity data"
"clearCacheConfirmMessage": "Do you really want to clear the cache?\n\nThis includes:\n- Wallet balances\n- Certifications\n- Identity data",
"qrCodeNotAddress": "This QR code is not a valid address"
}
......@@ -285,5 +285,6 @@
"clearCacheExplanation": "Borrar datos en caché (saldos, certificaciones, etc.)",
"generalSettings": "General",
"clearCacheConfirmTitle": "Confirmación de borrado de caché",
"clearCacheConfirmMessage": "¿Realmente desea borrar el caché?\n\nEsto incluye:\n- Saldos de carteras\n- Certificaciones\n- Datos de identidad"
"clearCacheConfirmMessage": "¿Realmente desea borrar el caché?\n\nEsto incluye:\n- Saldos de carteras\n- Certificaciones\n- Datos de identidad",
"qrCodeNotAddress": "Este código QR no es una dirección válida"
}
......@@ -284,5 +284,6 @@
"clearCacheExplanation": "Effacer les données mises en cache (soldes, certifications, etc.)",
"generalSettings": "Général",
"clearCacheConfirmTitle": "Confirmation de suppression du cache",
"clearCacheConfirmMessage": "Voulez-vous vraiment effacer le cache ?\n\nCela inclut :\n- Les soldes des portefeuilles\n- Les certifications\n- Les données d'identité"
"clearCacheConfirmMessage": "Voulez-vous vraiment effacer le cache ?\n\nCela inclut :\n- Les soldes des portefeuilles\n- Les certifications\n- Les données d'identité",
"qrCodeNotAddress": "Ce QR code n'est pas une adresse valide"
}
......@@ -216,5 +216,6 @@
"blockN": "blocco N°{}",
"thisIsNotAGoodCode": "Questo codice non é valido",
"youHaveToBeConnectedToValidateChest": "Vous devez vous connecter à internet\npour valider votre coffre",
"thisIdentityAlreadyExist": "Identitá giá esistente"
"thisIdentityAlreadyExist": "Identitá giá esistente",
"qrCodeNotAddress": "Questo QR code non é un indirizzo valido"
}
\ No newline at end of file
......@@ -526,10 +526,11 @@ class SubstrateSdk with ChangeNotifier {
}
Future<String> pubkeyV1ToAddress(String pubkey) async {
pubkey = pubkey.split(':')[0];
final pubkeyByte = Base58Decode(pubkey);
final String pubkeyHex = '0x${HEX.encode(pubkeyByte)}';
final address = await sdk.api.account.encodeAddress([pubkeyHex]);
return address!.keys.first;
return address!.values.first;
}
Future initCurrencyParameters() async {
......
......@@ -28,6 +28,8 @@ class WalletsProfilesProvider with ChangeNotifier {
bool isCommentVisible = false;
final sub = Provider.of<SubstrateSdk>(homeContext, listen: false);
String _comment = '';
String get comment => _comment;
set comment(String value) {
......@@ -53,7 +55,7 @@ class WalletsProfilesProvider with ChangeNotifier {
notifyListeners();
}
Future<String> scan(context) async {
Future<void> scan(context) async {
if (Platform.isAndroid || Platform.isIOS) {
await Permission.camera.request();
}
......@@ -62,10 +64,20 @@ class WalletsProfilesProvider with ChangeNotifier {
barcode = await BarcodeScanner.scan();
} catch (e) {
log.e("BarcodeScanner ERR: $e");
return 'false';
return;
}
final barcodeContent = barcode.rawContent;
if (barcodeContent == '') return;
if (await isAddressOrPubkey(barcodeContent)) {
if (!(await isAddress(barcodeContent))) {
address = await sub.pubkeyV1ToAddress(barcodeContent);
} else {
address = barcodeContent;
}
if (await isAddress(barcode.rawContent)) {
address = barcode.rawContent;
Navigator.popUntil(
context,
ModalRoute.withName('/'),
......@@ -74,15 +86,19 @@ class WalletsProfilesProvider with ChangeNotifier {
context,
MaterialPageRoute(builder: (context) {
return WalletViewScreen(
address: barcode!.rawContent,
address: address,
username: null,
);
}),
);
} else {
return 'false';
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('qrCodeNotAddress'.tr()),
duration: const Duration(seconds: 2),
),
);
}
return barcode.rawContent;
}
void resetdHistory() {
......@@ -121,27 +137,26 @@ class WalletsProfilesProvider with ChangeNotifier {
}
}
// bool isAddress(address) {
// final RegExp regExp = RegExp(
// r'^[a-zA-Z0-9]+$',
// caseSensitive: false,
// multiLine: false,
// );
// if (regExp.hasMatch(address) == true &&
// address.length > 45 &&
// address.length < 52) {
// return true;
// } else {
// return false;
// }
// }
Future<bool> isAddressOrPubkey(String address) async {
return await isAddress(address) || isPubkey(address);
}
Future<bool> isAddress(String address) async {
final sub = Provider.of<SubstrateSdk>(homeContext, listen: false);
return await sub.sdk.api.account.checkAddressFormat(address, sub.initSs58).timeout(const Duration(milliseconds: 300)).onError((_, __) => false) ?? false;
}
bool isPubkey(String pubkey) {
pubkey = pubkey.split(':')[0];
final RegExp regExp = RegExp(
r'^[a-zA-Z0-9]+$',
caseSensitive: false,
multiLine: false,
);
return regExp.hasMatch(pubkey) == true && pubkey.length > 42 && pubkey.length < 45;
}
snackMessage(context, {required String message, int duration = 2, double fontSize = 14}) {
final snackBar = SnackBar(
backgroundColor: Colors.grey[900],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment