wd portal done, closes #5

This commit is contained in:
Sewmina Dilshan 2023-07-07 12:42:16 +05:30
parent 21d543ca1c
commit 6b7fe0af5d
4 changed files with 131 additions and 6 deletions

View File

@ -180,7 +180,7 @@ class DataManager{
static void CalculateEarnings() async{ static Future<void> CalculateEarnings() async{
Debug.Log("Going to calculate earnings from games"); Debug.Log("Going to calculate earnings from games");
while(UserJson == null){ while(UserJson == null){
await Future.delayed(const Duration(seconds: 1)); await Future.delayed(const Duration(seconds: 1));
@ -262,6 +262,27 @@ class DataManager{
return (response.body.toString()); return (response.body.toString());
} }
static Future<bool> RequestWd(String coin) async{
Map<String,String> body = <String, String>{
"id": UserJson['id'],
"username" : UserJson['name'],
"coin": coin
};
var response = (await http.post(
Uri.parse('${API_ENDPOINT}request_wd.php'),
body: body));
Debug.Log("Request WD response: " +response.body.toString());
if(response.body.toString().contains("{")){
UserJson['earnings'] =(response.body.toString());
await CalculateEarnings();
return true;
}else{
return false;
}
}
static Future<List<dynamic>> GetWithdrawalHistory() async{ static Future<List<dynamic>> GetWithdrawalHistory() async{
Map<String,String> body = <String, String>{ Map<String,String> body = <String, String>{

View File

@ -82,6 +82,7 @@ class LoginManager {
try{ try{
DataManager.UserJson = jsonDecode(loginResponse.body.toString()); DataManager.UserJson = jsonDecode(loginResponse.body.toString());
await DataManager.GetGamesProgress(); await DataManager.GetGamesProgress();
await DataManager.CalculateEarnings();
Debug.LogResponse(DataManager.UserJson); Debug.LogResponse(DataManager.UserJson);
prefs.setString("username", username); prefs.setString("username", username);
prefs.setString("password", password); prefs.setString("password", password);

View File

@ -401,9 +401,7 @@ class _HomeState extends State<Home> with WidgetsBindingObserver {
return; return;
} }
Navigator.of(context).push(MaterialPageRoute( Navigator.of(context).push(wdRoute);
builder: (BuildContext context) =>
WithdrawalPortal()));
}, child: Text("Withdraw"),height: 40, width: 200, color: Colors.greenAccent), }, child: Text("Withdraw"),height: 40, width: 200, color: Colors.greenAccent),
GlassButton(onTap: (){ GlassButton(onTap: (){
Navigator.of(context).push(MaterialPageRoute( Navigator.of(context).push(MaterialPageRoute(

View File

@ -4,7 +4,8 @@ import 'package:fhub/backend/Dialogs.dart';
import 'package:fhub/backend/helpers.dart'; import 'package:fhub/backend/helpers.dart';
import 'package:fhub/src/CustomWidgets.dart'; import 'package:fhub/src/CustomWidgets.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
var wdRoute = MaterialPageRoute(builder: (context) => WithdrawalPortal());
class WithdrawalPortal extends StatefulWidget { class WithdrawalPortal extends StatefulWidget {
const WithdrawalPortal({Key? key}) : super(key: key); const WithdrawalPortal({Key? key}) : super(key: key);
@ -100,7 +101,10 @@ class _WithdrawalPortalState extends State<WithdrawalPortal> {
) )
]), ]),
GlassButton(onTap: (){ GlassButton(onTap: (){
if(selectedCurrencies.length > 0){
ShowConfirmationDialog();}else{
Dialogs.showAlertDialog(context, "No Cryptos Selected", "Please select desired cryptos first to withdraw");
}
}, child: Text("Withdraw"), width: 300,height: 50,color: selectedCurrencies.length > 0 ? Colors.greenAccent: Colors.blueGrey) }, child: Text("Withdraw"), width: 300,height: 50,color: selectedCurrencies.length > 0 ? Colors.greenAccent: Colors.blueGrey)
], ],
))), ))),
@ -111,6 +115,107 @@ class _WithdrawalPortalState extends State<WithdrawalPortal> {
); );
} }
void ShowConfirmationDialog(){
// set up the AlertDialog
AlertDialog alert = AlertDialog(
backgroundColor: Color(0xFF1F1F1F),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
title: Text("Are you Sure?",textAlign: TextAlign.center,),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text("You are about to Withdraw ${selectedCurrenciesTxt()} to ${DataManager.UserJson['wd_address']} Coinbase account.\n",textAlign: TextAlign.center,),
Text("Warning: Make sure the address is correct and a valid coinbase account. This transaction is non-reversible.\n\n",style:TextStyle(color: Colors.orange)),
Text("Press 'Confirm' To Initiate the Withdrawal",style: TextStyle(fontWeight: FontWeight.bold),textAlign: TextAlign.center,)
],
),
actions: withdrawing ? [Text("Processing...",style: TextStyle(color: Colors.deepPurpleAccent),)] : [
TextButton(
onPressed: Confirmed,
child: Text("Confirm"),
),
TextButton(
child: Text("Cancel"),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
// show the dialog
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
bool withdrawing = false;
void Confirmed() async{
Navigator.of(context).pop();
ShowProcessingDialog();
// await Future.delayed(const Duration(seconds: 2));
bool success =false;
for(int i=0; i < selectedCurrencies.length; i++){
success = await DataManager.RequestWd(selectedCurrencies[i]);
}
Navigator.of(context).pop();
if(success) {
Dialogs.showAlertDialog(context, "Withdrawal Success",
"Your Withdrawal is now processing. Cryptos will be in your coinbase account within 5 business days.\n\nEnjoy!");
}else{
Dialogs.showAlertDialog(context, "Failed", "Something went wrong with your withdrawal. Please contact faucethub@playpoolstudios.com for support");
}
Navigator.of(context).removeRoute(wdRoute);
setState(() {
});
}
void ShowProcessingDialog(){
AlertDialog alert = AlertDialog(
backgroundColor: Color(0xFF1F1F1F),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SpinKitCircle(color: Colors.deepPurpleAccent,),
SizedBox(width: 50,),
Text("Processing",),
],
),
);
showDialog(context: context, builder: (BuildContext context){
return alert;
},
barrierDismissible: false);
}
String selectedCurrenciesTxt(){
String out = "";
selectedCurrencies.forEach((element) {
if(out.length <= 0){
out+=element;
}else{
out+="," + element;
}
});
return out;
}
List<String> selectedCurrencies = []; List<String> selectedCurrencies = [];
Widget WalletCurrencyListItem(String coin) { Widget WalletCurrencyListItem(String coin) {