Merge remote-tracking branch 'origin/staging' into add-ethereum

# Conflicts:
#	lib/utilities/show_loading.dart
This commit is contained in:
julian 2023-03-28 12:37:09 -06:00
commit 24904f3476
17 changed files with 240 additions and 178 deletions

@ -1 +1 @@
Subproject commit e81b1b7c2d8114435a9458ab2e439f4393f626e7
Subproject commit e62cfc2cae093346bd547ed1379f99c1ed1fe537

View file

@ -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);

View file

@ -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<Currency> currencies = await ExchangeDataLoadingService
.instance.isar.currencies
.where()
.exchangeNameEqualTo(MajesticBankExchange.exchangeName)
.findAll();
List<Currency> currencies = [];
// await ExchangeDataLoadingService
// .instance.isar.currencies
// .where()
// .exchangeNameEqualTo(MajesticBankExchange.exchangeName)
// .findAll();
final cn = await ChangeNowExchange.instance.getPairedCurrencies(
widget.pairedTicker!,

View file

@ -579,7 +579,7 @@ class _Step4ViewState extends ConsumerState<Step4View> {
time,
]);
final txData = results.last
final txData = results.first
as Map<String, dynamic>;
if (!wasCancelled) {

View file

@ -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),

View file

@ -93,7 +93,8 @@ class _TradeDetailsViewState extends ConsumerState<TradeDetailsView> {
.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);

View file

@ -14,7 +14,9 @@ import 'package:stackwallet/providers/global/wallets_provider.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/biometrics.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
import 'package:stackwallet/utilities/show_loading.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/background.dart';
@ -80,19 +82,47 @@ class _LockscreenViewState extends ConsumerState<LockscreenView> {
if (widget.popOnSuccess) {
Navigator.of(context).pop(widget.routeOnSuccessArguments);
} else {
unawaited(Navigator.of(context).pushReplacementNamed(
final loadIntoWallet = widget.routeOnSuccess == HomeView.routeName &&
widget.routeOnSuccessArguments is String;
if (loadIntoWallet) {
final walletId = widget.routeOnSuccessArguments as String;
final manager =
ref.read(walletsChangeNotifierProvider).getManager(walletId);
if (manager.coin == Coin.monero || manager.coin == Coin.wownero) {
await showLoading(
opaqueBG: true,
whileFuture: manager.initializeExisting(),
context: context,
message: "Loading ${manager.coin.prettyName} wallet...",
);
}
}
if (mounted) {
unawaited(
Navigator.of(context).pushReplacementNamed(
widget.routeOnSuccess,
arguments: widget.routeOnSuccessArguments,
));
if (widget.routeOnSuccess == HomeView.routeName &&
widget.routeOnSuccessArguments is String) {
),
);
if (loadIntoWallet) {
final walletId = widget.routeOnSuccessArguments as String;
unawaited(Navigator.of(context).pushNamed(WalletView.routeName,
unawaited(
Navigator.of(context).pushNamed(
WalletView.routeName,
arguments: Tuple2(
walletId,
ref
.read(walletsChangeNotifierProvider)
.getManagerProvider(walletId))));
.getManagerProvider(walletId),
),
),
);
}
}
}
}

View file

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_native_splash/cli_commands.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/rounded_container.dart';
class AddressTag extends StatelessWidget {
@ -16,10 +17,12 @@ class AddressTag extends StatelessWidget {
vertical: 5,
horizontal: 7,
),
color: Colors.black,
color: Theme.of(context).extension<StackColors>()!.buttonBackPrimary,
child: Text(
tag.capitalize(),
style: STextStyles.w500_14(context),
style: STextStyles.w500_14(context).copyWith(
color: Theme.of(context).extension<StackColors>()!.buttonTextPrimary,
),
),
);
}

View file

