2025-04-23 12:19:59 +02:00
|
|
|
import 'dart:io';
|
2022-03-30 17:57:04 +02:00
|
|
|
|
2025-04-23 12:19:59 +02:00
|
|
|
import 'package:cw_core/balance.dart';
|
|
|
|
import 'package:cw_core/pathForWallet.dart';
|
|
|
|
import 'package:cw_core/transaction_history.dart';
|
|
|
|
import 'package:cw_core/transaction_info.dart';
|
|
|
|
import 'package:cw_core/wallet_base.dart';
|
|
|
|
import 'package:cw_core/wallet_credentials.dart';
|
|
|
|
import 'package:cw_core/wallet_info.dart';
|
|
|
|
import 'package:cw_core/wallet_service.dart';
|
|
|
|
import 'package:cw_core/wallet_type.dart';
|
|
|
|
import 'package:hive/hive.dart';
|
2022-03-30 17:57:04 +02:00
|
|
|
|
2025-04-23 12:19:59 +02:00
|
|
|
class HavenWalletService extends WalletService {
|
|
|
|
final Box<WalletInfo> walletInfoSource;
|
2023-03-15 17:30:06 +02:00
|
|
|
|
2025-04-23 12:19:59 +02:00
|
|
|
HavenWalletService(this.walletInfoSource);
|
2023-03-15 17:30:06 +02:00
|
|
|
|
|
|
|
@override
|
2025-04-23 12:19:59 +02:00
|
|
|
WalletType getType() => WalletType.haven;
|
2023-03-15 17:30:06 +02:00
|
|
|
|
|
|
|
@override
|
2025-04-23 12:19:59 +02:00
|
|
|
Future<void> remove(String wallet) async {
|
|
|
|
final path = await pathForWalletDir(name: wallet, type: WalletType.haven);
|
2023-03-15 17:30:06 +02:00
|
|
|
|
2025-04-23 12:19:59 +02:00
|
|
|
final file = Directory(path);
|
|
|
|
final isExist = file.existsSync();
|
2023-03-15 17:30:06 +02:00
|
|
|
|
2025-04-23 12:19:59 +02:00
|
|
|
if (isExist) {
|
|
|
|
await file.delete(recursive: true);
|
2023-03-15 17:30:06 +02:00
|
|
|
}
|
|
|
|
|
2025-04-23 12:19:59 +02:00
|
|
|
final walletInfo = walletInfoSource.values
|
|
|
|
.firstWhere((info) => info.id == WalletBase.idFor(wallet, getType()));
|
|
|
|
await walletInfoSource.delete(walletInfo.key);
|
2023-03-15 17:30:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2025-04-23 12:19:59 +02:00
|
|
|
Future<WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>> create(
|
|
|
|
WalletCredentials credentials,
|
|
|
|
{bool? isTestnet}) {
|
|
|
|
throw UnimplementedError();
|
2023-03-15 17:30:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2025-04-23 12:19:59 +02:00
|
|
|
Future<bool> isWalletExit(String name) {
|
|
|
|
throw UnimplementedError();
|
2023-03-15 17:30:06 +02:00
|
|
|
}
|
2022-03-30 17:57:04 +02:00
|
|
|
|
2022-10-12 13:09:57 -04:00
|
|
|
@override
|
2025-04-23 12:19:59 +02:00
|
|
|
Future<WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>> openWallet(
|
|
|
|
String name, String password) {
|
|
|
|
throw UnimplementedError();
|
2023-03-15 17:30:06 +02:00
|
|
|
}
|
2022-03-30 17:57:04 +02:00
|
|
|
|
2022-10-12 13:09:57 -04:00
|
|
|
@override
|
2025-04-23 12:19:59 +02:00
|
|
|
Future<void> rename(String currentName, String password, String newName) {
|
|
|
|
throw UnimplementedError();
|
2023-03-15 17:30:06 +02:00
|
|
|
}
|
|
|
|
|
2022-10-12 13:09:57 -04:00
|
|
|
@override
|
2025-04-23 12:19:59 +02:00
|
|
|
Future<WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>>
|
|
|
|
restoreFromHardwareWallet(WalletCredentials credentials) {
|
|
|
|
throw UnimplementedError();
|
2023-03-15 17:30:06 +02:00
|
|
|
}
|
2022-03-30 17:57:04 +02:00
|
|
|
|
2022-10-12 13:09:57 -04:00
|
|
|
@override
|
2025-04-23 12:19:59 +02:00
|
|
|
Future<WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>>
|
|
|
|
restoreFromKeys(WalletCredentials credentials, {bool? isTestnet}) {
|
|
|
|
throw UnimplementedError();
|
2023-03-15 17:30:06 +02:00
|
|
|
}
|
2022-03-30 17:57:04 +02:00
|
|
|
|
2022-10-12 13:09:57 -04:00
|
|
|
@override
|
2025-04-23 12:19:59 +02:00
|
|
|
Future<WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo>>
|
|
|
|
restoreFromSeed(WalletCredentials credentials, {bool? isTestnet}) {
|
|
|
|
throw UnimplementedError();
|
2023-03-15 17:30:06 +02:00
|
|
|
}
|
2022-03-30 17:57:04 +02:00
|
|
|
}
|