mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 12:09:43 +00:00
f6670c0236
* Added CoinsInfo to monero_api_cpp * Add struct on dart * Add struct on dart * Set coins value * CW-415 Use add-coin-to-monero branch * CW-415 Add get Coin and build Monero Deps using Docker * CW-415 Fix Typo * CW-415 add debug log info * CW-415 Add preferred key Images for coin control to Monero * CW-415 Fix generation * CW-415 Skip GA Cache Externals * CW-415 Skip GA Cache Externals * CW-415 Coin Control: remove Block Explorer for Monero, Add Tx hash, save note on field exit * CW-415 Coin Control: Throw Exception when all outputs are deselected * CW-415 Coin Control: Show Frozen Balance on Dashboard * CW-415 Coin Control: Show Frozen Balance on Dashboard * CW-415 Ignore cached Monero deps in Workflow * CW-415 Fix displaying frozen Balance * Use own Translator with http 1.1.0 * CW-415 Resolve requested Changes * CW-415 Resolve requested Changes * CW-415 Resolve requested Changes * CW-415 Apply requested Changes * CW-415 Apply requested Changes * CW-415 Ensure opening of UnspentCoinsInfo Box, even for Monero.com --------- Co-authored-by: Konstantin Ullrich <konstantinullrich12@gmail.com>
91 lines
2.5 KiB
Dart
91 lines
2.5 KiB
Dart
import 'package:flutter/services.dart';
|
|
import 'package:mobx/mobx.dart';
|
|
import 'package:cw_monero/api/coins_info.dart';
|
|
import 'package:cw_monero/api/subaddress_list.dart' as subaddress_list;
|
|
import 'package:cw_core/subaddress.dart';
|
|
|
|
part 'monero_subaddress_list.g.dart';
|
|
|
|
class MoneroSubaddressList = MoneroSubaddressListBase
|
|
with _$MoneroSubaddressList;
|
|
|
|
abstract class MoneroSubaddressListBase with Store {
|
|
MoneroSubaddressListBase()
|
|
: _isRefreshing = false,
|
|
_isUpdating = false,
|
|
subaddresses = ObservableList<Subaddress>();
|
|
|
|
@observable
|
|
ObservableList<Subaddress> subaddresses;
|
|
|
|
bool _isRefreshing;
|
|
bool _isUpdating;
|
|
|
|
void update({required int accountIndex}) {
|
|
refreshCoins(accountIndex);
|
|
|
|
if (_isUpdating) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
_isUpdating = true;
|
|
refresh(accountIndex: accountIndex);
|
|
subaddresses.clear();
|
|
subaddresses.addAll(getAll());
|
|
_isUpdating = false;
|
|
} catch (e) {
|
|
_isUpdating = false;
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
List<Subaddress> getAll() {
|
|
var subaddresses = subaddress_list.getAllSubaddresses();
|
|
|
|
if (subaddresses.length > 2) {
|
|
final primary = subaddresses.first;
|
|
final rest = subaddresses.sublist(1).reversed;
|
|
subaddresses = [primary] + rest.toList();
|
|
}
|
|
|
|
return subaddresses
|
|
.map((subaddressRow) => Subaddress(
|
|
id: subaddressRow.getId(),
|
|
address: subaddressRow.getAddress(),
|
|
label: subaddressRow.getId() == 0 &&
|
|
subaddressRow.getLabel().toLowerCase() == 'Primary account'.toLowerCase()
|
|
? 'Primary address'
|
|
: subaddressRow.getLabel()))
|
|
.toList();
|
|
}
|
|
|
|
Future<void> addSubaddress({required int accountIndex, required String label}) async {
|
|
await subaddress_list.addSubaddress(
|
|
accountIndex: accountIndex, label: label);
|
|
update(accountIndex: accountIndex);
|
|
}
|
|
|
|
Future<void> setLabelSubaddress(
|
|
{required int accountIndex, required int addressIndex, required String label}) async {
|
|
await subaddress_list.setLabelForSubaddress(
|
|
accountIndex: accountIndex, addressIndex: addressIndex, label: label);
|
|
update(accountIndex: accountIndex);
|
|
}
|
|
|
|
void refresh({required int accountIndex}) {
|
|
if (_isRefreshing) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
_isRefreshing = true;
|
|
subaddress_list.refreshSubaddresses(accountIndex: accountIndex);
|
|
_isRefreshing = false;
|
|
} on PlatformException catch (e) {
|
|
_isRefreshing = false;
|
|
print(e);
|
|
rethrow;
|
|
}
|
|
}
|
|
}
|