Skip to content

Commit 6ab480a

Browse files
authored
Merge pull request #1639 from SatoshiPortal/1212-bip85-ux
feat: bip85 alias, revoke, activate, copy and UI improvements
2 parents 9347f23 + 9bf386e commit 6ab480a

13 files changed

Lines changed: 352 additions & 85 deletions

lib/core/ark/usecases/create_ark_secret_usecase.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CreateArkSecretUsecase {
4242
// If a revoked derivation exists, reactivate it
4343
if (existingArkDerivation != null) {
4444
if (existingArkDerivation.status == Bip85Status.revoked) {
45-
await _bip85Repository.reactivate(existingArkDerivation.path);
45+
await _bip85Repository.activate(existingArkDerivation);
4646
final xprvBase58 = Bip32Derivation.getXprvFromSeed(
4747
defaultSeed.bytes,
4848
Network.bitcoinMainnet,

lib/core/ark/usecases/revoke_ark_usecase.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class RevokeArkUsecase {
1515
for (final derivation in derivations) {
1616
if (derivation.application == Bip85Application.hex &&
1717
derivation.index == Ark.bip85Index) {
18-
await _bip85Repository.revoke(derivation.path);
18+
await _bip85Repository.revoke(derivation);
1919
break;
2020
}
2121
}

lib/core/bip85/bip85_locator.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import 'package:bb_mobile/core/bip85/data/bip85_datasource.dart';
22
import 'package:bb_mobile/core/bip85/data/bip85_repository.dart';
3+
import 'package:bb_mobile/core/bip85/domain/activate_bip85_derivation_usecase.dart';
4+
import 'package:bb_mobile/core/bip85/domain/alias_bip85_derivation_usecase.dart';
35
import 'package:bb_mobile/core/bip85/domain/derive_next_bip85_hex_from_default_wallet_usecase.dart';
46
import 'package:bb_mobile/core/bip85/domain/derive_next_bip85_mnemonic_from_default_wallet_usecase.dart';
57
import 'package:bb_mobile/core/bip85/domain/fetch_all_derivations_usecase.dart';
8+
import 'package:bb_mobile/core/bip85/domain/revoke_bip85_derivation_usecase.dart';
69
import 'package:bb_mobile/core/seed/data/repository/seed_repository.dart';
710
import 'package:bb_mobile/core/storage/sqlite_database.dart';
811
import 'package:bb_mobile/core/wallet/data/repositories/wallet_repository.dart';
@@ -43,5 +46,20 @@ class Bip85DerivationsLocator {
4346
bip85Repository: locator<Bip85Repository>(),
4447
),
4548
);
49+
locator.registerFactory<AliasBip85DerivationUsecase>(
50+
() => AliasBip85DerivationUsecase(
51+
bip85Repository: locator<Bip85Repository>(),
52+
),
53+
);
54+
locator.registerFactory<RevokeBip85DerivationUsecase>(
55+
() => RevokeBip85DerivationUsecase(
56+
bip85Repository: locator<Bip85Repository>(),
57+
),
58+
);
59+
locator.registerFactory<ActivateBip85DerivationUsecase>(
60+
() => ActivateBip85DerivationUsecase(
61+
bip85Repository: locator<Bip85Repository>(),
62+
),
63+
);
4664
}
4765
}

lib/core/bip85/data/bip85_datasource.dart

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,24 +88,23 @@ class Bip85Datasource {
8888
}
8989

9090
Future<Bip85DerivationModel?> fetch(String path) async {
91-
final row =
92-
await _sqlite.managers.bip85Derivations
93-
.filter((b) => b.path(path))
94-
.getSingleOrNull();
91+
final row = await _sqlite.managers.bip85Derivations
92+
.filter((b) => b.path(path))
93+
.getSingleOrNull();
9594

9695
return row != null ? Bip85DerivationModel.fromSqlite(row) : null;
9796
}
9897

9998
Future<int> fetchNextIndexForApplication(
10099
Bip85ApplicationColumn application,
101100
) async {
102-
final rows =
103-
await _sqlite.managers.bip85Derivations
104-
.filter((b) => b.application(application))
105-
.get();
101+
final rows = await _sqlite.managers.bip85Derivations
102+
.filter((b) => b.application(application))
103+
.get();
106104

107-
final models =
108-
rows.map((row) => Bip85DerivationModel.fromSqlite(row)).toList();
105+
final models = rows
106+
.map((row) => Bip85DerivationModel.fromSqlite(row))
107+
.toList();
109108

110109
int nextIndex = 0;
111110
for (final model in models) {
@@ -134,7 +133,7 @@ class Bip85Datasource {
134133
}
135134
}
136135

137-
Future<void> reactivate(String path) async {
136+
Future<void> activate(String path) async {
138137
try {
139138
await _sqlite.managers.bip85Derivations
140139
.filter((b) => b.path(path))
@@ -144,6 +143,16 @@ class Bip85Datasource {
144143
}
145144
}
146145

146+
Future<void> alias(String path, String alias) async {
147+
try {
148+
await _sqlite.managers.bip85Derivations
149+
.filter((b) => b.path(path))
150+
.update((b) => b(alias: Value(alias)));
151+
} catch (e) {
152+
rethrow;
153+
}
154+
}
155+
147156
// We should not use _store without properly formatting the derivation path.
148157
Future<void> _store(Bip85DerivationModel bip85) async {
149158
try {

lib/core/bip85/data/bip85_repository.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,25 @@ class Bip85Repository {
6767
}
6868
}
6969

70-
Future<void> revoke(String path) async {
70+
Future<void> revoke(Bip85DerivationEntity derivation) async {
7171
try {
72-
await _datasource.revoke(path);
72+
await _datasource.revoke(derivation.path);
7373
} catch (e) {
7474
rethrow;
7575
}
7676
}
7777

78-
Future<void> reactivate(String path) async {
78+
Future<void> activate(Bip85DerivationEntity derivation) async {
7979
try {
80-
await _datasource.reactivate(path);
80+
await _datasource.activate(derivation.path);
81+
} catch (e) {
82+
rethrow;
83+
}
84+
}
85+
86+
Future<void> alias(Bip85DerivationEntity derivation, String alias) async {
87+
try {
88+
await _datasource.alias(derivation.path, alias);
8189
} catch (e) {
8290
rethrow;
8391
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'package:bb_mobile/core/bip85/data/bip85_repository.dart';
2+
import 'package:bb_mobile/core/bip85/domain/bip85_derivation_entity.dart';
3+
4+
class ActivateBip85DerivationUsecase {
5+
final Bip85Repository _bip85Repository;
6+
7+
ActivateBip85DerivationUsecase({required Bip85Repository bip85Repository})
8+
: _bip85Repository = bip85Repository;
9+
10+
Future<void> execute(Bip85DerivationEntity derivation) async {
11+
try {
12+
await _bip85Repository.activate(derivation);
13+
} catch (e) {
14+
rethrow;
15+
}
16+
}
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import 'package:bb_mobile/core/bip85/data/bip85_repository.dart';
2+
import 'package:bb_mobile/core/bip85/domain/bip85_derivation_entity.dart';
3+
4+
class AliasBip85DerivationUsecase {
5+
final Bip85Repository _bip85Repository;
6+
7+
AliasBip85DerivationUsecase({required Bip85Repository bip85Repository})
8+
: _bip85Repository = bip85Repository;
9+
10+
Future<void> execute({
11+
required Bip85DerivationEntity derivation,
12+
required String alias,
13+
}) async {
14+
await _bip85Repository.alias(derivation, alias);
15+
}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'package:bb_mobile/core/bip85/data/bip85_repository.dart';
2+
import 'package:bb_mobile/core/bip85/domain/bip85_derivation_entity.dart';
3+
4+
class RevokeBip85DerivationUsecase {
5+
final Bip85Repository _bip85Repository;
6+
7+
RevokeBip85DerivationUsecase({required Bip85Repository bip85Repository})
8+
: _bip85Repository = bip85Repository;
9+
10+
Future<void> execute(Bip85DerivationEntity derivation) async {
11+
try {
12+
await _bip85Repository.revoke(derivation);
13+
} catch (e) {
14+
rethrow;
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)