-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtokenomics.php
More file actions
133 lines (125 loc) · 5.06 KB
/
tokenomics.php
File metadata and controls
133 lines (125 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/* Todo;
- add current price
-
*/
require_once 'bootstrap.php';
include_once 'include/graph.php';
require_once 'include/layout.php';
$graphConfigs = require 'include/graph_configs.php';
use Siagraph\Utils\Cache;
use Siagraph\Utils\Formatter;
use Siagraph\Utils\ApiClient;
use Siagraph\Utils\CurrencyDisplay;
$currencyCookie = CurrencyDisplay::selectedCurrency();
$recentstats = Cache::getCache(Cache::RECENT_STATS_KEY);
if ($recentstats) {
$recentstats = json_decode($recentstats, true);
}
// Fetch monthly metrics to calculate yearly inflation
$metricsData = ApiClient::fetchJson('/api/v1/monthly/metrics');
$dataError = !is_array($metricsData);
if ($dataError) {
$metricsData = [];
}
$yearData = [];
foreach ($metricsData as $row) {
$year = substr($row['date'], 0, 4);
if (!isset($yearData[$year])) {
$yearData[$year] = ['start' => $row['circulating_supply'], 'end' => $row['circulating_supply']];
} else {
$yearData[$year]['end'] = $row['circulating_supply'];
}
}
$inflationRates = [];
foreach ($yearData as $y => $vals) {
$start = $vals['start'];
$end = $vals['end'];
$inflationRates[$y] = $start > 0 ? (($end - $start) / $start) * 100 : 0;
}
?>
<?php render_header("SiaGraph - Tokenomics"); ?>
<?php if ($dataError): ?>
<p class="text-center text-muted">Tokenomics data unavailable.</p>
<?php endif; ?>
<!-- Main Content Section -->
<section id="main-content" class="sg-container">
<h1 class="sg-container__heading text-center mb-2"><i class="bi bi-currency-bitcoin me-2"></i>Tokenomics</h1>
<section id="graph-section" class="card mt-4">
<h2 class="card__heading">Tokenomics: Inflation</h2>
<div class="card__content">
<div class="text-center text-light my-2">
<i class="bi bi-currency-bitcoin me-1"></i>
<span>Price:</span>
<span class="fw-bold">
<?php
$coinFiat = !empty($recentstats) && isset($recentstats['actual']['coin_price'][$currencyCookie])
? (float) $recentstats['actual']['coin_price'][$currencyCookie]
: null;
echo CurrencyDisplay::formatMonetary([
'scValue' => 1,
'fiatValue' => $coinFiat,
'currency' => $currencyCookie,
'decimals' => 6,
'scDecimals' => 0,
]);
?>
</span>
</div>
<section class="graph-container">
<!-- Include the Chart.js graph using an iframe -->
<?php include $_SERVER['DOCUMENT_ROOT'] . "/graphs/CoinGrowthGraph.php"; ?>
<!-- Add any additional content related to the Network graph -->
</section>
</div>
</section>
<section id="marketcap-section" class="card mt-4">
<h2 class="card__heading">Tokenomics: Coin Market Cap</h2>
<div class="card__content">
<section class="graph-container">
<?php
renderGraph(
$canvasid = "marketcap",
[
array_merge(
$graphConfigs['market_cap'],
['unit' => strtoupper($currencyCookie)]
)
],
$dateKey = 'date',
$jsonUrl = '/api/v1/daily/metrics',
$jsonData = null,
$charttype = 'line',
$interval = 'week',
$rangeslider = true,
$displaylegend = 'true',
$defaultrangeinmonths = 12,
$displayYAxis = 'false',
$unitType = $currencyCookie
);
?>
</section>
</div>
</section>
<section id="inflation-table" class="card mt-4">
<h2 class="card__heading">Tokenomics: Yearly Inflation Rate</h2>
<div class="card__content">
<div class="table-responsive">
<table class="table table-dark table-clean text-white w-full border-collapse border border-gray-300">
<thead class="bg-gray-800">
<tr><th class="px-4 py-2 border border-gray-300">Year</th><th class="px-4 py-2 border border-gray-300">Inflation</th></tr>
</thead>
<tbody>
<?php foreach($inflationRates as $year => $rate){ ?>
<tr>
<td class="px-4 py-2 border border-gray-300 text-center"><?php echo $year; ?></td>
<td class="px-4 py-2 border border-gray-300 text-right"><?php echo round($rate,2); ?>%</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</section>
<!-- Footer Section -->
<?php render_footer(); ?>