Skip to content

Commit

Permalink
Migrating to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
trentpiercy committed Aug 9, 2020
1 parent 8ebefa7 commit decefe8
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 124 deletions.
1 change: 1 addition & 0 deletions .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +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"}
8 changes: 4 additions & 4 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if (keystorePropertiesFile.exists()) {
}

android {
compileSdkVersion 28
compileSdkVersion 29

lintOptions {
disable 'InvalidPackage'
Expand All @@ -30,9 +30,9 @@ android {
defaultConfig {
applicationId "com.trentpiercy.trace"
minSdkVersion 21
targetSdkVersion 28
versionCode 9
versionName "1.0.8"
targetSdkVersion 29
versionCode 10
versionName "1.0.9"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand Down
1 change: 1 addition & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
15 changes: 15 additions & 0 deletions ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=C:\Code\flutter"
export "FLUTTER_APPLICATION_PATH=C:\Code\trace"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build\ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=C:\Code\flutter\bin\cache\artifacts\engine\ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.packages"
36 changes: 21 additions & 15 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,47 @@ String upArrow = "⬆";
String downArrow = "⬇";

int lastUpdate;

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

Future<Null> _pullData(start, limit) async {
Future<Null> _pullData(page) async {
var response = await http.get(
Uri.encodeFull("https://api.coinmarketcap.com/v2/ticker/" +
"?start=" +
start.toString() +
"&limit=" +
limit.toString()),
Uri.encodeFull("https://min-api.cryptocompare.com/data/top/mktcapfull?tsym=USD&limit=100" +
"&page=" +
page.toString()),
headers: {"Accept": "application/json"});

Map rawMarketListData = new JsonDecoder().convert(response.body)["data"];
tempMarketListData.addAll(rawMarketListData.values);
List rawMarketListData = new JsonDecoder().convert(response.body)["Data"];
tempMarketListData.addAll(rawMarketListData);
}

List<Future> futures = [];
for (int i = 0; i <= numberOfCoins / 100 - 1; i++) {
int start = i * 100 + 1;
int limit = i * 100 + 100;
futures.add(_pullData(start, limit));
for (int i = 0; i < pages; i++) {
futures.add(_pullData(i));
}
await Future.wait(futures);

marketListData = tempMarketListData;
marketListData = [];
// Filter out lack of financial data
for (Map coin in tempMarketListData) {
if (coin.containsKey("RAW")) {
marketListData.add(coin);
}
}

getApplicationDocumentsDirectory().then((Directory directory) async {
File jsonFile = new File(directory.path + "/marketData.json");
jsonFile.writeAsStringSync(json.encode(marketListData));
});
print("Got new market data.");

lastUpdate = DateTime.now().millisecondsSinceEpoch;
}

void main() async {
WidgetsFlutterBinding.ensureInitialized();

await getApplicationDocumentsDirectory().then((Directory directory) async {
File jsonFile = new File(directory.path + "/portfolio.json");
if (jsonFile.existsSync()) {
Expand All @@ -80,6 +85,7 @@ void main() async {
jsonFile.createSync();
jsonFile.writeAsStringSync("[]");
marketListData = [];
// getMarketData(); ?does this work?
}
});

Expand Down
54 changes: 27 additions & 27 deletions lib/market/change_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ class QuickPercentChangeBar extends StatelessWidget {
.apply(color: Theme.of(context).hintColor)),
new Padding(padding: const EdgeInsets.only(right: 3.0)),
new Text(
snapshot["percent_change_1h"] >= 0
? "+" + snapshot["percent_change_1h"].toString() + "%"
: snapshot["percent_change_1h"].toString() + "%",
snapshot["CHANGEPCTHOUR"] >= 0
? "+" + snapshot["CHANGEPCTHOUR"].toString() + "%"
: snapshot["CHANGEPCTHOUR"].toString() + "%",
style: Theme.of(context).primaryTextTheme.body2.apply(
color: snapshot["percent_change_1h"] >= 0
color: snapshot["CHANGEPCTHOUR"] >= 0
? Colors.green
: Colors.red))
],
Expand All @@ -102,34 +102,34 @@ class QuickPercentChangeBar extends StatelessWidget {
.apply(color: Theme.of(context).hintColor)),
new Padding(padding: const EdgeInsets.only(right: 3.0)),
new Text(
snapshot["percent_change_24h"] >= 0
? "+" + snapshot["percent_change_24h"].toString() + "%"
: snapshot["percent_change_24h"].toString() + "%",
snapshot["CHANGEPCT24HOUR"] >= 0
? "+" + snapshot["CHANGEPCT24HOUR"].toString() + "%"
: snapshot["CHANGEPCT24HOUR"].toString() + "%",
style: Theme.of(context).primaryTextTheme.body2.apply(
color: snapshot["percent_change_24h"] >= 0
color: snapshot["CHANGEPCT24HOUR"] >= 0
? Colors.green
: Colors.red))
],
),
new Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Text("7D",
style: Theme.of(context)
.textTheme
.body1
.apply(color: Theme.of(context).hintColor)),
new Padding(padding: const EdgeInsets.only(right: 3.0)),
new Text(
snapshot["percent_change_7d"] >= 0
? "+" + snapshot["percent_change_7d"].toString() + "%"
: snapshot["percent_change_7d"].toString() + "%",
style: Theme.of(context).primaryTextTheme.body2.apply(
color: snapshot["percent_change_7d"] >= 0
? Colors.green
: Colors.red)),
],
)
// new Row(
// mainAxisSize: MainAxisSize.min,
// children: <Widget>[
// new Text("7D",
// style: Theme.of(context)
// .textTheme
// .body1
// .apply(color: Theme.of(context).hintColor)),
// new Padding(padding: const EdgeInsets.only(right: 3.0)),
// new Text(
// snapshot["percent_change_7d"] >= 0
// ? "+" + snapshot["percent_change_7d"].toString() + "%"
// : snapshot["percent_change_7d"].toString() + "%",
// style: Theme.of(context).primaryTextTheme.body2.apply(
// color: snapshot["percent_change_7d"] >= 0
// ? Colors.green
// : Colors.red)),
// ],
// )
],
),
);
Expand Down
18 changes: 9 additions & 9 deletions lib/market/coin_tabs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class CoinDetailsState extends State<CoinDetails>
_makeTabs();
_tabController = new TabController(length: _tabAmt, vsync: this);

