Skip to content

Commit

Permalink
Prepare 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JaceHensley committed Oct 21, 2017
1 parent a545994 commit 8d5cc37
Show file tree
Hide file tree
Showing 6 changed files with 7,929 additions and 7,694 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.3.0

- Use `https://api.coinmarketcap.com/v1/ticker/vertcoin/` to fetch data
- Add hour and week changes

## 1.2.0

- Make badge colored based on trend
Expand Down
14 changes: 9 additions & 5 deletions lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@ class AppComponent extends UiComponent<AppProps> {
if (props.data == null) return false;

return (Dom.div()..className = 'container')(
_renderDayChange(),
_renderChanges(),
_renderFiatPrices(),
_renderCryptoPrices(),
_renderDivider(),
_renderIcons(),
);
}

ReactElement _renderDayChange() {
return (Dom.div()..className = 'columns')(
(Dom.div()..className = 'column col-8 col-mx-auto text-center')('24hr Δ: ${props.data.dayChange}%')
);
ReactElement _renderChanges() {
return (Switcher()
..prices = [
'Δ ${props.data.dayChange}% (24hr)',
'Δ ${props.data.hourChange}% (1hr)',
'Δ ${props.data.weekChange}% (7d)',
]
)();
}

ReactElement _renderFiatPrices() {
Expand Down
4 changes: 3 additions & 1 deletion lib/src/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class Data {
final String ethPrice;
final String zecPrice;
final String satPrice;
final String hourChange;
final String dayChange;
final String weekChange;

Data({this.eurPrice, this.usdPrice, this.btcPrice, this.ltcPrice, this.ethPrice, this.zecPrice, this.satPrice, this.dayChange});
Data({this.eurPrice, this.usdPrice, this.btcPrice, this.ltcPrice, this.ethPrice, this.zecPrice, this.satPrice, this.hourChange, this.dayChange, this.weekChange});
}
59 changes: 35 additions & 24 deletions lib/src/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,46 @@ import 'package:verter/src/data.dart';

void sendRequest(callback(Data)) {
var httpRequest = new HttpRequest();
const baseUrl = 'https://api.coinmarketcap.com/v1/ticker/vertcoin/';
var allJson = {};

httpRequest.onReadyStateChange.listen((_) {
if (httpRequest.readyState == 4) {
Map<String, num> json = JSON.decode(httpRequest.responseText);
var usdPrice = json['price_usd'].toStringAsFixed(2);
var eurPrice = json['price_eur'].toStringAsFixed(2);
var btcPrice = json['price_btc'].toStringAsFixed(10);
var ethPrice = json['price_eth'].toStringAsFixed(10);
var ltcPrice = json['price_ltc'].toStringAsFixed(10);
var zecPrice = json['price_zec'].toStringAsFixed(10);
var satPrice = (double.parse(btcPrice) * 100000000).toStringAsFixed(0);
var dayChange = json['cap24hrChange'].toString();

var data = new Data(
usdPrice: usdPrice,
eurPrice: eurPrice,
btcPrice: btcPrice,
ethPrice: ethPrice,
ltcPrice: ltcPrice,
zecPrice: zecPrice,
satPrice: satPrice,
dayChange: dayChange
);

callback(data);
allJson.addAll(JSON.decode(httpRequest.responseText).single);
}
});

httpRequest
..open('GET', 'http://coincap.io/page/VTC', async: false)
var currencies = ['USD', 'EUR', 'BTC', 'LTC', 'ETH', 'ZEC'];

for (var currency in currencies) {
httpRequest
..open('GET', '$baseUrl?convert=$currency', async: false)
..send();
}

var eurPrice = double.parse(allJson['price_eur']).toStringAsFixed(2);
var usdPrice = double.parse(allJson['price_usd']).toStringAsFixed(2);
var btcPrice = double.parse(allJson['price_btc']).toStringAsFixed(10);
var ethPrice = double.parse(allJson['price_eth']).toStringAsFixed(10);
var ltcPrice = double.parse(allJson['price_ltc']).toStringAsFixed(10);
var zecPrice = double.parse(allJson['price_zec']).toStringAsFixed(10);
var satPrice = (double.parse(btcPrice) * 100000000).toStringAsFixed(0);
var hourChange = allJson['percent_change_1h'];
var dayChange = allJson['percent_change_24h'];
var weekChange = allJson['percent_change_7d'];

var data = new Data(
usdPrice: usdPrice,
eurPrice: eurPrice,
btcPrice: btcPrice,
ethPrice: ethPrice,
ltcPrice: ltcPrice,
zecPrice: zecPrice,
satPrice: satPrice,
hourChange: hourChange,
dayChange: dayChange,
weekChange: weekChange,
);

callback(data);
}
Loading

0 comments on commit 8d5cc37

Please sign in to comment.