Skip to content

Commit 0872e72

Browse files
committed
hook up salvium wallet files deletion
1 parent 97f5995 commit 0872e72

File tree

2 files changed

+41
-14
lines changed

2 files changed

+41
-14
lines changed

lib/services/wallets.dart

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import 'dart:async';
12+
import 'dart:io';
1213

1314
import 'package:compat/compat.dart' as lib_monero_compat;
1415
import 'package:isar/isar.dart';
@@ -22,6 +23,7 @@ import '../utilities/logger.dart';
2223
import '../utilities/prefs.dart';
2324
import '../utilities/stack_file_system.dart';
2425
import '../wallets/crypto_currency/crypto_currency.dart';
26+
import '../wallets/crypto_currency/intermediate/cryptonote_currency.dart';
2527
import '../wallets/isar/models/wallet_info.dart';
2628
import '../wallets/wallet/impl/epiccash_wallet.dart';
2729
import '../wallets/wallet/intermediate/lib_monero_wallet.dart';
@@ -68,6 +70,38 @@ class Wallets {
6870
}
6971
}
7072

73+
Future<void> _deleteCryptonoteWalletFilesHelper(WalletInfo info) async {
74+
final walletId = info.walletId;
75+
if (info.coin is Wownero) {
76+
await lib_monero_compat.deleteWalletFiles(
77+
name: walletId,
78+
type: lib_monero_compat.WalletType.wownero,
79+
appRoot: await StackFileSystem.applicationRootDirectory(),
80+
);
81+
Logging.instance.d("Wownero wallet: $walletId deleted");
82+
} else if (info.coin is Monero) {
83+
await lib_monero_compat.deleteWalletFiles(
84+
name: walletId,
85+
type: lib_monero_compat.WalletType.monero,
86+
appRoot: await StackFileSystem.applicationRootDirectory(),
87+
);
88+
Logging.instance.d("Monero wallet: $walletId deleted");
89+
} else if (info.coin is Salvium) {
90+
final path = await salviumWalletDir(
91+
walletId: walletId,
92+
appRoot: await StackFileSystem.applicationRootDirectory(),
93+
);
94+
final file = Directory(path);
95+
final isExist = file.existsSync();
96+
97+
if (isExist) {
98+
await file.delete(recursive: true);
99+
}
100+
} else {
101+
throw Exception("Not a valid CN coin");
102+
}
103+
}
104+
71105
Future<void> deleteWallet(
72106
WalletInfo info,
73107
SecureStorageInterface secureStorage,
@@ -88,20 +122,8 @@ class Wallets {
88122
key: Wallet.getViewOnlyWalletDataSecStoreKey(walletId: walletId),
89123
);
90124

91-
if (info.coin is Wownero) {
92-
await lib_monero_compat.deleteWalletFiles(
93-
name: walletId,
94-
type: lib_monero_compat.WalletType.wownero,
95-
appRoot: await StackFileSystem.applicationRootDirectory(),
96-
);
97-
Logging.instance.d("monero wallet: $walletId deleted");
98-
} else if (info.coin is Monero) {
99-
await lib_monero_compat.deleteWalletFiles(
100-
name: walletId,
101-
type: lib_monero_compat.WalletType.monero,
102-
appRoot: await StackFileSystem.applicationRootDirectory(),
103-
);
104-
Logging.instance.d("monero wallet: $walletId deleted");
125+
if (info.coin is CryptonoteCurrency) {
126+
await _deleteCryptonoteWalletFilesHelper(info);
105127
} else if (info.coin is Epiccash) {
106128
final deleteResult = await deleteEpicWallet(
107129
walletId: walletId,

lib/wallets/wallet/intermediate/lib_salvium_wallet.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,11 @@ Future<String> _pathForWallet({
15301530
appRoot: appRoot,
15311531
).then((path) => '$path/$name');
15321532

1533+
Future<String> salviumWalletDir({
1534+
required String walletId,
1535+
required Directory appRoot,
1536+
}) => _pathForWalletDir(name: walletId, appRoot: appRoot);
1537+
15331538
// =============================================================================
15341539
// The following sync status stuff copy pasted here for now to simplify the
15351540
// integration of salvium.

0 commit comments

Comments
 (0)