wd portal init
This commit is contained in:
@@ -41,12 +41,16 @@ class DataManager{
|
|||||||
while(true){
|
while(true){
|
||||||
await Future.delayed(const Duration(minutes: 1));
|
await Future.delayed(const Duration(minutes: 1));
|
||||||
|
|
||||||
|
await GrabOnce();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> GrabOnce() async{
|
||||||
await GetSettings();
|
await GetSettings();
|
||||||
await GetGames();
|
await GetGames();
|
||||||
await GetChallenges();
|
await GetChallenges();
|
||||||
CalculateEarnings();
|
CalculateEarnings();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static Future<void> GetGamesProgress() async{
|
static Future<void> GetGamesProgress() async{
|
||||||
FilterLinkedGames();
|
FilterLinkedGames();
|
||||||
@@ -104,6 +108,20 @@ class DataManager{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static double MinWdAmount(){
|
||||||
|
return double.parse(GetSettingById("min_wd_amount"));
|
||||||
|
}
|
||||||
|
|
||||||
|
static String GetSettingById(String id){
|
||||||
|
String val = "";
|
||||||
|
Settings.forEach((key, value) {
|
||||||
|
if(key == id){
|
||||||
|
val = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
static Future<bool>GetGames() async{
|
static Future<bool>GetGames() async{
|
||||||
try {
|
try {
|
||||||
var response = (await http.post(Uri.parse('${API_ENDPOINT}get_games.php')));
|
var response = (await http.post(Uri.parse('${API_ENDPOINT}get_games.php')));
|
||||||
@@ -229,5 +247,19 @@ class DataManager{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<String> SetWdAddress(String newAddress) async{
|
||||||
|
String prevAddress = UserJson['wd_address'] ?? "";
|
||||||
|
Map<String,String> body = <String, String>{
|
||||||
|
"id": UserJson['id'],
|
||||||
|
"newAddress" : newAddress
|
||||||
|
};
|
||||||
|
var response = (await http.post(
|
||||||
|
Uri.parse('${API_ENDPOINT}set_wd_address.php'),
|
||||||
|
body: body));
|
||||||
|
Debug.Log("Set WD Address response: " +response.body.toString());
|
||||||
|
UserJson['wd_address'] =(response.body.toString() == newAddress) ? newAddress : prevAddress;
|
||||||
|
|
||||||
|
return (response.body.toString());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -20,9 +20,9 @@ class Dialogs{
|
|||||||
// set up the AlertDialog
|
// set up the AlertDialog
|
||||||
AlertDialog alert = AlertDialog(
|
AlertDialog alert = AlertDialog(
|
||||||
backgroundColor: Color(0xFF1F1F1F),
|
backgroundColor: Color(0xFF1F1F1F),
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
|
||||||
title: Text(title),
|
title: Text(title,textAlign: TextAlign.center,),
|
||||||
content: Text(message),
|
content: Text(message,textAlign: TextAlign.center,),
|
||||||
actions: [
|
actions: [
|
||||||
okButton,
|
okButton,
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -11,13 +11,41 @@ class GameInfoPage extends StatefulWidget {
|
|||||||
State<GameInfoPage> createState() => _GameInfoPageState();
|
State<GameInfoPage> createState() => _GameInfoPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _GameInfoPageState extends State<GameInfoPage> {
|
class _GameInfoPageState extends State<GameInfoPage> with WidgetsBindingObserver {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
// TODO: implement initState
|
// TODO: implement initState
|
||||||
super.initState();
|
super.initState();
|
||||||
kickstartAnimations();
|
kickstartAnimations();
|
||||||
|
|
||||||
|
WidgetsBinding.instance.addObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
// TODO: implement dispose
|
||||||
|
super.dispose();
|
||||||
|
|
||||||
|
WidgetsBinding.instance.removeObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
|
// TODO: implement didChangeAppLifecycleState
|
||||||
|
super.didChangeAppLifecycleState(state);
|
||||||
|
|
||||||
|
if(state == AppLifecycleState.resumed){
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Refresh() async{
|
||||||
|
await DataManager.GrabOnce();
|
||||||
|
setState(() {
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void kickstartAnimations() async {
|
void kickstartAnimations() async {
|
||||||
|
|||||||
103
lib/home.dart
103
lib/home.dart
@@ -4,6 +4,7 @@ import 'package:fhub/backend/DebugHelper.dart';
|
|||||||
import 'package:fhub/backend/Dialogs.dart';
|
import 'package:fhub/backend/Dialogs.dart';
|
||||||
import 'package:fhub/gameInfo.dart';
|
import 'package:fhub/gameInfo.dart';
|
||||||
import 'package:fhub/src/CustomWidgets.dart';
|
import 'package:fhub/src/CustomWidgets.dart';
|
||||||
|
import 'package:fhub/wd_portal.dart';
|
||||||
import 'package:fhub/welcome.dart';
|
import 'package:fhub/welcome.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
@@ -19,14 +20,46 @@ class Home extends StatefulWidget {
|
|||||||
State<Home> createState() => _HomeState();
|
State<Home> createState() => _HomeState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _HomeState extends State<Home> {
|
class _HomeState extends State<Home> with WidgetsBindingObserver {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
// TODO: implement initState
|
// TODO: implement initState
|
||||||
super.initState();
|
super.initState();
|
||||||
kickstartAnimations();
|
kickstartAnimations();
|
||||||
|
|
||||||
|
TxtCoinbaseAddress.text = DataManager.UserJson['wd_address'] ?? "";
|
||||||
|
|
||||||
|
WidgetsBinding.instance.addObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
// TODO: implement dispose
|
||||||
|
super.dispose();
|
||||||
|
|
||||||
|
WidgetsBinding.instance.removeObserver(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
|
// TODO: implement didChangeAppLifecycleState
|
||||||
|
super.didChangeAppLifecycleState(state);
|
||||||
|
// Debug.Log(state);
|
||||||
|
|
||||||
|
if(state == AppLifecycleState.resumed){
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Refresh()async{
|
||||||
|
await DataManager.GrabOnce();
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void kickstartAnimations() async {
|
void kickstartAnimations() async {
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
@@ -338,7 +371,46 @@ class _HomeState extends State<Home> {
|
|||||||
Widget wallet() {
|
Widget wallet() {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
TotalEarningsCard(),
|
GlassCard(
|
||||||
|
child: Container(
|
||||||
|
// height: screenHeight * 0.18,
|
||||||
|
width: screenWidth * 0.9,
|
||||||
|
padding: EdgeInsets.all(20),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Text("Earnings"),
|
||||||
|
SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
|
Text('~ \$${DataManager.currentEarnings.toStringAsFixed(2)} ',
|
||||||
|
style: TextStyle(fontSize: 50)),
|
||||||
|
|
||||||
|
SizedBox(height: 20,),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
|
children: [
|
||||||
|
GlassButton(onTap: (){
|
||||||
|
if(DataManager.currentEarnings <= 1){
|
||||||
|
Dialogs.showAlertDialog(context, "Not Enough To Withdraw", "You need atleast \$1 to initiate a withdraw.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!DataManager.UserJson['wd_address'].toString().contains("@")){
|
||||||
|
Dialogs.showAlertDialog(context, "Invalid Withdrawal Address", "Please enter a valid email address for coinbase address. Your earnings will be sent to that address via coinbase");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Navigator.of(context).push(MaterialPageRoute(
|
||||||
|
builder: (BuildContext context) =>
|
||||||
|
WithdrawalPortal()));
|
||||||
|
}, child: Text("Withdraw"),height: 40, width: 200, color: Colors.greenAccent),
|
||||||
|
GlassButton(onTap: (){}, child: Icon(Icons.history), width: 60, height: 40)
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
(DataManager.currentEarnings <=0) ? Container() : Column(children: [
|
(DataManager.currentEarnings <=0) ? Container() : Column(children: [
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 30,
|
height: 30,
|
||||||
@@ -367,7 +439,7 @@ class _HomeState extends State<Home> {
|
|||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.symmetric(
|
padding: EdgeInsets.symmetric(
|
||||||
vertical: 8, horizontal: 20),
|
vertical: 8, horizontal: 20),
|
||||||
child: Text("Games"),
|
child: Text("Game"),
|
||||||
))),
|
))),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: 5,
|
width: 5,
|
||||||
@@ -383,7 +455,7 @@ class _HomeState extends State<Home> {
|
|||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.symmetric(
|
padding: EdgeInsets.symmetric(
|
||||||
vertical: 8, horizontal: 20),
|
vertical: 8, horizontal: 20),
|
||||||
child: Text("Earnings"),
|
child: Text("Crypto"),
|
||||||
))),
|
))),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -502,10 +574,11 @@ class _HomeState extends State<Home> {
|
|||||||
}
|
}
|
||||||
TextEditingController TxtCoinbaseAddress = TextEditingController();
|
TextEditingController TxtCoinbaseAddress = TextEditingController();
|
||||||
Widget settings() {
|
Widget settings() {
|
||||||
TxtCoinbaseAddress.text = "sewmina7@gmail.com";
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
GlassCard(child: Padding(padding: EdgeInsets.all(15), child: Column(
|
GlassCard(child: AnimatedSize(
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
child: Padding(padding: EdgeInsets.all(15), child: Column(
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
@@ -514,9 +587,23 @@ class _HomeState extends State<Home> {
|
|||||||
InkWell(onTap: (){Dialogs.showAlertDialog(context, "Coinbase Address", "Withdrawals will be accounted to this address");},child: Icon(Icons.help))
|
InkWell(onTap: (){Dialogs.showAlertDialog(context, "Coinbase Address", "Withdrawals will be accounted to this address");},child: Icon(Icons.help))
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
TextField(controller: TxtCoinbaseAddress,)
|
TextField(controller: TxtCoinbaseAddress, onChanged: (e){setState(() {
|
||||||
|
|
||||||
|
});},),
|
||||||
|
(TxtCoinbaseAddress.text != (DataManager.UserJson['wd_address'] ?? "") )? Container(padding: EdgeInsets.all(10), child: GlassButton(onTap: () async{
|
||||||
|
String response = await DataManager.SetWdAddress(TxtCoinbaseAddress.text);
|
||||||
|
bool success = response == TxtCoinbaseAddress.text;
|
||||||
|
// DataManager.UserJson['wd_address'] = TxtCoinbaseAddress.text;
|
||||||
|
if(!success){
|
||||||
|
Dialogs.showAlertDialog(context, "Error saving Coinbase Address", response);
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
|
||||||
|
});
|
||||||
|
}, child: Text("Save"), width: 250),) : Container()
|
||||||
],
|
],
|
||||||
),)),
|
),),
|
||||||
|
)),
|
||||||
SizedBox(height: 10,),
|
SizedBox(height: 10,),
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: ()async{
|
onTap: ()async{
|
||||||
|
|||||||
@@ -221,7 +221,7 @@ Widget GlassButton({Color color = Colors.white,double height = 30,required Funct
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget GlassCard({bool highlighted = false,required Widget child}) {
|
Widget GlassCard({bool highlighted = false,Color color = Colors.white,required Widget child}) {
|
||||||
return Container(
|
return Container(
|
||||||
// padding: EdgeInsets.all(30),
|
// padding: EdgeInsets.all(30),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@@ -229,8 +229,8 @@ Widget GlassCard({bool highlighted = false,required Widget child}) {
|
|||||||
begin: Alignment.topLeft,
|
begin: Alignment.topLeft,
|
||||||
end: Alignment.bottomCenter,
|
end: Alignment.bottomCenter,
|
||||||
colors: [
|
colors: [
|
||||||
Colors.white.withOpacity(highlighted ? 0.4 : 0.12),
|
color.withOpacity(highlighted ? 0.4 : 0.12),
|
||||||
Colors.white.withOpacity(highlighted? 0.15:0.05),
|
color.withOpacity(highlighted? 0.15:0.05),
|
||||||
]),
|
]),
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
|
||||||
|
|||||||
167
lib/wd_portal.dart
Normal file
167
lib/wd_portal.dart
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
import 'package:fhub/backend/DataManager.dart';
|
||||||
|
import 'package:fhub/backend/DebugHelper.dart';
|
||||||
|
import 'package:fhub/backend/Dialogs.dart';
|
||||||
|
import 'package:fhub/backend/helpers.dart';
|
||||||
|
import 'package:fhub/src/CustomWidgets.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class WithdrawalPortal extends StatefulWidget {
|
||||||
|
const WithdrawalPortal({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<WithdrawalPortal> createState() => _WithdrawalPortalState();
|
||||||
|
}
|
||||||
|
ScrollController scrollController = ScrollController();
|
||||||
|
class _WithdrawalPortalState extends State<WithdrawalPortal> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
// TODO: implement initState
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
kickstartAnimations();
|
||||||
|
}
|
||||||
|
|
||||||
|
void kickstartAnimations() async {
|
||||||
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
op1 = 0.5;
|
||||||
|
op2 = 0.5;
|
||||||
|
op3 = 0.5;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: Colors.black,
|
||||||
|
body: CustomBody(
|
||||||
|
child: SafeArea(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.max,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Column(children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
InkWell(
|
||||||
|
child: Container(
|
||||||
|
margin: EdgeInsets.all(10),
|
||||||
|
child: Icon(Icons.keyboard_arrow_left, size: 50)),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
GradientText(
|
||||||
|
text: "Withdrawal Portal",
|
||||||
|
gradient: LinearGradient(colors: [
|
||||||
|
Colors.white.withOpacity(0.6),
|
||||||
|
Colors.white.withOpacity(0.5),
|
||||||
|
Colors.white.withOpacity(0.2)
|
||||||
|
]),
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 29, fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
width: 40,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 50,
|
||||||
|
),
|
||||||
|
GlassCard(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(12.0),
|
||||||
|
child: AnimatedSize(
|
||||||
|
duration: const Duration(milliseconds: 100),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Text("Select Cryptos to Withdraw"),
|
||||||
|
SizedBox(height: 20,),
|
||||||
|
ListView.builder(
|
||||||
|
shrinkWrap: true,
|
||||||
|
controller: scrollController,
|
||||||
|
itemCount: DataManager.CryptoEarnings.length,
|
||||||
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
return WalletCurrencyListItem(
|
||||||
|
DataManager.CryptoEarnings.keys.elementAt(index));
|
||||||
|
},
|
||||||
|
),
|
||||||
|
SizedBox(height: 10,),
|
||||||
|
(selectedCurrencies.length > 0) ? Text("Selected ${selectedCurrencies.length} currencies to withdraw") : Container()
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
]),
|
||||||
|
GlassButton(onTap: (){
|
||||||
|
|
||||||
|
}, child: Text("Withdraw"), width: 300,height: 50,color: selectedCurrencies.length > 0 ? Colors.greenAccent: Colors.blueGrey)
|
||||||
|
],
|
||||||
|
))),
|
||||||
|
context: context,
|
||||||
|
onAnimEnd: () {
|
||||||
|
kickstartAnimations();
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> selectedCurrencies = [];
|
||||||
|
|
||||||
|
Widget WalletCurrencyListItem(String coin) {
|
||||||
|
double amount = Helpers.SatsToCoin(DataManager.CryptoEarnings[coin] ?? 0);
|
||||||
|
double amountDollars = Helpers.CryptoToDollars(amount: amount, Crypto: coin);
|
||||||
|
return InkWell(
|
||||||
|
onTap: (){
|
||||||
|
if(amountDollars < 1){
|
||||||
|
Dialogs.showAlertDialog(context, "Not Enough to Withdraw", "You need to reach the minimum withdrawal amount of\n\$1\nto Withdraw");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(selectedCurrencies.contains(coin)){
|
||||||
|
selectedCurrencies.remove(coin);
|
||||||
|
}else{
|
||||||
|
selectedCurrencies.add(coin);
|
||||||
|
}
|
||||||
|
Debug.Log(selectedCurrencies);
|
||||||
|
setState(() {
|
||||||
|
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(3.0),
|
||||||
|
child: GlassCard(
|
||||||
|
color: selectedCurrencies.contains(coin) ? Colors.blue : Colors.white,
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(10.0),
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 10),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
children: [SizedBox(width: 100, child: Text(coin))],
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
"~\$${amountDollars.toStringAsFixed(2)}"),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Text("${amount.toStringAsFixed(8)}"),
|
||||||
|
SizedBox(
|
||||||
|
width: 5,
|
||||||
|
),
|
||||||
|
Icon(Helpers.GetIconForCrypto(coin))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user