symbol = widget.snapshot["symbol"];
symbol = widget.snapshot["CoinInfo"]["Name"];

_makeGeneralStats();
if (historyOHLCV == null) {
Expand All @@ -79,7 +79,7 @@ class CoinDetailsState extends State<CoinDetails>
backgroundColor: Theme.of(context).primaryColor,
titleSpacing: 2.0,
elevation: appBarElevation,
title: new Text(widget.snapshot["name"],
title: new Text(widget.snapshot["CoinInfo"]["FullName"],
style: Theme.of(context).textTheme.title),
bottom: new PreferredSize(
preferredSize: const Size.fromHeight(25.0),
Expand Down Expand Up @@ -145,8 +145,8 @@ class CoinDetailsState extends State<CoinDetails>

_makeGeneralStats() {
for (Map coin in marketListData) {
if (coin["symbol"] == symbol) {
generalStats = coin["quotes"]["USD"];
if (coin["CoinInfo"]["Name"] == symbol) {
generalStats = coin["RAW"]["USD"];
break;
}
}
Expand Down Expand Up @@ -237,7 +237,7 @@ class CoinDetailsState extends State<CoinDetails>
"\$" +
(generalStats != null
? normalizeNumNoCommas(
generalStats["price"])
generalStats["PRICE"])
: "0"),
style: Theme.of(context)
.textTheme
Expand Down Expand Up @@ -279,7 +279,7 @@ class CoinDetailsState extends State<CoinDetails>
generalStats != null
? "\$" +
normalizeNum(
generalStats["market_cap"])
generalStats["MKTCAP"])
: "0",
style: Theme.of(context)
.textTheme
Expand All @@ -291,7 +291,7 @@ class CoinDetailsState extends State<CoinDetails>
generalStats != null
? "\$" +
normalizeNum(
generalStats["volume_24h"])
generalStats["TOTALVOLUME24H"])
: "0",
style: Theme.of(context)
.textTheme
Expand Down Expand Up @@ -827,7 +827,7 @@ class CoinDetailsState extends State<CoinDetails>

for (Map transaction in transactionList) {
cost += transaction["quantity"] * transaction["price_usd"];
value += transaction["quantity"] * generalStats["price"];
value += transaction["quantity"] * generalStats["PRICE"];
holdings += transaction["quantity"];
}

Expand Down Expand Up @@ -917,7 +917,7 @@ class CoinDetailsState extends State<CoinDetails>
delegate: new SliverChildBuilderDelegate(
(context, index) => new TransactionItem(
snapshot: transactionList[index],
currentPrice: generalStats["price"],
currentPrice: generalStats["PRICE"],
symbol: symbol,
refreshPage: () {
setState(() {
Expand Down
42 changes: 22 additions & 20 deletions lib/market_coin_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class CoinListItem extends StatelessWidget {
final snapshot;

_getImage() {
if (assetImages.contains(snapshot["symbol"].toLowerCase())) {
if (assetImages.contains(snapshot["CoinInfo"]["Name"].toLowerCase())) {
return new Image.asset(
"assets/images/" + snapshot["symbol"].toLowerCase() + ".png",
"assets/images/" + snapshot["CoinInfo"]["Name"].toLowerCase() + ".png",
height: 28.0);
} else {
return new Container();
Expand All @@ -21,16 +21,18 @@ class CoinListItem extends StatelessWidget {

@override
Widget build(BuildContext context) {
snapshot.forEach((k, v) {
if (v == null) {
snapshot[k] = "0";
}
});
snapshot["quotes"]["USD"].forEach((k, v) {
if (v == null) {
snapshot["quotes"]["USD"][k] = 0;
}
});
// 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);

return new InkWell(
onTap: () {
Expand All @@ -57,7 +59,7 @@ class CoinListItem extends StatelessWidget {
new Padding(padding: const EdgeInsets.only(right: 7.0)),
_getImage(),
new Padding(padding: const EdgeInsets.only(right: 7.0)),
new Text(snapshot["symbol"],
new Text(snapshot["CoinInfo"]["Name"],
style: Theme.of(context).textTheme.body2),
],
),
Expand All @@ -71,13 +73,13 @@ class CoinListItem extends StatelessWidget {
new Text(
"\$" +
normalizeNum(
snapshot["quotes"]["USD"]["market_cap"]),
snapshot["RAW"]["USD"]["MKTCAP"]),
style: Theme.of(context).textTheme.body2),
new Padding(padding: const EdgeInsets.only(bottom: 4.0)),
new Text(
"\$" +
normalizeNum(
snapshot["quotes"]["USD"]["volume_24h"]),
snapshot["RAW"]["USD"]["TOTALVOLUME24H"]),
style: Theme.of(context)
.textTheme
.body2
Expand All @@ -92,16 +94,16 @@ class CoinListItem extends StatelessWidget {
children: <Widget>[
new Text("\$" +
normalizeNumNoCommas(
snapshot["quotes"]["USD"]["price"])),
snapshot["RAW"]["USD"]["PRICE"])),
new Padding(padding: const EdgeInsets.only(bottom: 4.0)),
new Text(
(snapshot["quotes"]["USD"]["percent_change_24h"] ?? 0) >= 0
? "+" + (snapshot["quotes"]["USD"]["percent_change_24h"] ?? 0)
(snapshot["RAW"]["USD"]["CHANGEPCT24HOUR"] ?? 0) >= 0
? "+" + (snapshot["RAW"]["USD"]["CHANGEPCT24HOUR"] ?? 0)
.toStringAsFixed(2) + "%"
: (snapshot["quotes"]["USD"]["percent_change_24h"] ?? 0)
: (snapshot["RAW"]["USD"]["CHANGEPCT24HOUR"] ?? 0)
.toStringAsFixed(2) + "%",
style: Theme.of(context).primaryTextTheme.body1.apply(
color: (snapshot["quotes"]["USD"]["percent_change_24h"] ?? 0) >= 0
color: (snapshot["RAW"]["USD"]["CHANGEPCT24HOUR"] ?? 0) >= 0
? Colors.green
: Colors.red)),
],
Expand Down
4 changes: 2 additions & 2 deletions lib/portfolio/portfolio_tabs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ class PortfolioTabsState extends State<PortfolioTabs>
portfolioMap.forEach((symbol, transactions) {
num currentPrice;
for (Map coin in marketListData) {
if (coin["symbol"] == symbol) {
currentPrice = coin["quotes"]["USD"]["price"];
if (coin["CoinInfo"]["Name"] == symbol) {
currentPrice = coin["RAW"]["USD"]["PRICE"];
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/portfolio/transaction_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class TransactionSheetState extends State<TransactionSheet> {
_checkValidSymbol(String inputSymbol) async {
if (symbolList == null || symbolList.isEmpty) {
symbolList = [];
widget.marketListData.forEach((value) => symbolList.add(value["symbol"]));
widget.marketListData.forEach((value) => symbolList.add(value["CoinInfo"]["Name"]));
}

if (symbolList.contains(inputSymbol.toUpperCase())) {
Expand All @@ -122,8 +122,8 @@ class TransactionSheetState extends State<TransactionSheet> {
_getExchangeList();

for (var value in widget.marketListData) {
if (value["symbol"] == symbol) {
price = value["quotes"]["USD"]["price"];
if (value["CoinInfo"]["Name"] == symbol) {
price = value["RAW"]["USD"]["PRICE"];
_priceController.text = price.toString();
priceTextColor = validColor;
break;
Expand Down
2 changes: 1 addition & 1 deletion lib/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class ImportPageState extends State<ImportPage> {
void initState() {
super.initState();
marketListData.forEach((coin) {
validSymbols.add(coin["symbol"]);
validSymbols.add(coin["CoinInfo"]["Name"]);
});
}

Expand Down
Loading

0 comments on commit decefe8

Please sign in to comment.