Skip to content

Commit

Permalink
More fixups after new API
Browse files Browse the repository at this point in the history
* Switched to change percent 1h instead of 7D
  • Loading branch information
trentpiercy committed Aug 9, 2020
1 parent decefe8 commit 025271a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"package_info","path":"C:\\\\Users\\\\TJ\\\\AppData\\\\Roaming\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\package_info-0.3.2+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\Users\\\\TJ\\\\AppData\\\\Roaming\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.4.1\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\Users\\\\TJ\\\\AppData\\\\Roaming\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"url_launcher","path":"C:\\\\Users\\\\TJ\\\\AppData\\\\Roaming\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher-3.0.3\\\\","dependencies":[]}],"android":[{"name":"package_info","path":"C:\\\\Users\\\\TJ\\\\AppData\\\\Roaming\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\package_info-0.3.2+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\Users\\\\TJ\\\\AppData\\\\Roaming\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.4.1\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\Users\\\\TJ\\\\AppData\\\\Roaming\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"url_launcher","path":"C:\\\\Users\\\\TJ\\\\AppData\\\\Roaming\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher-3.0.3\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"package_info","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"shared_preferences","dependencies":[]},{"name":"url_launcher","dependencies":[]}],"date_created":"2020-08-08 20:33:45.672362","version":"1.21.0-8.0.pre.47"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"package_info","path":"C:\\\\Users\\\\TJ\\\\AppData\\\\Roaming\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\package_info-0.3.2+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\Users\\\\TJ\\\\AppData\\\\Roaming\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.4.1\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\Users\\\\TJ\\\\AppData\\\\Roaming\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"url_launcher","path":"C:\\\\Users\\\\TJ\\\\AppData\\\\Roaming\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher-3.0.3\\\\","dependencies":[]}],"android":[{"name":"package_info","path":"C:\\\\Users\\\\TJ\\\\AppData\\\\Roaming\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\package_info-0.3.2+1\\\\","dependencies":[]},{"name":"path_provider","path":"C:\\\\Users\\\\TJ\\\\AppData\\\\Roaming\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\path_provider-0.4.1\\\\","dependencies":[]},{"name":"shared_preferences","path":"C:\\\\Users\\\\TJ\\\\AppData\\\\Roaming\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\shared_preferences-0.4.3\\\\","dependencies":[]},{"name":"url_launcher","path":"C:\\\\Users\\\\TJ\\\\AppData\\\\Roaming\\\\Pub\\\\Cache\\\\hosted\\\\pub.dartlang.org\\\\url_launcher-3.0.3\\\\","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"package_info","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"shared_preferences","dependencies":[]},{"name":"url_launcher","dependencies":[]}],"date_created":"2020-08-09 00:30:24.358227","version":"1.21.0-8.0.pre.47"}
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ String downArrow = "⬇";

int lastUpdate;
Future<Null> getMarketData() async {
int pages = 10;
int pages = 5;
List tempMarketListData = [];

Future<Null> _pullData(page) async {
Expand All @@ -49,7 +49,7 @@ Future<Null> getMarketData() async {
marketListData = [];
// Filter out lack of financial data
for (Map coin in tempMarketListData) {
if (coin.containsKey("RAW")) {
if (coin.containsKey("RAW") && coin.containsKey("CoinInfo")) {
marketListData.add(coin);
}
}
Expand Down
9 changes: 5 additions & 4 deletions lib/market/change_bar.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import '../main.dart';

final Map ohlcvWidthOptions = {
"1h": [
Expand Down Expand Up @@ -84,8 +85,8 @@ class QuickPercentChangeBar extends StatelessWidget {
new Padding(padding: const EdgeInsets.only(right: 3.0)),
new Text(
snapshot["CHANGEPCTHOUR"] >= 0
? "+" + snapshot["CHANGEPCTHOUR"].toString() + "%"
: snapshot["CHANGEPCTHOUR"].toString() + "%",
? "+" + snapshot["CHANGEPCTHOUR"].toStringAsFixed(2) + "%"
: snapshot["CHANGEPCTHOUR"].toStringAsFixed(2) + "%",
style: Theme.of(context).primaryTextTheme.body2.apply(
color: snapshot["CHANGEPCTHOUR"] >= 0
? Colors.green
Expand All @@ -103,8 +104,8 @@ class QuickPercentChangeBar extends StatelessWidget {
new Padding(padding: const EdgeInsets.only(right: 3.0)),
new Text(
snapshot["CHANGEPCT24HOUR"] >= 0
? "+" + snapshot["CHANGEPCT24HOUR"].toString() + "%"
: snapshot["CHANGEPCT24HOUR"].toString() + "%",
? "+" + snapshot["CHANGEPCT24HOUR"].toStringAsFixed(2) + "%"
: snapshot["CHANGEPCT24HOUR"].toStringAsFixed(2) + "%",
style: Theme.of(context).primaryTextTheme.body2.apply(
color: snapshot["CHANGEPCT24HOUR"] >= 0
? Colors.green
Expand Down
2 changes: 1 addition & 1 deletion lib/market/coin_tabs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class CoinDetailsState extends State<CoinDetails>

_getGeneralStats() async {
const int fifteenMin = 15*60*1000;
if (DateTime.now().millisecondsSinceEpoch - lastUpdate >= fifteenMin) {
if (lastUpdate != null && fifteenMin != null && DateTime.now().millisecondsSinceEpoch - lastUpdate >= fifteenMin) {
await getMarketData();
}
_makeGeneralStats();
Expand Down
17 changes: 4 additions & 13 deletions lib/market_coin_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ final assetImages = ['\$pac', 'block', 'ctxc', 'ethos', 'hush', 'msr', 'pot', 's
class CoinListItem extends StatelessWidget {
CoinListItem(this.snapshot, this.columnProps);
final columnProps;
final snapshot;
final Map snapshot;

_getImage() {
if (assetImages.contains(snapshot["CoinInfo"]["Name"].toLowerCase())) {
Expand All @@ -21,18 +21,9 @@ class CoinListItem extends StatelessWidget {

@override
Widget build(BuildContext context) {
// snapshot.forEach((k, v) {
// if (v == null) {
// snapshot[k] = "0";
// }
// });
// snapshot["RAW"]["USD"].forEach((k, v) {
// if (v == null) {
// snapshot["RAW"]["USD"][k] = 0;
// }
// });;
// print("snapshot: ");
// print(snapshot);
if (!snapshot.containsKey("CoinInfo") || !snapshot.containsKey("RAW") || snapshot == null || snapshot.isEmpty) {
return new Container();
}

return new InkWell(
onTap: () {
Expand Down
2 changes: 1 addition & 1 deletion lib/portfolio_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import 'market_coin_item.dart';

class PortfolioListItem extends StatelessWidget {
PortfolioListItem(this.snapshot, this.columnProps);
final snapshot;
final columnProps;
final Map snapshot;

_getImage() {
if (assetImages.contains(snapshot["symbol"].toLowerCase())) {
Expand Down
19 changes: 10 additions & 9 deletions lib/tabs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,29 @@ class TabsState extends State<Tabs> with SingleTickerProviderStateMixin {
"symbol": symbol,
"price_usd": coin["RAW"]["USD"]["PRICE"],
"percent_change_24h": coin["RAW"]["USD"]["CHANGEPCT24HOUR"],
"percent_change_7d": 0, // TODO
"percent_change_1h": coin["RAW"]["USD"]["CHANGEPCTHOUR"],
"total_quantity": portfolioTotals[symbol],
"id": coin["CoinInfo"]["Id"],
"name": coin["CoinInfo"]["FullName"],
"CoinInfo" : coin["CoinInfo"]
});
totalPortfolioValue += (portfolioTotals[symbol] * coin["RAW"]["USD"]["PRICE"]);
}
});

num total24hChange = 0;
num total7dChange = 0;
num total1hChange = 0;
portfolioDisplay.forEach((coin) {
total24hChange += (coin["percent_change_24h"] *
((coin["price_usd"] * coin["total_quantity"]) / totalPortfolioValue));
total7dChange += (coin["percent_change_7d"] *
total1hChange += (coin["percent_change_1h"] *
((coin["price_usd"] * coin["total_quantity"]) / totalPortfolioValue));
});

totalPortfolioStats = {
"value_usd": totalPortfolioValue,
"percent_change_24h": total24hChange,
"percent_change_7d": total7dChange
"percent_change_1h": total1hChange
};

_sortPortfolioDisplay();
Expand Down Expand Up @@ -434,23 +435,23 @@ class TabsState extends State<Tabs> with SingleTickerProviderStateMixin {
),
new Column(
children: <Widget>[
new Text("7D Change",
new Text("1h Change",
style: Theme.of(context).textTheme.caption),
new Padding(
padding: const EdgeInsets.symmetric(vertical: 1.0)),
new Text(
totalPortfolioStats["percent_change_7d"] >= 0
totalPortfolioStats["percent_change_1h"] >= 0
? "+" +
totalPortfolioStats["percent_change_7d"]
totalPortfolioStats["percent_change_1h"]
.toStringAsFixed(2) +
"%"
: totalPortfolioStats["percent_change_7d"]
: totalPortfolioStats["percent_change_1h"]
.toStringAsFixed(2) +
"%",
style:
Theme.of(context).primaryTextTheme.body2.apply(
color: totalPortfolioStats[
"percent_change_7d"] >=
"percent_change_1h"] >=
0
? Colors.green
: Colors.red,
Expand Down

0 comments on commit 025271a

Please sign in to comment.