2022-08-26 08:11:35 +00:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
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/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_libmonero/monero/monero.dart';
|
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
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';
|
|
|
|
import 'package:stackwallet/hive/db.dart';
|
|
|
|
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/isar/models/log.dart';
|
|
|
|
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/exchange_view/exchange_view.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-09-19 01:27:25 +00:00
|
|
|
import 'package:stackwallet/pages_desktop_specific/home/desktop_home_view.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/providers/exchange/available_currencies_state_provider.dart';
|
|
|
|
import 'package:stackwallet/providers/exchange/available_floating_rate_pairs_state_provider.dart';
|
2022-08-30 22:38:07 +00:00
|
|
|
import 'package:stackwallet/providers/exchange/change_now_provider.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/providers/exchange/changenow_initial_load_status.dart';
|
2022-08-31 18:06:57 +00:00
|
|
|
import 'package:stackwallet/providers/exchange/estimate_rate_exchange_form_provider.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/providers/exchange/fixed_rate_exchange_form_provider.dart';
|
|
|
|
import 'package:stackwallet/providers/exchange/fixed_rate_market_pairs_provider.dart';
|
|
|
|
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';
|
2022-09-22 22:17:21 +00:00
|
|
|
import 'package:stackwallet/providers/ui/color_theme_provider.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:stackwallet/route_generator.dart';
|
|
|
|
import 'package:stackwallet/services/debug_service.dart';
|
|
|
|
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/trade_service.dart';
|
|
|
|
import 'package:stackwallet/services/wallets.dart';
|
|
|
|
import 'package:stackwallet/utilities/constants.dart';
|
2022-09-06 15:12:23 +00:00
|
|
|
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';
|
|
|
|
import 'package:stackwallet/utilities/logger.dart';
|
|
|
|
import 'package:stackwallet/utilities/prefs.dart';
|
2022-09-21 00:46:07 +00:00
|
|
|
import 'package:stackwallet/utilities/theme/color_theme.dart';
|
2022-09-22 23:48:50 +00:00
|
|
|
import 'package:stackwallet/utilities/theme/dark_colors.dart';
|
|
|
|
import 'package:stackwallet/utilities/theme/light_colors.dart';
|
|
|
|
import 'package:stackwallet/utilities/theme/stack_colors.dart';
|
2022-09-19 20:18:31 +00:00
|
|
|
import 'package:stackwallet/utilities/util.dart';
|
2022-09-15 00:28:11 +00:00
|
|
|
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 {
|
|
|
|
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
|
2022-09-15 00:28:11 +00:00
|
|
|
|
2022-09-19 20:18:31 +00:00
|
|
|
if (Util.isDesktop) {
|
2022-09-15 00:28:11 +00:00
|
|
|
setWindowTitle('Stack Wallet');
|
|
|
|
setWindowMinSize(const Size(1200, 900));
|
|
|
|
setWindowMaxSize(Size.infinite);
|
|
|
|
}
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
Directory appDirectory = (await getApplicationDocumentsDirectory());
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
appDirectory = (await getLibraryDirectory());
|
|
|
|
}
|
|
|
|
// FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
|
|
|
|
await Hive.initFlutter(appDirectory.path);
|
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],
|
|
|
|
directory: appDirectory.path,
|
|
|
|
inspector: false,
|
|
|
|
);
|
|
|
|
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
|
2022-09-01 09:06:28 +00:00
|
|
|
unawaited(DebugService.instance.purgeInfoLogs());
|
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());
|
|
|
|
|
|
|
|
// reference lookup data adapter
|
|
|
|
Hive.registerAdapter(TradeWalletLookupAdapter());
|
|
|
|
|
|
|
|
// node model adapter
|
|
|
|
Hive.registerAdapter(NodeModelAdapter());
|
|
|
|
|
|
|
|
Hive.registerAdapter(NodeAdapter());
|
|
|
|
|
|
|
|
Hive.registerAdapter(WalletInfoAdapter());
|
|
|
|
|
|
|
|
Hive.registerAdapter(WalletTypeAdapter());
|
|
|
|
|
|
|
|
Hive.registerAdapter(UnspentCoinsInfoAdapter());
|
|
|
|
|
2022-09-06 15:12:23 +00:00
|
|
|
await Hive.openBox<dynamic>(DB.boxNameDBInfo);
|
|
|
|
int dbVersion = DB.instance.get<dynamic>(
|
|
|
|
boxName: DB.boxNameDBInfo, key: "hive_data_version") as int? ??
|
|
|
|
0;
|
|
|
|
if (dbVersion < Constants.currentHiveDbVersion) {
|
|
|
|
await DbVersionMigrator().migrate(dbVersion);
|
|
|
|
}
|
2022-08-26 08:11:35 +00:00
|
|
|
|
2022-09-06 15:12:23 +00:00
|
|
|
monero.onStartup();
|
2022-08-26 08:11:35 +00:00
|
|
|
|
2022-09-21 23:57:59 +00:00
|
|
|
await Hive.openBox<dynamic>(DB.boxNameTheme);
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
// SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
|
|
|
|
// overlays: [SystemUiOverlay.bottom]);
|
|
|
|
await NotificationApi.init();
|
|
|
|
|
|
|
|
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(
|
|
|
|
child: MaterialAppWithTheme(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
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-08-26 08:11:35 +00:00
|
|
|
Future<void> load() async {
|
2022-08-26 16:38:33 +00:00
|
|
|
if (didLoad) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
didLoad = true;
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
await DB.instance.init();
|
|
|
|
|
|
|
|
_notificationsService = ref.read(notificationsProvider);
|
|
|
|
_nodeService = ref.read(nodeServiceChangeNotifierProvider);
|
|
|
|
_tradesService = ref.read(tradesServiceProvider);
|
|
|
|
|
|
|
|
NotificationApi.prefs = _prefs;
|
|
|
|
NotificationApi.notificationsService = _notificationsService;
|
|
|
|
|
2022-08-30 22:38:07 +00:00
|
|
|
unawaited(ref.read(baseCurrenciesProvider).update());
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
await _nodeService.updateDefaults();
|
|
|
|
await _notificationsService.init(
|
|
|
|
nodeService: _nodeService,
|
|
|
|
tradesService: _tradesService,
|
|
|
|
prefs: _prefs,
|
2022-08-30 22:38:07 +00:00
|
|
|
changeNow: ref.read(changeNowProvider),
|
2022-08-26 08:11:35 +00:00
|
|
|
);
|
|
|
|
await _prefs.init();
|
|
|
|
ref.read(priceAnd24hChangeNotifierProvider).start(true);
|
|
|
|
await _wallets.load(_prefs);
|
|
|
|
loadingCompleter.complete();
|
2022-08-31 22:07:20 +00:00
|
|
|
// TODO: this should probably run unawaited. Keep commented out for now as proper community nodes ui hasn't been implemented yet
|
|
|
|
// unawaited(_nodeService.updateCommunityNodes());
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
if (_prefs.isAutoBackupEnabled) {
|
|
|
|
switch (_prefs.backupFrequencyType) {
|
|
|
|
case BackupFrequencyType.everyTenMinutes:
|
|
|
|
ref
|
|
|
|
.read(autoSWBServiceProvider)
|
|
|
|
.startPeriodicBackupTimer(duration: const Duration(minutes: 10));
|
|
|
|
break;
|
|
|
|
case BackupFrequencyType.everyAppStart:
|
2022-08-30 22:38:07 +00:00
|
|
|
unawaited(ref.read(autoSWBServiceProvider).doBackup());
|
2022-08-26 08:11:35 +00:00
|
|
|
break;
|
|
|
|
case BackupFrequencyType.afterClosingAWallet:
|
|
|
|
// ignore this case here
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _loadChangeNowStandardCurrencies() async {
|
|
|
|
if (ref
|
|
|
|
.read(availableChangeNowCurrenciesStateProvider.state)
|
|
|
|
.state
|
|
|
|
.isNotEmpty &&
|
|
|
|
ref
|
|
|
|
.read(availableFloatingRatePairsStateProvider.state)
|
|
|
|
.state
|
|
|
|
.isNotEmpty) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-30 22:38:07 +00:00
|
|
|
final response = await ref.read(changeNowProvider).getAvailableCurrencies();
|
|
|
|
final response2 =
|
|
|
|
await ref.read(changeNowProvider).getAvailableFloatingRatePairs();
|
2022-08-26 08:11:35 +00:00
|
|
|
if (response.value != null) {
|
|
|
|
ref.read(availableChangeNowCurrenciesStateProvider.state).state =
|
|
|
|
response.value!;
|
|
|
|
if (response2.value != null) {
|
|
|
|
ref.read(availableFloatingRatePairsStateProvider.state).state =
|
|
|
|
response2.value!;
|
|
|
|
|
|
|
|
if (response.value!.length > 1) {
|
|
|
|
if (ref.read(estimatedRateExchangeFormProvider).from == null) {
|
|
|
|
if (response.value!.where((e) => e.ticker == "btc").isNotEmpty) {
|
2022-08-30 22:38:07 +00:00
|
|
|
await ref.read(estimatedRateExchangeFormProvider).updateFrom(
|
2022-08-26 08:11:35 +00:00
|
|
|
response.value!.firstWhere((e) => e.ticker == "btc"), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ref.read(estimatedRateExchangeFormProvider).to == null) {
|
|
|
|
if (response.value!.where((e) => e.ticker == "doge").isNotEmpty) {
|
2022-08-30 22:38:07 +00:00
|
|
|
await ref.read(estimatedRateExchangeFormProvider).updateTo(
|
2022-08-26 08:11:35 +00:00
|
|
|
response.value!.firstWhere((e) => e.ticker == "doge"), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Logging.instance.log(
|
|
|
|
"Failed to load changeNOW available floating rate pairs: ${response2.exception?.errorMessage}",
|
|
|
|
level: LogLevel.Error);
|
|
|
|
ref.read(changeNowEstimatedInitialLoadStatusStateProvider.state).state =
|
|
|
|
ChangeNowLoadStatus.failed;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Logging.instance.log(
|
|
|
|
"Failed to load changeNOW currencies: ${response.exception?.errorMessage}",
|
|
|
|
level: LogLevel.Error);
|
|
|
|
await Future<void>.delayed(const Duration(seconds: 1));
|
|
|
|
ref.read(changeNowEstimatedInitialLoadStatusStateProvider.state).state =
|
|
|
|
ChangeNowLoadStatus.failed;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ref.read(changeNowEstimatedInitialLoadStatusStateProvider.state).state =
|
|
|
|
ChangeNowLoadStatus.success;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _loadFixedRateMarkets() async {
|
|
|
|
Logging.instance.log("Starting initial fixed rate market data loading...",
|
|
|
|
level: LogLevel.Info);
|
|
|
|
if (ref.read(fixedRateMarketPairsStateProvider.state).state.isNotEmpty) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-30 22:38:07 +00:00
|
|
|
final response3 =
|
|
|
|
await ref.read(changeNowProvider).getAvailableFixedRateMarkets();
|
2022-08-26 08:11:35 +00:00
|
|
|
if (response3.value != null) {
|
|
|
|
ref.read(fixedRateMarketPairsStateProvider.state).state =
|
|
|
|
response3.value!;
|
|
|
|
|
|
|
|
if (ref.read(fixedRateExchangeFormProvider).market == null) {
|
|
|
|
final matchingMarkets =
|
|
|
|
response3.value!.where((e) => e.to == "doge" && e.from == "btc");
|
|
|
|
if (matchingMarkets.isNotEmpty) {
|
2022-08-30 22:38:07 +00:00
|
|
|
await ref
|
2022-08-26 08:11:35 +00:00
|
|
|
.read(fixedRateExchangeFormProvider)
|
|
|
|
.updateMarket(matchingMarkets.first, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Logging.instance.log("Initial fixed rate market data loading complete.",
|
|
|
|
level: LogLevel.Info);
|
|
|
|
} else {
|
|
|
|
Logging.instance.log(
|
|
|
|
"Failed to load changeNOW fixed rate markets: ${response3.exception?.errorMessage}",
|
|
|
|
level: LogLevel.Error);
|
|
|
|
|
|
|
|
ref.read(changeNowFixedInitialLoadStatusStateProvider.state).state =
|
|
|
|
ChangeNowLoadStatus.failed;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ref.read(changeNowFixedInitialLoadStatusStateProvider.state).state =
|
|
|
|
ChangeNowLoadStatus.success;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _loadChangeNowData() async {
|
|
|
|
List<Future<dynamic>> concurrentFutures = [];
|
|
|
|
concurrentFutures.add(_loadChangeNowStandardCurrencies());
|
|
|
|
if (kFixedRateEnabled) {
|
|
|
|
concurrentFutures.add(_loadFixedRateMarkets());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
2022-09-23 14:33:44 +00:00
|
|
|
final colorScheme = DB.instance
|
|
|
|
.get<dynamic>(boxName: DB.boxNameTheme, key: "colorScheme") as String?;
|
|
|
|
|
|
|
|
ThemeType themeType;
|
|
|
|
switch (colorScheme) {
|
|
|
|
case "dark":
|
|
|
|
themeType = ThemeType.dark;
|
|
|
|
break;
|
|
|
|
case "light":
|
|
|
|
default:
|
|
|
|
themeType = ThemeType.light;
|
|
|
|
}
|
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);
|
|
|
|
|
|
|
|
_prefs = ref.read(prefsChangeNotifierProvider);
|
|
|
|
_wallets = ref.read(walletsChangeNotifierProvider);
|
|
|
|
|
2022-09-22 23:48:50 +00:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
|
|
|
ref.read(colorThemeProvider.state).state =
|
|
|
|
StackColors.fromStackColorTheme(
|
2022-09-23 14:33:44 +00:00
|
|
|
themeType == ThemeType.dark ? DarkColors() : LightColors());
|
2022-09-22 23:48:50 +00:00
|
|
|
|
|
|
|
if (Platform.isAndroid) {
|
2022-09-05 23:31:24 +00:00
|
|
|
// fetch open file if it exists
|
|
|
|
await getOpenFile();
|
2022-08-26 08:11:35 +00:00
|
|
|
|
2022-09-05 23:31:24 +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
|
|
|
|
2022-09-05 23:31:24 +00:00
|
|
|
await goToRestoreSWB(
|
|
|
|
ref.read(openedFromSWBFileStringStateProvider.state).state!);
|
|
|
|
ref.read(openedFromSWBFileStringStateProvider.state).state = null;
|
|
|
|
}
|
|
|
|
// ref.read(shouldShowLockscreenOnResumeStateProvider.state).state = false;
|
2022-09-22 23:48:50 +00:00
|
|
|
}
|
|
|
|
});
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
dispose() {
|
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@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:
|
2022-09-05 23:31:24 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-05 23:31:24 +00:00
|
|
|
/// 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);
|
|
|
|
}
|
|
|
|
|
2022-09-05 23:31:24 +00:00
|
|
|
/// 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 (!_prefs.hasPin) {
|
|
|
|
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 {
|
2022-08-30 22:38:07 +00:00
|
|
|
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-30 22:38:07 +00:00
|
|
|
));
|
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);
|
|
|
|
// });
|
|
|
|
|
2022-09-22 22:17:21 +00:00
|
|
|
final colorScheme = ref.watch(colorThemeProvider.state).state;
|
|
|
|
|
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,
|
2022-08-26 08:11:35 +00:00
|
|
|
brightness: Brightness.light,
|
|
|
|
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,
|
2022-09-21 21:59:52 +00:00
|
|
|
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
|
|
|
),
|
|
|
|
),
|
|
|
|
home: FutureBuilder(
|
|
|
|
future: load(),
|
|
|
|
builder: (BuildContext context, AsyncSnapshot<void> snapshot) {
|
|
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
|
|
|
// FlutterNativeSplash.remove();
|
|
|
|
if (_wallets.hasWallets || _prefs.hasPin) {
|
|
|
|
// return HomeView();
|
|
|
|
|
|
|
|
// run without awaiting
|
|
|
|
if (Constants.enableExchange) {
|
|
|
|
_loadChangeNowData();
|
|
|
|
}
|
|
|
|
|
2022-09-09 16:51:34 +00:00
|
|
|
String? startupWalletId;
|
|
|
|
if (ref.read(prefsChangeNotifierProvider).gotoWalletOnStartup) {
|
|
|
|
startupWalletId =
|
|
|
|
ref.read(prefsChangeNotifierProvider).startupWalletId;
|
|
|
|
}
|
|
|
|
|
2022-09-19 01:27:25 +00:00
|
|
|
// TODO proper desktop auth view
|
2022-09-19 20:18:31 +00:00
|
|
|
if (Util.isDesktop) {
|
2022-09-19 01:27:25 +00:00
|
|
|
Future<void>.delayed(Duration.zero).then((value) =>
|
|
|
|
Navigator.of(context).pushNamedAndRemoveUntil(
|
|
|
|
DesktopHomeView.routeName, (route) => false));
|
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
|
2022-09-09 16:51:34 +00:00
|
|
|
return LockscreenView(
|
2022-08-26 08:11:35 +00:00
|
|
|
isInitialAppLogin: true,
|
|
|
|
routeOnSuccess: HomeView.routeName,
|
2022-09-09 16:51:34 +00:00
|
|
|
routeOnSuccessArguments: startupWalletId,
|
2022-08-26 08:11:35 +00:00
|
|
|
biometricsAuthenticationTitle: "Unlock Stack",
|
|
|
|
biometricsLocalizedReason:
|
|
|
|
"Unlock your stack wallet using biometrics",
|
|
|
|
biometricsCancelButtonString: "Cancel",
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const IntroView();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|