zwallet/lib/main.dart

97 lines
3.2 KiB
Dart
Raw Normal View History

2021-07-07 08:40:05 -07:00
import 'package:decimal/decimal.dart';
2021-06-21 17:40:59 -07:00
import 'package:flutter/material.dart';
2021-06-26 07:30:12 -07:00
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
2021-06-21 19:17:48 -07:00
import 'package:warp_api/warp_api.dart';
2021-06-26 07:30:12 -07:00
import 'package:splashscreen/splashscreen.dart';
2021-06-21 17:40:59 -07:00
2021-06-26 07:30:12 -07:00
import 'account.dart';
import 'account_manager.dart';
2021-07-12 04:32:49 -07:00
import 'backup.dart';
2021-08-02 22:58:02 -07:00
import 'multisend.dart';
2021-07-09 06:33:39 -07:00
import 'settings.dart';
2021-06-26 07:30:12 -07:00
import 'restore.dart';
import 'send.dart';
import 'store.dart';
2021-07-09 22:44:34 -07:00
import 'transaction.dart';
2021-06-21 19:17:48 -07:00
2021-06-26 07:30:12 -07:00
const ZECUNIT = 100000000.0;
2021-07-07 08:40:05 -07:00
var ZECUNIT_DECIMAL = Decimal.parse('100000000');
const mZECUNIT = 100000;
const DEFAULT_FEE = 1000;
2021-06-21 17:40:59 -07:00
2021-06-26 07:30:12 -07:00
var accountManager = AccountManager();
var priceStore = PriceStore();
var syncStatus = SyncStatus();
var settings = Settings();
2021-08-02 22:58:02 -07:00
var multipayData = MultiPayStore();
2021-06-21 17:40:59 -07:00
2021-06-26 07:30:12 -07:00
Future<Database> getDatabase() async {
var databasesPath = await getDatabasesPath();
final path = join(databasesPath, 'zec.db');
var db = await openDatabase(path);
return db;
}
2021-06-21 17:40:59 -07:00
2021-06-26 07:30:12 -07:00
void main() {
2021-07-12 04:32:49 -07:00
WidgetsFlutterBinding.ensureInitialized();
2021-07-09 06:33:39 -07:00
final home = ZWalletApp();
2021-07-12 04:32:49 -07:00
runApp(FutureBuilder(
future: settings.restore(),
builder: (context, state) => state.hasData
? Observer(
builder: (context) => MaterialApp(
2021-07-31 00:36:40 -07:00
title: 'ZWallet',
2021-07-12 04:32:49 -07:00
theme: settings.themeData,
home: home,
scaffoldMessengerKey: rootScaffoldMessengerKey,
onGenerateRoute: (RouteSettings settings) {
var routes = <String, WidgetBuilder>{
'/account': (context) => AccountPage(),
'/restore': (context) => RestorePage(),
2021-07-18 08:59:02 -07:00
'/send': (context) => SendPage(settings.arguments),
2021-07-12 04:32:49 -07:00
'/accounts': (context) => AccountManagerPage(),
'/settings': (context) => SettingsPage(),
'/tx': (context) => TransactionPage(settings.arguments),
'/backup': (context) => BackupPage(),
2021-08-02 22:58:02 -07:00
'/multipay': (context) => MultiPayPage(),
2021-07-12 04:32:49 -07:00
};
return MaterialPageRoute(builder: routes[settings.name]);
},
))
: Container()));
2021-06-26 07:30:12 -07:00
}
2021-06-21 17:40:59 -07:00
2021-07-09 06:33:39 -07:00
class ZWalletApp extends StatelessWidget {
2021-06-26 07:30:12 -07:00
Future<Widget> _init() async {
final dbPath = await getDatabasesPath();
2021-07-09 06:33:39 -07:00
await settings.restore();
WarpApi.initWallet(dbPath + "/zec.db", settings.getLWD());
2021-06-26 07:30:12 -07:00
await accountManager.init();
await syncStatus.init();
2021-07-12 04:32:49 -07:00
return Future.value(accountManager.accounts.isNotEmpty
? AccountPage()
: AccountManagerPage());
2021-06-21 17:40:59 -07:00
}
@override
Widget build(BuildContext context) {
2021-07-12 04:32:49 -07:00
final theme = Theme.of(context);
2021-06-26 07:30:12 -07:00
return SplashScreen(
2021-07-12 04:32:49 -07:00
navigateAfterFuture: _init(),
title: new Text(
'ZWallet',
style: new TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0),
),
image: new Image.asset('assets/zcash.png'),
backgroundColor: theme.backgroundColor,
photoSize: 50.0,
loaderColor: theme.primaryColor,
);
2021-06-21 17:40:59 -07:00
}
}
2021-06-26 07:30:12 -07:00
final GlobalKey<ScaffoldMessengerState> rootScaffoldMessengerKey =
GlobalKey<ScaffoldMessengerState>();