-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.dart
369 lines (323 loc) · 13.3 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
import 'dart:io';
import 'package:eosdart/eosdart.dart';
import 'package:eosio_passid_mobile_app/screen/requestType.dart';
import 'package:eosio_passid_mobile_app/constants/constants.dart';
import 'package:eosio_passid_mobile_app/utils/storage.dart';
import 'package:eosio_passid_mobile_app/utils/structure.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:keyboard_dismisser/keyboard_dismisser.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:eosio_passid_mobile_app/screen/main/stepper/stepper.dart';
import 'package:eosio_passid_mobile_app/screen/main/stepper/stepEnterAccount/stepEnterAccount.dart';
import 'package:eosio_passid_mobile_app/screen/main/stepper/stepEnterAccount/stepEnterAccountHeader/stepEnterAccountHeader.dart';
import 'package:eosio_passid_mobile_app/screen/main/stepper/stepScan/stepScanHeader/stepScanHeader.dart';
import 'package:eosio_passid_mobile_app/screen/main/stepper/stepScan/stepScan.dart';
import 'package:eosio_passid_mobile_app/screen/main/stepper/stepAttestation/stepAttestation.dart';
import 'package:eosio_passid_mobile_app/screen/main/stepper/stepAttestation/stepAttestationHeader/stepAttestationHeader.dart';
import 'package:eosio_passid_mobile_app/screen/main/stepper/stepReview/stepReview.dart';
import 'package:eosio_passid_mobile_app/screen/main/stepper/stepReview/stepReviewHeader/stepReviewHeader.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:eosio_passid_mobile_app/screen/theme.dart';
import 'package:eosio_passid_mobile_app/screen/settings/settings.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:logging/logging.dart';
import 'package:eosio_passid_mobile_app/screen/slideToSideRoute.dart';
import 'package:device_preview/device_preview.dart' as DevPreview;
import 'package:eosio_passid_mobile_app/utils/logging/loggerHandler.dart' as LH;
import 'package:eosio_passid_mobile_app/utils/net/eosio/eosio.dart';
var RUN_IN_DEVICE_PREVIEW_MODE = false;
final _logStorage = Logger('Storage initialization');
void main() {
//SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
// systemNavigationBarColor: Colors.grey,
//));
runApp(
RUN_IN_DEVICE_PREVIEW_MODE?
DevPreview.DevicePreview(
enabled: !kReleaseMode,
builder: (context) => PassId(),
):
PassId()
);
//changeNavigationBarColor();
}
Map<NetworkType, Network> fillNetworkTypes(Map<NetworkType, Network> networks){
_logStorage.fine("Fill network type if it's empty.");
if (networks != null && networks.isNotEmpty) {
_logStorage.fine("Netowrk types is already written in database.");
return null;
}
NetworkType.values.forEach((element) {
if (NETWORK_CHAINS[element] != null) {
_logStorage.finer("Network type: $element, "
"name: ${NETWORK_CHAINS[element][NETWORK_CHAIN_NAME]}"
"chainID: ${NETWORK_CHAINS[element][NETWORK_CHAIN_ID]}");
if ( NETWORK_CHAINS[element][NETWORK_CHAIN_DEFAULT] == true)
networks[element] = Network(networkType: element,
name: NETWORK_CHAINS[element][NETWORK_CHAIN_NAME],
chainID: NETWORK_CHAINS[element][NETWORK_CHAIN_ID]);
else
networks[element] = Network(networkType: element,
name: "Custom",
chainID: "Write you own chainID.");
}
});
return networks;
}
Future<void> fillDatabase() async
{
Storage storage = new Storage();
Map<NetworkType, Network> nets = fillNetworkTypes(storage.nodeSet.networks);
if (nets != null)
storage.nodeSet.networks = nets;
await storage.load(callback: (isAlreadyUpdated, isValid, {exc}) {
if (storage.nodeSet.nodes.isEmpty) {
storage.nodeSet.add(networkType: NetworkType.KYLIN,
isSelected: true,
server: NodeServer(host: "kylin.eosnode.io",
port: 443,
isEncryptedEndpoint: true));
storage.nodeSet.add(networkType: NetworkType.EOSIO_TESTNET,
isSelected: false,
server: NodeServer(host: "eosio.eosnode.io",
port: 443,
isEncryptedEndpoint: true));
storage.nodeSet.add(networkType: NetworkType.EOSIO_TESTNET,
isSelected: false,
server: NodeServer(host: "456786.eosnode.io",
port: 443,
isEncryptedEndpoint: true));
storage.nodeSet.add(networkType: NetworkType.MAINNET,
isSelected: false,
server: NodeServer(host: "mainenet.eosnode.io",
port: 443,
isEncryptedEndpoint: true));
storage.nodeSet.add(networkType: NetworkType.CUSTOM,
isSelected: false,
server: NodeServer(host: "custom.eosnode.io",
port: 443,
isEncryptedEndpoint: true));
}
if (storage.cloudSet.servers.isEmpty){
storage.cloudSet.add(networkTypeServer: NetworkTypeServer.MAIN_SERVER,
isSelected: true,
server: ServerCloud(name: "ZeroPass server", host: "163.172.144.187", port: 443, isEncryptedEndpoint: true));
}
StepDataEnterAccount storageStepEnterAccount = storage.getStorageData(0);
storageStepEnterAccount.isUnlocked = true;
StepDataAttestation stepDataAttestation = storage.getStorageData(2);
stepDataAttestation.requestType = RequestType.ATTESTATION_REQUEST;
stepDataAttestation.isOutsideCall = OutsideCall(reqeustedBy: "Ultra DEX");
});/**/
//to call it just one time
//if(storage.nodeSet)
// return;
storage.save();
}
/*
* To load from disc previously stored values
*/
void loadDatabase({Future<void> Function(Storage, bool, bool, {String exc}) callbackStatus})
{
Storage storage = new Storage();
storage.load(callback: (isAlreadyUpdated, isValid, {String exc}){
callbackStatus?.call(storage, isAlreadyUpdated, isValid, exc:exc);
});
}
class PassId extends StatelessWidget {
@override
Widget build(BuildContext context) {
return PlatformProvider(
//initialPlatform: initialPlatform,
builder: (BuildContext context) => PlatformApp(
title: 'PassID',
localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
DefaultMaterialLocalizations.delegate,
DefaultWidgetsLocalizations.delegate
],
android: (_) => MaterialAppData(
theme: AndroidTheme().getLight(),
darkTheme: AndroidTheme().getDark()),
ios: (_) => CupertinoAppData(
theme: iosThemeData(),
),
home: PassIdWidget()));
}
}
///*****************************************************************************
///
/// PassIdWidget
///
///****************************************************************************/
class PassIdWidget extends StatefulWidget {
@override
_PassIdWidgetState createState() => _PassIdWidgetState();
}
class _PassIdWidgetState extends State<PassIdWidget> with TickerProviderStateMixin {
final _log = Logger("main");
@override
void initState(){
super.initState();
initializeDateFormatting();
randomTests();
//clean old logger handler
Logger.root.level = Level.ALL;
LH.LoggerHandler loggerHandler = LH.LoggerHandler();
loggerHandler.cleanLegacyLogs();
//update database
loadDatabase(callbackStatus: (storage, isAlreadyUpdated, isValid, {String exc}) async {
if(isValid) {
if(storage.loggingEnabled){
bool isStarted = await loggerHandler.startLoggingToAppMemory();
if(!isStarted) {
print("main: couldn't start logging!");
loggerHandler.stopLoggingToAppMemory((){}, (){});
}
}
setState(() {});
}
});
fillDatabase().then((value) {
setState(() {});
});
if(!Platform.isIOS){
SystemChrome.setEnabledSystemUIOverlays([]); // hide status bar
}
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
//WidgetsBinding.instance
// .addPostFrameCallback((_) => widget.scaffoldContext.state.showSnackBar(SnackBar(content: Text("Your message here..")));
}
void randomTests() async{
return;
/*Keys keys = new Keys();
keys.add(PrivateKey("5KVTRoGQ1kW5BxzQ6SavdppVQPwVzfQGSBdCANc5gJpX74tPyXo"));
StorageNode storageNode = StorageNode(name: "myNode", host: "https://api-kylin.eoslaomao.com", port: 443, isEncryptedEndpoint: true, networkType: NetworkType.KYLIN, chainID: "5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191");
Eosio eosio = Eosio(storageNode, EosioVersion.v1, keys, httpTimeout: 60);
eosio.getAccountInfo("frkavbajti12").then((value) {
print (value);
});
Map data = {
'from': 'frkavbajti12',
'to': 'frkavbajti13',
'quantity': '0.0001 EOS',
'memo': 'ejga test',
};
eosio.pushTransaction("eosio.token", "transfer", [Eosio.createAuth("frkavbajti12", "active")], data).then((PushTrxResponse value) {
if (value.isValid)
var t = 9;
else
print(value.error);
});*/
}
@override
Widget build(BuildContext context) {
// Logger.root.level = Level.ALL;
// Logger.root.onRecord.listen((record) {
// print(
// '${record.loggerName} ${record.level.name}: ${record.time}: ${record.message}');
// });
changeNavigationBarColor();
return PlatformScaffold(
appBar: PlatformAppBar(
automaticallyImplyLeading: true,
title: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
width: 35,
height: 35,
child: Image(image: AssetImage('assets/images/passid.png'))),
Text(" Pass",
style: TextStyle(color: Colors.white)),
Text("ID",
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold))
],
),
trailingActions: <Widget>[
PlatformIconButton(
cupertino: (_,__) => CupertinoIconButtonData(
icon: Icon(
Icons.menu,
color: Colors.white,
size: 35
),
padding: EdgeInsets.all(0),
),
androidIcon: Icon(Icons.menu, size: 30.0),
material: (_,__) => MaterialIconButtonData(tooltip: 'Settings'),
onPressed: () {
final page = Settings();
Navigator.of(context).push(SlideToSideRoute(page));
}
)
],
),
body: MultiBlocProvider(
providers: [
BlocProvider<StepEnterAccountHeaderBloc>(
create: (BuildContext context) => StepEnterAccountHeaderBloc()),
BlocProvider<StepScanHeaderBloc>(
create: (BuildContext context) => StepScanHeaderBloc()),
BlocProvider<StepEnterAccountBloc>(
create: (BuildContext context) => StepEnterAccountBloc()),
BlocProvider<StepScanBloc>(
create: (BuildContext context) => StepScanBloc()),
BlocProvider<StepAttestationBloc>(
create: (BuildContext context) => StepAttestationBloc()),
BlocProvider<StepAttestationHeaderBloc>(
create: (BuildContext context) => StepAttestationHeaderBloc()),
BlocProvider<StepReviewBloc>(
create: (BuildContext context) => StepReviewBloc()),
BlocProvider<StepReviewHeaderBloc>(
create: (BuildContext context) => StepReviewHeaderBloc()),
BlocProvider<StepperBloc>(
create: (BuildContext context) => StepperBloc(maxSteps: 4 /*set maximum steps you have in any/all modes*/)),
],
child: KeyboardDismisser(
gestures:[
GestureType.onTapDown,
GestureType.onTapUp,
GestureType.onTap,
GestureType.onTapCancel,
GestureType.onSecondaryTapDown,
GestureType.onSecondaryTapUp,
GestureType.onSecondaryTapCancel,
GestureType.onDoubleTap,
GestureType. onLongPress,
GestureType.onLongPressStart,
GestureType.onLongPressMoveUpdate,
GestureType.onLongPressUp,
GestureType.onLongPressEnd,
GestureType.onVerticalDragDown,
GestureType.onVerticalDragStart,
GestureType.onVerticalDragUpdate,
GestureType.onVerticalDragEnd,
GestureType.onVerticalDragCancel,
GestureType.onHorizontalDragDown,
GestureType.onHorizontalDragStart,
GestureType.onHorizontalDragUpdate,
GestureType.onHorizontalDragEnd,
GestureType.onHorizontalDragCancel,
GestureType.onForcePressStart,
GestureType.onForcePressPeak,
GestureType.onForcePressUpdate,
GestureType.onForcePressEnd,
GestureType.onPanDown,
GestureType.onPanUpdateDownDirection,
GestureType.onPanUpdateUpDirection,
GestureType.onPanUpdateLeftDirection,
GestureType.onPanUpdateRightDirection,
],
child:Scaffold(
//resizeToAvoidBottomInset: false,
body:StepperForm()),
))
);
}
}