Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dropdown options for crypto currencies in the new UI #30

Merged
merged 1 commit into from
Sep 30, 2024
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
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ <h2>Crypto Price Predictor</h2>
<label for="crypto">Enter Cryptocurrency Symbol (e.g., BITCOIN(BTC), ETHERUM(ETH)):</label>
<input type="text" id="crypto" name="crypto">
<button id="predict-btn">Predict Price</button>
<div id="crypto-suggestions"></div>
</div>
<div id="price-result">
<h3>Predicted Price:</h3>
Expand Down
212 changes: 120 additions & 92 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,127 @@
document.getElementById("predict-btn").addEventListener("click", function() {
let cryptoInput = document.getElementById("crypto").value.toUpperCase();

// A map of symbols to their corresponding API names
const cryptoMap = {
// Major cryptocurrencies
'BTC': 'bitcoin',
'ETH': 'ethereum',
'USDT': 'tether',
'BNB': 'binancecoin',
'USDC': 'usd-coin',
'XRP': 'ripple',
'DOGE': 'dogecoin',
'ADA': 'cardano',
'SOL': 'solana',
'DOT': 'polkadot',
'MATIC': 'matic-network',
'SHIB': 'shiba-inu',
'LTC': 'litecoin',
'TRX': 'tron',
'AVAX': 'avalanche-2',
'ATOM': 'cosmos',
'LINK': 'chainlink',
'XMR': 'monero',
'BCH': 'bitcoin-cash',
'ALGO': 'algorand',
'ICP': 'internet-computer',
'VET': 'vechain',
'FIL': 'filecoin',
'NEAR': 'near',
'HBAR': 'hedera-hashgraph',

// Stablecoins
'DAI': 'dai',
'BUSD': 'binance-usd',
'PAX': 'paxos-standard',

// DeFi tokens
'UNI': 'uniswap',
'AAVE': 'aave',
'SUSHI': 'sushi',
'COMP': 'compound-governance-token',
'YFI': 'yearn-finance',

// Layer 2 solutions and scaling
'LRC': 'loopring',
'ZRX': '0x',
'OMG': 'omisego',

// NFT and metaverse tokens
'MANA': 'decentraland',
'SAND': 'the-sandbox',
'ENJ': 'enjincoin',
'AXS': 'axie-infinity',
'GALA': 'gala',

// Privacy coins
'ZEC': 'zcash',
'DASH': 'dash',
// A map of symbols to their corresponding API names
const cryptoMap = {
// Major cryptocurrencies
'BTC': 'bitcoin',
'ETH': 'ethereum',
'USDT': 'tether',
'BNB': 'binancecoin',
'USDC': 'usd-coin',
'XRP': 'ripple',
'DOGE': 'dogecoin',
'ADA': 'cardano',
'SOL': 'solana',
'DOT': 'polkadot',
'MATIC': 'matic-network',
'SHIB': 'shiba-inu',
'LTC': 'litecoin',
'TRX': 'tron',
'AVAX': 'avalanche-2',
'ATOM': 'cosmos',
'LINK': 'chainlink',
'XMR': 'monero',
'BCH': 'bitcoin-cash',
'ALGO': 'algorand',
'ICP': 'internet-computer',
'VET': 'vechain',
'FIL': 'filecoin',
'NEAR': 'near',
'HBAR': 'hedera-hashgraph',

// Stablecoins
'DAI': 'dai',
'BUSD': 'binance-usd',
'PAX': 'paxos-standard',

// Other popular tokens
'FTM': 'fantom',
'GRT': 'the-graph',
'1INCH': '1inch',
'CHZ': 'chiliz',
'BAT': 'basic-attention-token',
'CRV': 'curve-dao-token',
'KSM': 'kusama',
'QTUM': 'qtum',
'ZIL': 'zilliqa',
'EGLD': 'elrond-erd-2',
'HOT': 'holotoken',
'THETA': 'theta-token',
'HNT': 'helium',
'SNX': 'synthetix-network-token',
'RUNE': 'thorchain',
'XLM': 'stellar',
'REN': 'ren',
'FTT': 'ftx-token',
'RVN': 'ravencoin',
'KAVA': 'kava',
'CRO': 'crypto-com-chain',
'MIOTA': 'iota',
'ETC': 'ethereum-classic',
// DeFi tokens
'UNI': 'uniswap',
'AAVE': 'aave',
'SUSHI': 'sushi',
'COMP': 'compound-governance-token',
'YFI': 'yearn-finance',

// Meme coins
'BABYDOGE': 'baby-doge-coin',
'SAFEMOON': 'safemoon',
'ELON': 'dogelon-mars',

// Add more symbols and tokens as needed
};
// Layer 2 solutions and scaling
'LRC': 'loopring',
'ZRX': '0x',
'OMG': 'omisego',

// NFT and metaverse tokens
'MANA': 'decentraland',
'SAND': 'the-sandbox',
'ENJ': 'enjincoin',
'AXS': 'axie-infinity',
'GALA': 'gala',

// Privacy coins
'ZEC': 'zcash',
'DASH': 'dash',

// Other popular tokens
'FTM': 'fantom',
'GRT': 'the-graph',
'1INCH': '1inch',
'CHZ': 'chiliz',
'BAT': 'basic-attention-token',
'CRV': 'curve-dao-token',
'KSM': 'kusama',
'QTUM': 'qtum',
'ZIL': 'zilliqa',
'EGLD': 'elrond-erd-2',
'HOT': 'holotoken',
'THETA': 'theta-token',
'HNT': 'helium',
'SNX': 'synthetix-network-token',
'RUNE': 'thorchain',
'XLM': 'stellar',
'REN': 'ren',
'FTT': 'ftx-token',
'RVN': 'ravencoin',
'KAVA': 'kava',
'CRO': 'crypto-com-chain',
'MIOTA': 'iota',
'ETC': 'ethereum-classic',

// Meme coins
'BABYDOGE': 'baby-doge-coin',
'SAFEMOON': 'safemoon',
'ELON': 'dogelon-mars',

// Add more symbols and tokens as needed
};

const cryptoInput = document.getElementById('crypto');
const suggestionsBox = document.getElementById('crypto-suggestions');

cryptoInput.addEventListener('input', function() {
const inputValue = cryptoInput.value.toUpperCase();
suggestionsBox.innerHTML = '';

const filteredCryptos = Object.keys(cryptoMap).filter(crypto => crypto.includes(inputValue));

if (inputValue && filteredCryptos.length > 0) {
suggestionsBox.style.display = 'block';
filteredCryptos.forEach(crypto => {
const suggestionItem = document.createElement('div');
suggestionItem.textContent = crypto;
suggestionItem.addEventListener('click', function() {
cryptoInput.value = crypto;
suggestionsBox.style.display = 'none';
});
suggestionsBox.appendChild(suggestionItem);
});
} else {
suggestionsBox.style.display = 'none';
}
});

document.addEventListener('click', function(event) {
if (!event.target.closest('#crypto-form')) {
suggestionsBox.style.display = 'none';
}
});

// Convert the input to either the API-friendly name or keep it as it is
let crypto = cryptoMap[cryptoInput] || cryptoInput.toLowerCase();
document.getElementById('predict-btn').addEventListener('click', function() {
const cryptoInputValue = cryptoInput.value.toUpperCase();
const crypto = cryptoMap[cryptoInputValue];

if (crypto) {
fetch(`https://api.coingecko.com/api/v3/simple/price?ids=${crypto}&vs_currencies=usd`)
Expand Down
28 changes: 28 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,32 @@ h1, h2, h3{
}
#repo-info a{
color:#ffee00;
}

#crypto-suggestions {
display: none;
position: absolute;
border: 1px solid #ccc;
border-radius: 5px;
background-color: white;
max-height: 150px;
overflow-y: auto;
width: 384px;
z-index: 1000;
color: #000000;
left: 3rem;
top: 7rem;
}

#crypto-suggestions div {
padding: 10px;
cursor: pointer;
}

#crypto-suggestions div:hover {
background-color: #f0f0f0;
}

#crypto-form {
position: relative;
}