Skip to content

Commit ff8ff6d

Browse files
authored
Merge branch 'staging' into feat/monero-uri
2 parents 1d93e52 + 037e13f commit ff8ff6d

11 files changed

Lines changed: 251 additions & 182 deletions

File tree

crypto_plugins/flutter_libmwc

lib/db/db_version_migration.dart

Lines changed: 74 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,11 @@ class DbVersionMigrator with WalletDB {
170170
final count = await MainDB.instance.isar.addresses.count();
171171
// add change/receiving tags to address labels
172172
for (var i = 0; i < count; i += 50) {
173-
final addresses =
174-
await MainDB.instance.isar.addresses
175-
.where()
176-
.offset(i)
177-
.limit(50)
178-
.findAll();
173+
final addresses = await MainDB.instance.isar.addresses
174+
.where()
175+
.offset(i)
176+
.limit(50)
177+
.findAll();
179178

180179
final List<isar_models.AddressLabel> labels = [];
181180
for (final address in addresses) {
@@ -203,14 +202,13 @@ class DbVersionMigrator with WalletDB {
203202

204203
// update/create label if tags is not empty
205204
if (tags != null) {
206-
isar_models.AddressLabel? label =
207-
await MainDB.instance.isar.addressLabels
208-
.where()
209-
.addressStringWalletIdEqualTo(
210-
address.value,
211-
address.walletId,
212-
)
213-
.findFirst();
205+
isar_models.AddressLabel? label = await MainDB
206+
.instance
207+
.isar
208+
.addressLabels
209+
.where()
210+
.addressStringWalletIdEqualTo(address.value, address.walletId)
211+
.findFirst();
214212
if (label == null) {
215213
label = isar_models.AddressLabel(
216214
walletId: address.walletId,
@@ -268,13 +266,12 @@ class DbVersionMigrator with WalletDB {
268266
Bitcoincash(CryptoCurrencyNetwork.main).identifier ||
269267
info.coinIdentifier ==
270268
Bitcoincash(CryptoCurrencyNetwork.test).identifier) {
271-
final ids =
272-
await MainDB.instance
273-
.getAddresses(walletId)
274-
.filter()
275-
.typeEqualTo(isar_models.AddressType.p2sh)
276-
.idProperty()
277-
.findAll();
269+
final ids = await MainDB.instance
270+
.getAddresses(walletId)
271+
.filter()
272+
.typeEqualTo(isar_models.AddressType.p2sh)
273+
.idProperty()
274+
.findAll();
278275

279276
await MainDB.instance.isar.writeTxn(() async {
280277
await MainDB.instance.isar.addresses.deleteAll(ids);
@@ -376,6 +373,32 @@ class DbVersionMigrator with WalletDB {
376373
// try to continue migrating
377374
return await migrate(15, secureStore: secureStore);
378375

376+
case 15:
377+
// Clear stale MWC wallet handles from older builds.
378+
await DB.instance.hive.openBox<dynamic>(DB.boxNameAllWalletsData);
379+
final mwcMigrationWalletsService = WalletsService();
380+
final mwcMigrationWalletNames =
381+
await mwcMigrationWalletsService.walletNames;
382+
final mwcIdentifier = Mimblewimblecoin(
383+
CryptoCurrencyNetwork.main,
384+
).identifier;
385+
for (final walletId in mwcMigrationWalletNames.keys) {
386+
if (mwcMigrationWalletNames[walletId]!.coinIdentifier ==
387+
mwcIdentifier) {
388+
await secureStore.delete(key: '${walletId}_wallet');
389+
}
390+
}
391+
392+
// update version
393+
await DB.instance.put<dynamic>(
394+
boxName: DB.boxNameDBInfo,
395+
key: "hive_data_version",
396+
value: 16,
397+
);
398+
399+
// try to continue migrating
400+
return await migrate(16, secureStore: secureStore);
401+
379402
default:
380403
// finally return
381404
return;
@@ -421,17 +444,15 @@ class DbVersionMigrator with WalletDB {
421444
walletId: walletId,
422445
txid: tx.txid,
423446
timestamp: tx.timestamp,
424-
type:
425-
isIncoming
426-
? isar_models.TransactionType.incoming
427-
: isar_models.TransactionType.outgoing,
447+
type: isIncoming
448+
? isar_models.TransactionType.incoming
449+
: isar_models.TransactionType.outgoing,
428450
subType: isar_models.TransactionSubType.none,
429451
amount: tx.amount,
430-
amountString:
431-
Amount(
432-
rawValue: BigInt.from(tx.amount),
433-
fractionDigits: epic.fractionDigits,
434-
).toJsonString(),
452+
amountString: Amount(
453+
rawValue: BigInt.from(tx.amount),
454+
fractionDigits: epic.fractionDigits,
455+
).toJsonString(),
435456
fee: tx.fees,
436457
height: tx.height,
437458
isCancelled: tx.isCancelled,
@@ -453,14 +474,12 @@ class DbVersionMigrator with WalletDB {
453474
publicKey: [],
454475
derivationIndex: isIncoming ? rcvIndex : -1,
455476
derivationPath: null,
456-
type:
457-
isIncoming
458-
? isar_models.AddressType.mimbleWimble
459-
: isar_models.AddressType.unknown,
460-
subType:
461-
isIncoming
462-
? isar_models.AddressSubType.receiving
463-
: isar_models.AddressSubType.unknown,
477+
type: isIncoming
478+
? isar_models.AddressType.mimbleWimble
479+
: isar_models.AddressType.unknown,
480+
subType: isIncoming
481+
? isar_models.AddressSubType.receiving
482+
: isar_models.AddressSubType.unknown,
464483
);
465484
transactionsData.add(Tuple2(iTx, address));
466485
}
@@ -518,28 +537,25 @@ class DbVersionMigrator with WalletDB {
518537
final crypto = AppConfig.getCryptoCurrencyFor(info.coinIdentifier)!;
519538

520539
for (var i = 0; i < count; i += 50) {
521-
final txns =
522-
await MainDB.instance
523-
.getTransactions(walletId)
524-
.offset(i)
525-
.limit(50)
526-
.findAll();
540+
final txns = await MainDB.instance
541+
.getTransactions(walletId)
542+
.offset(i)
543+
.limit(50)
544+
.findAll();
527545

528546
// migrate amount to serialized amount string
529-
final txnsData =
530-
txns
531-
.map(
532-
(tx) => Tuple2(
533-
tx
534-
..amountString =
535-
Amount(
536-
rawValue: BigInt.from(tx.amount),
537-
fractionDigits: crypto.fractionDigits,
538-
).toJsonString(),
539-
tx.address.value,
540-
),
541-
)
542-
.toList();
547+
final txnsData = txns
548+
.map(
549+
(tx) => Tuple2(
550+
tx
551+
..amountString = Amount(
552+
rawValue: BigInt.from(tx.amount),
553+
fractionDigits: crypto.fractionDigits,
554+
).toJsonString(),
555+
tx.address.value,
556+
),
557+
)
558+
.toList();
543559

544560
// update db records
545561
await MainDB.instance.addNewTransactionData(txnsData, walletId);

lib/models/node_model.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class NodeModel {
4747
final bool forceNoTor;
4848
// @HiveField(14)
4949
final bool isPrimary;
50+
// @HiveField(15)
51+
final String? nodeApiSecret;
5052

5153
NodeModel({
5254
required this.host,
@@ -64,6 +66,7 @@ class NodeModel {
6466
this.forceNoTor = false,
6567
this.loginName,
6668
this.trusted,
69+
this.nodeApiSecret,
6770
});
6871

6972
NodeModel copyWith({
@@ -81,6 +84,7 @@ class NodeModel {
8184
bool? forceNoTor,
8285
bool? clearnetEnabled,
8386
bool? isPrimary,
87+
String? nodeApiSecret,
8488
}) {
8589
return NodeModel(
8690
host: host ?? this.host,
@@ -98,6 +102,7 @@ class NodeModel {
98102
clearnetEnabled: clearnetEnabled ?? this.clearnetEnabled,
99103
forceNoTor: forceNoTor ?? this.forceNoTor,
100104
isPrimary: isPrimary ?? this.isPrimary,
105+
nodeApiSecret: nodeApiSecret ?? this.nodeApiSecret,
101106
);
102107
}
103108

@@ -123,6 +128,7 @@ class NodeModel {
123128
map['clearEnabled'] = clearnetEnabled;
124129
map['forceNoTor'] = forceNoTor;
125130
map['isPrimary'] = isPrimary;
131+
map['nodeApiSecret'] = nodeApiSecret;
126132
return map;
127133
}
128134

lib/models/type_adaptors/node_model.g.dart

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/pages/settings_views/global_settings_view/manage_nodes_views/add_edit_node_view.dart

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ class _AddEditNodeViewState extends ConsumerState<AddEditNodeView> {
259259
clearnetEnabled: plainEnabled,
260260
forceNoTor: forceNoTor,
261261
isPrimary: false,
262+
nodeApiSecret: formData.apiSecret,
262263
);
263264

264265
await ref
@@ -288,6 +289,7 @@ class _AddEditNodeViewState extends ConsumerState<AddEditNodeView> {
288289
clearnetEnabled: plainEnabled,
289290
forceNoTor: forceNoTor,
290291
isPrimary: formData.isPrimary ?? false,
292+
nodeApiSecret: formData.apiSecret,
291293
);
292294

293295
await ref
@@ -750,7 +752,7 @@ class _AddEditNodeViewState extends ConsumerState<AddEditNodeView> {
750752
}
751753

752754
class NodeFormData {
753-
String? name, host, login, password;
755+
String? name, host, login, password, apiSecret;
754756
int? port;
755757
bool? useSSL, isFailover, trusted, forceNoTor, isPrimary;
756758
TorPlainNetworkOption? netOption;
@@ -791,12 +793,14 @@ class _NodeFormState extends ConsumerState<NodeForm> {
791793
late final TextEditingController _portController;
792794
late final TextEditingController _passwordController;
793795
late final TextEditingController _usernameController;
796+
late final TextEditingController _apiSecretController;
794797

795798
final _nameFocusNode = FocusNode();
796799
final _passwordFocusNode = FocusNode();
797800
final _portFocusNode = FocusNode();
798801
final _hostFocusNode = FocusNode();
799802
final _usernameFocusNode = FocusNode();
803+
final _apiSecretFocusNode = FocusNode();
800804

801805
bool _useSSL = false;
802806
bool _isFailover = false;
@@ -858,6 +862,9 @@ class _NodeFormState extends ConsumerState<NodeForm> {
858862
ref.read(nodeFormDataProvider).password = _passwordController.text.isEmpty
859863
? null
860864
: _passwordController.text;
865+
ref.read(nodeFormDataProvider).apiSecret = _apiSecretController.text.isEmpty
866+
? null
867+
: _apiSecretController.text;
861868
ref.read(nodeFormDataProvider).port = port;
862869
ref.read(nodeFormDataProvider).useSSL = _useSSL;
863870
ref.read(nodeFormDataProvider).isFailover = _isFailover;
@@ -876,6 +883,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
876883
_portController = TextEditingController();
877884
_passwordController = TextEditingController();
878885
_usernameController = TextEditingController();
886+
_apiSecretController = TextEditingController();
879887

880888
enableAuthFields = _checkShouldEnableAuthFields(widget.coin);
881889

@@ -897,6 +905,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
897905
_hostController.text = node.host;
898906
_portController.text = node.port.toString();
899907
_usernameController.text = node.loginName ?? "";
908+
_apiSecretController.text = node.nodeApiSecret ?? "";
900909
_useSSL = node.useSSL;
901910
_isFailover = node.isFailover;
902911
_trusted = node.trusted ?? false;
@@ -940,12 +949,14 @@ class _NodeFormState extends ConsumerState<NodeForm> {
940949
_portController.dispose();
941950
_passwordController.dispose();
942951
_usernameController.dispose();
952+
_apiSecretController.dispose();
943953

944954
_nameFocusNode.dispose();
945955
_passwordFocusNode.dispose();
946956
_usernameFocusNode.dispose();
947957
_hostFocusNode.dispose();
948958
_portFocusNode.dispose();
959+
_apiSecretFocusNode.dispose();
949960
super.dispose();
950961
}
951962

@@ -1244,6 +1255,54 @@ class _NodeFormState extends ConsumerState<NodeForm> {
12441255
),
12451256
),
12461257
if (enableAuthFields) const SizedBox(height: 8),
1258+
if (widget.coin is Mimblewimblecoin)
1259+
ClipRRect(
1260+
borderRadius: BorderRadius.circular(
1261+
Constants.size.circularBorderRadius,
1262+
),
1263+
child: TextField(
1264+
autocorrect: Util.isDesktop ? false : true,
1265+
enableSuggestions: Util.isDesktop ? false : true,
1266+
controller: _apiSecretController,
1267+
readOnly: shouldBeReadOnly,
1268+
enabled: enableField(_apiSecretController),
1269+
obscureText: true,
1270+
focusNode: _apiSecretFocusNode,
1271+
style: STextStyles.field(context),
1272+
decoration:
1273+
standardInputDecoration(
1274+
"API secret (optional)",
1275+
_apiSecretFocusNode,
1276+
context,
1277+
).copyWith(
1278+
suffixIcon:
1279+
!shouldBeReadOnly &&
1280+
_apiSecretController.text.isNotEmpty
1281+
? Padding(
1282+
padding: const EdgeInsets.only(right: 0),
1283+
child: UnconstrainedBox(
1284+
child: Row(
1285+
children: [
1286+
TextFieldIconButton(
1287+
child: const XIcon(),
1288+
onTap: () async {
1289+
_apiSecretController.text = "";
1290+
_updateState();
1291+
},
1292+
),
1293+
],
1294+
),
1295+
),
1296+
)
1297+
: null,
1298+
),
1299+
onChanged: (newValue) {
1300+
_updateState();
1301+
setState(() {});
1302+
},
1303+
),
1304+
),
1305+
if (widget.coin is Mimblewimblecoin) const SizedBox(height: 8),
12471306
if (widget.coin is! CryptonoteCurrency)
12481307
Row(
12491308
children: [

0 commit comments

Comments
 (0)