diff --git a/lib/Backend/Backend.dart b/lib/Backend/Backend.dart index b159f84..61937a6 100644 --- a/lib/Backend/Backend.dart +++ b/lib/Backend/Backend.dart @@ -4,13 +4,13 @@ import 'dart:math'; import 'package:http/http.dart' as http; import 'package:mhunt_launcher/Backend/Structures.dart'; +import 'package:mhunt_launcher/Shared/Helpers.dart'; import 'package:path_provider/path_provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'DebugHelper.dart'; class Backend { - static const String API_ENDPOINT = "https://vps.playpoolstudios.com/metahunt/api/launcher/"; - static const String SOLOGIN_ENDPOINT = "http://vps.playpoolstudios.com:20017/"; + static const String API_ENDPOINT = Helpers.WEB2_ENDPOINT; static List Games = [ GameData(0, "mhunt", "Metahunt", "High-Stake Battle Royale game with Play to earn abilities", "images/mhunt_thumbnail.png", true, "METAHUNT.exe"), @@ -23,6 +23,8 @@ class Backend { static String displayName = ""; static String walletAddress = ""; static String pubKey = ""; + static int SolBalance =0; + static int TicketsBalance = 0; static Map UserJson = {'username': 'test', 'passwd': 'test123'}; @@ -38,6 +40,8 @@ class Backend { } try { Username = username; + displayName = username; + SetUsernamePassword(username, password); return true; @@ -78,11 +82,32 @@ class Backend { } static Future GetPubkey() async{ - var response = await http.get(Uri.parse('${SOLOGIN_ENDPOINT}getPubkey?email=${Username}')); + String url ='${API_ENDPOINT}get_wallet.php?username=${Username}'; + var response = await http.get(Uri.parse(url)); + Debug.LogResponse(response.body.toString(), src: url); pubKey = jsonDecode(response.body.toString())["pub_key"]; return pubKey; } + static Future GetWalletBalance() async{ + SolBalance = await GetSolBalance(); + TicketsBalance = await GetTicketsBalance(); + } + + static Future GetSolBalance() async{ + String url ='${API_ENDPOINT}get_wallet_balance.php?wallet=${pubKey}'; + var response = await http.get(Uri.parse(url)); + Debug.LogResponse(response.body.toString(), src: url); + return jsonDecode(response.body.toString())["balance"]; + } + + static Future GetTicketsBalance() async{ + String url ='${API_ENDPOINT}get_tickets_balance.php?wallet=${pubKey}'; + var response = await http.get(Uri.parse(url)); + Debug.LogResponse(response.body.toString(), src: url); + return jsonDecode(response.body.toString())["balance"]; + } + static void SetUsernamePassword(String username, String passwd) { UserJson = {'username': username, 'passwd': passwd}; } diff --git a/lib/Shared/Dialogs.dart b/lib/Shared/Dialogs.dart index 5d9b5c4..4bbb664 100644 --- a/lib/Shared/Dialogs.dart +++ b/lib/Shared/Dialogs.dart @@ -36,4 +36,5 @@ class Dialogs{ }, ); } + } \ No newline at end of file diff --git a/lib/Shared/Helpers.dart b/lib/Shared/Helpers.dart new file mode 100644 index 0000000..524ad92 --- /dev/null +++ b/lib/Shared/Helpers.dart @@ -0,0 +1,10 @@ +class Helpers{ + static const int LAMPORTS_PER_SOL = 1000000000; + static const String DASHBOARD_URL = 'https://auth.playpoolstudios.com'; + static const String WEB2_ENDPOINT = "https://vps.playpoolstudios.com/metahunt/api/launcher/"; + + + static String trimTrailingZeros(double number) { + return number.toStringAsFixed(10).replaceAll(RegExp(r'0*$'), '').replaceAll(RegExp(r'\.$'), ''); + } +} \ No newline at end of file diff --git a/lib/Shared/TextStyles.dart b/lib/Shared/TextStyles.dart new file mode 100644 index 0000000..48b1579 --- /dev/null +++ b/lib/Shared/TextStyles.dart @@ -0,0 +1,11 @@ +import 'package:flutter/material.dart'; + +class TextStyles{ + + static TextStyle? titleTextStyle = const TextStyle(fontSize: 24, fontWeight: FontWeight.bold); + static TextStyle? title2BTextStyle = const TextStyle(fontSize: 20, fontWeight: FontWeight.bold); + static TextStyle? title2TextStyle = const TextStyle(fontSize: 20, fontWeight: FontWeight.normal); + + +} + diff --git a/lib/Widgets/Home/AccountsPage.dart b/lib/Widgets/Home/AccountsPage.dart deleted file mode 100644 index d32acaf..0000000 --- a/lib/Widgets/Home/AccountsPage.dart +++ /dev/null @@ -1,75 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:url_launcher/url_launcher_string.dart'; - -import '../../Backend/Backend.dart'; -import '../CustomWidgets.dart'; - -Widget AccountPage(){ - return Padding( - padding: const EdgeInsets.all(25.0), - child: Column( - children: [ - Row( - children: [ - Text("Hello, ${Backend.displayName}", style: TextStyle(fontSize: 30)), - ], - ), - SizedBox(height: 100,), - Text(Backend.pubKey), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Column( - children: [ - Text("Vault Credits",style: TextStyle(fontWeight: FontWeight.bold,fontSize: 15),), - Row( - children: [ - Image.asset('images/vault.png',width: 40,height: 40,), - Text(Backend.vault.php.toString(),style: TextStyle(fontSize: 50),), - ], - ) - ], - ), - SizedBox(width: 60,), - Column( - children: [ - Text("Pre-hunt Points",style: TextStyle(fontWeight: FontWeight.bold,fontSize: 15),), - Row( - children: [ - Image.asset('images/token.png',width: 40,height: 40,), - Text(Backend.vault.vc.toString(),style: TextStyle(fontSize: 50),), - ], - ) - ], - ), - ], - ), - // Text("Your wallet address is "), - // Row( - // mainAxisAlignment: MainAxisAlignment.center, - // children: [ - // Text(Backend.walletAddress, style: TextStyle(fontSize: 25),), - // InkWell(child: Padding( - // padding: const EdgeInsets.all(16.0), - // child: Icon(Icons.copy), - // ), onTap: (){ - // //Copy wallet - // },) - // ], - // ), - SizedBox(height: 50,), - GlassButton(onTap: (){ - launchUrlString('https://auth.playpoolstudios.com'); - }, child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text("Open Dashboard"), - SizedBox(width: 10,), - Icon(Icons.open_in_new, color: Colors.grey) - ], - ), width: 250, height: 50) - - ], - ), - ); -} diff --git a/lib/Widgets/Home/AccountsPage/AccountsPage.dart b/lib/Widgets/Home/AccountsPage/AccountsPage.dart new file mode 100644 index 0000000..b7fbbac --- /dev/null +++ b/lib/Widgets/Home/AccountsPage/AccountsPage.dart @@ -0,0 +1,167 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:mhunt_launcher/Shared/Helpers.dart'; +import 'package:mhunt_launcher/Shared/TextStyles.dart'; +import 'package:toastification/toastification.dart'; +import 'package:url_launcher/url_launcher_string.dart'; + +import '../../../Backend/Backend.dart'; +import '../../CustomWidgets.dart'; +import 'BuyDialog.dart'; + +Widget AccountPage(BuildContext context, Function onUpdate) { + return Padding( + padding: const EdgeInsets.all(25.0), + child: Column( + children: [ + Row( + children: [ + Text("Hello, ${Backend.displayName}", + style: TextStyle(fontSize: 30)), + ], + ), + SizedBox( + height: 100, + ), + GlassCard( + child: Container( + padding: const EdgeInsets.all(12.0), + margin: const EdgeInsets.symmetric(horizontal: 50), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Column( + children: [ + Text("Solana Wallet Address", style: TextStyles.title2BTextStyle,), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text(Backend.pubKey), + InkWell( + onTap: ()async { + await Clipboard.setData(ClipboardData(text: Backend.pubKey)); + toastification.show( + context: context, // optional if you use ToastificationWrapper + title: Text('Wallet address copied to clipboard'), + autoCloseDuration: const Duration(seconds: 2), + style: ToastificationStyle.simple, + ); + }, + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 10), + child: Icon(Icons.copy), + ), + ) + ], + ), + ], + ), + SizedBox(width: 50,), + Row( + children: [ + Column( + children: [ + Text("SOL Balance", style: TextStyles.title2BTextStyle,), + + Text('${Helpers.trimTrailingZeros(Backend.SolBalance / Helpers.LAMPORTS_PER_SOL).toString()} SOL') + ], + ), + InkWell( + onTap: ()async{ + await Backend.GetWalletBalance(); + onUpdate(); + }, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Icon(Icons.refresh), + ), + ) + ], + ) + ], + ), + ), + ), + SizedBox( + height: 20, + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Column( + children: [ + Text( + "Vault Credits", + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15), + ), + Row( + children: [ + Image.asset( + 'images/vault.png', + width: 40, + height: 40, + ), + Text( + Backend.vault.php.toString(), + style: TextStyle(fontSize: 50), + ), + ], + ) + ], + ), + SizedBox( + width: 60, + ), + Column( + children: [ + Text( + "Tickets", + style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15), + ), + Row( + children: [ + Icon( + Icons.airplane_ticket_rounded, + color: Colors.amber, + size: 35, + ), + Text( + Backend.TicketsBalance.toString(), + style: TextStyle(fontSize: 50), + ), + ], + ), + GlassButton( + onTap: () { + Navigator.of(context).restorablePush(buyTicketsDialogBuilder); + }, child: Text("Buy Tickets"), width: 100) + ], + ), + ], + ), + SizedBox( + height: 50, + ), + GlassButton( + onTap: () { + launchUrlString(Helpers.DASHBOARD_URL); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text("Open Dashboard"), + SizedBox( + width: 10, + ), + Icon(Icons.open_in_new, color: Colors.grey) + ], + ), + width: 250, + height: 50) + ], + ), + ); +} + + + diff --git a/lib/Widgets/Home/AccountsPage/BuyDialog.dart b/lib/Widgets/Home/AccountsPage/BuyDialog.dart new file mode 100644 index 0000000..dabd3b8 --- /dev/null +++ b/lib/Widgets/Home/AccountsPage/BuyDialog.dart @@ -0,0 +1,85 @@ +import 'package:flutter/material.dart'; + +Route buyTicketsDialogBuilder(BuildContext context, Object? arguments) { + return DialogRoute( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('How many Tickets?'), + content: PurchaseTicketsContent(), + actions: [ + TextButton( + style: TextButton.styleFrom( + textStyle: Theme.of(context).textTheme.labelLarge, + ), + child: const Text('Purchase',style: TextStyle(color: Colors.green),), + onPressed: () { + // Handle the purchase with the selected ticketCount + Navigator.of(context).pop(); + }, + ), + TextButton( + style: TextButton.styleFrom( + textStyle: Theme.of(context).textTheme.labelLarge, + ), + child: const Text('Cancel'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); +} + + +class PurchaseTicketsContent extends StatefulWidget { + const PurchaseTicketsContent({super.key}); + + @override + State createState() => _PurchaseTicketsContentState(); +} +int ticketCount = 1; +class _PurchaseTicketsContentState extends State { + @override + Widget build(BuildContext context) { + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + 'Select an amount of Tickets you want to purchase', + ), + SizedBox(height: 20,), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + InkWell( + onTap: () { + setState(() { + if (ticketCount > 1) ticketCount--; + }); + }, + child: Icon(Icons.remove_circle), + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: Text( + '$ticketCount', + style: TextStyle(fontSize: 40), + ), + ), + InkWell( + onTap: () { + setState(() { + ticketCount++; + }); + }, + child: Icon(Icons.add_circle_rounded), + ), + ], + ) + ], + ); + } +} \ No newline at end of file diff --git a/lib/home.dart b/lib/home.dart index 84a0bed..499f763 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -20,7 +20,7 @@ import 'package:http/http.dart' as http; import 'Backend/FileHashEntry.dart'; import 'Backend/Structures.dart'; -import 'Widgets/Home/AccountsPage.dart'; +import 'Widgets/Home/AccountsPage/AccountsPage.dart'; import 'Widgets/Home/Dashboard.dart'; import 'Widgets/Home/Downloads.dart'; import 'Widgets/Home/Library.dart'; @@ -138,7 +138,9 @@ class _HomePageState extends State { } ); }else if(selectedSidebarIndex == 3){ - content = AccountPage(); + content = AccountPage(context, (){setState(() { + + });}); } return Scaffold( diff --git a/lib/login.dart b/lib/login.dart index 1914edb..f03093c 100644 --- a/lib/login.dart +++ b/lib/login.dart @@ -292,6 +292,12 @@ class _LoginPageState extends State { width: 300, child: TextField( controller: gamertagController, + onChanged: (newVal){ + usernameExists=false; + setState(() { + + }); + }, )) ], mainAxisAlignment: MainAxisAlignment.center, @@ -341,6 +347,8 @@ class _LoginPageState extends State { setState(() { usernameExists=true; }); + + return; } String username = await Backend.GetNextGuestUsername(); diff --git a/pubspec.lock b/pubspec.lock index 742e367..ecaf8b8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -73,6 +73,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.8" + equatable: + dependency: transitive + description: + name: equatable + sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2 + url: "https://pub.dev" + source: hosted + version: "2.0.5" fake_async: dependency: transitive description: @@ -105,6 +113,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.3" + fixnum: + dependency: transitive + description: + name: fixnum + sha256: b6dc7065e46c974bc7c5f143080a6764ec7a4be6da1285ececdc37be96de53be + url: "https://pub.dev" + source: hosted + version: "1.1.1" flutter: dependency: "direct main" description: flutter @@ -152,6 +168,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.2" + iconsax_flutter: + dependency: transitive + description: + name: iconsax_flutter + sha256: "95b65699da8ea98f87c5d232f06b0debaaf1ec1332b697e4d90969ec9a93037d" + url: "https://pub.dev" + source: hosted + version: "1.0.0" leak_tracker: dependency: transitive description: @@ -280,6 +304,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.2.1" + pausable_timer: + dependency: transitive + description: + name: pausable_timer + sha256: "6ef1a95441ec3439de6fb63f39a011b67e693198e7dae14e20675c3c00e86074" + url: "https://pub.dev" + source: hosted + version: "3.1.0+3" platform: dependency: transitive description: @@ -381,6 +413,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.10.0" + sprintf: + dependency: transitive + description: + name: sprintf + sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23" + url: "https://pub.dev" + source: hosted + version: "7.0.0" stack_trace: dependency: transitive description: @@ -429,6 +469,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.0" + toastification: + dependency: "direct main" + description: + name: toastification + sha256: "4d97fbfa463dfe83691044cba9f37cb185a79bb9205cfecb655fa1f6be126a13" + url: "https://pub.dev" + source: hosted + version: "2.3.0" typed_data: dependency: transitive description: @@ -501,6 +549,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.1" + uuid: + dependency: transitive + description: + name: uuid + sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff + url: "https://pub.dev" + source: hosted + version: "4.5.1" vector_math: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index aeaaff3..a152fc5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -44,6 +44,7 @@ dependencies: background_downloader: ^8.5.2 url_launcher: ^6.2.6 flutter_spinkit: ^5.2.1 + toastification: ^2.3.0 dev_dependencies: flutter_test: