-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from SayNode/Send-and-Recieve
Send and recieve
- Loading branch information
Showing
23 changed files
with
860 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
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'; | ||
|
||
final FlutterAppAuth appAuth = FlutterAppAuth(); | ||
final FlutterSecureStorage secureStorage = const FlutterSecureStorage(); | ||
const AUTH0_DOMAIN = 'saynode.eu.auth0.com'; | ||
const AUTH0_CLIENT_ID = 'NtesFp8kbFYekf05rleULMSdBS5hEWRN'; | ||
|
||
const AUTH0_REDIRECT_URI = 'com.auth0.vidaia://login-callback'; | ||
const AUTH0_ISSUER = 'https://$AUTH0_DOMAIN'; | ||
|
||
class Auth0TestPage extends StatefulWidget { | ||
Auth0TestPage(); | ||
|
||
@override | ||
State<Auth0TestPage> createState() => _Auth0TestPageState(); | ||
} | ||
|
||
class _Auth0TestPageState extends State<Auth0TestPage> { | ||
String errorMessage = ''; | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text('Auth0 Test'), | ||
), | ||
body: Center( | ||
child: globals.isBusy | ||
? CircularProgressIndicator() | ||
: Login(loginAction, errorMessage), | ||
), | ||
); | ||
} | ||
|
||
Future<void> loginAction() async { | ||
setState(() { | ||
globals.isBusy = true; | ||
errorMessage = ''; | ||
}); | ||
|
||
try { | ||
final AuthorizationTokenResponse? result = | ||
await appAuth.authorizeAndExchangeCode( | ||
AuthorizationTokenRequest(AUTH0_CLIENT_ID, AUTH0_REDIRECT_URI, | ||
issuer: 'https://$AUTH0_DOMAIN', | ||
scopes: ['openid', 'profile', 'offline_access'], | ||
promptValues: ['login']), | ||
); | ||
|
||
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); | ||
|
||
setState(() { | ||
globals.isBusy = false; | ||
globals.isLoggedIn = true; | ||
globals.name = idToken['globals.name']; | ||
globals.picture = profile['globals.picture']; | ||
}); | ||
Navigator.push( | ||
context, | ||
MaterialPageRoute(builder: (context) => HomePage2()), | ||
); | ||
if (!globals.mnemonicNoted) { | ||
showMnemonicAlert(context); | ||
} | ||
} catch (e, s) { | ||
print('login error: $e - stack: $s'); | ||
|
||
setState(() { | ||
globals.isBusy = false; | ||
globals.isLoggedIn = false; | ||
errorMessage = e.toString(); | ||
}); | ||
} | ||
} | ||
|
||
@override | ||
void initState() { | ||
initAction(); | ||
super.initState(); | ||
} | ||
|
||
void initAction() async { | ||
final storedRefreshToken = await secureStorage.read(key: 'refresh_token'); | ||
if (storedRefreshToken == null) return; | ||
|
||
setState(() { | ||
globals.isBusy = true; | ||
}); | ||
|
||
try { | ||
final response = await appAuth.token(TokenRequest( | ||
AUTH0_CLIENT_ID, | ||
AUTH0_REDIRECT_URI, | ||
issuer: AUTH0_ISSUER, | ||
refreshToken: storedRefreshToken, | ||
)); | ||
|
||
final idToken = parseIdToken(response!.idToken!); | ||
final profile = await getUserDetails(response.accessToken!); | ||
|
||
secureStorage.write(key: 'refresh_token', value: response.refreshToken); | ||
|
||
setState(() { | ||
globals.isBusy = false; | ||
globals.isLoggedIn = true; | ||
globals.name = idToken['globals.name']; | ||
globals.picture = profile['globals.picture']; | ||
}); | ||
} catch (e, s) { | ||
print('error on refresh token: $e - stack: $s'); | ||
logoutAction(context); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:vidaia/main.dart'; | ||
import 'package:vidaia/pages/exchange/exchange_page_stack.dart'; | ||
import 'package:vidaia/pages/exchange/receive/recieve_page.dart'; | ||
import 'package:vidaia/pages/exchange/send/send_page.dart'; | ||
import 'package:vidaia/pages/home/history/buy_history_page.dart'; | ||
import 'package:vidaia/pages/home/home/home_page.dart'; | ||
import 'package:vidaia/pages/home/redeem/redeem_page.dart'; | ||
import 'package:vidaia/repositories/dataRepository.dart'; | ||
|
||
class ExchangePage extends StatefulWidget { | ||
ExchangePage({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<ExchangePage> createState() => _ExchangePageState(); | ||
} | ||
|
||
class _ExchangePageState extends State<ExchangePage> { | ||
late Future<bool> isDataLoaded; | ||
|
||
DataRepository dataRepository = getIt.get<DataRepository>(); | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
isDataLoaded = dataRepository.init(); | ||
} | ||
|
||
final _pages = [SendPage(), RecievePage()]; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return FutureBuilder<bool>( | ||
future: isDataLoaded, | ||
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) { | ||
if (snapshot.connectionState == ConnectionState.done && snapshot.data == true) { | ||
return ExchangePageStack(_pages); | ||
} else if (snapshot.connectionState == ConnectionState.done && snapshot.hasError) { | ||
return Padding( | ||
padding: const EdgeInsets.only(top: 30), | ||
child: Text( | ||
'Error: ${snapshot.error}', | ||
style: TextStyle(fontSize: 20), | ||
), | ||
); | ||
} else { | ||
return Center( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
Center( | ||
child: CircularProgressIndicator(), | ||
), | ||
SizedBox( | ||
height: 20, | ||
), | ||
Text( | ||
"Loading data", | ||
style: TextStyle(color: Colors.black38, fontSize: 15, fontWeight: FontWeight.w400), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import 'package:easy_localization/easy_localization.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:vidaia/utils/constants.dart'; | ||
import 'package:vidaia/utils/wallet.dart'; | ||
|
||
import '../../widgets/vidaia_drawer.dart'; | ||
|
||
class ExchangePageStack extends StatefulWidget { | ||
final List<Widget> list; | ||
|
||
ExchangePageStack(this.list); | ||
|
||
@override | ||
State<ExchangePageStack> createState() => _ExchangePageStackState(); | ||
} | ||
|
||
class _ExchangePageStackState extends State<ExchangePageStack> { | ||
int _selectedIndex = 0; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
} | ||
|
||
void _onItemTapped(int index) { | ||
setState(() { | ||
_selectedIndex = index; | ||
}); | ||
} | ||
|
||
var scaffoldKey = GlobalKey<ScaffoldState>(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
backgroundColor: BACKGROUND, | ||
key: scaffoldKey, | ||
drawerEnableOpenDragGesture: false, | ||
appBar: AppBar( | ||
automaticallyImplyLeading: false, | ||
elevation: 0, | ||
backgroundColor: BACKGROUND, | ||
toolbarHeight: 90, | ||
title: Stack(alignment: AlignmentDirectional.centerEnd, children: [ | ||
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ | ||
Row( | ||
children: [ | ||
Container( | ||
padding: EdgeInsets.only( | ||
left: 5, | ||
), | ||
child: Image( | ||
image: AssetImage("assets/images/vidar.png"), | ||
height: 25, | ||
), | ||
), | ||
Container( | ||
padding: EdgeInsets.only( | ||
left: 5, | ||
), | ||
child: Text( | ||
'VID', | ||
style: TextStyle(color: Colors.black), | ||
), | ||
), | ||
], | ||
), | ||
StreamBuilder<BigInt>( | ||
//initialData: 0.0, | ||
stream: checkBalance(), | ||
builder: (context, snapshot) { | ||
switch (snapshot.connectionState) { | ||
case ConnectionState.waiting: | ||
return Container( | ||
width: 20, | ||
height: 20, | ||
child: CircularProgressIndicator( | ||
strokeWidth: 2, | ||
color: PRIMARY_LIGHT, | ||
)); | ||
default: | ||
if (snapshot.hasError) { | ||
return Text(snapshot.error.toString()); | ||
} else { | ||
final balance = snapshot.data.toString(); | ||
|
||
return Text(balance, | ||
style: TextStyle(color: PRIMARY_DARK, fontSize: 16)); | ||
} | ||
} | ||
}, | ||
), | ||
]), | ||
]), | ||
centerTitle: true, | ||
), | ||
bottomNavigationBar: BottomNavigationBar( | ||
selectedItemColor: PRIMARY, | ||
unselectedItemColor: SECONDARY, | ||
items: <BottomNavigationBarItem>[ | ||
BottomNavigationBarItem( | ||
icon: Container(), | ||
label: 'Send', | ||
), | ||
BottomNavigationBarItem( | ||
icon: Container(), | ||
label: 'Recieve'.tr() | ||
), | ||
], | ||
currentIndex: _selectedIndex, | ||
onTap: _onItemTapped, | ||
), | ||
body: IndexedStack( | ||
index: _selectedIndex, | ||
children: widget.list, | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.