Import YFVK

This commit is contained in:
Hanh 2023-05-26 08:29:26 +10:00
parent 72188129d0
commit e1d5f21fd0
7 changed files with 101 additions and 33 deletions

View File

@ -183,7 +183,6 @@ class QRAddressState extends State<QRAddressWidget> {
final address = _address();
final shortAddress = centerTrim(address);
final addrMode = active.addrMode;
final hasTAddr = active.taddress.isNotEmpty;
final qrSize = getScreenSize(context) / 2.5;
final coinDef = active.coinDef;
final nextMode = _getNextMode();

View File

@ -49,7 +49,6 @@ class AccountList {
(a) => Account(coin.coin, a.id, a.name!, a.keyType, a.balance, 0))
.toList();
final id = WarpApi.getActiveAccountId(coin.coin);
print("active $id");
if (id != 0) {
accounts.firstWhere((a) => a.id == id).active = true;
}

View File

@ -1,13 +1,9 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:warp_api/warp_api.dart';
import 'coin/coins.dart';
import 'generated/l10n.dart';
import 'main.dart';
final String instantSyncHost = "zec.hanh00.fun"; // temporary & under debugmode
class DevPage extends StatefulWidget {
DevPageState createState() => DevPageState();
}
@ -42,6 +38,10 @@ class DevPageState extends State<DevPage> {
title: Text('Clear Tx Details'),
trailing: Icon(Icons.chevron_right),
onTap: _clearTxDetails),
ListTile(
title: Text('Import YFVK'),
trailing: Icon(Icons.chevron_right),
onTap: _importYFVK),
ListTile(
title: Text('Revoke Dev mode'),
trailing: Icon(Icons.chevron_right),
@ -70,6 +70,49 @@ class DevPageState extends State<DevPage> {
WarpApi.clearTxDetails(active.coin, active.id);
}
_importYFVK() async {
final nameController = TextEditingController();
final keyController = TextEditingController();
final formKey = GlobalKey<FormBuilderState>();
await showDialog(
context: this.context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: Text("Import YFVK"),
content: FormBuilder(
key: formKey,
child: SingleChildScrollView(
child: Column(
children: [
TextFormField(
decoration: InputDecoration(labelText: 'Account Name'),
controller: nameController,
),
TextFormField(
decoration: InputDecoration(labelText: 'Key'),
controller: keyController,
minLines: 8,
maxLines: 16,
validator: (k) => _validateYFVK(nameController.text, k),
),
],
),
)),
actions: confirmButtons(context, () {
final form = formKey.currentState!;
if (form.validate()) Navigator.of(context).pop();
})));
}
String? _validateYFVK(String name, String? key) {
try {
WarpApi.importYFVK(active.coin, name, key!);
} catch (e) {
return "Invalid key: $e";
}
return null;
}
_resetDevMode() {
showSnackBar('Dev mode disabled');
settings.resetDevMode();

@ -1 +1 @@
Subproject commit 652f71a83d8c39e840f416c47e926c7b99dc8b32
Subproject commit 5d17896d2593f3b916a3bd7f8e6463f902fdde5d

View File

@ -321,10 +321,10 @@ class WarpApi {
}, null);
}
// static String ledgerSign(int coin, String txFilename) {
// final res = warp_api_lib.ledger_sign(coin, txFilename.toNativeUtf8().cast<Int8>());
// return res.cast<Utf8>().toDartString();
// }
static void importYFVK(int coin, String name, String yfvk) {
unwrapResultU8(
warp_api_lib.import_uvk(coin, toNative(name), toNative(yfvk)));
}
static DateTime getActivationDate() {
final res = unwrapResultU32(warp_api_lib.get_activation_date());

View File

@ -1429,6 +1429,23 @@ class NativeLibrary {
late final _dart_set_property _set_property =
_set_property_ptr.asFunction<_dart_set_property>();
CResult_u8 import_uvk(
int coin,
ffi.Pointer<ffi.Int8> name,
ffi.Pointer<ffi.Int8> yfvk,
) {
return _import_uvk(
coin,
name,
yfvk,
);
}
late final _import_uvk_ptr =
_lookup<ffi.NativeFunction<_c_import_uvk>>('import_uvk');
late final _dart_import_uvk _import_uvk =
_import_uvk_ptr.asFunction<_dart_import_uvk>();
CResult_____c_char ledger_send(
int coin,
ffi.Pointer<ffi.Int8> tx_plan,
@ -1582,11 +1599,9 @@ const int Account_VT_ID = 4;
const int Account_VT_NAME = 6;
const int Account_VT_COLD = 8;
const int Account_VT_KEY_TYPE = 8;
const int Account_VT_HARDWARE = 10;
const int Account_VT_BALANCE = 12;
const int Account_VT_BALANCE = 10;
const int AccountVec_VT_ACCOUNTS = 4;
@ -2644,6 +2659,18 @@ typedef _dart_set_property = CResult_u8 Function(
ffi.Pointer<ffi.Int8> value,
);
typedef _c_import_uvk = CResult_u8 Function(
ffi.Uint8 coin,
ffi.Pointer<ffi.Int8> name,
ffi.Pointer<ffi.Int8> yfvk,
);
typedef _dart_import_uvk = CResult_u8 Function(
int coin,
ffi.Pointer<ffi.Int8> name,
ffi.Pointer<ffi.Int8> yfvk,
);
typedef _c_ledger_send = CResult_____c_char Function(
ffi.Uint8 coin,
ffi.Pointer<ffi.Int8> tx_plan,

View File

@ -29,10 +29,10 @@ packages:
dependency: transitive
description:
name: async
sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
url: "https://pub.dev"
source: hosted
version: "2.10.0"
version: "2.11.0"
boolean_selector:
dependency: transitive
description:
@ -109,10 +109,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
url: "https://pub.dev"
source: hosted
version: "1.2.1"
version: "1.3.0"
checked_yaml:
dependency: transitive
description:
@ -149,10 +149,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
url: "https://pub.dev"
source: hosted
version: "1.17.0"
version: "1.17.1"
convert:
dependency: "direct main"
description:
@ -287,10 +287,10 @@ packages:
dependency: transitive
description:
name: js
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.5"
version: "0.6.7"
json_annotation:
dependency: "direct main"
description:
@ -319,10 +319,10 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
url: "https://pub.dev"
source: hosted
version: "0.12.13"
version: "0.12.15"
material_color_utilities:
dependency: transitive
description:
@ -335,10 +335,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
url: "https://pub.dev"
source: hosted
version: "1.8.0"
version: "1.9.1"
mime:
dependency: transitive
description:
@ -359,10 +359,10 @@ packages:
dependency: transitive
description:
name: path
sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
url: "https://pub.dev"
source: hosted
version: "1.8.2"
version: "1.8.3"
pool:
dependency: transitive
description:
@ -492,10 +492,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
url: "https://pub.dev"
source: hosted
version: "0.4.16"
version: "0.5.1"
timing:
dependency: transitive
description:
@ -545,5 +545,5 @@ packages:
source: hosted
version: "3.1.1"
sdks:
dart: ">=2.18.0 <3.0.0"
dart: ">=3.0.0-0 <4.0.0"
flutter: ">=1.20.0"