cake_wallet/cw_nano/lib/nano_wallet_addresses.dart

46 lines
1.3 KiB
Dart
Raw Normal View History

2023-08-15 19:05:38 +00:00
import 'package:cw_core/cake_hive.dart';
2023-07-24 20:23:09 +00:00
import 'package:cw_core/wallet_addresses.dart';
import 'package:cw_core/wallet_info.dart';
2023-08-10 22:34:20 +00:00
import 'package:cw_core/nano_account.dart';
2023-07-24 20:23:09 +00:00
import 'package:cw_nano/nano_account_list.dart';
2023-08-10 22:34:20 +00:00
// import 'package:cw_core/account.dart';
// import 'package:cw_core/subaddress.dart';
2023-07-24 20:23:09 +00:00
import 'package:mobx/mobx.dart';
2023-08-10 22:34:20 +00:00
import 'package:hive/hive.dart';
2023-07-24 20:23:09 +00:00
2023-07-25 15:21:49 +00:00
part 'nano_wallet_addresses.g.dart';
2023-07-24 20:23:09 +00:00
2023-07-25 15:21:49 +00:00
class NanoWalletAddresses = NanoWalletAddressesBase with _$NanoWalletAddresses;
2023-07-24 20:23:09 +00:00
abstract class NanoWalletAddressesBase extends WalletAddresses with Store {
NanoWalletAddressesBase(WalletInfo walletInfo)
2023-08-10 22:34:20 +00:00
: accountList = NanoAccountList(walletInfo.address),
address = '',
2023-07-25 15:21:49 +00:00
super(walletInfo);
2023-07-24 20:23:09 +00:00
@override
2023-08-10 22:34:20 +00:00
@observable
2023-07-24 20:23:09 +00:00
String address;
2023-07-25 15:21:49 +00:00
2023-08-10 22:34:20 +00:00
@observable
NanoAccount? account;
NanoAccountList accountList;
2023-07-24 20:23:09 +00:00
@override
Future<void> init() async {
2023-08-15 19:05:38 +00:00
var box = await CakeHive.openBox<NanoAccount>(walletInfo.address);
2023-08-10 22:34:20 +00:00
try {
box.getAt(0);
} catch (e) {
2023-08-10 23:29:51 +00:00
box.add(NanoAccount(id: 0, label: "Primary Account", balance: "0.00"));
2023-08-10 22:34:20 +00:00
}
2023-08-10 23:29:51 +00:00
await accountList.update(walletInfo.address);
2023-08-10 22:34:20 +00:00
account = accountList.accounts.first;
2023-07-25 17:36:24 +00:00
address = walletInfo.address;
2023-07-24 20:23:09 +00:00
}
2023-07-25 15:21:49 +00:00
@override
2023-08-10 23:29:51 +00:00
Future<void> updateAddressesInBox() async {}
2023-08-10 22:34:20 +00:00
}