mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-26 21:50:27 +00:00
01150ef2a7
* hv * Change build version
83 lines
No EOL
2.4 KiB
Dart
83 lines
No EOL
2.4 KiB
Dart
import 'dart:ffi';
|
|
import 'package:ffi/ffi.dart';
|
|
import 'package:cw_haven/api/signatures.dart';
|
|
import 'package:cw_haven/api/types.dart';
|
|
import 'package:cw_haven/api/haven_api.dart';
|
|
import 'package:cw_haven/api/structs/account_row.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:cw_haven/api/wallet.dart';
|
|
|
|
final accountSizeNative = havenApi
|
|
.lookup<NativeFunction<account_size>>('account_size')
|
|
.asFunction<SubaddressSize>();
|
|
|
|
final accountRefreshNative = havenApi
|
|
.lookup<NativeFunction<account_refresh>>('account_refresh')
|
|
.asFunction<AccountRefresh>();
|
|
|
|
final accountGetAllNative = havenApi
|
|
.lookup<NativeFunction<account_get_all>>('account_get_all')
|
|
.asFunction<AccountGetAll>();
|
|
|
|
final accountAddNewNative = havenApi
|
|
.lookup<NativeFunction<account_add_new>>('account_add_row')
|
|
.asFunction<AccountAddNew>();
|
|
|
|
final accountSetLabelNative = havenApi
|
|
.lookup<NativeFunction<account_set_label>>('account_set_label_row')
|
|
.asFunction<AccountSetLabel>();
|
|
|
|
bool isUpdating = false;
|
|
|
|
void refreshAccounts() {
|
|
try {
|
|
isUpdating = true;
|
|
accountRefreshNative();
|
|
isUpdating = false;
|
|
} catch (e) {
|
|
isUpdating = false;
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
List<AccountRow> getAllAccount() {
|
|
final size = accountSizeNative();
|
|
final accountAddressesPointer = accountGetAllNative();
|
|
final accountAddresses = accountAddressesPointer.asTypedList(size);
|
|
|
|
return accountAddresses
|
|
.map((addr) => Pointer<AccountRow>.fromAddress(addr).ref)
|
|
.toList();
|
|
}
|
|
|
|
void addAccountSync({String label}) {
|
|
final labelPointer = Utf8.toUtf8(label);
|
|
accountAddNewNative(labelPointer);
|
|
free(labelPointer);
|
|
}
|
|
|
|
void setLabelForAccountSync({int accountIndex, String label}) {
|
|
final labelPointer = Utf8.toUtf8(label);
|
|
accountSetLabelNative(accountIndex, labelPointer);
|
|
free(labelPointer);
|
|
}
|
|
|
|
void _addAccount(String label) => addAccountSync(label: label);
|
|
|
|
void _setLabelForAccount(Map<String, dynamic> args) {
|
|
final label = args['label'] as String;
|
|
final accountIndex = args['accountIndex'] as int;
|
|
|
|
setLabelForAccountSync(label: label, accountIndex: accountIndex);
|
|
}
|
|
|
|
Future<void> addAccount({String label}) async {
|
|
await compute(_addAccount, label);
|
|
await store();
|
|
}
|
|
|
|
Future<void> setLabelForAccount({int accountIndex, String label}) async {
|
|
await compute(
|
|
_setLabelForAccount, {'accountIndex': accountIndex, 'label': label});
|
|
await store();
|
|
} |