stack_wallet/lib/main.dart

772 lines
28 KiB
Dart
Raw Normal View History

2023-05-26 21:21:16 +00:00
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/
2022-08-26 08:11:35 +00:00
import 'dart:async';
import 'dart:io';
import 'dart:math';
2022-08-26 08:11:35 +00:00
import 'package:cw_core/node.dart';
import 'package:cw_core/unspent_coins_info.dart';
import 'package:cw_core/wallet_info.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:flutter/foundation.dart';
2022-08-26 08:11:35 +00:00
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_libmonero/monero/monero.dart';
2022-09-27 08:09:31 +00:00
import 'package:flutter_libmonero/wownero/wownero.dart';
2022-08-26 08:11:35 +00:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
2022-11-09 22:43:26 +00:00
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
2022-08-26 08:11:35 +00:00
import 'package:google_fonts/google_fonts.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:isar/isar.dart';
import 'package:keyboard_dismisser/keyboard_dismisser.dart';
import 'package:path_provider/path_provider.dart';
2023-03-01 21:52:13 +00:00
import 'package:stackwallet/db/hive/db.dart';
import 'package:stackwallet/db/isar/main_db.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/models/exchange/change_now/exchange_transaction.dart';
import 'package:stackwallet/models/exchange/change_now/exchange_transaction_status.dart';
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
2023-03-30 16:41:28 +00:00
import 'package:stackwallet/models/isar/models/isar_models.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/models/models.dart';
import 'package:stackwallet/models/node_model.dart';
import 'package:stackwallet/models/notification_model.dart';
import 'package:stackwallet/models/trade_wallet_lookup.dart';
import 'package:stackwallet/pages/home_view/home_view.dart';
import 'package:stackwallet/pages/intro_view.dart';
import 'package:stackwallet/pages/loading_view.dart';
import 'package:stackwallet/pages/pinpad_views/create_pin_view.dart';
import 'package:stackwallet/pages/pinpad_views/lock_screen_view.dart';
import 'package:stackwallet/pages/settings_views/global_settings_view/stack_backup_views/restore_from_encrypted_string_view.dart';
2022-12-01 14:48:23 +00:00
import 'package:stackwallet/pages_desktop_specific/password/desktop_login_view.dart';
2022-11-04 19:32:02 +00:00
import 'package:stackwallet/providers/desktop/storage_crypto_handler_provider.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/providers/global/auto_swb_service_provider.dart';
import 'package:stackwallet/providers/global/base_currencies_provider.dart';
// import 'package:stackwallet/providers/global/has_authenticated_start_state_provider.dart';
import 'package:stackwallet/providers/global/trades_service_provider.dart';
import 'package:stackwallet/providers/providers.dart';
import 'package:stackwallet/route_generator.dart';
2023-01-24 21:28:11 +00:00
// import 'package:stackwallet/services/buy/buy_data_loading_service.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/services/debug_service.dart';
import 'package:stackwallet/services/exchange/exchange_data_loading_service.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/services/locale_service.dart';
import 'package:stackwallet/services/node_service.dart';
import 'package:stackwallet/services/notifications_api.dart';
import 'package:stackwallet/services/notifications_service.dart';
import 'package:stackwallet/services/tor_service.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/services/trade_service.dart';
import 'package:stackwallet/themes/theme_providers.dart';
import 'package:stackwallet/themes/theme_service.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/db_version_migration.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/utilities/enums/backup_frequency_type.dart';
2022-11-09 22:43:26 +00:00
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
2022-08-26 08:11:35 +00:00
import 'package:stackwallet/utilities/logger.dart';
2023-03-20 22:02:20 +00:00
import 'package:stackwallet/utilities/prefs.dart';
2022-11-12 22:04:16 +00:00
import 'package:stackwallet/utilities/stack_file_system.dart';
2022-09-19 20:18:31 +00:00
import 'package:stackwallet/utilities/util.dart';
2023-05-09 17:54:15 +00:00
import 'package:stackwallet/widgets/crypto_notifications.dart';
import 'package:window_size/window_size.dart';
2022-08-26 08:11:35 +00:00
final openedFromSWBFileStringStateProvider =
StateProvider<String?>((ref) => null);
// main() is the entry point to the app. It initializes Hive (local database),
// runs the MyApp widget and checks for new users, caching the value in the
// miscellaneous box for later use
void main() async {
2023-05-23 23:47:52 +00:00
WidgetsFlutterBinding.ensureInitialized();
2022-09-24 21:20:58 +00:00
GoogleFonts.config.allowRuntimeFetching = false;
2022-10-28 18:03:52 +00:00
if (Platform.isIOS) {
Util.libraryPath = await getLibraryDirectory();
}
2022-11-28 18:46:35 +00:00
Screen? screen;
if (Platform.isLinux || (Util.isDesktop && !Platform.isIOS)) {
2022-11-28 18:46:35 +00:00
screen = await getCurrentScreen();
Util.screenWidth = screen?.frame.width;
}
if (Util.isDesktop && !Platform.isIOS) {
setWindowTitle('Stack Wallet');
setWindowMinSize(const Size(1220, 100));
setWindowMaxSize(Size.infinite);
2022-11-28 18:46:35 +00:00
final screenHeight = screen?.frame.height;
if (screenHeight != null && !kDebugMode) {
// starting to height be 3/4 screen height or 900, whichever is smaller
final height = min<double>(screenHeight * 0.75, 900);
setWindowFrame(
Rect.fromLTWH(0, 0, 1220, height),
);
}
}
2022-08-26 08:11:35 +00:00
// FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
2022-09-01 09:06:47 +00:00
if (!(Logging.isArmLinux || Logging.isTestEnv)) {
2022-09-01 08:51:06 +00:00
final isar = await Isar.open(
[LogSchema],
2022-11-12 22:04:16 +00:00
directory: (await StackFileSystem.applicationIsarDirectory()).path,
2022-09-01 08:51:06 +00:00
inspector: false,
2023-02-11 00:41:21 +00:00
maxSizeMiB: 512,
2022-09-01 08:51:06 +00:00
);
await Logging.instance.init(isar);
await DebugService.instance.init(isar);
2022-08-26 08:11:35 +00:00
2022-09-01 08:51:06 +00:00
// clear out all info logs on startup. No need to await and block
unawaited(DebugService.instance.deleteLogsOlderThan());
2022-09-01 08:51:06 +00:00
}
2022-08-26 08:11:35 +00:00
// Registering Transaction Model Adapters
Hive.registerAdapter(TransactionDataAdapter());
Hive.registerAdapter(TransactionChunkAdapter());
Hive.registerAdapter(TransactionAdapter());
Hive.registerAdapter(InputAdapter());
Hive.registerAdapter(OutputAdapter());
// Registering Utxo Model Adapters
Hive.registerAdapter(UtxoDataAdapter());
Hive.registerAdapter(UtxoObjectAdapter());
Hive.registerAdapter(StatusAdapter());
// Registering Lelantus Model Adapters
Hive.registerAdapter(LelantusCoinAdapter());
// notification model adapter
Hive.registerAdapter(NotificationModelAdapter());
// change now trade adapters
Hive.registerAdapter(ExchangeTransactionAdapter());
Hive.registerAdapter(ExchangeTransactionStatusAdapter());
2022-10-03 00:55:54 +00:00
Hive.registerAdapter(TradeAdapter());
2022-08-26 08:11:35 +00:00
// reference lookup data adapter
Hive.registerAdapter(TradeWalletLookupAdapter());
// node model adapter
Hive.registerAdapter(NodeModelAdapter());
Hive.registerAdapter(NodeAdapter());
2022-09-27 08:09:31 +00:00
if (!Hive.isAdapterRegistered(WalletInfoAdapter().typeId)) {
Hive.registerAdapter(WalletInfoAdapter());
}
2022-08-26 08:11:35 +00:00
Hive.registerAdapter(WalletTypeAdapter());
Hive.registerAdapter(UnspentCoinsInfoAdapter());
2022-11-12 22:04:16 +00:00
await Hive.initFlutter(
(await StackFileSystem.applicationHiveDirectory()).path);
2022-08-26 08:11:35 +00:00
await Hive.openBox<dynamic>(DB.boxNameDBInfo);
2023-03-20 22:02:20 +00:00
await Hive.openBox<dynamic>(DB.boxNamePrefs);
await Prefs.instance.init();
2022-11-09 22:43:26 +00:00
2023-08-07 17:06:44 +00:00
// TODO remove this!!!!
Prefs.instance.useTor = true;
if (Prefs.instance.useTor) {
2023-08-07 16:46:34 +00:00
await TorService.sharedInstance.start();
}
2023-07-04 00:25:18 +00:00
await StackFileSystem.initThemesDir();
2023-01-18 14:07:25 +00:00
// Desktop migrate handled elsewhere (currently desktop_login_view.dart)
2022-11-09 22:43:26 +00:00
if (!Util.isDesktop) {
int dbVersion = DB.instance.get<dynamic>(
boxName: DB.boxNameDBInfo, key: "hive_data_version") as int? ??
0;
2023-05-15 20:21:09 +00:00
if (dbVersion < Constants.currentDataVersion) {
2022-11-09 22:43:26 +00:00
try {
await DbVersionMigrator().migrate(
dbVersion,
secureStore: const SecureStorageWrapper(
store: FlutterSecureStorage(),
isDesktop: false,
),
);
} catch (e, s) {
2023-01-18 14:07:25 +00:00
Logging.instance.log("Cannot migrate mobile database\n$e $s",
2022-11-09 22:43:26 +00:00
level: LogLevel.Error, printFullLength: true);
}
2022-10-19 22:51:50 +00:00
}
}
2022-08-26 08:11:35 +00:00
if (!Platform.isWindows) {
monero.onStartup();
}
if (!Platform.isLinux && !Platform.isWindows) {
2023-05-23 23:47:52 +00:00
wownero.onStartup();
}
2022-08-26 08:11:35 +00:00
// SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
// overlays: [SystemUiOverlay.bottom]);
await NotificationApi.init();
await MainDB.instance.initMainDB();
ThemeService.instance.init(MainDB.instance);
// check and update or install default themes
await ThemeService.instance.checkDefaultThemesOnStartup();
2023-06-07 14:36:47 +00:00
// verify current user preference theme and revert to default
// if problems are found to prevent app being unusable
if (!(await ThemeService.instance
.verifyInstalled(themeId: Prefs.instance.themeId))) {
Prefs.instance.themeId = "light";
2023-05-10 14:53:46 +00:00
}
2023-06-07 14:36:47 +00:00
// verify current user preference light brightness theme and revert to default
// if problems are found to prevent app being unusable
if (!(await ThemeService.instance
.verifyInstalled(themeId: Prefs.instance.systemBrightnessLightThemeId))) {
Prefs.instance.systemBrightnessLightThemeId = "light";
}
// verify current user preference dark brightness theme and revert to default
// if problems are found to prevent app being unusable
if (!(await ThemeService.instance
.verifyInstalled(themeId: Prefs.instance.systemBrightnessDarkThemeId))) {
Prefs.instance.systemBrightnessDarkThemeId = "dark";
2023-05-10 14:53:46 +00:00
}
2022-08-26 08:11:35 +00:00
runApp(const ProviderScope(child: MyApp()));
}
/// MyApp initialises relevant services with a MultiProvider
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final localeService = LocaleService();
localeService.loadLocale();
return const KeyboardDismisser(
2023-05-09 18:01:55 +00:00
child: MaterialAppWithTheme(),
2022-08-26 08:11:35 +00:00
);
}
}
// Sidenote: MaterialAppWithTheme and InitView are only separated for clarity. No other reason.
class MaterialAppWithTheme extends ConsumerStatefulWidget {
const MaterialAppWithTheme({
Key? key,
}) : super(key: key);
@override
ConsumerState<MaterialAppWithTheme> createState() =>
_MaterialAppWithThemeState();
}
class _MaterialAppWithThemeState extends ConsumerState<MaterialAppWithTheme>
with WidgetsBindingObserver {
static const platform = MethodChannel("STACK_WALLET_RESTORE");
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
// late final Wallets _wallets;
// late final Prefs _prefs;
2022-08-26 08:11:35 +00:00
late final NotificationsService _notificationsService;
late final NodeService _nodeService;
late final TradesService _tradesService;
late final Completer<void> loadingCompleter;
2022-08-26 16:38:33 +00:00
bool didLoad = false;
2022-11-11 15:31:01 +00:00
bool didLoadShared = false;
2022-11-04 19:32:02 +00:00
bool _desktopHasPassword = false;
2022-08-26 16:38:33 +00:00
Future<void> loadShared() async {
2022-11-11 15:31:01 +00:00
if (didLoadShared) {
return;
}
didLoadShared = true;
await DB.instance.init();
await ref.read(prefsChangeNotifierProvider).init();
2022-11-25 23:14:06 +00:00
final familiarity = ref.read(prefsChangeNotifierProvider).familiarity + 1;
ref.read(prefsChangeNotifierProvider).familiarity = familiarity;
Constants.exchangeForExperiencedUsers(familiarity);
if (Util.isDesktop) {
_desktopHasPassword =
await ref.read(storageCryptoHandlerProvider).hasPassword();
}
2023-03-30 16:41:28 +00:00
ref
.read(priceAnd24hChangeNotifierProvider)
.tokenContractAddressesToCheck
.addAll(
await MainDB.instance.getEthContracts().addressProperty().findAll(),
);
}
2022-08-26 08:11:35 +00:00
Future<void> load() async {
2022-10-28 18:03:52 +00:00
try {
if (didLoad) {
return;
}
didLoad = true;
if (!Util.isDesktop) {
await loadShared();
2022-11-04 19:32:02 +00:00
}
2023-04-24 14:36:12 +00:00
ref.read(applicationThemesDirectoryPathProvider.notifier).state =
2023-07-04 00:25:18 +00:00
StackFileSystem.themesDir!.path;
2022-10-28 18:03:52 +00:00
_notificationsService = ref.read(notificationsProvider);
_nodeService = ref.read(nodeServiceChangeNotifierProvider);
_tradesService = ref.read(tradesServiceProvider);
NotificationApi.prefs = ref.read(prefsChangeNotifierProvider);
2022-10-28 18:03:52 +00:00
NotificationApi.notificationsService = _notificationsService;
unawaited(ref.read(baseCurrenciesProvider).update());
await _nodeService.updateDefaults();
await _notificationsService.init(
nodeService: _nodeService,
tradesService: _tradesService,
prefs: ref.read(prefsChangeNotifierProvider),
2022-10-28 18:03:52 +00:00
);
ref.read(priceAnd24hChangeNotifierProvider).start(true);
await ref
.read(walletsChangeNotifierProvider)
.load(ref.read(prefsChangeNotifierProvider));
2022-10-28 18:03:52 +00:00
loadingCompleter.complete();
// TODO: this should probably run unawaited. Keep commented out for now as proper community nodes ui hasn't been implemented yet
// unawaited(_nodeService.updateCommunityNodes());
await ExchangeDataLoadingService.instance.initDB();
2022-10-28 18:03:52 +00:00
// run without awaiting
2023-01-12 00:13:34 +00:00
if (ref.read(prefsChangeNotifierProvider).externalCalls &&
await ref.read(prefsChangeNotifierProvider).isExternalCallsSet()) {
2023-01-12 00:13:34 +00:00
if (Constants.enableExchange) {
await ExchangeDataLoadingService.instance.setCurrenciesIfEmpty(
2023-05-03 20:03:31 +00:00
ref.read(efCurrencyPairProvider),
ref.read(efRateTypeProvider),
);
unawaited(ExchangeDataLoadingService.instance.loadAll());
2023-01-12 00:13:34 +00:00
}
2023-01-14 17:22:48 +00:00
// if (Constants.enableBuy) {
// unawaited(BuyDataLoadingService().loadAll(ref));
// }
2022-10-28 18:03:52 +00:00
}
2022-10-04 14:46:22 +00:00
if (ref.read(prefsChangeNotifierProvider).isAutoBackupEnabled) {
switch (ref.read(prefsChangeNotifierProvider).backupFrequencyType) {
2022-10-28 18:03:52 +00:00
case BackupFrequencyType.everyTenMinutes:
ref.read(autoSWBServiceProvider).startPeriodicBackupTimer(
duration: const Duration(minutes: 10));
break;
case BackupFrequencyType.everyAppStart:
unawaited(ref.read(autoSWBServiceProvider).doBackup());
break;
case BackupFrequencyType.afterClosingAWallet:
// ignore this case here
break;
}
2022-08-26 08:11:35 +00:00
}
// ref
// .read(prefsChangeNotifierProvider)
// .userID; // Just reading the ref should set it if it's not already set
// We shouldn't need to do this, instead only generating an ID when (or if) the userID is looked up when creating a quote
2022-10-28 18:03:52 +00:00
} catch (e, s) {
Logger.print("$e $s", normalLength: false);
2022-08-26 08:11:35 +00:00
}
}
@override
void initState() {
String themeId;
2023-03-20 22:02:20 +00:00
if (ref.read(prefsChangeNotifierProvider).enableSystemBrightness) {
final brightness = WidgetsBinding.instance.window.platformBrightness;
2023-03-20 22:02:20 +00:00
switch (brightness) {
case Brightness.dark:
themeId =
ref.read(prefsChangeNotifierProvider).systemBrightnessDarkThemeId;
2023-03-20 22:02:20 +00:00
break;
case Brightness.light:
themeId = ref
.read(prefsChangeNotifierProvider)
.systemBrightnessLightThemeId;
2023-03-20 22:02:20 +00:00
break;
}
} else {
themeId = ref.read(prefsChangeNotifierProvider).themeId;
2022-09-23 14:33:44 +00:00
}
2022-08-26 08:11:35 +00:00
loadingCompleter = Completer();
WidgetsBinding.instance.addObserver(this);
// load locale and prefs
ref
.read(localeServiceChangeNotifierProvider.notifier)
.loadLocale(notify: false);
WidgetsBinding.instance.addPostFrameCallback((_) async {
//Add themes path to provider
ref.read(applicationThemesDirectoryPathProvider.notifier).state =
2023-07-04 00:25:18 +00:00
StackFileSystem.themesDir!.path;
ref.read(themeProvider.state).state = ref.read(pThemeService).getTheme(
themeId: themeId,
)!;
if (Platform.isAndroid) {
// fetch open file if it exists
await getOpenFile();
2022-08-26 08:11:35 +00:00
if (ref.read(openedFromSWBFileStringStateProvider.state).state !=
null) {
// waiting for loading to complete before going straight to restore if the app was opened via file
await loadingCompleter.future;
2022-08-26 08:11:35 +00:00
await goToRestoreSWB(
ref.read(openedFromSWBFileStringStateProvider.state).state!);
ref.read(openedFromSWBFileStringStateProvider.state).state = null;
}
// ref.read(shouldShowLockscreenOnResumeStateProvider.state).state = false;
}
});
2022-08-26 08:11:35 +00:00
WidgetsBinding.instance.window.onPlatformBrightnessChanged = () {
String themeId;
switch (WidgetsBinding.instance.window.platformBrightness) {
case Brightness.dark:
themeId =
ref.read(prefsChangeNotifierProvider).systemBrightnessDarkThemeId;
break;
case Brightness.light:
themeId = ref
.read(prefsChangeNotifierProvider)
.systemBrightnessLightThemeId;
break;
}
WidgetsBinding.instance.addPostFrameCallback((_) {
2023-03-21 00:08:45 +00:00
if (ref.read(prefsChangeNotifierProvider).enableSystemBrightness) {
ref.read(themeProvider.state).state =
ref.read(pThemeService).getTheme(
themeId: themeId,
)!;
2023-03-21 00:08:45 +00:00
}
});
};
2022-08-26 08:11:35 +00:00
super.initState();
}
@override
dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeLocales(List<Locale>? locales) {
ref.read(localeServiceChangeNotifierProvider).loadLocale();
super.didChangeLocales(locales);
}
2022-08-26 08:11:35 +00:00
@override
void didChangeAppLifecycleState(AppLifecycleState state) async {
debugPrint("didChangeAppLifecycleState: ${state.name}");
if (state == AppLifecycleState.resumed) {}
switch (state) {
case AppLifecycleState.inactive:
break;
case AppLifecycleState.paused:
break;
case AppLifecycleState.resumed:
if (Platform.isAndroid) {
// fetch open file if it exists
await getOpenFile();
// go straight to restore if the app was resumed via file
if (ref.read(openedFromSWBFileStringStateProvider.state).state !=
null) {
await goToRestoreSWB(
ref.read(openedFromSWBFileStringStateProvider.state).state!);
ref.read(openedFromSWBFileStringStateProvider.state).state = null;
}
2022-08-26 08:11:35 +00:00
}
// if (ref.read(hasAuthenticatedOnStartStateProvider.state).state &&
// ref.read(shouldShowLockscreenOnResumeStateProvider.state).state) {
// final now = DateTime.now().toUtc().millisecondsSinceEpoch ~/ 1000;
//
// if (now - _prefs.lastUnlocked > _prefs.lastUnlockedTimeout) {
// ref.read(shouldShowLockscreenOnResumeStateProvider.state).state =
// false;
// Navigator.of(navigatorKey.currentContext!).push(
// MaterialPageRoute<dynamic>(
// builder: (_) => LockscreenView(
// routeOnSuccess: "",
// popOnSuccess: true,
// biometricsAuthenticationTitle: "Unlock Stack",
// biometricsLocalizedReason:
// "Unlock your stack wallet using biometrics",
// biometricsCancelButtonString: "Cancel",
// onSuccess: () {
// ref
// .read(shouldShowLockscreenOnResumeStateProvider.state)
// .state = true;
// },
// ),
// ),
// );
// }
// }
break;
case AppLifecycleState.detached:
break;
}
}
/// should only be called on android currently
2022-08-26 08:11:35 +00:00
Future<void> getOpenFile() async {
// update provider with new file content state
ref.read(openedFromSWBFileStringStateProvider.state).state =
await platform.invokeMethod("getOpenFile");
// call reset to clear cached value
await resetOpenPath();
Logging.instance.log(
"This is the .swb content from intent: ${ref.read(openedFromSWBFileStringStateProvider.state).state}",
level: LogLevel.Info);
}
/// should only be called on android currently
2022-08-26 08:11:35 +00:00
Future<void> resetOpenPath() async {
await platform.invokeMethod("resetOpenPath");
}
Future<void> goToRestoreSWB(String encrypted) async {
if (!ref.read(prefsChangeNotifierProvider).hasPin) {
2022-08-26 08:11:35 +00:00
await Navigator.of(navigatorKey.currentContext!)
.pushNamed(CreatePinView.routeName, arguments: true)
.then((value) {
if (value is! bool || value == false) {
Navigator.of(navigatorKey.currentContext!).pushNamed(
RestoreFromEncryptedStringView.routeName,
arguments: encrypted);
}
});
} else {
unawaited(Navigator.push(
2022-08-26 08:11:35 +00:00
navigatorKey.currentContext!,
RouteGenerator.getRoute(
shouldUseMaterialRoute: RouteGenerator.useMaterialPageRoute,
builder: (_) => LockscreenView(
showBackButton: true,
routeOnSuccess: RestoreFromEncryptedStringView.routeName,
routeOnSuccessArguments: encrypted,
biometricsCancelButtonString: "CANCEL",
biometricsLocalizedReason:
"Authenticate to restore Stack Wallet backup",
biometricsAuthenticationTitle: "Restore Stack backup",
),
settings: const RouteSettings(name: "/swbrestorelockscreen"),
),
));
2022-08-26 08:11:35 +00:00
}
}
InputBorder _buildOutlineInputBorder(Color color) {
return OutlineInputBorder(
borderSide: BorderSide(
width: 1,
color: color,
),
borderRadius: BorderRadius.circular(Constants.size.circularBorderRadius),
);
}
@override
Widget build(BuildContext context) {
debugPrint("BUILD: $runtimeType");
// ref.listen(shouldShowLockscreenOnResumeStateProvider, (previous, next) {
// Logging.instance.log("shouldShowLockscreenOnResumeStateProvider set to: $next",
// addToDebugMessagesDB: false);
// });
2023-04-24 14:36:12 +00:00
final colorScheme = ref.watch(colorProvider.state).state;
2022-09-22 22:17:21 +00:00
2022-08-26 08:11:35 +00:00
return MaterialApp(
key: GlobalKey(),
navigatorKey: navigatorKey,
title: 'Stack Wallet',
onGenerateRoute: RouteGenerator.generateRoute,
theme: ThemeData(
2022-09-22 22:17:21 +00:00
extensions: [colorScheme],
highlightColor: colorScheme.highlight,
2023-03-17 22:10:22 +00:00
brightness: colorScheme.brightness,
2022-08-26 08:11:35 +00:00
fontFamily: GoogleFonts.inter().fontFamily,
2022-09-22 22:17:21 +00:00
unselectedWidgetColor: colorScheme.radioButtonBorderDisabled,
// textTheme: GoogleFonts.interTextTheme().copyWith(
// button: STextStyles.button(context),
// subtitle1: STextStyles.field(context).copyWith(
// color: colorScheme.textDark,
// ),
// ),
2022-08-26 08:11:35 +00:00
radioTheme: const RadioThemeData(
splashRadius: 0,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
// splashFactory: NoSplash.splashFactory,
splashColor: Colors.transparent,
buttonTheme: ButtonThemeData(
2022-09-22 22:17:21 +00:00
splashColor: colorScheme.splash,
2022-08-26 08:11:35 +00:00
),
textButtonTheme: TextButtonThemeData(
style: ButtonStyle(
// splashFactory: NoSplash.splashFactory,
2022-09-22 22:17:21 +00:00
overlayColor: MaterialStateProperty.all(colorScheme.splash),
2022-08-26 08:11:35 +00:00
minimumSize: MaterialStateProperty.all<Size>(const Size(46, 46)),
2022-09-22 22:17:21 +00:00
// textStyle: MaterialStateProperty.all<TextStyle>(
// STextStyles.button(context)),
foregroundColor:
MaterialStateProperty.all(colorScheme.buttonTextSecondary),
2022-09-21 00:46:07 +00:00
backgroundColor: MaterialStateProperty.all<Color>(
2022-09-22 22:17:21 +00:00
colorScheme.buttonBackSecondary),
2022-08-26 08:11:35 +00:00
shape: MaterialStateProperty.all<OutlinedBorder>(
RoundedRectangleBorder(
// 1000 to be relatively sure it keeps its pill shape
borderRadius: BorderRadius.circular(1000),
),
),
),
),
2022-09-22 22:17:21 +00:00
primaryColor: colorScheme.accentColorDark,
primarySwatch: Util.createMaterialColor(colorScheme.accentColorDark),
2022-08-26 08:11:35 +00:00
checkboxTheme: CheckboxThemeData(
splashRadius: 0,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(Constants.size.checkboxBorderRadius),
),
checkColor: MaterialStateColor.resolveWith(
(state) {
if (state.contains(MaterialState.selected)) {
2022-09-22 22:17:21 +00:00
return colorScheme.checkboxIconChecked;
2022-08-26 08:11:35 +00:00
}
2022-09-22 22:17:21 +00:00
return colorScheme.checkboxBGChecked;
2022-08-26 08:11:35 +00:00
},
),
fillColor: MaterialStateColor.resolveWith(
(states) {
if (states.contains(MaterialState.selected)) {
2022-09-22 22:17:21 +00:00
return colorScheme.checkboxBGChecked;
2022-08-26 08:11:35 +00:00
}
2022-09-22 22:17:21 +00:00
return colorScheme.checkboxBorderEmpty;
2022-08-26 08:11:35 +00:00
},
),
),
2022-09-21 00:46:07 +00:00
appBarTheme: AppBarTheme(
2022-08-26 08:11:35 +00:00
centerTitle: false,
2022-09-22 22:17:21 +00:00
color: colorScheme.background,
2022-08-26 08:11:35 +00:00
elevation: 0,
),
inputDecorationTheme: InputDecorationTheme(
2022-09-22 22:17:21 +00:00
focusColor: colorScheme.textFieldDefaultBG,
fillColor: colorScheme.textFieldDefaultBG,
2022-08-26 08:11:35 +00:00
filled: true,
contentPadding: const EdgeInsets.symmetric(
vertical: 6,
horizontal: 12,
),
2022-09-22 22:17:21 +00:00
// labelStyle: STextStyles.fieldLabel(context),
// hintStyle: STextStyles.fieldLabel(context),
enabledBorder:
_buildOutlineInputBorder(colorScheme.textFieldDefaultBG),
focusedBorder:
_buildOutlineInputBorder(colorScheme.textFieldDefaultBG),
errorBorder: _buildOutlineInputBorder(colorScheme.textFieldDefaultBG),
disabledBorder:
_buildOutlineInputBorder(colorScheme.textFieldDefaultBG),
focusedErrorBorder:
_buildOutlineInputBorder(colorScheme.textFieldDefaultBG),
2022-08-26 08:11:35 +00:00
),
),
2023-05-09 18:01:55 +00:00
home: CryptoNotifications(
child: Util.isDesktop
? FutureBuilder(
future: loadShared(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (_desktopHasPassword) {
String? startupWalletId;
if (ref
.read(prefsChangeNotifierProvider)
.gotoWalletOnStartup) {
startupWalletId = ref
.read(prefsChangeNotifierProvider)
.startupWalletId;
}
return DesktopLoginView(
startupWalletId: startupWalletId,
load: load,
);
} else {
return const IntroView();
}
} else {
2023-05-09 18:01:55 +00:00
return const LoadingView();
}
2023-05-09 18:01:55 +00:00
},
)
: FutureBuilder(
future: load(),
builder: (BuildContext context, AsyncSnapshot<void> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
// FlutterNativeSplash.remove();
if (ref.read(walletsChangeNotifierProvider).hasWallets ||
ref.read(prefsChangeNotifierProvider).hasPin) {
// return HomeView();
String? startupWalletId;
if (ref
.read(prefsChangeNotifierProvider)
.gotoWalletOnStartup) {
startupWalletId = ref
.read(prefsChangeNotifierProvider)
.startupWalletId;
}
return LockscreenView(
isInitialAppLogin: true,
routeOnSuccess: HomeView.routeName,
routeOnSuccessArguments: startupWalletId,
biometricsAuthenticationTitle: "Unlock Stack",
biometricsLocalizedReason:
"Unlock your stack wallet using biometrics",
biometricsCancelButtonString: "Cancel",
);
} else {
return const IntroView();
}
} else {
2023-05-09 18:01:55 +00:00
// CURRENTLY DISABLED as cannot be animated
// technically not needed as FlutterNativeSplash will overlay
// anything returned here until the future completes but
// FutureBuilder requires you to return something
return const LoadingView();
}
2023-05-09 18:01:55 +00:00
},
),
),
2022-08-26 08:11:35 +00:00
);
}
}