Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions app/lib/models/market_data.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
class TftMarketData {
final double lastPrice;
final double lastUsdPrice;
final double change24h;
final double high24h;
final double low24h;
final double volume24h;

TftMarketData({
required this.lastPrice,
required this.lastUsdPrice,
required this.change24h,
required this.high24h,
required this.low24h,
required this.volume24h,
});

factory TftMarketData.fromTrades(List<dynamic> trades) {
Expand All @@ -25,41 +21,28 @@ class TftMarketData {

double high24h = lastUsdcPrice;
double low24h = lastUsdcPrice;
double volume24h = 0;

final oldestTrade = trades.last;
final double oldestUsdcPrice = double.parse(oldestTrade['base_amount']) /
double.parse(oldestTrade['counter_amount']);

for (var trade in trades) {
double usdcPrice = double.parse(trade['base_amount']) /
double.parse(trade['counter_amount']);
high24h = usdcPrice > high24h ? usdcPrice : high24h;
low24h = usdcPrice < low24h ? usdcPrice : low24h;
volume24h += double.parse(trade['counter_amount']);
}

final double change24h =
((lastUsdcPrice - oldestUsdcPrice) / oldestUsdcPrice) * 100;

return TftMarketData(
lastPrice: 1 / lastPrice,
lastUsdPrice: lastUsdcPrice,
change24h: change24h,
high24h: high24h,
low24h: low24h,
volume24h: volume24h / 1000,
);
}

factory TftMarketData.empty() {
return TftMarketData(
lastPrice: 0,
lastUsdPrice: 0,
change24h: 0,
high24h: 0,
low24h: 0,
volume24h: 0,
);
}
}
4 changes: 0 additions & 4 deletions app/lib/screens/market/overview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,6 @@ class _OverviewWidgetState extends ConsumerState<OverviewWidget> {
'${marketData!.lastPrice.toStringAsFixed(7)} USDC'),
_buildMarketColumn('Last USD Price',
'\$${marketData!.lastUsdPrice.toStringAsFixed(7)}'),
_buildMarketColumn('24H Change',
'${marketData!.change24h.toStringAsFixed(7)}%'),
],
),
),
Expand All @@ -455,8 +453,6 @@ class _OverviewWidgetState extends ConsumerState<OverviewWidget> {
'${marketData!.high24h.toStringAsFixed(7)} USDC'),
_buildMarketColumn('24H Low',
'${marketData!.low24h.toStringAsFixed(7)} USDC'),
_buildMarketColumn('24H Volume',
'${marketData!.volume24h.toStringAsFixed(7)}K USDC'),
],
),
),
Expand Down