diff --git a/lib/models/exchange/exchange_form_state.dart b/lib/models/exchange/exchange_form_state.dart index 32578ebd9..58562e449 100644 --- a/lib/models/exchange/exchange_form_state.dart +++ b/lib/models/exchange/exchange_form_state.dart @@ -2,9 +2,7 @@ import 'package:decimal/decimal.dart'; import 'package:flutter/foundation.dart'; import 'package:stackwallet/models/exchange/aggregate_currency.dart'; import 'package:stackwallet/models/exchange/response_objects/estimate.dart'; -import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dart'; import 'package:stackwallet/services/exchange/exchange.dart'; -import 'package:stackwallet/services/exchange/majestic_bank/majestic_bank_exchange.dart'; import 'package:stackwallet/utilities/enums/exchange_rate_type_enum.dart'; import 'package:stackwallet/utilities/logger.dart'; @@ -325,28 +323,28 @@ class ExchangeFormState extends ChangeNotifier { required bool shouldNotifyListeners, }) async { try { - switch (exchange.name) { - case ChangeNowExchange.exchangeName: - if (!_exchangeSupported( - exchangeName: exchange.name, - sendCurrency: sendCurrency, - receiveCurrency: receiveCurrency, - exchangeRateType: exchangeRateType, - )) { - _exchange = MajesticBankExchange.instance; - } - break; - case MajesticBankExchange.exchangeName: - if (!_exchangeSupported( - exchangeName: exchange.name, - sendCurrency: sendCurrency, - receiveCurrency: receiveCurrency, - exchangeRateType: exchangeRateType, - )) { - _exchange = ChangeNowExchange.instance; - } - break; - } + // switch (exchange.name) { + // case ChangeNowExchange.exchangeName: + // if (!_exchangeSupported( + // exchangeName: exchange.name, + // sendCurrency: sendCurrency, + // receiveCurrency: receiveCurrency, + // exchangeRateType: exchangeRateType, + // )) { + // _exchange = MajesticBankExchange.instance; + // } + // break; + // case MajesticBankExchange.exchangeName: + // if (!_exchangeSupported( + // exchangeName: exchange.name, + // sendCurrency: sendCurrency, + // receiveCurrency: receiveCurrency, + // exchangeRateType: exchangeRateType, + // )) { + // _exchange = ChangeNowExchange.instance; + // } + // break; + // } await _updateRanges(shouldNotifyListeners: false); await _updateEstimate(shouldNotifyListeners: false); diff --git a/lib/pages/exchange_view/exchange_coin_selection/exchange_currency_selection_view.dart b/lib/pages/exchange_view/exchange_coin_selection/exchange_currency_selection_view.dart index 1b2376b4c..6980706c3 100644 --- a/lib/pages/exchange_view/exchange_coin_selection/exchange_currency_selection_view.dart +++ b/lib/pages/exchange_view/exchange_coin_selection/exchange_currency_selection_view.dart @@ -9,7 +9,6 @@ import 'package:stackwallet/models/isar/exchange_cache/pair.dart'; import 'package:stackwallet/pages/buy_view/sub_widgets/crypto_selection_view.dart'; import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dart'; import 'package:stackwallet/services/exchange/exchange_data_loading_service.dart'; -import 'package:stackwallet/services/exchange/majestic_bank/majestic_bank_exchange.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; @@ -95,11 +94,12 @@ class _ExchangeCurrencySelectionViewState if (widget.pairedTicker == null) { return await _getCurrencies(); } - List currencies = await ExchangeDataLoadingService - .instance.isar.currencies - .where() - .exchangeNameEqualTo(MajesticBankExchange.exchangeName) - .findAll(); + List currencies = []; + // await ExchangeDataLoadingService + // .instance.isar.currencies + // .where() + // .exchangeNameEqualTo(MajesticBankExchange.exchangeName) + // .findAll(); final cn = await ChangeNowExchange.instance.getPairedCurrencies( widget.pairedTicker!, diff --git a/lib/pages/exchange_view/sub_widgets/exchange_provider_options.dart b/lib/pages/exchange_view/sub_widgets/exchange_provider_options.dart index c0f4312d0..043a10a5e 100644 --- a/lib/pages/exchange_view/sub_widgets/exchange_provider_options.dart +++ b/lib/pages/exchange_view/sub_widgets/exchange_provider_options.dart @@ -71,11 +71,12 @@ class _ExchangeProviderOptionsState sendCurrency: sendCurrency, receiveCurrency: receivingCurrency, ); - final showMajesticBank = exchangeSupported( - exchangeName: MajesticBankExchange.exchangeName, - sendCurrency: sendCurrency, - receiveCurrency: receivingCurrency, - ); + final showMajesticBank = false; + // exchangeSupported( + // exchangeName: MajesticBankExchange.exchangeName, + // sendCurrency: sendCurrency, + // receiveCurrency: receivingCurrency, + // ); return RoundedWhiteContainer( padding: isDesktop ? const EdgeInsets.all(0) : const EdgeInsets.all(12), diff --git a/lib/pages/exchange_view/trade_details_view.dart b/lib/pages/exchange_view/trade_details_view.dart index 76653bd18..ca853c6a4 100644 --- a/lib/pages/exchange_view/trade_details_view.dart +++ b/lib/pages/exchange_view/trade_details_view.dart @@ -93,7 +93,8 @@ class _TradeDetailsViewState extends ConsumerState { .trades .firstWhere((e) => e.tradeId == tradeId); - if (mounted) { + if (mounted && + trade.exchangeName != MajesticBankExchange.exchangeName) { final exchange = Exchange.fromName(trade.exchangeName); final response = await exchange.updateTrade(trade); diff --git a/lib/pages/stack_privacy_calls.dart b/lib/pages/stack_privacy_calls.dart index 8dc98a23d..e3b0534d1 100644 --- a/lib/pages/stack_privacy_calls.dart +++ b/lib/pages/stack_privacy_calls.dart @@ -148,15 +148,16 @@ class _StackPrivacyCalls extends ConsumerState { ), children: infoToggle ? [ + if (Constants.enableExchange) + const TextSpan( + text: + "Exchange data preloaded for a seamless experience.\n\n"), const TextSpan( text: - "Exchange data preloaded for a seamless experience."), - const TextSpan( - text: - "\n\nCoinGecko enabled: (24 hour price change shown in-app, total wallet value shown in USD or other currency)."), + "CoinGecko enabled: (24 hour price change shown in-app, total wallet value shown in USD or other currency).\n\n"), TextSpan( text: - "\n\nRecommended for most crypto users.", + "Recommended for most crypto users.", style: isDesktop ? STextStyles .desktopTextExtraExtraSmall600( @@ -170,15 +171,16 @@ class _StackPrivacyCalls extends ConsumerState { ), ] : [ + if (Constants.enableExchange) + const TextSpan( + text: + "Exchange data not preloaded (slower experience).\n\n"), const TextSpan( text: - "Exchange data not preloaded (slower experience)."), - const TextSpan( - text: - "\n\nCoinGecko disabled (price changes not shown, no wallet value shown in other currencies)."), + "CoinGecko disabled (price changes not shown, no wallet value shown in other currencies).\n\n"), TextSpan( text: - "\n\nRecommended for the privacy conscious.", + "Recommended for the privacy conscious.", style: isDesktop ? STextStyles .desktopTextExtraExtraSmall600( diff --git a/lib/pages/wallet_view/transaction_views/transaction_details_view.dart b/lib/pages/wallet_view/transaction_views/transaction_details_view.dart index 77decdfcb..056b8da4b 100644 --- a/lib/pages/wallet_view/transaction_views/transaction_details_view.dart +++ b/lib/pages/wallet_view/transaction_views/transaction_details_view.dart @@ -968,17 +968,25 @@ class _TransactionDetailsViewState ? const EdgeInsets.all(16) : const EdgeInsets.all(12), child: Builder(builder: (context) { - final height = widget.coin != Coin.epicCash && - _transaction.isConfirmed( - currentHeight, - coin.requiredConfirmations, - ) - ? "${_transaction.height == 0 ? "Unknown" : _transaction.height}" - : _transaction.getConfirmations( - currentHeight) > - 0 - ? "${_transaction.height}" - : "Pending"; + final String height; + + if (widget.coin == Coin.bitcoincash || + widget.coin == Coin.bitcoincashTestnet) { + height = + "${_transaction.height != null && _transaction.height! > 0 ? _transaction.height! : "Pending"}"; + } else { + height = widget.coin != Coin.epicCash && + _transaction.isConfirmed( + currentHeight, + coin.requiredConfirmations, + ) + ? "${_transaction.height == 0 ? "Unknown" : _transaction.height}" + : _transaction.getConfirmations( + currentHeight) > + 0 + ? "${_transaction.height}" + : "Pending"; + } return Row( mainAxisAlignment: diff --git a/lib/pages_desktop_specific/settings/settings_menu/advanced_settings/stack_privacy_dialog.dart b/lib/pages_desktop_specific/settings/settings_menu/advanced_settings/stack_privacy_dialog.dart index 9045e0006..ecd22237c 100644 --- a/lib/pages_desktop_specific/settings/settings_menu/advanced_settings/stack_privacy_dialog.dart +++ b/lib/pages_desktop_specific/settings/settings_menu/advanced_settings/stack_privacy_dialog.dart @@ -96,9 +96,10 @@ class _StackPrivacyDialog extends ConsumerState { ), children: infoToggle ? [ - const TextSpan( - text: - "Exchange data preloaded for a seamless experience."), + if (Constants.enableExchange) + const TextSpan( + text: + "Exchange data preloaded for a seamless experience."), const TextSpan( text: "\n\nCoinGecko enabled: (24 hour price change shown in-app, total wallet value shown in USD or other currency)."), diff --git a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart index a0c764ca3..daea482aa 100644 --- a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart +++ b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart @@ -2114,8 +2114,10 @@ class BitcoinCashWallet extends CoinServiceAPI .txidEqualTo(txHash["tx_hash"] as String) .findFirst(); - if (storedTx == null || - !storedTx.isConfirmed(currentHeight, MINIMUM_CONFIRMATIONS)) { + if (storedTx == null || storedTx.address.value == null + // zero conf messes this up + // !storedTx.isConfirmed(currentHeight, MINIMUM_CONFIRMATIONS) + ) { final tx = await cachedElectrumXClient.getTransaction( txHash: txHash["tx_hash"] as String, verbose: true, diff --git a/lib/services/exchange/exchange_data_loading_service.dart b/lib/services/exchange/exchange_data_loading_service.dart index ad754cb56..566640adb 100644 --- a/lib/services/exchange/exchange_data_loading_service.dart +++ b/lib/services/exchange/exchange_data_loading_service.dart @@ -273,25 +273,25 @@ class ExchangeDataLoadingService { // } Future loadMajesticBankCurrencies() async { - final exchange = MajesticBankExchange.instance; - final responseCurrencies = await exchange.getAllCurrencies(false); - - if (responseCurrencies.value != null) { - await isar.writeTxn(() async { - final idsToDelete = await isar.currencies - .where() - .exchangeNameEqualTo(MajesticBankExchange.exchangeName) - .idProperty() - .findAll(); - await isar.currencies.deleteAll(idsToDelete); - await isar.currencies.putAll(responseCurrencies.value!); - }); - } else { - Logging.instance.log( - "loadMajesticBankCurrencies: $responseCurrencies", - level: LogLevel.Warning, - ); - } + // final exchange = MajesticBankExchange.instance; + // final responseCurrencies = await exchange.getAllCurrencies(false); + // + // if (responseCurrencies.value != null) { + await isar.writeTxn(() async { + final idsToDelete = await isar.currencies + .where() + .exchangeNameEqualTo(MajesticBankExchange.exchangeName) + .idProperty() + .findAll(); + await isar.currencies.deleteAll(idsToDelete); + // await isar.currencies.putAll(responseCurrencies.value!); + }); + // } else { + // Logging.instance.log( + // "loadMajesticBankCurrencies: $responseCurrencies", + // level: LogLevel.Warning, + // ); + // } } // Future loadMajesticBankPairs() async { diff --git a/lib/services/exchange/majestic_bank/majestic_bank_api.dart b/lib/services/exchange/majestic_bank/majestic_bank_api.dart index 61eb886a4..5641afd55 100644 --- a/lib/services/exchange/majestic_bank/majestic_bank_api.dart +++ b/lib/services/exchange/majestic_bank/majestic_bank_api.dart @@ -14,10 +14,11 @@ import 'package:stackwallet/services/exchange/exchange_response.dart'; import 'package:stackwallet/utilities/logger.dart'; class MajesticBankAPI { - static const String scheme = "https"; - static const String authority = "majesticbank.sc"; - static const String version = "v1"; - static const kMajesticBankRefCode = "rjWugM"; + // ensure no api calls go out to mb + static const String scheme = ""; //"""https"; + static const String authority = ""; //"""majesticbank.sc"; + static const String version = ""; //"""v1"; + static const kMajesticBankRefCode = ""; //"""rjWugM"; MajesticBankAPI._(); @@ -33,6 +34,8 @@ class MajesticBankAPI { } Future _makeGetRequest(Uri uri) async { + return null; + final client = this.client ?? http.Client(); int code = -1; try { diff --git a/lib/services/notifications_service.dart b/lib/services/notifications_service.dart index 5408d6126..47170fd70 100644 --- a/lib/services/notifications_service.dart +++ b/lib/services/notifications_service.dart @@ -7,6 +7,7 @@ import 'package:stackwallet/hive/db.dart'; import 'package:stackwallet/models/exchange/response_objects/trade.dart'; import 'package:stackwallet/models/notification_model.dart'; import 'package:stackwallet/services/exchange/exchange_response.dart'; +import 'package:stackwallet/services/exchange/majestic_bank/majestic_bank_exchange.dart'; import 'package:stackwallet/services/node_service.dart'; import 'package:stackwallet/services/notifications_api.dart'; import 'package:stackwallet/services/trade_service.dart'; @@ -197,57 +198,59 @@ class NotificationsService extends ChangeNotifier { final oldTrade = trades.first; late final ExchangeResponse response; - try { - final exchange = Exchange.fromName(oldTrade.exchangeName); - response = await exchange.updateTrade(oldTrade); - } catch (_) { - return; - } - - if (response.value == null) { - return; - } - - final trade = response.value!; - - // only update if status has changed - if (trade.status != notification.title) { - bool shouldWatchForUpdates = true; - // TODO: make sure we set shouldWatchForUpdates to correct value here - switch (trade.status) { - case "Refunded": - case "refunded": - case "Failed": - case "failed": - case "closed": - case "expired": - case "Finished": - case "finished": - case "Completed": - case "completed": - case "Not found": - shouldWatchForUpdates = false; - break; - default: - shouldWatchForUpdates = true; + if (oldTrade.exchangeName != MajesticBankExchange.exchangeName) { + try { + final exchange = Exchange.fromName(oldTrade.exchangeName); + response = await exchange.updateTrade(oldTrade); + } catch (_) { + return; } - final updatedNotification = notification.copyWith( - title: trade.status, - shouldWatchForUpdates: shouldWatchForUpdates, - ); - - // remove from watch list if shouldWatchForUpdates was changed - if (!shouldWatchForUpdates) { - await _deleteWatchedTradeNotification(notification); + if (response.value == null) { + return; } - // replaces the current notification with the updated one - unawaited(add(updatedNotification, true)); + final trade = response.value!; - // update the trade in db - // over write trade stored in db with updated version - await tradesService.edit(trade: trade, shouldNotifyListeners: true); + // only update if status has changed + if (trade.status != notification.title) { + bool shouldWatchForUpdates = true; + // TODO: make sure we set shouldWatchForUpdates to correct value here + switch (trade.status) { + case "Refunded": + case "refunded": + case "Failed": + case "failed": + case "closed": + case "expired": + case "Finished": + case "finished": + case "Completed": + case "completed": + case "Not found": + shouldWatchForUpdates = false; + break; + default: + shouldWatchForUpdates = true; + } + + final updatedNotification = notification.copyWith( + title: trade.status, + shouldWatchForUpdates: shouldWatchForUpdates, + ); + + // remove from watch list if shouldWatchForUpdates was changed + if (!shouldWatchForUpdates) { + await _deleteWatchedTradeNotification(notification); + } + + // replaces the current notification with the updated one + unawaited(add(updatedNotification, true)); + + // update the trade in db + // over write trade stored in db with updated version + await tradesService.edit(trade: trade, shouldNotifyListeners: true); + } } } }