Skip to content

Commit

Permalink
cleaning up code
Browse files Browse the repository at this point in the history
  • Loading branch information
YannMarti committed May 13, 2022
1 parent 87bcff2 commit cdd97ff
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 45 deletions.
13 changes: 13 additions & 0 deletions vidaia/lib/pages/auth0_testing_page.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_appauth/flutter_appauth.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
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';

Expand Down Expand Up @@ -56,6 +59,13 @@ class _Auth0TestPageState extends State<Auth0TestPage> {

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);
Expand All @@ -70,6 +80,9 @@ class _Auth0TestPageState extends State<Auth0TestPage> {
context,
MaterialPageRoute(builder: (context) => HomePage2()),
);
if (!globals.mnemonicNoted) {
showMnemonicAlert(context);
}
} catch (e, s) {
print('login error: $e - stack: $s');

Expand Down
3 changes: 3 additions & 0 deletions vidaia/lib/pages/exchange/send/send_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,18 @@ class _SendPageState extends State<SendPage> {
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);
Expand Down
44 changes: 31 additions & 13 deletions vidaia/lib/pages/home/redeem/redeem_info_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -210,22 +213,37 @@ class _RedeemInfoPageState extends State<RedeemInfoPage> {
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);
}
}
},
),
),
)
],
Expand Down
12 changes: 12 additions & 0 deletions vidaia/lib/repositories/dataRepository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -45,6 +46,7 @@ class DataRepository {
return list.map((e) => Reward.fromJson(e)).toList();
}

/*
Future<User> loadUser() async {
//read json file
final jsondata = await rootBundle.rootBundle.loadString('assets/data/user.json');
Expand All @@ -53,6 +55,16 @@ class DataRepository {
return User.fromJson(data);
}
*/

Future<User> 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<BuyHistory> loadHistory() async {
//read json file
Expand Down
5 changes: 5 additions & 0 deletions vidaia/lib/utils/globals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 58 additions & 3 deletions vidaia/lib/utils/popups.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


import 'package:flutter/material.dart';

oneButtonPopup(BuildContext context, Text title, Text content) {
Expand All @@ -26,4 +24,61 @@ oneButtonPopup(BuildContext context, Text title, Text content) {
return alert;
},
);
}
}

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...')
],
),
));
},
);
}
29 changes: 0 additions & 29 deletions vidaia/lib/utils/wallet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit cdd97ff

Please sign in to comment.