mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-12-03 12:24:19 +01:00
feat: Swap flow for Pay Anything. (#2489)
* feat: Swap flow for Pay Anything. [WIP] * feat: Pay Anything Swap Flow [WIP] * feat: Pay anything swap flow [WIP] - Add fiat values for send and receive amounts to swap details confirmation bottomsheet * feat: Pay anything swap flow [WIP] - Switch exchangeviewmodel back to factory - Expand address box to fill width * Handle second swipe to swap cta * Add fiat for receive amount * Scope Observers for bottomsheets and add validator * fix: Repeated instances issue for exchangeVM * fix: Estimated fee and balance not correctly updating after wallet switching occurs * fix: Available balance not updating properly after wallet switching * Fix: Give wallet some time to open before populating send info --------- Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
This commit is contained in:
co-authored by
OmarHatem
parent
31b9bb7f53
commit
d1b62f2664
@@ -1,5 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cake_wallet/entities/calculate_fiat_amount.dart';
|
||||
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
|
||||
import 'package:cake_wallet/exchange/provider/chainflip_exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/provider/changenow_exchange_provider.dart';
|
||||
@@ -15,6 +17,7 @@ import 'package:cake_wallet/exchange/provider/xoswap_exchange_provider.dart';
|
||||
import 'package:cake_wallet/exchange/trade.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/src/screens/exchange_trade/exchange_trade_item.dart';
|
||||
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||
import 'package:cake_wallet/store/dashboard/trades_store.dart';
|
||||
import 'package:cake_wallet/view_model/send/fees_view_model.dart';
|
||||
import 'package:cake_wallet/view_model/send/output.dart';
|
||||
@@ -36,6 +39,7 @@ abstract class ExchangeTradeViewModelBase with Store {
|
||||
required this.tradesStore,
|
||||
required this.sendViewModel,
|
||||
required this.feesViewModel,
|
||||
required this.fiatConversionStore,
|
||||
}) : trade = tradesStore.trade!,
|
||||
isSendable = _checkIfCanSend(tradesStore, wallet),
|
||||
items = ObservableList<ExchangeTradeItem>() {
|
||||
@@ -69,7 +73,7 @@ abstract class ExchangeTradeViewModelBase with Store {
|
||||
case ExchangeProviderDescription.chainflip:
|
||||
_provider = ChainflipExchangeProvider(tradesStore: trades);
|
||||
break;
|
||||
case ExchangeProviderDescription.xoSwap:
|
||||
case ExchangeProviderDescription.xoSwap:
|
||||
_provider = XOSwapExchangeProvider();
|
||||
}
|
||||
|
||||
@@ -116,6 +120,49 @@ abstract class ExchangeTradeViewModelBase with Store {
|
||||
|
||||
Timer? timer;
|
||||
|
||||
final FiatConversionStore fiatConversionStore;
|
||||
|
||||
FiatCurrency get fiat => sendViewModel.fiat;
|
||||
|
||||
@computed
|
||||
bool get isFiatDisabled => feesViewModel.isFiatDisabled;
|
||||
|
||||
@computed
|
||||
String get receiveAmountFiatFormatted {
|
||||
var amount = '0.00';
|
||||
try {
|
||||
if (trade.receiveAmount?.isNotEmpty ?? false) {
|
||||
if (fiatConversionStore.prices[trade.to] == null) return '';
|
||||
|
||||
amount = calculateFiatAmount(
|
||||
price: fiatConversionStore.prices[trade.to]!,
|
||||
cryptoAmount: trade.receiveAmount,
|
||||
);
|
||||
}
|
||||
} catch (_) {
|
||||
printV('Error calculating receive amount fiat formatted: $_');
|
||||
}
|
||||
return isFiatDisabled ? '' : '$amount ${fiat.title}';
|
||||
}
|
||||
|
||||
@computed
|
||||
String get sendAmountFiatFormatted {
|
||||
var amount = '0.00';
|
||||
try {
|
||||
if (trade.amount.isNotEmpty) {
|
||||
if (fiatConversionStore.prices[trade.from] == null) return '';
|
||||
|
||||
amount = calculateFiatAmount(
|
||||
price: fiatConversionStore.prices[trade.from]!,
|
||||
cryptoAmount: trade.amount,
|
||||
);
|
||||
}
|
||||
} catch (_) {
|
||||
printV('Error calculating send amount fiat formatted: $_');
|
||||
}
|
||||
return isFiatDisabled ? '' : '$amount ${fiat.title}';
|
||||
}
|
||||
|
||||
void setUpOutput() {
|
||||
sendViewModel.clearOutputs();
|
||||
output = sendViewModel.outputs.first;
|
||||
@@ -168,13 +215,9 @@ abstract class ExchangeTradeViewModelBase with Store {
|
||||
|
||||
void _updateItems() {
|
||||
final trade = tradesStore.trade!;
|
||||
final tradeFrom = trade.fromRaw >= 0
|
||||
? trade.from
|
||||
: trade.userCurrencyFrom;
|
||||
final tradeFrom = trade.fromRaw >= 0 ? trade.from : trade.userCurrencyFrom;
|
||||
|
||||
final tradeTo = trade.toRaw >= 0
|
||||
? trade.to
|
||||
: trade.userCurrencyTo;
|
||||
final tradeTo = trade.toRaw >= 0 ? trade.to : trade.userCurrencyTo;
|
||||
|
||||
final tagFrom = tradeFrom?.tag != null ? '${tradeFrom!.tag}' + ' ' : '';
|
||||
final tagTo = tradeTo?.tag != null ? '${tradeTo!.tag}' + ' ' : '';
|
||||
@@ -221,22 +264,20 @@ abstract class ExchangeTradeViewModelBase with Store {
|
||||
final isExtraIdExist = trade.extraId != null && trade.extraId!.isNotEmpty;
|
||||
|
||||
if (isExtraIdExist) {
|
||||
|
||||
|
||||
final title = tradeFrom == CryptoCurrency.xrp
|
||||
? S.current.destination_tag
|
||||
: tradeFrom == CryptoCurrency.xlm || tradeFrom == CryptoCurrency.ton
|
||||
? S.current.memo
|
||||
: S.current.extra_id;
|
||||
? S.current.destination_tag
|
||||
: tradeFrom == CryptoCurrency.xlm || tradeFrom == CryptoCurrency.ton
|
||||
? S.current.memo
|
||||
: S.current.extra_id;
|
||||
|
||||
items.add(
|
||||
ExchangeTradeItem(
|
||||
title: title,
|
||||
data: trade.extraId ?? '',
|
||||
isCopied: true,
|
||||
isReceiveDetail: !isExtraIdExist,
|
||||
isExternalSendDetail: isExtraIdExist),
|
||||
);
|
||||
items.add(
|
||||
ExchangeTradeItem(
|
||||
title: title,
|
||||
data: trade.extraId ?? '',
|
||||
isCopied: true,
|
||||
isReceiveDetail: !isExtraIdExist,
|
||||
isExternalSendDetail: isExtraIdExist),
|
||||
);
|
||||
}
|
||||
|
||||
items.add(
|
||||
@@ -251,27 +292,21 @@ abstract class ExchangeTradeViewModelBase with Store {
|
||||
}
|
||||
|
||||
static bool _checkIfCanSend(TradesStore tradesStore, WalletBase wallet) {
|
||||
|
||||
final trade = tradesStore.trade!;
|
||||
final tradeFrom = trade.fromRaw >= 0
|
||||
? trade.from
|
||||
: trade.userCurrencyFrom;
|
||||
final tradeFrom = trade.fromRaw >= 0 ? trade.from : trade.userCurrencyFrom;
|
||||
|
||||
bool _isEthToken() =>
|
||||
wallet.currency == CryptoCurrency.eth &&
|
||||
tradeFrom?.tag == CryptoCurrency.eth.title;
|
||||
wallet.currency == CryptoCurrency.eth && tradeFrom?.tag == CryptoCurrency.eth.title;
|
||||
|
||||
bool _isPolygonToken() =>
|
||||
wallet.currency == CryptoCurrency.maticpoly &&
|
||||
tradeFrom?.tag == CryptoCurrency.maticpoly.tag;
|
||||
tradeFrom?.tag == CryptoCurrency.maticpoly.tag;
|
||||
|
||||
bool _isTronToken() =>
|
||||
wallet.currency == CryptoCurrency.trx &&
|
||||
tradeFrom?.tag == CryptoCurrency.trx.title;
|
||||
wallet.currency == CryptoCurrency.trx && tradeFrom?.tag == CryptoCurrency.trx.title;
|
||||
|
||||
bool _isSplToken() =>
|
||||
wallet.currency == CryptoCurrency.sol &&
|
||||
tradeFrom?.tag == CryptoCurrency.sol.title;
|
||||
wallet.currency == CryptoCurrency.sol && tradeFrom?.tag == CryptoCurrency.sol.title;
|
||||
|
||||
return tradeFrom == wallet.currency ||
|
||||
tradesStore.trade!.provider == ExchangeProviderDescription.xmrto ||
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
import 'dart:async';
|
||||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:bitcoin_base/bitcoin_base.dart';
|
||||
import 'package:cake_wallet/.secrets.g.dart' as secrets;
|
||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||
import 'package:cake_wallet/core/create_trade_result.dart';
|
||||
import 'package:cake_wallet/core/fiat_conversion_service.dart';
|
||||
import 'package:cake_wallet/core/wallet_change_listener_view_model.dart';
|
||||
import 'package:cake_wallet/entities/calculate_fiat_amount.dart';
|
||||
import 'package:cake_wallet/entities/exchange_api_mode.dart';
|
||||
import 'package:cake_wallet/entities/fiat_api_mode.dart';
|
||||
import 'package:cake_wallet/entities/fiat_currency.dart';
|
||||
import 'package:cake_wallet/entities/preferences_key.dart';
|
||||
import 'package:cake_wallet/entities/wallet_contact.dart';
|
||||
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
|
||||
@@ -30,6 +35,7 @@ import 'package:cake_wallet/exchange/trade.dart';
|
||||
import 'package:cake_wallet/exchange/trade_request.dart';
|
||||
import 'package:cake_wallet/generated/i18n.dart';
|
||||
import 'package:cake_wallet/store/app_store.dart';
|
||||
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
|
||||
import 'package:cake_wallet/store/dashboard/trades_store.dart';
|
||||
import 'package:cake_wallet/store/settings_store.dart';
|
||||
import 'package:cake_wallet/store/templates/exchange_template_store.dart';
|
||||
@@ -76,6 +82,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
this.unspentCoinsListViewModel,
|
||||
this.feesViewModel,
|
||||
this.walletInfoSource,
|
||||
this.fiatConversionStore,
|
||||
) : _cryptoNumberFormat = NumberFormat(),
|
||||
isSendAllEnabled = false,
|
||||
isFixedRateMode = false,
|
||||
@@ -129,8 +136,8 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
autorun((_) {
|
||||
if (selectedProviders.any((provider) => provider is TrocadorExchangeProvider)) {
|
||||
final trocadorProvider =
|
||||
selectedProviders.firstWhere((provider) => provider is TrocadorExchangeProvider)
|
||||
as TrocadorExchangeProvider;
|
||||
selectedProviders.firstWhere((provider) => provider is TrocadorExchangeProvider)
|
||||
as TrocadorExchangeProvider;
|
||||
|
||||
updateAllTrocadorProviderStates(trocadorProvider);
|
||||
}
|
||||
@@ -360,6 +367,44 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
|
||||
late Timer bestRateSync;
|
||||
|
||||
final FiatConversionStore fiatConversionStore;
|
||||
|
||||
FiatCurrency get fiat => _settingsStore.fiatCurrency;
|
||||
|
||||
@computed
|
||||
bool get isFiatDisabled => feesViewModel.isFiatDisabled;
|
||||
|
||||
@action
|
||||
Future<void> fetchFiatPrice(CryptoCurrency currency) async {
|
||||
if (fiatConversionStore.prices[currency] != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
fiatConversionStore.prices[currency] = await FiatConversionService.fetchPrice(
|
||||
crypto: currency,
|
||||
fiat: fiat,
|
||||
torOnly: _settingsStore.fiatApiMode == FiatApiMode.torOnly,
|
||||
);
|
||||
}
|
||||
|
||||
@computed
|
||||
String get receiveAmountFiatFormatted {
|
||||
var amount = '0.00';
|
||||
try {
|
||||
if (receiveAmount.isNotEmpty) {
|
||||
if (fiatConversionStore.prices[receiveCurrency] == null) return '';
|
||||
|
||||
amount = calculateFiatAmount(
|
||||
price: fiatConversionStore.prices[receiveCurrency]!,
|
||||
cryptoAmount: receiveAmount,
|
||||
);
|
||||
}
|
||||
} catch (_) {
|
||||
log('Error calculating receive amount fiat formatted: $_');
|
||||
}
|
||||
return isFiatDisabled ? '' : '$amount';
|
||||
}
|
||||
|
||||
@action
|
||||
void changeDepositCurrency({required CryptoCurrency currency}) {
|
||||
depositCurrency = currency;
|
||||
@@ -393,6 +438,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
|
||||
await calculateBestRate();
|
||||
}
|
||||
|
||||
_cryptoNumberFormat.maximumFractionDigits = depositMaxDigits;
|
||||
|
||||
depositAmount = _cryptoNumberFormat
|
||||
@@ -401,6 +447,16 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
.replaceAll(RegExp('\\,'), '');
|
||||
}
|
||||
|
||||
@action
|
||||
void setReceiveAmountFromFiat({required String fiatAmount}) {
|
||||
final crypto = double.parse(fiatAmount.replaceAll(',', '.')) /
|
||||
fiatConversionStore.prices[receiveCurrency]!;
|
||||
final receiveAmountTmp = _cryptoNumberFormat.format(crypto);
|
||||
if (receiveAmount != receiveAmountTmp) {
|
||||
changeReceiveAmount(amount: receiveAmountTmp);
|
||||
}
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> changeDepositAmount({required String amount}) async {
|
||||
depositAmount = amount;
|
||||
@@ -444,8 +500,8 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
bestRate = 0.0;
|
||||
return;
|
||||
}
|
||||
final amount = double.tryParse(isFixedRateMode ? receiveAmount : depositAmount)
|
||||
?? initialAmountByAssets(isFixedRateMode ? receiveCurrency : depositCurrency);
|
||||
final amount = double.tryParse(isFixedRateMode ? receiveAmount : depositAmount) ??
|
||||
initialAmountByAssets(isFixedRateMode ? receiveCurrency : depositCurrency);
|
||||
|
||||
final validProvidersForAmount = _tradeAvailableProviders.where((provider) {
|
||||
final limits = _providerLimits[provider];
|
||||
@@ -515,15 +571,15 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
.map((provider) async {
|
||||
final limits = await provider
|
||||
.fetchLimits(
|
||||
from: from,
|
||||
to: to,
|
||||
isFixedRateMode: isFixedRateMode,
|
||||
)
|
||||
from: from,
|
||||
to: to,
|
||||
isFixedRateMode: isFixedRateMode,
|
||||
)
|
||||
.onError((error, stackTrace) => Limits(max: 0.0, min: double.maxFinite))
|
||||
.timeout(
|
||||
Duration(seconds: 7),
|
||||
onTimeout: () => Limits(max: 0.0, min: double.maxFinite),
|
||||
);
|
||||
Duration(seconds: 7),
|
||||
onTimeout: () => Limits(max: 0.0, min: double.maxFinite),
|
||||
);
|
||||
return MapEntry(provider, limits);
|
||||
}).toList();
|
||||
|
||||
@@ -563,8 +619,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
Future<void> createTrade() async {
|
||||
if (depositCurrency == receiveCurrency) {
|
||||
tradeState = TradeIsCreatedFailure(
|
||||
title: S.current.trade_not_created,
|
||||
error: 'Can\'t exchange the same currency');
|
||||
title: S.current.trade_not_created, error: 'Can\'t exchange the same currency');
|
||||
return;
|
||||
}
|
||||
if (isSendAllEnabled) {
|
||||
@@ -881,8 +936,8 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
void _setAvailableProviders() {
|
||||
_tradeAvailableProviders.clear();
|
||||
|
||||
_tradeAvailableProviders.addAll(
|
||||
selectedProviders.where((provider) => providerList.contains(provider)));
|
||||
_tradeAvailableProviders
|
||||
.addAll(selectedProviders.where((provider) => providerList.contains(provider)));
|
||||
}
|
||||
|
||||
void _setProviders() {
|
||||
@@ -984,7 +1039,6 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
"X-API-Key": secrets.moralisApiKey,
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
final decodedResponse = jsonDecode(response.body)[0] as Map<String, dynamic>;
|
||||
|
||||
@@ -1018,7 +1072,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
|
||||
Future<List<Erc20Token>> _loadAllUniqueEvmTokens() async {
|
||||
final evmWallets = walletInfoSource.values.where(
|
||||
(w) => w.type == WalletType.ethereum || w.type == WalletType.polygon,
|
||||
(w) => w.type == WalletType.ethereum || w.type == WalletType.polygon,
|
||||
);
|
||||
|
||||
final seen = <String>{};
|
||||
@@ -1039,7 +1093,6 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
return unique;
|
||||
}
|
||||
|
||||
|
||||
@action
|
||||
Future<void> _injectUserEthTokensIntoCurrencyLists() async {
|
||||
final userTokens = await _loadAllUniqueEvmTokens();
|
||||
@@ -1134,8 +1187,7 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
}
|
||||
|
||||
Future<List<TronToken>> _loadAllUniqueTronTokens() async {
|
||||
final tronWallets =
|
||||
walletInfoSource.values.where((w) => w.type == WalletType.tron);
|
||||
final tronWallets = walletInfoSource.values.where((w) => w.type == WalletType.tron);
|
||||
|
||||
final seen = <String>{};
|
||||
final unique = <TronToken>[];
|
||||
@@ -1186,11 +1238,8 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
|
||||
CryptoCurrency.ada => 1000,
|
||||
CryptoCurrency.dash => 10,
|
||||
CryptoCurrency.rune => 10,
|
||||
|
||||
_ => 1
|
||||
};
|
||||
return amount.toDouble();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ abstract class PaymentViewModelBase with Store {
|
||||
return PaymentFlowResult.incompatible('Unable to detect address type');
|
||||
}
|
||||
|
||||
detectedWalletType = detectionResult.detectedWalletType!;
|
||||
detectedWalletType = detectionResult.detectedWalletType;
|
||||
|
||||
// Check if current wallet is compatible
|
||||
final currentWallet = appStore.wallet;
|
||||
@@ -56,11 +56,11 @@ abstract class PaymentViewModelBase with Store {
|
||||
|
||||
switch (compatibleWallets.length) {
|
||||
case 0:
|
||||
return PaymentFlowResult.noWallets(detectedWalletType!);
|
||||
return PaymentFlowResult.noWallets(detectedWalletType!, detectionResult);
|
||||
case 1:
|
||||
return PaymentFlowResult.singleWallet(compatibleWallets.first);
|
||||
return PaymentFlowResult.singleWallet(compatibleWallets.first, detectionResult);
|
||||
default:
|
||||
return PaymentFlowResult.multipleWallets(compatibleWallets);
|
||||
return PaymentFlowResult.multipleWallets(compatibleWallets, detectionResult);
|
||||
}
|
||||
} catch (e) {
|
||||
printV('PaymentViewModel error: $e');
|
||||
@@ -81,6 +81,7 @@ class PaymentFlowResult {
|
||||
final WalletInfo? wallet;
|
||||
final List<WalletInfo> wallets;
|
||||
final WalletType? walletType;
|
||||
final AddressDetectionResult? addressDetectionResult;
|
||||
|
||||
PaymentFlowResult._({
|
||||
required this.type,
|
||||
@@ -88,22 +89,38 @@ class PaymentFlowResult {
|
||||
this.wallet,
|
||||
this.wallets = const [],
|
||||
this.walletType,
|
||||
this.addressDetectionResult,
|
||||
});
|
||||
|
||||
/// Current wallet is compatible
|
||||
factory PaymentFlowResult.currentWalletCompatible() => PaymentFlowResult._(type: PaymentFlowType.currentWalletCompatible);
|
||||
factory PaymentFlowResult.currentWalletCompatible() =>
|
||||
PaymentFlowResult._(type: PaymentFlowType.currentWalletCompatible);
|
||||
|
||||
/// Single compatible wallet available
|
||||
factory PaymentFlowResult.singleWallet(WalletInfo wallet) =>
|
||||
PaymentFlowResult._(type: PaymentFlowType.singleWallet, wallet: wallet);
|
||||
factory PaymentFlowResult.singleWallet(
|
||||
WalletInfo wallet, AddressDetectionResult addressDetectionResult) =>
|
||||
PaymentFlowResult._(
|
||||
type: PaymentFlowType.singleWallet,
|
||||
wallet: wallet,
|
||||
walletType: wallet.type,
|
||||
addressDetectionResult: addressDetectionResult);
|
||||
|
||||
/// Multiple compatible wallets available
|
||||
factory PaymentFlowResult.multipleWallets(List<WalletInfo> wallets) =>
|
||||
PaymentFlowResult._(type: PaymentFlowType.multipleWallets, wallets: wallets);
|
||||
factory PaymentFlowResult.multipleWallets(
|
||||
List<WalletInfo> wallets, AddressDetectionResult addressDetectionResult) =>
|
||||
PaymentFlowResult._(
|
||||
type: PaymentFlowType.multipleWallets,
|
||||
wallets: wallets,
|
||||
walletType: wallets.first.type,
|
||||
addressDetectionResult: addressDetectionResult);
|
||||
|
||||
/// No compatible wallets available
|
||||
factory PaymentFlowResult.noWallets(WalletType walletType) =>
|
||||
PaymentFlowResult._(type: PaymentFlowType.noWallets, walletType: walletType);
|
||||
factory PaymentFlowResult.noWallets(
|
||||
WalletType walletType, AddressDetectionResult addressDetectionResult) =>
|
||||
PaymentFlowResult._(
|
||||
type: PaymentFlowType.noWallets,
|
||||
walletType: walletType,
|
||||
addressDetectionResult: addressDetectionResult);
|
||||
|
||||
/// Error occurred
|
||||
factory PaymentFlowResult.error(String message) =>
|
||||
|
||||
@@ -11,7 +11,10 @@ import 'package:cake_wallet/src/screens/send/widgets/extract_address_from_parsed
|
||||
import 'package:cake_wallet/tron/tron.dart';
|
||||
import 'package:cake_wallet/wownero/wownero.dart';
|
||||
import 'package:cake_wallet/zano/zano.dart';
|
||||
import 'package:cw_core/balance.dart';
|
||||
import 'package:cw_core/crypto_currency.dart';
|
||||
import 'package:cw_core/transaction_history.dart';
|
||||
import 'package:cw_core/transaction_info.dart';
|
||||
import 'package:cw_core/utils/print_verbose.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
@@ -220,7 +223,8 @@ abstract class OutputBase with Store {
|
||||
|
||||
WalletType get walletType => _wallet.type;
|
||||
final CryptoCurrency Function() cryptoCurrencyHandler;
|
||||
final WalletBase _wallet;
|
||||
@observable
|
||||
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> _wallet;
|
||||
final SettingsStore _settingsStore;
|
||||
final FiatConversionStore _fiatConversationStore;
|
||||
final NumberFormat _cryptoNumberFormat;
|
||||
@@ -230,6 +234,12 @@ abstract class OutputBase with Store {
|
||||
sendAll = true;
|
||||
}
|
||||
|
||||
@action
|
||||
void updateWallet(WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> newWallet) {
|
||||
_wallet = newWallet;
|
||||
_setCryptoNumMaximumFractionDigits();
|
||||
}
|
||||
|
||||
@action
|
||||
void reset() {
|
||||
sendAll = false;
|
||||
|
||||
@@ -72,6 +72,16 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
|
||||
wallet.type == WalletType.solana ||
|
||||
wallet.type == WalletType.tron ||
|
||||
wallet.type == WalletType.zano;
|
||||
|
||||
for (final output in outputs) {
|
||||
output.updateWallet(wallet);
|
||||
}
|
||||
|
||||
// Update unspent coins list view model with the new wallet reference
|
||||
unspentCoinsListViewModel.updateWallet(wallet);
|
||||
|
||||
// Update sending balance to reflect the new wallet's balance
|
||||
updateSendingBalance();
|
||||
}
|
||||
|
||||
UnspentCoinsListViewModel unspentCoinsListViewModel;
|
||||
|
||||
@@ -4,6 +4,9 @@ import 'package:cake_wallet/utils/exception_handler.dart';
|
||||
import 'package:cake_wallet/decred/decred.dart';
|
||||
import 'package:cake_wallet/view_model/unspent_coins/unspent_coins_item.dart';
|
||||
import 'package:cake_wallet/wownero/wownero.dart';
|
||||
import 'package:cw_core/balance.dart';
|
||||
import 'package:cw_core/transaction_history.dart';
|
||||
import 'package:cw_core/transaction_info.dart';
|
||||
import 'package:cw_core/unspent_coin_type.dart';
|
||||
import 'package:cw_core/unspent_coins_info.dart';
|
||||
import 'package:cw_core/unspent_transaction_output.dart';
|
||||
@@ -28,7 +31,8 @@ abstract class UnspentCoinsListViewModelBase with Store {
|
||||
items = ObservableList<UnspentCoinsItem>(),
|
||||
_originalState = {};
|
||||
|
||||
final WalletBase wallet;
|
||||
@observable
|
||||
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> wallet;
|
||||
final Box<UnspentCoinsInfo> _unspentCoinsInfo;
|
||||
final UnspentCoinType coinTypeToSpendFrom;
|
||||
|
||||
@@ -228,6 +232,11 @@ abstract class UnspentCoinsListViewModelBase with Store {
|
||||
@action
|
||||
void setIsDisposing(bool value) => isDisposing = value;
|
||||
|
||||
@action
|
||||
void updateWallet(WalletBase newWallet) {
|
||||
wallet = newWallet;
|
||||
}
|
||||
|
||||
@action
|
||||
Future<void> dispose() async {
|
||||
await _updateUnspents();
|
||||
|
||||
Reference in New Issue
Block a user