-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
150 lines (142 loc) · 5.66 KB
/
index.html
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<html>
<head>
<title>Pi to Currency Converter with Real-Time Analytics</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"></link>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body class="bg-gray-100 font-roboto">
<div class="flex items-center justify-center h-screen">
<div class="p-6 w-full max-w-md shadow-lg bg-white rounded-lg overflow-y-auto" style="max-height: 90vh;">
<div class="mb-4">
<h2 class="text-xl font-bold">Pi to Currency Converter</h2>
</div>
<div class="mb-2">
<p class="text-sm text-gray-600" id="current-rate">Fetching exchange rate...</p>
</div>
<input
type="number"
placeholder="Enter Pi amount"
class="w-full p-2 border border-gray-300 rounded mt-2"
/>
<select class="w-full p-2 border border-gray-300 rounded mt-2" id="currency-select">
<option value="usd">USD</option>
<option value="eur">EUR</option>
<option value="gbp">GBP</option>
<option value="jpy">JPY</option>
<option value="aud">AUD</option>
<option value="cad">CAD</option>
<option value="chf">CHF</option>
<option value="cny">CNY</option>
<option value="inr">INR</option>
<option value="krw">KRW</option>
<option value="sgd">SGD</option>
<option value="hkd">HKD</option>
<option value="idr">IDR</option>
<option value="myr">MYR</option>
<option value="php">PHP</option>
<option value="thb">THB</option>
<option value="vnd">VND</option>
</select>
<button class="mt-4 w-full bg-blue-500 text-white p-2 rounded hover:bg-blue-600">
Convert
</button>
<div class="mt-4">
<p class="text-lg font-semibold" id="equivalent">Equivalent: 0.00</p>
</div>
<div class="mt-6">
<h3 class="text-lg font-bold mb-2">Real-Time Analytics</h3>
<canvas id="exchangeRateChart" width="400" height="200"></canvas>
</div>
<div class="mt-6">
<h3 class="text-lg font-bold mb-2">TradingView Chart</h3>
<div class="tradingview-widget-container" style="height:100%;width:100%">
<div class="tradingview-widget-container__widget" style="height:calc(100% - 32px);width:100%"></div>
<div class="tradingview-widget-copyright">
<a href="https://www.tradingview.com/" rel="noopener nofollow" target="_blank">
<span class="blue-text">Track all markets on TradingView</span>
</a>
</div>
<script type="text/javascript" src="https://s3.tradingview.com/external-embedding/embed-widget-advanced-chart.js" async>
{
"autosize": true,
"symbol": "BITMART:PIUSDT",
"interval": "D",
"timezone": "Etc/UTC",
"theme": "dark",
"style": "1",
"locale": "en",
"backgroundColor": "rgba(0, 0, 0, 1)",
"allow_symbol_change": true,
"calendar": false,
"support_host": "https://www.tradingview.com"
}
</script>
</div>
</div>
</div>
</div>
<script>
const piAmountInput = document.querySelector('input[type="number"]');
const convertButton = document.querySelector('button');
const equivalentText = document.getElementById('equivalent');
const exchangeRateText = document.getElementById('current-rate');
const currencySelect = document.getElementById('currency-select');
const ctx = document.getElementById('exchangeRateChart').getContext('2d');
let exchangeRates = {};
let chart;
const fetchExchangeRates = async () => {
try {
const response = await fetch("https://api.coingecko.com/api/v3/simple/price?ids=pi-network-iou&vs_currencies=usd,eur,gbp,jpy,aud,cad,chf,cny,inr,krw,sgd,hkd,idr,myr,php,thb,vnd");
const data = await response.json();
exchangeRates = data["pi-network-iou"];
exchangeRateText.textContent = `Current Rate: 1 Pi = $${exchangeRates.usd} USD`;
updateChart();
} catch (error) {
console.error("Error fetching exchange rates:", error);
}
};
const convertToCurrency = () => {
const piValue = parseFloat(piAmountInput.value);
const selectedCurrency = currencySelect.value;
if (!isNaN(piValue) && exchangeRates[selectedCurrency] !== undefined) {
const equivalentAmount = (piValue * exchangeRates[selectedCurrency]).toFixed(2);
equivalentText.textContent = `Equivalent: ${equivalentAmount.replace(/\B(?=(\d{3})+(?!\d))/g, ",")} ${selectedCurrency.toUpperCase()}`;
} else {
equivalentText.textContent = "Equivalent: 0.00";
}
};
const updateChart = () => {
const labels = Object.keys(exchangeRates).map(currency => currency.toUpperCase());
const data = Object.values(exchangeRates);
if (chart) {
chart.destroy();
}
chart = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'Exchange Rate (1 Pi)',
data: data,
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 2,
fill: false
}]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: true
}
}
}
});
};
convertButton.addEventListener('click', convertToCurrency);
fetchExchangeRates();
</script>
</body>
</html>