Generic fixes (#1282)

* New versions

* Fix unspent coins issue

* Fix white screen issues for some users
This commit is contained in:
Omar Hatem
2024-01-30 19:57:47 +02:00
committed by GitHub
parent 952503f0d8
commit b92ccb5c0b
11 changed files with 82 additions and 53 deletions
@@ -16,30 +16,17 @@ abstract class UnspentCoinsListViewModelBase with Store {
UnspentCoinsListViewModelBase(
{required this.wallet, required Box<UnspentCoinsInfo> unspentCoinsInfo})
: _unspentCoinsInfo = unspentCoinsInfo {
_updateUnspentCoinsInfo();
_updateUnspents();
}
WalletBase wallet;
final Box<UnspentCoinsInfo> _unspentCoinsInfo;
@computed
ObservableList<UnspentCoinsItem> get items => ObservableList.of(_getUnspents().map((elem) {
final info =
getUnspentCoinInfo(elem.hash, elem.address, elem.value, elem.vout, elem.keyImage);
final ObservableList<UnspentCoinsItem> _items = ObservableList();
return UnspentCoinsItem(
address: elem.address,
amount: '${formatAmountToString(elem.value)} ${wallet.currency.title}',
hash: elem.hash,
isFrozen: info.isFrozen,
note: info.note,
isSending: info.isSending,
amountRaw: elem.value,
vout: elem.vout,
keyImage: elem.keyImage,
isChange: elem.isChange,
);
}));
@computed
ObservableList<UnspentCoinsItem> get items => _items;
Future<void> saveUnspentCoinInfo(UnspentCoinsItem item) async {
try {
@@ -77,9 +64,14 @@ abstract class UnspentCoinsListViewModelBase with Store {
}
Future<void> _updateUnspents() async {
if (wallet.type == WalletType.monero) return monero!.updateUnspents(wallet);
if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash].contains(wallet.type))
return bitcoin!.updateUnspents(wallet);
if (wallet.type == WalletType.monero) {
await monero!.updateUnspents(wallet);
}
if ([WalletType.bitcoin, WalletType.litecoin, WalletType.bitcoinCash].contains(wallet.type)) {
await bitcoin!.updateUnspents(wallet);
}
_updateUnspentCoinsInfo();
}
List<Unspent> _getUnspents() {
@@ -88,4 +80,26 @@ abstract class UnspentCoinsListViewModelBase with Store {
return bitcoin!.getUnspents(wallet);
return List.empty();
}
@action
void _updateUnspentCoinsInfo() {
_items.clear();
_items.addAll(_getUnspents().map((elem) {
final info =
getUnspentCoinInfo(elem.hash, elem.address, elem.value, elem.vout, elem.keyImage);
return UnspentCoinsItem(
address: elem.address,
amount: '${formatAmountToString(elem.value)} ${wallet.currency.title}',
hash: elem.hash,
isFrozen: info.isFrozen,
note: info.note,
isSending: info.isSending,
amountRaw: elem.value,
vout: elem.vout,
keyImage: elem.keyImage,
isChange: elem.isChange,
);
}));
}
}