diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index dbd3fe8a0..477544ee9 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -11,7 +11,6 @@ import 'package:cw_bitcoin/bitcoin_amount_format.dart'; import 'package:cw_core/utils/print_verbose.dart'; import 'package:cw_bitcoin/bitcoin_wallet.dart'; import 'package:cw_bitcoin/litecoin_wallet.dart'; -import 'package:path_provider/path_provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:blockchain_utils/blockchain_utils.dart'; import 'package:collection/collection.dart'; @@ -899,6 +898,13 @@ abstract class ElectrumWalletBase throw BitcoinTransactionNoDustException(); } + // if mweb isn't enabled, don't consider spending mweb coins: + if (this is LitecoinWallet) { + var mwebEnabled = (this as LitecoinWallet).mwebEnabled; + if (!mwebEnabled) { + coinTypeToSpendFrom = UnspentCoinType.nonMweb; + } + } // If there is only one output, and the amount to send is more than the max spendable amount // then it is actually a send all transaction diff --git a/cw_bitcoin/lib/litecoin_wallet.dart b/cw_bitcoin/lib/litecoin_wallet.dart index 91d927da0..bdbbe3f67 100644 --- a/cw_bitcoin/lib/litecoin_wallet.dart +++ b/cw_bitcoin/lib/litecoin_wallet.dart @@ -886,6 +886,8 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { if (unspent.vout == 0) { unspent.isChange = true; } + + // printV("unspent: $unspent ${unspent.vout} ${utxo.value}"); mwebUnspentCoins.add(unspent); }); @@ -1140,13 +1142,27 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { @override Future createTransaction(Object credentials) async { try { - var tx = await super.createTransaction(credentials) as PendingBitcoinTransaction; + var creds; + if (!mwebEnabled) { + BitcoinTransactionCredentials btcCreds = (credentials as BitcoinTransactionCredentials); + // sets unspent coin type to nonMweb: + creds = BitcoinTransactionCredentials( + btcCreds.outputs, + priority: btcCreds.priority, + feeRate: btcCreds.feeRate, + coinTypeToSpendFrom: UnspentCoinType.nonMweb, + ); + } else { + creds = credentials; + } + var tx = await super.createTransaction(creds as Object) as PendingBitcoinTransaction; tx.isMweb = mwebEnabled; if (!mwebEnabled) { tx.changeAddressOverride = (await (walletAddresses as LitecoinWalletAddresses) .getChangeAddress(coinTypeToSpendFrom: UnspentCoinType.nonMweb)) .address; + if (tx.shouldCommitUR()) { tx.unsignedPsbt = await buildPsbt(tx, false); } @@ -1165,17 +1181,17 @@ abstract class LitecoinWalletBase extends ElectrumWallet with Store { final address = output.address.toLowerCase(); final extractedAddress = output.extractedAddress?.toLowerCase(); - if (address.contains("mweb")) { + if (address.startsWith("ltcmweb")) { hasMwebOutput = true; } - if (!address.contains("mweb")) { + if (!address.startsWith("ltcmweb")) { hasRegularOutput = true; } if (extractedAddress != null && extractedAddress.isNotEmpty) { - if (extractedAddress.contains("mweb")) { + if (extractedAddress.startsWith("ltcmweb")) { hasMwebOutput = true; } - if (!extractedAddress.contains("mweb")) { + if (!extractedAddress.startsWith("ltcmweb")) { hasRegularOutput = true; } } diff --git a/cw_bitcoin/lib/litecoin_wallet_addresses.dart b/cw_bitcoin/lib/litecoin_wallet_addresses.dart index 9b3211867..1493fbfb2 100644 --- a/cw_bitcoin/lib/litecoin_wallet_addresses.dart +++ b/cw_bitcoin/lib/litecoin_wallet_addresses.dart @@ -188,7 +188,7 @@ abstract class LitecoinWalletAddressesBase extends ElectrumWalletAddresses with if (!element.isSending || element.isFrozen) { return; } - if (element.address.contains("mweb")) { + if (element.address.startsWith("ltcmweb")) { comesFromMweb = true; } }); diff --git a/lib/view_model/transaction_details_view_model.dart b/lib/view_model/transaction_details_view_model.dart index ffe22facf..810d08c16 100644 --- a/lib/view_model/transaction_details_view_model.dart +++ b/lib/view_model/transaction_details_view_model.dart @@ -59,6 +59,7 @@ abstract class TransactionDetailsViewModelBase with Store { if (!canReplaceByFee) _checkForRBF(tx); break; case WalletType.litecoin: + _addLitecoinListItems(tx, dateFormat); case WalletType.bitcoinCash: _addElectrumListItems(tx, dateFormat); break; @@ -388,6 +389,30 @@ abstract class TransactionDetailsViewModelBase with Store { items.addAll(_items); } + void _addLitecoinListItems(TransactionInfo tx, DateFormat dateFormat) { + _addElectrumListItems(tx, dateFormat); + + bool isMweb = bitcoin!.txIsMweb(tx); + + final _items = [ + if (isMweb) + BlockExplorerListItem( + title: S.current.view_in_block_explorer, + value: S.current.view_transaction_on + 'mwebexplorer.com', + onTap: () async { + try { + final uri = Uri.parse('https://www.mwebexplorer.com/blocks/block/${tx.height}'); + if (await canLaunchUrl(uri)) + await launchUrl(uri, mode: LaunchMode.externalApplication); + } catch (e) {} + }, + key: ValueKey('block_explorer_list_item_mweb_wallet_type_key'), + ), + ]; + + items.addAll(_items); + } + void _addHavenListItems(TransactionInfo tx, DateFormat dateFormat) { items.addAll([ StandartListItem(