Seperate challenges
This commit is contained in:
parent
cb8d1bb74c
commit
5f052bd76a
|
|
@ -22,6 +22,9 @@ class Helpers{
|
|||
case "LTC":
|
||||
return CryptoFontIcons.LTC;
|
||||
break;
|
||||
case "BCH":
|
||||
return CryptoFontIcons.AUR;
|
||||
break;
|
||||
}
|
||||
|
||||
return CryptoFontIcons.BTC;
|
||||
|
|
@ -54,4 +57,18 @@ class Helpers{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
static double CryptoToDollars({required double amount, required String Crypto}){
|
||||
if(Hoarder.cryptoRates==null){Debug.Log("Crypto rates haven't been updated yet"); return 0;}
|
||||
Debug.Log(Hoarder.cryptoRates);
|
||||
if(Hoarder.cryptoRates[Crypto] == null){
|
||||
Debug.Log("$Crypto not found in ${Hoarder.cryptoRates}");
|
||||
return 0;
|
||||
}
|
||||
return amount * double.parse(Hoarder.cryptoRates[Crypto]);
|
||||
}
|
||||
|
||||
static double SatsToCoin(int sats){
|
||||
return sats.toDouble() * 0.00000001;
|
||||
}
|
||||
}
|
||||
|
|
@ -56,16 +56,22 @@ class Hoarder{
|
|||
FetchChallenges();
|
||||
}
|
||||
static double currentEarnings = 0;
|
||||
static double previousEarnings = 0;
|
||||
static Map<String, int> ThisSeasonGamesEarnings = {};
|
||||
static Map<String, int> ThisSeasonCryptoEarnings = {};
|
||||
|
||||
static dynamic cryptoRates;
|
||||
static Future<void> FetchChallenges() async {
|
||||
var response = null;
|
||||
|
||||
List<List<dynamic>> _Challenges = [];
|
||||
double _currentEarnings = 0;
|
||||
Map<String,int> _ThisSeasonGamesEarnings = {};
|
||||
Map<String, int> _ThisSeasonCryptoEarnings = {};
|
||||
|
||||
var cryptoValuesResponse = await http.get(Uri.parse('http://vps.playpoolstudios.com:2009/'));
|
||||
dynamic cryptoValues = jsonDecode(cryptoValuesResponse.body.toString());
|
||||
cryptoRates = cryptoValues;
|
||||
Debug.Log(cryptoValues);
|
||||
for (var value in Brain.LinkedGamesJson) {
|
||||
try {
|
||||
|
|
@ -91,6 +97,7 @@ class Hoarder{
|
|||
if(total <= current){
|
||||
_currentEarnings+= rewardInDollars;
|
||||
// Debug.Log(_ThisSeasonCryptoEarnings[GameJson['coin']]);
|
||||
_ThisSeasonGamesEarnings.update(GameJson['code'], (value) => value + reward, ifAbsent: ()=> reward);
|
||||
_ThisSeasonCryptoEarnings.update(GameJson['coin'], (value) => value + reward, ifAbsent: ()=> reward);
|
||||
// Debug.Log(_ThisSeasonCryptoEarnings[GameJson['coin']]);
|
||||
}
|
||||
|
|
@ -103,11 +110,12 @@ class Hoarder{
|
|||
Debug.LogError("Error while fetching challenges $e");
|
||||
}
|
||||
}
|
||||
ThisSeasonGamesEarnings = _ThisSeasonGamesEarnings;
|
||||
ThisSeasonCryptoEarnings = _ThisSeasonCryptoEarnings;
|
||||
Challenges = _Challenges;
|
||||
currentEarnings = _currentEarnings;
|
||||
|
||||
Debug.Log(ThisSeasonCryptoEarnings);
|
||||
Debug.Log(ThisSeasonGamesEarnings);
|
||||
|
||||
// Debug.Log(Challenges);
|
||||
// Debug.Log("Challenge, " + (Hoarder.Challenges[0][0]['game']));
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class _HomePageState extends State<HomePage> {
|
|||
await Hoarder.FetchChallenges();
|
||||
|
||||
DateTime now = DateTime.now();
|
||||
DateTime nextMonth = DateTime(now.year, now.month);
|
||||
DateTime nextMonth = DateTime(now.year, (now.month < 12) ? now.month +1 : 1);
|
||||
|
||||
daysLeft = "${nextMonth.difference(now).inDays} Days Remaining";
|
||||
setState(() {});
|
||||
|
|
@ -52,7 +52,6 @@ class _HomePageState extends State<HomePage> {
|
|||
void dispose() {
|
||||
// TODO: implement dispose
|
||||
super.dispose();
|
||||
|
||||
looping = false;
|
||||
}
|
||||
|
||||
|
|
@ -131,7 +130,7 @@ class _HomePageState extends State<HomePage> {
|
|||
// ),
|
||||
// title: "Earnings"),
|
||||
HomeCard(
|
||||
title: "Seasonal Challenges $daysLeft",
|
||||
title: "Ongoing Challenges",
|
||||
child: Container(
|
||||
child: Column(
|
||||
children: [
|
||||
|
|
@ -286,7 +285,8 @@ class _HomePageState extends State<HomePage> {
|
|||
value: current / total,
|
||||
color: Colors.green,
|
||||
)),
|
||||
SizedBox(
|
||||
SizedBox(width: 15,),
|
||||
(total <= current) ? SizedBox(height: 30,width: 70 ,child: MaterialButton(onPressed: (){}, child: Text("Claim"),color: Colors.green,)): SizedBox(
|
||||
width: 60,
|
||||
child: Text("$current / $total $prefix",
|
||||
textAlign: TextAlign.end,
|
||||
|
|
@ -398,25 +398,6 @@ class _HomePageState extends State<HomePage> {
|
|||
context,
|
||||
MaterialPageRoute(builder: (context) => GamePage(code)),
|
||||
);
|
||||
|
||||
// showLinkGameDialog(context, Brain.NonLinkedGamesJson[index]);
|
||||
// try {
|
||||
// ///checks if the app is installed on your mobile device
|
||||
// String id = Brain.NonLinkedGamesJson[index]['link'];
|
||||
// Debug.Log(id);
|
||||
// bool isInstalled = await DeviceApps.isAppInstalled(id);
|
||||
// if (isInstalled) {
|
||||
// DeviceApps.openApp(id);
|
||||
// } else {
|
||||
// ///if the app is not installed it lunches google play store so you can install it from there
|
||||
// // launchUrl(Uri(path: "market://details?id=" +Brain.NonLinkedGamesJson[index]['link']),mode: LaunchMode.externalApplication,);
|
||||
// // try{launch("market://details?id=" +Brain.NonLinkedGamesJson[index]['link']);}catch(e){
|
||||
// launch("https://play.google.com/store/apps/details?id=$id");
|
||||
// // }
|
||||
// }
|
||||
// } catch (e) {
|
||||
// print(e);
|
||||
// }
|
||||
},
|
||||
child: ListTile(
|
||||
leading: ClipRRect(
|
||||
|
|
@ -458,7 +439,7 @@ class _HomePageState extends State<HomePage> {
|
|||
size: 60,
|
||||
),
|
||||
title: Text(Brain.Username),
|
||||
subtitle: Text("Total Earnings : \$42.69"),
|
||||
subtitle: Text("Total Earnings : \$${(Hoarder.previousEarnings + Hoarder.currentEarnings).toStringAsFixed(2)}"),
|
||||
trailing: IconButton(
|
||||
icon: Icon(Icons.settings),
|
||||
onPressed: () {
|
||||
|
|
@ -484,10 +465,6 @@ class _HomePageState extends State<HomePage> {
|
|||
SizedBox(
|
||||
height: 30,
|
||||
),
|
||||
Text(
|
||||
"Sort by",
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
DefaultTabController(
|
||||
length: 2,
|
||||
child: Column(
|
||||
|
|
@ -509,21 +486,33 @@ class _HomePageState extends State<HomePage> {
|
|||
Container(
|
||||
child: Column(
|
||||
children: [
|
||||
CurrencyListItem("BTC", "0.0004000 = \$1.20"),
|
||||
CurrencyListItem("ETH", "0.0004000 = \$0.50"),
|
||||
CurrencyListItem("XRP", "0.0004000 = \$0.20"),
|
||||
CurrencyListItem("DOGE", "0.0004000 = \$0.020")
|
||||
ListView.builder(
|
||||
shrinkWrap: true,
|
||||
controller: scrollController,
|
||||
itemCount: Hoarder.ThisSeasonCryptoEarnings.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return CurrencyListItem(Hoarder.ThisSeasonCryptoEarnings.keys.elementAt(index));
|
||||
})
|
||||
],
|
||||
)),
|
||||
Container(
|
||||
child: Column(
|
||||
children: [
|
||||
GameListItem(
|
||||
Hoarder.GamesJson[0], "0.0004000 = \$1.20"),
|
||||
GameListItem(
|
||||
Hoarder.GamesJson[1], "0.0004000 = \$1.20"),
|
||||
GameListItem(
|
||||
Hoarder.GamesJson[2], "0.0004000 = \$1.20"),
|
||||
ListView.builder(
|
||||
shrinkWrap: true,
|
||||
controller: scrollController,
|
||||
itemCount: Hoarder.ThisSeasonGamesEarnings.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
String gameName= Hoarder.ThisSeasonGamesEarnings.keys.elementAt(index);
|
||||
dynamic GameJson = Helpers.GetGameFromCode(gameName);
|
||||
if(GameJson == null){
|
||||
Debug.LogError("Error receiving game json from ${gameName}. returned:\n$GameJson");
|
||||
return Text("Error");
|
||||
}
|
||||
double amount = Helpers.SatsToCoin(Hoarder.ThisSeasonGamesEarnings.values.elementAt(index));
|
||||
return GameListItem(
|
||||
GameJson, "$amount ~ \$${Helpers.CryptoToDollars(amount: amount, Crypto: GameJson['coin']).toStringAsFixed(2)}");
|
||||
})
|
||||
],
|
||||
)),
|
||||
]),
|
||||
|
|
@ -620,7 +609,8 @@ class _HomePageState extends State<HomePage> {
|
|||
]))));
|
||||
}
|
||||
|
||||
Widget CurrencyListItem(String currencyName, String value) {
|
||||
Widget CurrencyListItem(String currencyName) {
|
||||
double val = (Hoarder.ThisSeasonCryptoEarnings[currencyName] ?? 0).toDouble() * (0.00000001);
|
||||
return Container(
|
||||
padding: EdgeInsets.all(5),
|
||||
child: Row(
|
||||
|
|
@ -637,7 +627,7 @@ class _HomePageState extends State<HomePage> {
|
|||
Text(currencyName)
|
||||
],
|
||||
),
|
||||
Text(value)
|
||||
Text('${val.toStringAsFixed(8)} ~ \$${Helpers.CryptoToDollars(amount: val, Crypto: currencyName).toStringAsFixed(2)}' )
|
||||
],
|
||||
),
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user