Seperate challenges
This commit is contained in:
parent
cb8d1bb74c
commit
5f052bd76a
|
|
@ -22,6 +22,9 @@ class Helpers{
|
||||||
case "LTC":
|
case "LTC":
|
||||||
return CryptoFontIcons.LTC;
|
return CryptoFontIcons.LTC;
|
||||||
break;
|
break;
|
||||||
|
case "BCH":
|
||||||
|
return CryptoFontIcons.AUR;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CryptoFontIcons.BTC;
|
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();
|
FetchChallenges();
|
||||||
}
|
}
|
||||||
static double currentEarnings = 0;
|
static double currentEarnings = 0;
|
||||||
|
static double previousEarnings = 0;
|
||||||
|
static Map<String, int> ThisSeasonGamesEarnings = {};
|
||||||
static Map<String, int> ThisSeasonCryptoEarnings = {};
|
static Map<String, int> ThisSeasonCryptoEarnings = {};
|
||||||
|
|
||||||
|
static dynamic cryptoRates;
|
||||||
static Future<void> FetchChallenges() async {
|
static Future<void> FetchChallenges() async {
|
||||||
var response = null;
|
var response = null;
|
||||||
|
|
||||||
List<List<dynamic>> _Challenges = [];
|
List<List<dynamic>> _Challenges = [];
|
||||||
double _currentEarnings = 0;
|
double _currentEarnings = 0;
|
||||||
Map<String,int> _ThisSeasonCryptoEarnings = {};
|
Map<String,int> _ThisSeasonGamesEarnings = {};
|
||||||
|
Map<String, int> _ThisSeasonCryptoEarnings = {};
|
||||||
|
|
||||||
var cryptoValuesResponse = await http.get(Uri.parse('http://vps.playpoolstudios.com:2009/'));
|
var cryptoValuesResponse = await http.get(Uri.parse('http://vps.playpoolstudios.com:2009/'));
|
||||||
dynamic cryptoValues = jsonDecode(cryptoValuesResponse.body.toString());
|
dynamic cryptoValues = jsonDecode(cryptoValuesResponse.body.toString());
|
||||||
|
cryptoRates = cryptoValues;
|
||||||
Debug.Log(cryptoValues);
|
Debug.Log(cryptoValues);
|
||||||
for (var value in Brain.LinkedGamesJson) {
|
for (var value in Brain.LinkedGamesJson) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -91,6 +97,7 @@ class Hoarder{
|
||||||
if(total <= current){
|
if(total <= current){
|
||||||
_currentEarnings+= rewardInDollars;
|
_currentEarnings+= rewardInDollars;
|
||||||
// Debug.Log(_ThisSeasonCryptoEarnings[GameJson['coin']]);
|
// Debug.Log(_ThisSeasonCryptoEarnings[GameJson['coin']]);
|
||||||
|
_ThisSeasonGamesEarnings.update(GameJson['code'], (value) => value + reward, ifAbsent: ()=> reward);
|
||||||
_ThisSeasonCryptoEarnings.update(GameJson['coin'], (value) => value + reward, ifAbsent: ()=> reward);
|
_ThisSeasonCryptoEarnings.update(GameJson['coin'], (value) => value + reward, ifAbsent: ()=> reward);
|
||||||
// Debug.Log(_ThisSeasonCryptoEarnings[GameJson['coin']]);
|
// Debug.Log(_ThisSeasonCryptoEarnings[GameJson['coin']]);
|
||||||
}
|
}
|
||||||
|
|
@ -103,11 +110,12 @@ class Hoarder{
|
||||||
Debug.LogError("Error while fetching challenges $e");
|
Debug.LogError("Error while fetching challenges $e");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ThisSeasonGamesEarnings = _ThisSeasonGamesEarnings;
|
||||||
ThisSeasonCryptoEarnings = _ThisSeasonCryptoEarnings;
|
ThisSeasonCryptoEarnings = _ThisSeasonCryptoEarnings;
|
||||||
Challenges = _Challenges;
|
Challenges = _Challenges;
|
||||||
currentEarnings = _currentEarnings;
|
currentEarnings = _currentEarnings;
|
||||||
|
|
||||||
Debug.Log(ThisSeasonCryptoEarnings);
|
Debug.Log(ThisSeasonGamesEarnings);
|
||||||
|
|
||||||
// Debug.Log(Challenges);
|
// Debug.Log(Challenges);
|
||||||
// Debug.Log("Challenge, " + (Hoarder.Challenges[0][0]['game']));
|
// Debug.Log("Challenge, " + (Hoarder.Challenges[0][0]['game']));
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class _HomePageState extends State<HomePage> {
|
||||||
await Hoarder.FetchChallenges();
|
await Hoarder.FetchChallenges();
|
||||||
|
|
||||||
DateTime now = DateTime.now();
|
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";
|
daysLeft = "${nextMonth.difference(now).inDays} Days Remaining";
|
||||||
setState(() {});
|
setState(() {});
|
||||||
|
|
@ -52,7 +52,6 @@ class _HomePageState extends State<HomePage> {
|
||||||
void dispose() {
|
void dispose() {
|
||||||
// TODO: implement dispose
|
// TODO: implement dispose
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
|
||||||
looping = false;
|
looping = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,7 +130,7 @@ class _HomePageState extends State<HomePage> {
|
||||||
// ),
|
// ),
|
||||||
// title: "Earnings"),
|
// title: "Earnings"),
|
||||||
HomeCard(
|
HomeCard(
|
||||||
title: "Seasonal Challenges $daysLeft",
|
title: "Ongoing Challenges",
|
||||||
child: Container(
|
child: Container(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
|
|
@ -286,7 +285,8 @@ class _HomePageState extends State<HomePage> {
|
||||||
value: current / total,
|
value: current / total,
|
||||||
color: Colors.green,
|
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,
|
width: 60,
|
||||||
child: Text("$current / $total $prefix",
|
child: Text("$current / $total $prefix",
|
||||||
textAlign: TextAlign.end,
|
textAlign: TextAlign.end,
|
||||||
|
|
@ -398,25 +398,6 @@ class _HomePageState extends State<HomePage> {
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => GamePage(code)),
|
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(
|
child: ListTile(
|
||||||
leading: ClipRRect(
|
leading: ClipRRect(
|
||||||
|
|
@ -458,7 +439,7 @@ class _HomePageState extends State<HomePage> {
|
||||||
size: 60,
|
size: 60,
|
||||||
),
|
),
|
||||||
title: Text(Brain.Username),
|
title: Text(Brain.Username),
|
||||||
subtitle: Text("Total Earnings : \$42.69"),
|
subtitle: Text("Total Earnings : \$${(Hoarder.previousEarnings + Hoarder.currentEarnings).toStringAsFixed(2)}"),
|
||||||
trailing: IconButton(
|
trailing: IconButton(
|
||||||
icon: Icon(Icons.settings),
|
icon: Icon(Icons.settings),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
|
@ -484,10 +465,6 @@ class _HomePageState extends State<HomePage> {
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 30,
|
height: 30,
|
||||||
),
|
),
|
||||||
Text(
|
|
||||||
"Sort by",
|
|
||||||
style: TextStyle(fontSize: 12),
|
|
||||||
),
|
|
||||||
DefaultTabController(
|
DefaultTabController(
|
||||||
length: 2,
|
length: 2,
|
||||||
child: Column(
|
child: Column(
|
||||||
|
|
@ -508,24 +485,36 @@ class _HomePageState extends State<HomePage> {
|
||||||
child: TabBarView(children: [
|
child: TabBarView(children: [
|
||||||
Container(
|
Container(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
CurrencyListItem("BTC", "0.0004000 = \$1.20"),
|
ListView.builder(
|
||||||
CurrencyListItem("ETH", "0.0004000 = \$0.50"),
|
shrinkWrap: true,
|
||||||
CurrencyListItem("XRP", "0.0004000 = \$0.20"),
|
controller: scrollController,
|
||||||
CurrencyListItem("DOGE", "0.0004000 = \$0.020")
|
itemCount: Hoarder.ThisSeasonCryptoEarnings.length,
|
||||||
],
|
itemBuilder: (BuildContext context, int index) {
|
||||||
)),
|
return CurrencyListItem(Hoarder.ThisSeasonCryptoEarnings.keys.elementAt(index));
|
||||||
|
})
|
||||||
|
],
|
||||||
|
)),
|
||||||
Container(
|
Container(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
GameListItem(
|
ListView.builder(
|
||||||
Hoarder.GamesJson[0], "0.0004000 = \$1.20"),
|
shrinkWrap: true,
|
||||||
GameListItem(
|
controller: scrollController,
|
||||||
Hoarder.GamesJson[1], "0.0004000 = \$1.20"),
|
itemCount: Hoarder.ThisSeasonGamesEarnings.length,
|
||||||
GameListItem(
|
itemBuilder: (BuildContext context, int index) {
|
||||||
Hoarder.GamesJson[2], "0.0004000 = \$1.20"),
|
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(
|
return Container(
|
||||||
padding: EdgeInsets.all(5),
|
padding: EdgeInsets.all(5),
|
||||||
child: Row(
|
child: Row(
|
||||||
|
|
@ -637,7 +627,7 @@ class _HomePageState extends State<HomePage> {
|
||||||
Text(currencyName)
|
Text(currencyName)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Text(value)
|
Text('${val.toStringAsFixed(8)} ~ \$${Helpers.CryptoToDollars(amount: val, Crypto: currencyName).toStringAsFixed(2)}' )
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user