cake_wallet/cw_nano/lib/nano_wallet_addresses.dart

59 lines
1.5 KiB
Dart
Raw Normal View History

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;
// NanoSubaddressList subaddressList;
NanoAccountList accountList;
2023-07-24 20:23:09 +00:00
@override
Future<void> init() async {
2023-08-10 22:34:20 +00:00
var box = await Hive.openBox<NanoAccount>(walletInfo.address);
try {
box.getAt(0);
} catch (e) {
box.add(NanoAccount(id: 0, label: "Primary Account", balance: "0"));
}
await accountList.update();
print("####################");
print(accountList.accounts);
account = accountList.accounts.first;
2023-07-25 17:36:24 +00:00
address = walletInfo.address;
2023-08-10 22:34:20 +00:00
2023-07-25 17:36:24 +00:00
await updateAddressesInBox();
2023-07-24 20:23:09 +00:00
}
2023-07-25 15:21:49 +00:00
@override
Future<void> updateAddressesInBox() async {
2023-08-10 22:34:20 +00:00
// try {
// addressesMap.clear();
// addressesMap[address] = '';
// await saveAddressesInBox();
// } catch (e) {
// print(e.toString());
// }
2023-07-24 20:23:09 +00:00
}
2023-08-10 22:34:20 +00:00
}