CW-415 add coin control for xmr (#985)

* 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>
This commit is contained in:
Godwin Asuquo
2023-08-24 16:54:05 +03:00
committed by GitHub
co-authored by Konstantin Ullrich
parent 3577730de8
commit f6670c0236
56 changed files with 1584 additions and 545 deletions
+6 -2
View File
@@ -172,6 +172,10 @@ abstract class SendViewModelBase with Store {
.where((template) => _isEqualCurrency(template.cryptoCurrency))
.toList();
@computed
bool get hasCoinControl =>
_wallet.type == WalletType.bitcoin || _wallet.type == WalletType.litecoin || _wallet.type == WalletType.monero;
@computed
bool get isElectrumWallet =>
_wallet.type == WalletType.bitcoin || _wallet.type == WalletType.litecoin;
@@ -206,12 +210,12 @@ abstract class SendViewModelBase with Store {
@computed
List<ContactRecord> get contactsToShow => contactListViewModel.contacts
.where((element) => selectedCryptoCurrency == null || element.type == selectedCryptoCurrency)
.where((element) => element.type == selectedCryptoCurrency)
.toList();
@computed
List<WalletContact> get walletContactsToShow => contactListViewModel.walletContacts
.where((element) => selectedCryptoCurrency == null || element.type == selectedCryptoCurrency)
.where((element) => element.type == selectedCryptoCurrency)
.toList();
@action
@@ -23,6 +23,7 @@ abstract class UnspentCoinsDetailsViewModelBase with Store {
note = unspentCoinsItem.note {
items = [
StandartListItem(title: S.current.transaction_details_amount, value: unspentCoinsItem.amount),
StandartListItem(title: S.current.transaction_details_transaction_id, value: unspentCoinsItem.hash),
StandartListItem(title: S.current.widgets_address, value: unspentCoinsItem.address),
TextFieldListItem(
title: S.current.note_tap_to_change,
@@ -42,19 +43,22 @@ abstract class UnspentCoinsDetailsViewModelBase with Store {
unspentCoinsItem.isSending = !value;
}
await unspentCoinsListViewModel.saveUnspentCoinInfo(unspentCoinsItem);
}),
BlockExplorerListItem(
title: S.current.view_in_block_explorer,
value: _explorerDescription(unspentCoinsListViewModel.wallet.type),
onTap: () {
try {
final url = Uri.parse(
_explorerUrl(unspentCoinsListViewModel.wallet.type, unspentCoinsItem.hash));
return launchUrl(url);
} catch (e) {}
})
];
if ([WalletType.bitcoin, WalletType.litecoin].contains(unspentCoinsListViewModel.wallet.type)) {
items.add(BlockExplorerListItem(
title: S.current.view_in_block_explorer,
value: _explorerDescription(unspentCoinsListViewModel.wallet.type),
onTap: () {
try {
final url = Uri.parse(
_explorerUrl(unspentCoinsListViewModel.wallet.type, unspentCoinsItem.hash));
return launchUrl(url);
} catch (e) {}
},
));
}
}
String _explorerUrl(WalletType type, String txId) {
@@ -13,7 +13,9 @@ abstract class UnspentCoinsItemBase with Store {
required this.note,
required this.isSending,
required this.amountRaw,
required this.vout});
required this.vout,
required this.keyImage
});
@observable
String address;
@@ -38,4 +40,7 @@ abstract class UnspentCoinsItemBase with Store {
@observable
int vout;
}
@observable
String? keyImage;
}
@@ -1,10 +1,15 @@
import 'package:cw_core/unspent_coins_info.dart';
import 'package:collection/collection.dart';
import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cake_wallet/entities/unspent_transaction_output.dart';
import 'package:cake_wallet/monero/monero.dart';
import 'package:cake_wallet/view_model/unspent_coins/unspent_coins_item.dart';
import 'package:cw_bitcoin/bitcoin_wallet.dart';
import 'package:cw_core/unspent_coins_info.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:cw_monero/monero_wallet.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:collection/collection.dart';
part 'unspent_coins_list_view_model.g.dart';
@@ -14,7 +19,7 @@ abstract class UnspentCoinsListViewModelBase with Store {
UnspentCoinsListViewModelBase(
{required this.wallet, required Box<UnspentCoinsInfo> unspentCoinsInfo})
: _unspentCoinsInfo = unspentCoinsInfo {
bitcoin!.updateUnspents(wallet);
_updateUnspents();
}
WalletBase wallet;
@@ -22,11 +27,10 @@ abstract class UnspentCoinsListViewModelBase with Store {
@computed
ObservableList<UnspentCoinsItem> get items =>
ObservableList.of(bitcoin!.getUnspents(wallet).map((elem) {
final amount = bitcoin!.formatterBitcoinAmountToString(amount: elem.value) +
' ${wallet.currency.title}';
ObservableList.of(_getUnspents().map((elem) {
final amount = formatAmountToString(elem.value) + ' ${wallet.currency.title}';
final info = getUnspentCoinInfo(elem.hash, elem.address, elem.value, elem.vout);
final info = getUnspentCoinInfo(elem.hash, elem.address, elem.value, elem.vout, elem.keyImage);
return UnspentCoinsItem(
address: elem.address,
@@ -36,12 +40,14 @@ abstract class UnspentCoinsListViewModelBase with Store {
note: info?.note ?? '',
isSending: info?.isSending ?? true,
amountRaw: elem.value,
vout: elem.vout);
vout: elem.vout,
keyImage: elem.keyImage
);
}));
Future<void> saveUnspentCoinInfo(UnspentCoinsItem item) async {
try {
final info = getUnspentCoinInfo(item.hash, item.address, item.amountRaw, item.vout);
final info = getUnspentCoinInfo(item.hash, item.address, item.amountRaw, item.vout, item.keyImage);
if (info == null) {
final newInfo = UnspentCoinsInfo(
walletId: wallet.id,
@@ -51,10 +57,12 @@ abstract class UnspentCoinsListViewModelBase with Store {
vout: item.vout,
isFrozen: item.isFrozen,
isSending: item.isSending,
noteRaw: item.note);
noteRaw: item.note,
keyImage: item.keyImage
);
await _unspentCoinsInfo.add(newInfo);
bitcoin!.updateUnspents(wallet);
_updateUnspents();
wallet.updateBalance();
return;
}
@@ -63,19 +71,45 @@ abstract class UnspentCoinsListViewModelBase with Store {
info.note = item.note;
await info.save();
bitcoin!.updateUnspents(wallet);
_updateUnspents();
wallet.updateBalance();
} catch (e) {
print(e.toString());
}
}
UnspentCoinsInfo? getUnspentCoinInfo(String hash, String address, int value, int vout) {
UnspentCoinsInfo? getUnspentCoinInfo(String hash, String address, int value, int vout, String? keyImage) {
return _unspentCoinsInfo.values.firstWhereOrNull((element) =>
element.walletId == wallet.id &&
element.hash == hash &&
element.address == address &&
element.value == value &&
element.vout == vout);
element.vout == vout &&
element.keyImage == keyImage
);
}
String formatAmountToString(int fullBalance) {
if (wallet.type == WalletType.monero)
return monero!.formatterMoneroAmountToString(amount: fullBalance);
if ([WalletType.bitcoin, WalletType.litecoin].contains(wallet.type))
return bitcoin!.formatterBitcoinAmountToString(amount: fullBalance);
return '';
}
void _updateUnspents() {
if (wallet.type == WalletType.monero)
return monero!.updateUnspents(wallet);
if ([WalletType.bitcoin, WalletType.litecoin].contains(wallet.type))
return bitcoin!.updateUnspents(wallet);
}
List<Unspent> _getUnspents() {
if (wallet.type == WalletType.monero)
return monero!.getUnspents(wallet);
if ([WalletType.bitcoin, WalletType.litecoin].contains(wallet.type))
return bitcoin!.getUnspents(wallet);
return List.empty();
}
}