49 lines
2.0 KiB
JavaScript
49 lines
2.0 KiB
JavaScript
document.addEventListener('DOMContentLoaded', () => {
|
|
const connectWalletButton = document.getElementById('connectWallet');
|
|
const swapTokenButton = document.getElementById('swapToken');
|
|
const generateApiKeyButton = document.getElementById('generate-api-key');
|
|
const apiKeyDisplay = document.getElementById('api-key-display');
|
|
|
|
if (connectWalletButton) {
|
|
connectWalletButton.addEventListener('click', async () => {
|
|
try {
|
|
const { solana } = window;
|
|
if (solana && solana.isPhantom) {
|
|
const response = await solana.connect({ onlyIfTrusted: true });
|
|
console.log('Connected with Public Key:', response.publicKey.toString());
|
|
} else {
|
|
alert('Phantom wallet not found. Please install it.');
|
|
}
|
|
} catch (error) {
|
|
console.error(error);
|
|
alert('Connection to Phantom Wallet failed');
|
|
}
|
|
});
|
|
}
|
|
|
|
if (swapTokenButton) {
|
|
swapTokenButton.addEventListener('click', () => {
|
|
const tokenName = document.getElementById('tokenName').value;
|
|
const amount = document.getElementById('amount').value;
|
|
fetch('/swap', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({token_name: tokenName, amount: amount})
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => alert(data.message));
|
|
});
|
|
}
|
|
|
|
if (generateApiKeyButton) {
|
|
generateApiKeyButton.addEventListener('click', async () => {
|
|
const response = await fetch('/generate_api_key', { method: 'POST' });
|
|
const data = await response.json();
|
|
apiKeyDisplay.textContent = `Your API Key: ${data.api_key}`;
|
|
});
|
|
}
|
|
|
|
// Add more JavaScript for fetching and displaying wallet data, transactions, and holdings
|
|
}); |