mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-23 03:05:11 +00:00
Disable mweb coins for exchanges (#1919)
* Disable mweb coins for exchanges * Take into consideration to not use non-mweb coins in ALL calculations
This commit is contained in:
parent
0ebfd671f9
commit
5ea443235d
4 changed files with 40 additions and 23 deletions
|
@ -149,7 +149,8 @@ class CWBitcoin extends Bitcoin {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<int> estimateFakeSendAllTxAmount(Object wallet, TransactionPriority priority) async {
|
||||
Future<int> estimateFakeSendAllTxAmount(Object wallet, TransactionPriority priority,
|
||||
{UnspentCoinType coinTypeToSpendFrom = UnspentCoinType.any}) async {
|
||||
try {
|
||||
final sk = ECPrivate.random();
|
||||
final electrumWallet = wallet as ElectrumWallet;
|
||||
|
@ -173,6 +174,7 @@ class CWBitcoin extends Bitcoin {
|
|||
? priority as LitecoinTransactionPriority
|
||||
: priority as BitcoinTransactionPriority,
|
||||
),
|
||||
coinTypeToSpendFrom: coinTypeToSpendFrom,
|
||||
);
|
||||
|
||||
return estimatedTx.amount;
|
||||
|
|
|
@ -9,6 +9,7 @@ import 'package:cake_wallet/exchange/provider/stealth_ex_exchange_provider.dart'
|
|||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:cw_core/sync_status.dart';
|
||||
import 'package:cw_core/transaction_priority.dart';
|
||||
import 'package:cw_core/unspent_coin_type.dart';
|
||||
import 'package:cw_core/utils/print_verbose.dart';
|
||||
import 'package:cw_core/wallet_type.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
|
@ -122,7 +123,8 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
|||
depositAmount = '';
|
||||
receiveAmount = '';
|
||||
receiveAddress = '';
|
||||
depositAddress = depositCurrency == wallet.currency ? wallet.walletAddresses.addressForExchange : '';
|
||||
depositAddress =
|
||||
depositCurrency == wallet.currency ? wallet.walletAddresses.addressForExchange : '';
|
||||
provider = providersForCurrentPair().first;
|
||||
final initialProvider = provider;
|
||||
provider!.checkIsAvailable().then((bool isAvailable) {
|
||||
|
@ -157,8 +159,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
|||
wallet.type == WalletType.bitcoinCash;
|
||||
|
||||
bool get hideAddressAfterExchange =>
|
||||
wallet.type == WalletType.monero ||
|
||||
wallet.type == WalletType.wownero;
|
||||
wallet.type == WalletType.monero || wallet.type == WalletType.wownero;
|
||||
|
||||
bool _useTorOnly;
|
||||
final Box<Trade> trades;
|
||||
|
@ -167,17 +168,17 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
|||
final SharedPreferences sharedPreferences;
|
||||
|
||||
List<ExchangeProvider> get _allProviders => [
|
||||
ChangeNowExchangeProvider(settingsStore: _settingsStore),
|
||||
SideShiftExchangeProvider(),
|
||||
SimpleSwapExchangeProvider(),
|
||||
ThorChainExchangeProvider(tradesStore: trades),
|
||||
if (FeatureFlag.isExolixEnabled) ExolixExchangeProvider(),
|
||||
QuantexExchangeProvider(),
|
||||
LetsExchangeExchangeProvider(),
|
||||
StealthExExchangeProvider(),
|
||||
TrocadorExchangeProvider(
|
||||
useTorOnly: _useTorOnly, providerStates: _settingsStore.trocadorProviderStates),
|
||||
];
|
||||
ChangeNowExchangeProvider(settingsStore: _settingsStore),
|
||||
SideShiftExchangeProvider(),
|
||||
SimpleSwapExchangeProvider(),
|
||||
ThorChainExchangeProvider(tradesStore: trades),
|
||||
if (FeatureFlag.isExolixEnabled) ExolixExchangeProvider(),
|
||||
QuantexExchangeProvider(),
|
||||
LetsExchangeExchangeProvider(),
|
||||
StealthExExchangeProvider(),
|
||||
TrocadorExchangeProvider(
|
||||
useTorOnly: _useTorOnly, providerStates: _settingsStore.trocadorProviderStates),
|
||||
];
|
||||
|
||||
@observable
|
||||
ExchangeProvider? provider;
|
||||
|
@ -613,8 +614,10 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
|||
isReceiveAmountEntered = false;
|
||||
depositAmount = '';
|
||||
receiveAmount = '';
|
||||
depositAddress = depositCurrency == wallet.currency ? wallet.walletAddresses.addressForExchange : '';
|
||||
receiveAddress = receiveCurrency == wallet.currency ? wallet.walletAddresses.addressForExchange : '';
|
||||
depositAddress =
|
||||
depositCurrency == wallet.currency ? wallet.walletAddresses.addressForExchange : '';
|
||||
receiveAddress =
|
||||
receiveCurrency == wallet.currency ? wallet.walletAddresses.addressForExchange : '';
|
||||
isDepositAddressEnabled = !(depositCurrency == wallet.currency);
|
||||
isFixedRateMode = false;
|
||||
_onPairChange();
|
||||
|
@ -640,7 +643,12 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
|||
wallet.type == WalletType.bitcoinCash) {
|
||||
final priority = _settingsStore.priority[wallet.type]!;
|
||||
|
||||
final amount = await bitcoin!.estimateFakeSendAllTxAmount(wallet, priority);
|
||||
final amount = await bitcoin!.estimateFakeSendAllTxAmount(
|
||||
wallet,
|
||||
priority,
|
||||
coinTypeToSpendFrom:
|
||||
wallet.type == WalletType.litecoin ? UnspentCoinType.nonMweb : UnspentCoinType.any,
|
||||
);
|
||||
|
||||
changeDepositAmount(amount: bitcoin!.formatterBitcoinAmountToString(amount: amount));
|
||||
}
|
||||
|
|
|
@ -394,7 +394,7 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
|
|||
|
||||
if (wallet.isHardwareWallet) state = IsAwaitingDeviceResponseState();
|
||||
|
||||
pendingTransaction = await wallet.createTransaction(_credentials());
|
||||
pendingTransaction = await wallet.createTransaction(_credentials(provider));
|
||||
|
||||
if (provider is ThorChainExchangeProvider) {
|
||||
final outputCount = pendingTransaction?.outputCount ?? 0;
|
||||
|
@ -522,7 +522,7 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
|
|||
void setTransactionPriority(TransactionPriority priority) =>
|
||||
_settingsStore.priority[wallet.type] = priority;
|
||||
|
||||
Object _credentials() {
|
||||
Object _credentials([ExchangeProvider? provider]) {
|
||||
final priority = _settingsStore.priority[wallet.type];
|
||||
|
||||
if (priority == null &&
|
||||
|
@ -535,7 +535,6 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
|
|||
|
||||
switch (wallet.type) {
|
||||
case WalletType.bitcoin:
|
||||
case WalletType.litecoin:
|
||||
case WalletType.bitcoinCash:
|
||||
return bitcoin!.createBitcoinTransactionCredentials(
|
||||
outputs,
|
||||
|
@ -543,6 +542,14 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
|
|||
feeRate: customBitcoinFeeRate,
|
||||
coinTypeToSpendFrom: coinTypeToSpendFrom,
|
||||
);
|
||||
case WalletType.litecoin:
|
||||
return bitcoin!.createBitcoinTransactionCredentials(
|
||||
outputs,
|
||||
priority: priority!,
|
||||
feeRate: customBitcoinFeeRate,
|
||||
// if it's an exchange flow then disable sending from mweb coins
|
||||
coinTypeToSpendFrom: provider != null ? UnspentCoinType.nonMweb : coinTypeToSpendFrom,
|
||||
);
|
||||
|
||||
case WalletType.monero:
|
||||
return monero!
|
||||
|
|
|
@ -109,7 +109,6 @@ import 'package:cw_bitcoin/electrum.dart';
|
|||
import 'package:cw_bitcoin/electrum_transaction_info.dart';
|
||||
import 'package:cw_bitcoin/pending_bitcoin_transaction.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_receive_page_option.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_wallet.dart';
|
||||
import 'package:cw_bitcoin/electrum_wallet.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_unspent.dart';
|
||||
import 'package:cw_bitcoin/bitcoin_mnemonic.dart';
|
||||
|
@ -173,7 +172,8 @@ abstract class Bitcoin {
|
|||
List<ElectrumSubAddress> getSilentPaymentAddresses(Object wallet);
|
||||
List<ElectrumSubAddress> getSilentPaymentReceivedAddresses(Object wallet);
|
||||
|
||||
Future<int> estimateFakeSendAllTxAmount(Object wallet, TransactionPriority priority);
|
||||
Future<int> estimateFakeSendAllTxAmount(Object wallet, TransactionPriority priority,
|
||||
{UnspentCoinType coinTypeToSpendFrom = UnspentCoinType.any});
|
||||
List<ElectrumSubAddress> getSubAddresses(Object wallet);
|
||||
|
||||
String formatterBitcoinAmountToString({required int amount});
|
||||
|
|
Loading…
Reference in a new issue