From cdd97ffa12c8b0395d0b646b9067a13db9b5435a Mon Sep 17 00:00:00 2001 From: YannMarti <100758384+YannMarti@users.noreply.github.com> Date: Fri, 13 May 2022 14:06:25 +0200 Subject: [PATCH] cleaning up code --- vidaia/lib/pages/auth0_testing_page.dart | 13 ++++ vidaia/lib/pages/exchange/send/send_page.dart | 3 + .../pages/home/redeem/redeem_info_page.dart | 44 +++++++++---- vidaia/lib/repositories/dataRepository.dart | 12 ++++ vidaia/lib/utils/globals.dart | 5 ++ vidaia/lib/utils/popups.dart | 61 ++++++++++++++++++- vidaia/lib/utils/wallet.dart | 29 --------- 7 files changed, 122 insertions(+), 45 deletions(-) diff --git a/vidaia/lib/pages/auth0_testing_page.dart b/vidaia/lib/pages/auth0_testing_page.dart index 46ae2d8..273e5cd 100644 --- a/vidaia/lib/pages/auth0_testing_page.dart +++ b/vidaia/lib/pages/auth0_testing_page.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:flutter/material.dart'; import 'package:flutter_appauth/flutter_appauth.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; @@ -5,6 +7,7 @@ import 'package:vidaia/pages/profile_testing.dart'; import 'package:vidaia/utils/auth0.dart'; import 'package:vidaia/utils/globals.dart' as globals; +import '../utils/wallet.dart'; import 'home/home_page_loader.dart'; import 'login_testing.dart'; @@ -56,6 +59,13 @@ class _Auth0TestPageState extends State { final idToken = parseIdToken(result!.idToken!); final profile = await getUserDetails(result.accessToken!); + print('-------------------> '+json.encode(profile)); + var name = profile['name']; + globals.user = """{ + "userId": "1", + "displayName": "$name", + "walletAdress": "0x0..." +}"""; await secureStorage.write( key: 'refresh_token', value: result.refreshToken); @@ -70,6 +80,9 @@ class _Auth0TestPageState extends State { context, MaterialPageRoute(builder: (context) => HomePage2()), ); + if (!globals.mnemonicNoted) { + showMnemonicAlert(context); + } } catch (e, s) { print('login error: $e - stack: $s'); diff --git a/vidaia/lib/pages/exchange/send/send_page.dart b/vidaia/lib/pages/exchange/send/send_page.dart index 4ed6891..e8721e8 100644 --- a/vidaia/lib/pages/exchange/send/send_page.dart +++ b/vidaia/lib/pages/exchange/send/send_page.dart @@ -90,15 +90,18 @@ class _SendPageState extends State { child: Text('set address')), ElevatedButton( onPressed: () async { + onLoading(context); var res; try { res = await transferVidar(int.parse(valueController.text), addressController.text, 'https://testnet.veblocks.net'); } on InvalidAddressException { + Navigator.pop(context); oneButtonPopup(context, Text('Transaction Failed'), Text('The Address is not valid')); } finally { if (res.containsKey('id')) { + Navigator.pop(context); txConfirmedAlert(context, res['id']); } else { txError(context); diff --git a/vidaia/lib/pages/home/redeem/redeem_info_page.dart b/vidaia/lib/pages/home/redeem/redeem_info_page.dart index 7327a3c..626d236 100644 --- a/vidaia/lib/pages/home/redeem/redeem_info_page.dart +++ b/vidaia/lib/pages/home/redeem/redeem_info_page.dart @@ -5,6 +5,9 @@ import 'package:vidaia/models/Reward.dart'; import 'package:vidaia/utils/constants.dart'; import 'package:vidaia/widgets/roundedButton.dart'; import 'package:vidaia/utils/wallet.dart'; +import '../../../utils/invalid_Address_Exception.dart'; +import '../../../utils/popups.dart'; + class RedeemInfoPage extends StatefulWidget { final Reward reward; @@ -210,22 +213,37 @@ class _RedeemInfoPageState extends State { child: Theme( data: ThemeData.light(), child: ListTile( - contentPadding: EdgeInsets.all(8), - title: Text( - widget.reward.name, - style: TextStyle(fontSize: 18, color: PRIMARY), - ), - trailing: Text( - widget.reward.cost.toString() + ' VID', - style: TextStyle(fontSize: 16, color: PRIMARY), - ), - onTap: () { - transferVidar( + contentPadding: EdgeInsets.all(8), + title: Text( + widget.reward.name, + style: TextStyle(fontSize: 18, color: PRIMARY), + ), + trailing: Text( + widget.reward.cost.toString() + ' VID', + style: TextStyle(fontSize: 16, color: PRIMARY), + ), + onTap: () async { + onLoading(context); + late Map res; + try { + res = await transferVidar( widget.reward.cost, '0x00bab3d8de4ebbefb07d53b1ff8c0f2434bd616d', 'https://testnet.veblocks.net'); - confirmPurchase(context); - }), + + } on InvalidAddressException { + oneButtonPopup(context, Text('Transaction Failed'), + Text('The Address is not valid')); + } finally { + if (res.containsKey('id')) { + Navigator.pop(context); + confirmPurchase(context); + } else { + txError(context); + } + } + }, + ), ), ) ], diff --git a/vidaia/lib/repositories/dataRepository.dart b/vidaia/lib/repositories/dataRepository.dart index 653eb27..981a48b 100644 --- a/vidaia/lib/repositories/dataRepository.dart +++ b/vidaia/lib/repositories/dataRepository.dart @@ -6,6 +6,7 @@ import 'package:vidaia/models/HistoryEntry.dart'; import 'package:vidaia/models/Reward.dart'; import 'package:vidaia/models/User.dart'; import 'package:vidaia/models/Product.dart'; +import 'package:vidaia/utils/globals.dart' as globals; class DataRepository { //can be split up in seperate repositories in the future if needd @@ -45,6 +46,7 @@ class DataRepository { return list.map((e) => Reward.fromJson(e)).toList(); } +/* Future loadUser() async { //read json file final jsondata = await rootBundle.rootBundle.loadString('assets/data/user.json'); @@ -53,6 +55,16 @@ class DataRepository { return User.fromJson(data); } + */ + + Future loadUser() async { + //read json file + final jsondata = globals.user; + //decode json data as list + final data = json.decode(jsondata) as dynamic; + + return User.fromJson(data); + } Future loadHistory() async { //read json file diff --git a/vidaia/lib/utils/globals.dart b/vidaia/lib/utils/globals.dart index b1a9222..aa2112e 100644 --- a/vidaia/lib/utils/globals.dart +++ b/vidaia/lib/utils/globals.dart @@ -22,6 +22,11 @@ bool isBusy = false; bool isLoggedIn = false; String? name; String? picture; +String user = """{ + "userId": "W_Liechti", + "displayName": "Werner Liechti", + "walletAdress": "www.comits.be" +}"""; //priv c337cf0b3c7c3e4b7f5480b985724e0f221120554459b5c247870d2789726089 diff --git a/vidaia/lib/utils/popups.dart b/vidaia/lib/utils/popups.dart index 01d11e3..6a30907 100644 --- a/vidaia/lib/utils/popups.dart +++ b/vidaia/lib/utils/popups.dart @@ -1,5 +1,3 @@ - - import 'package:flutter/material.dart'; oneButtonPopup(BuildContext context, Text title, Text content) { @@ -26,4 +24,61 @@ oneButtonPopup(BuildContext context, Text title, Text content) { return alert; }, ); -} \ No newline at end of file +} + +confirmPurchase(BuildContext context) { + // set up the buttons + Widget cancelButton = TextButton( + child: Text("OK"), + onPressed: () { + Navigator.pop(context); + Navigator.pop(context); + Navigator.pop(context); + }, + ); + + // set up the AlertDialog + AlertDialog alert = AlertDialog( + title: Text("Purchase Confirmed"), + content: Text( + "Thank you for your purchase. Your Reward will be sent to you by Email."), + actions: [ + cancelButton, + ], + ); + // show the dialog + showDialog( + barrierDismissible: false, + context: context, + builder: (BuildContext context) { + return alert; + }, + ); +} + +onLoading(BuildContext context) { + showDialog( + context: context, + barrierDismissible: false, + builder: (_) { + return Dialog( + elevation: 0, + backgroundColor: Colors.transparent, + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 20), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + // The loading indicator + CircularProgressIndicator(), + SizedBox( + height: 15, + ), + // Some text + Text('Loading...') + ], + ), + )); + }, + ); +} diff --git a/vidaia/lib/utils/wallet.dart b/vidaia/lib/utils/wallet.dart index 28c14af..995666d 100644 --- a/vidaia/lib/utils/wallet.dart +++ b/vidaia/lib/utils/wallet.dart @@ -192,35 +192,6 @@ showMnemonicWordsAlert(BuildContext context) async { ); } -confirmPurchase(BuildContext context) { - // set up the buttons - Widget cancelButton = TextButton( - child: Text("OK"), - onPressed: () { - Navigator.pop(context); - Navigator.pop(context); - Navigator.pop(context); - }, - ); - - // set up the AlertDialog - AlertDialog alert = AlertDialog( - title: Text("Purchase Confirmed"), - content: Text("Thank you for your purchase. Your Reward will be sent to you by Email."), - actions: [ - cancelButton, - ], - ); - // show the dialog - showDialog( - barrierDismissible: false, - context: context, - builder: (BuildContext context) { - return alert; - }, - ); -} - txConfirmedAlert(BuildContext context, String txId) { // set up the buttons Widget cancelButton = TextButton(