@ -63,6 +63,44 @@ class _AddEditNodeViewState extends ConsumerState<AddEditNodeView> {
late bool saveEnabled;
late bool testConnectionEnabled;
Future<bool> _xmrHelper(String url, int? port) async {
final uri = Uri.parse(url);
final String path = uri.path.isEmpty ? "/json_rpc" : uri.path;
final uriString = "${uri.scheme}://${uri.host}:${port ?? 0}$path";
ref.read(nodeFormDataProvider).useSSL = true;
final response = await testMoneroNodeConnection(
Uri.parse(uriString),
false,
);
if (response.cert != null) {
if (mounted) {
final shouldAllowBadCert = await showBadX509CertificateDialog(
response.cert!,
response.url!,
response.port!,
context,
);
if (shouldAllowBadCert) {
final response =
await testMoneroNodeConnection(Uri.parse(uriString), true);
ref.read(nodeFormDataProvider).host = url;
return response.success;
}
}
} else {
ref.read(nodeFormDataProvider).host = url;
return response.success;
}
return false;
}
Future<bool> _testConnection({bool showFlushBar = true}) async {
final formData = ref.read(nodeFormDataProvider);
@ -87,41 +125,19 @@ class _AddEditNodeViewState extends ConsumerState<AddEditNodeView> {
case Coin.monero:
case Coin.wownero:
try {
final uri = Uri.parse(formData.host!);
if (uri.scheme.startsWith("http")) {
final String path = uri.path.isEmpty ? "/json_rpc" : uri.path;
final url = formData.host!;
final uri = Uri.tryParse(url);
if (uri != null) {
if (!uri.hasScheme) {
// try https first
testPassed = await _xmrHelper("https://$url", formData.port);
String uriString =
"${uri.scheme}://${uri.host}:${formData.port ?? 0}$path";
if (uri.host == "https") {
ref.read(nodeFormDataProvider).useSSL = true;
} else {
ref.read(nodeFormDataProvider).useSSL = false;
}
final response = await testMoneroNodeConnection(
Uri.parse(uriString),
false,
);
if (response.cert != null) {
if (mounted) {
final shouldAllowBadCert = await showBadX509CertificateDialog(
response.cert!,
response.url!,
response.port!,
context,
);
if (shouldAllowBadCert) {
final response = await testMoneroNodeConnection(
Uri.parse(uriString), true);
testPassed = response.success;
}
if (testPassed == false) {
// try http
testPassed = await _xmrHelper("http://$url", formData.port);
}
} else {
testPassed = response.success;
testPassed = await _xmrHelper(url, formData.port);
}
}
} catch (e, s) {
@ -167,7 +183,7 @@ class _AddEditNodeViewState extends ConsumerState<AddEditNodeView> {
} catch (_) {}
}
if (showFlushBar) {
if (showFlushBar && mounted) {
if (testPassed) {
unawaited(showFloatingFlushBar(
type: FlushBarType.success,
@ -191,7 +207,7 @@ class _AddEditNodeViewState extends ConsumerState<AddEditNodeView> {
bool? shouldSave;
if (!canConnect) {
if (!canConnect && mounted) {
await showDialog<dynamic>(
context: context,
useSafeArea: true,
@ -985,7 +1001,6 @@ class _NodeFormState extends ConsumerState<NodeForm> {
controller: _usernameController,
readOnly: shouldBeReadOnly,
enabled: enableField(_usernameController),
keyboardType: TextInputType.number,
focusNode: _usernameFocusNode,
style: STextStyles.field(context),
decoration: standardInputDecoration(
@ -1034,7 +1049,7 @@ class _NodeFormState extends ConsumerState<NodeForm> {
controller: _passwordController,
readOnly: shouldBeReadOnly,
enabled: enableField(_passwordController),
keyboardType: TextInputType.number,
obscureText: true,
focusNode: _passwordFocusNode,
style: STextStyles.field(context),
decoration: standardInputDecoration(

View file

@ -148,15 +148,16 @@ class _StackPrivacyCalls extends ConsumerState<StackPrivacyCalls> {
),
children: infoToggle
? [
if (Constants.enableExchange)
const TextSpan(
text:
"Exchange data preloaded for a seamless experience."),
"Exchange data preloaded for a seamless experience.\n\n"),
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<StackPrivacyCalls> {
),
]
: [
if (Constants.enableExchange)
const TextSpan(
text:
"Exchange data not preloaded (slower experience)."),
"Exchange data not preloaded (slower experience).\n\n"),
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(

View file

@ -45,6 +45,7 @@ import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
import 'package:stackwallet/utilities/enums/wallet_balance_toggle_state.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/show_loading.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/theme/stack_colors.dart';
import 'package:stackwallet/widgets/background.dart';
@ -261,11 +262,6 @@ class _WalletViewState extends ConsumerState<WalletView> {
void _onExchangePressed(BuildContext context) async {
final coin = ref.read(managerProvider).coin;
final currency = ExchangeDataLoadingService.instance.isar.currencies
.where()
.tickerEqualToAnyExchangeNameName(coin.ticker)
.findFirstSync();
if (coin.isTestNet) {
await showDialog<void>(
context: context,
@ -274,6 +270,15 @@ class _WalletViewState extends ConsumerState<WalletView> {
),
);
} else {
final currency = await showLoading(
whileFuture: ExchangeDataLoadingService.instance.isar.currencies
.where()
.tickerEqualToAnyExchangeNameName(coin.ticker)
.findFirst(),
context: context,
message: "Loading...",
);
if (mounted) {
unawaited(
Navigator.of(context).pushNamed(

View file

@ -96,6 +96,7 @@ class _StackPrivacyDialog extends ConsumerState<StackPrivacyDialog> {
),
children: infoToggle
? [
if (Constants.enableExchange)
const TextSpan(
text:
"Exchange data preloaded for a seamless experience."),

View file

@ -273,10 +273,10 @@ class ExchangeDataLoadingService {
// }
Future<void> loadMajesticBankCurrencies() async {
final exchange = MajesticBankExchange.instance;
final responseCurrencies = await exchange.getAllCurrencies(false);
if (responseCurrencies.value != null) {
// final exchange = MajesticBankExchange.instance;
// final responseCurrencies = await exchange.getAllCurrencies(false);
//
// if (responseCurrencies.value != null) {
await isar.writeTxn(() async {
final idsToDelete = await isar.currencies
.where()
@ -284,14 +284,14 @@ class ExchangeDataLoadingService {
.idProperty()
.findAll();
await isar.currencies.deleteAll(idsToDelete);
await isar.currencies.putAll(responseCurrencies.value!);
// await isar.currencies.putAll(responseCurrencies.value!);
});
} else {
Logging.instance.log(
"loadMajesticBankCurrencies: $responseCurrencies",
level: LogLevel.Warning,
);
}
// } else {
// Logging.instance.log(
// "loadMajesticBankCurrencies: $responseCurrencies",
// level: LogLevel.Warning,
// );
// }
}
// Future<void> loadMajesticBankPairs() async {

View file

@ -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<dynamic> _makeGetRequest(Uri uri) async {
return null;
final client = this.client ?? http.Client();
int code = -1;
try {

View file

@ -7,6 +7,7 @@ import 'package:stackwallet/exceptions/electrumx/no_such_transaction.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,6 +198,7 @@ class NotificationsService extends ChangeNotifier {
final oldTrade = trades.first;
late final ExchangeResponse<Trade> response;
if (oldTrade.exchangeName != MajesticBankExchange.exchangeName) {
try {
final exchange = Exchange.fromName(oldTrade.exchangeName);
response = await exchange.updateTrade(oldTrade);
@ -251,6 +253,7 @@ class NotificationsService extends ChangeNotifier {
}
}
}
}
bool get hasUnreadNotifications {
// final count = (_unreadCountBox.get("count") ?? 0) > 0;

View file

@ -10,6 +10,7 @@ Future<T> showLoading<T>({
required String message,
String? subMessage,
bool isDesktop = false,
bool opaqueBG = false,
}) async {
unawaited(
showDialog<void>(
@ -21,7 +22,7 @@ Future<T> showLoading<T>({
color: Theme.of(context)
.extension<StackColors>()!
.overlay
.withOpacity(0.6),
.withOpacity(opaqueBG ? 1.0 : 0.6),
child: CustomLoadingOverlay(
message: message,
subMessage: subMessage,
@ -34,10 +35,9 @@ Future<T> showLoading<T>({
final result = await whileFuture;
// TODO: update to flutter 3.7.x to take advantage of context.mounted
// if (mounted) {
if (context.mounted) {
Navigator.of(context, rootNavigator: isDesktop).pop();
// }
}
return result;
}

View file

@ -11,7 +11,7 @@ description: Stack Wallet
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.6.5+147
version: 1.6.6+148
environment:
sdk: ">=2.17.0 <3.0.0"