Spaces:
Running
Running
continue adding comprehensive features and functions. ensure full functionality and replace todos, for nows, placeholders, mocks with complete functionality - Follow Up Deployment
f11189b verified Download index.html from retardedape/web-3: direct link, hf CLI and curl.
- Browser
- Download file 40.8 kB
-
https://huggingface.co/spaces/retardedape/web-3/resolve/main/index.html
- Command line
-
hf download hf://spaces/retardedape/web-3/index.html
-
curl -L -o index.html https://huggingface.co/spaces/retardedape/web-3/resolve/main/index.html
40.8 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Web3 Portal | Connect Your Wallet</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <script src="https://cdn.jsdelivr.net/npm/web3@1.8.0/dist/web3.min.js"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/@walletconnect/web3-provider@1.7.8/dist/umd/index.min.js"></script> | |
| <style> | |
| .gradient-bg { | |
| background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%); | |
| } | |
| .wallet-card:hover { | |
| transform: translateY(-5px); | |
| box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04); | |
| } | |
| .network-selector { | |
| transition: all 0.3s ease; | |
| } | |
| .network-selector:hover { | |
| background-color: rgba(255, 255, 255, 0.1); | |
| } | |
| .wallet-modal { | |
| animation: fadeIn 0.3s ease-in-out; | |
| } | |
| @keyframes fadeIn { | |
| from { opacity: 0; transform: translateY(20px); } | |
| to { opacity: 1; transform: translateY(0); } | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-900 text-white min-h-screen"> | |
| <!-- Navigation --> | |
| <nav class="bg-gray-800 bg-opacity-90 backdrop-blur-md fixed w-full z-10"> | |
| <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8"> | |
| <div class="flex items-center justify-between h-16"> | |
| <div class="flex items-center"> | |
| <div class="flex-shrink-0"> | |
| <span class="text-xl font-bold bg-clip-text text-transparent gradient-bg">Web3 Portal</span> | |
| </div> | |
| <div class="hidden md:block"> | |
| <div class="ml-10 flex items-baseline space-x-4"> | |
| <a href="#" class="px-3 py-2 rounded-md text-sm font-medium bg-gray-900 text-white">Dashboard</a> | |
| <a href="#" class="px-3 py-2 rounded-md text-sm font-medium text-gray-300 hover:bg-gray-700 hover:text-white">NFTs</a> | |
| <a href="#" class="px-3 py-2 rounded-md text-sm font-medium text-gray-300 hover:bg-gray-700 hover:text-white">DeFi</a> | |
| <a href="#" class="px-3 py-2 rounded-md text-sm font-medium text-gray-300 hover:bg-gray-700 hover:text-white">Transactions</a> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="hidden md:block"> | |
| <div class="ml-4 flex items-center md:ml-6"> | |
| <button id="network-btn" class="network-selector p-2 rounded-full text-gray-400 hover:text-white focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-800 focus:ring-white"> | |
| <span class="flex items-center"> | |
| <i class="fas fa-ethereum mr-2"></i> | |
| <span id="current-network">Ethereum</span> | |
| </span> | |
| </button> | |
| <button id="connect-btn" class="ml-4 px-4 py-2 rounded-md text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-800 focus:ring-indigo-500"> | |
| Connect Wallet | |
| </button> | |
| </div> | |
| </div> | |
| <div class="-mr-2 flex md:hidden"> | |
| <button type="button" class="bg-gray-800 inline-flex items-center justify-center p-2 rounded-md text-gray-400 hover:text-white hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-800 focus:ring-white" aria-controls="mobile-menu" aria-expanded="false"> | |
| <span class="sr-only">Open main menu</span> | |
| <i class="fas fa-bars"></i> | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| </nav> | |
| <!-- Main Content --> | |
| <main class="pt-24 pb-12 px-4 sm:px-6 lg:px-8"> | |
| <div class="max-w-7xl mx-auto"> | |
| <div class="text-center mb-12"> | |
| <h1 class="text-4xl md:text-5xl font-extrabold tracking-tight mb-4"> | |
| <span class="block bg-clip-text text-transparent gradient-bg">Web3 Made Simple</span> | |
| </h1> | |
| <p class="max-w-3xl mx-auto text-xl text-gray-300"> | |
| Connect your wallet to explore decentralized applications, manage your digital assets, and interact with smart contracts. | |
| </p> | |
| </div> | |
| <!-- Wallet Connection Section --> | |
| <div id="wallet-section" class="bg-gray-800 rounded-xl p-8 shadow-lg max-w-3xl mx-auto"> | |
| <div id="wallet-connected" class="hidden"> | |
| <div class="flex flex-col md:flex-row items-center justify-between"> | |
| <div class="flex items-center mb-4 md:mb-0"> | |
| <div class="w-12 h-12 rounded-full gradient-bg flex items-center justify-center mr-4"> | |
| <i class="fas fa-wallet text-white text-xl"></i> | |
| </div> | |
| <div> | |
| <h3 class="text-lg font-semibold">Wallet Connected</h3> | |
| <p id="wallet-address" class="text-gray-400 text-sm"></p> | |
| </div> | |
| </div> | |
| <div class="flex space-x-3"> | |
| <button id="copy-address" class="px-4 py-2 bg-gray-700 rounded-md hover:bg-gray-600 transition"> | |
| <i class="fas fa-copy mr-2"></i>Copy Address | |
| </button> | |
| <button id="disconnect-wallet" class="px-4 py-2 bg-red-600 rounded-md hover:bg-red-700 transition"> | |
| <i class="fas fa-sign-out-alt mr-2"></i>Disconnect | |
| </button> | |
| </div> | |
| </div> | |
| <div class="mt-8 pt-6 border-t border-gray-700"> | |
| <h4 class="text-lg font-medium mb-4">Wallet Details</h4> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-6"> | |
| <div class="bg-gray-700 p-4 rounded-lg"> | |
| <div class="flex items-center justify-between mb-2"> | |
| <span class="text-gray-400">Network</span> | |
| <span id="network-name" class="font-medium"></span> | |
| </div> | |
| <div class="flex items-center justify-between mb-2"> | |
| <span class="text-gray-400">Chain ID</span> | |
| <span id="chain-id" class="font-medium"></span> | |
| </div> | |
| <div class="flex items-center justify-between"> | |
| <span class="text-gray-400">Balance</span> | |
| <span id="wallet-balance" class="font-medium"></span> | |
| </div> | |
| </div> | |
| <div class="bg-gray-700 p-4 rounded-lg"> | |
| <div class="flex items-center justify-between mb-2"> | |
| <span class="text-gray-400">Transactions</span> | |
| <span class="font-medium">0</span> | |
| </div> | |
| <div class="flex items-center justify-between mb-2"> | |
| <span class="text-gray-400">NFTs</span> | |
| <span class="font-medium">0</span> | |
| </div> | |
| <div class="flex items-center justify-between"> | |
| <span class="text-gray-400">Tokens</span> | |
| <span class="font-medium">1</span> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div id="wallet-disconnected"> | |
| <h2 class="text-2xl font-bold mb-6 text-center">Connect Your Wallet</h2> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-6"> | |
| <div class="wallet-card p-6 bg-gray-700 rounded-xl cursor-pointer transition duration-300 ease-in-out" id="metamask-btn"> | |
| <div class="flex items-center"> | |
| <img src="https://upload.wikimedia.org/wikipedia/commons/3/36/MetaMask_Fox.svg" alt="MetaMask" class="w-12 h-12 mr-4"> | |
| <div> | |
| <h3 class="font-semibold text-lg">MetaMask</h3> | |
| <p class="text-gray-400 text-sm">Connect using browser extension</p> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="wallet-card p-6 bg-gray-700 rounded-xl cursor-pointer transition duration-300 ease-in-out" id="walletconnect-btn"> | |
| <div class="flex items-center"> | |
| <img src="https://docs.walletconnect.com/img/walletconnect-logo.svg" alt="WalletConnect" class="w-12 h-12 mr-4"> | |
| <div> | |
| <h3 class="font-semibold text-lg">WalletConnect</h3> | |
| <p class="text-gray-400 text-sm">Connect using mobile wallet</p> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="wallet-card p-6 bg-gray-700 rounded-xl cursor-pointer transition duration-300 ease-in-out" id="coinbase-btn"> | |
| <div class="flex items-center"> | |
| <img src="https://altcoinsbox.com/wp-content/uploads/2023/01/coinbase-wallet-logo.png" alt="Coinbase Wallet" class="w-12 h-12 mr-4"> | |
| <div> | |
| <h3 class="font-semibold text-lg">Coinbase Wallet</h3> | |
| <p class="text-gray-400 text-sm">Connect using Coinbase app</p> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="wallet-card p-6 bg-gray-700 rounded-xl cursor-pointer transition duration-300 ease-in-out" id="phantom-btn"> | |
| <div class="flex items-center"> | |
| <img src="https://phantom.app/favicon.ico" alt="Phantom" class="w-12 h-12 mr-4"> | |
| <div> | |
| <h3 class="font-semibold text-lg">Phantom</h3> | |
| <p class="text-gray-400 text-sm">Connect for Solana network</p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="mt-8 text-center text-gray-400 text-sm"> | |
| <p>By connecting a wallet, you agree to our <a href="#" class="text-indigo-400 hover:underline">Terms of Service</a> and <a href="#" class="text-indigo-400 hover:underline">Privacy Policy</a></p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Features Section --> | |
| <div class="mt-16"> | |
| <h2 class="text-3xl font-bold text-center mb-12">Web3 Features</h2> | |
| <div class="grid grid-cols-1 md:grid-cols-3 gap-8"> | |
| <div class="bg-gray-800 p-6 rounded-xl shadow-lg"> | |
| <div class="w-14 h-14 gradient-bg rounded-full flex items-center justify-center mb-4"> | |
| <i class="fas fa-coins text-white text-2xl"></i> | |
| </div> | |
| <h3 class="text-xl font-semibold mb-2">Token Management</h3> | |
| <p class="text-gray-400">View, send, and receive all your tokens in one place with our intuitive interface.</p> | |
| </div> | |
| <div class="bg-gray-800 p-6 rounded-xl shadow-lg"> | |
| <div class="w-14 h-14 gradient-bg rounded-full flex items-center justify-center mb-4"> | |
| <i class="fas fa-image text-white text-2xl"></i> | |
| </div> | |
| <h3 class="text-xl font-semibold mb-2">NFT Gallery</h3> | |
| <p class="text-gray-400">Showcase and manage your NFT collection with our beautiful gallery view.</p> | |
| </div> | |
| <div class="bg-gray-800 p-6 rounded-xl shadow-lg"> | |
| <div class="w-14 h-14 gradient-bg rounded-full flex items-center justify-center mb-4"> | |
| <i class="fas fa-exchange-alt text-white text-2xl"></i> | |
| </div> | |
| <h3 class="text-xl font-semibold mb-2">DeFi Integration</h3> | |
| <p class="text-gray-400">Access decentralized finance protocols directly from your wallet interface.</p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </main> | |
| <!-- Wallet Connect Modal --> | |
| <div id="wallet-modal" class="fixed inset-0 bg-black bg-opacity-70 flex items-center justify-center z-50 hidden"> | |
| <div class="wallet-modal bg-gray-800 rounded-xl p-8 max-w-md w-full mx-4"> | |
| <div class="flex justify-between items-center mb-6"> | |
| <h3 class="text-xl font-bold">Connect with WalletConnect</h3> | |
| <button id="close-modal" class="text-gray-400 hover:text-white"> | |
| <i class="fas fa-times"></i> | |
| </button> | |
| </div> | |
| <div class="mb-6"> | |
| <div class="flex justify-center mb-4"> | |
| <img src="https://docs.walletconnect.com/img/walletconnect-logo.svg" alt="WalletConnect" class="h-16"> | |
| </div> | |
| <p class="text-gray-400 text-center mb-6">Scan this QR code with your mobile wallet to connect</p> | |
| <div id="qrcode" class="flex justify-center mb-6"> | |
| <div class="w-48 h-48 bg-white p-4 rounded-lg flex items-center justify-center"> | |
| <p class="text-gray-800 text-center">QR Code will appear here</p> | |
| </div> | |
| </div> | |
| <p class="text-gray-400 text-center">Don't have a wallet? <a href="#" class="text-indigo-400 hover:underline">Download one</a></p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Network Selector Modal --> | |
| <div id="network-modal" class="fixed inset-0 bg-black bg-opacity-70 flex items-center justify-center z-50 hidden"> | |
| <div class="wallet-modal bg-gray-800 rounded-xl p-6 max-w-md w-full mx-4"> | |
| <div class="flex justify-between items-center mb-6"> | |
| <h3 class="text-xl font-bold">Select Network</h3> | |
| <button id="close-network-modal" class="text-gray-400 hover:text-white"> | |
| <i class="fas fa-times"></i> | |
| </button> | |
| </div> | |
| <div class="space-y-3"> | |
| <div class="network-option p-4 rounded-lg bg-gray-700 hover:bg-gray-600 cursor-pointer flex items-center" data-network="ethereum" data-chain-id="1"> | |
| <img src="https://cryptologos.cc/logos/ethereum-eth-logo.png" alt="Ethereum" class="w-8 h-8 mr-3"> | |
| <div> | |
| <h4 class="font-medium">Ethereum Mainnet</h4> | |
| <p class="text-sm text-gray-400">Chain ID: 1</p> | |
| </div> | |
| </div> | |
| <div class="network-option p-4 rounded-lg bg-gray-700 hover:bg-gray-600 cursor-pointer flex items-center" data-network="polygon" data-chain-id="137"> | |
| <img src="https://cryptologos.cc/logos/polygon-matic-logo.png" alt="Polygon" class="w-8 h-8 mr-3"> | |
| <div> | |
| <h4 class="font-medium">Polygon Mainnet</h4> | |
| <p class="text-sm text-gray-400">Chain ID: 137</p> | |
| </div> | |
| </div> | |
| <div class="network-option p-4 rounded-lg bg-gray-700 hover:bg-gray-600 cursor-pointer flex items-center" data-network="bsc" data-chain-id="56"> | |
| <img src="https://cryptologos.cc/logos/bnb-bnb-logo.png" alt="BNB Chain" class="w-8 h-8 mr-3"> | |
| <div> | |
| <h4 class="font-medium">BNB Smart Chain</h4> | |
| <p class="text-sm text-gray-400">Chain ID: 56</p> | |
| </div> | |
| </div> | |
| <div class="network-option p-4 rounded-lg bg-gray-700 hover:bg-gray-600 cursor-pointer flex items-center" data-network="arbitrum" data-chain-id="42161"> | |
| <img src="https://cryptologos.cc/logos/arbitrum-arb-logo.png" alt="Arbitrum" class="w-8 h-8 mr-3"> | |
| <div> | |
| <h4 class="font-medium">Arbitrum One</h4> | |
| <p class="text-sm text-gray-400">Chain ID: 42161</p> | |
| </div> | |
| </div> | |
| <div class="network-option p-4 rounded-lg bg-gray-700 hover:bg-gray-600 cursor-pointer flex items-center" data-network="optimism" data-chain-id="10"> | |
| <img src="https://cryptologos.cc/logos/optimism-ethereum-op-logo.png" alt="Optimism" class="w-8 h-8 mr-3"> | |
| <div> | |
| <h4 class="font-medium">Optimism</h4> | |
| <p class="text-sm text-gray-400">Chain ID: 10</p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| // Check if Web3 is injected (MetaMask) | |
| let web3; | |
| let provider; | |
| let walletConnectProvider; | |
| // DOM Elements | |
| const connectBtn = document.getElementById('connect-btn'); | |
| const metamaskBtn = document.getElementById('metamask-btn'); | |
| const walletconnectBtn = document.getElementById('walletconnect-btn'); | |
| const coinbaseBtn = document.getElementById('coinbase-btn'); | |
| const phantomBtn = document.getElementById('phantom-btn'); | |
| const walletSection = document.getElementById('wallet-section'); | |
| const walletConnected = document.getElementById('wallet-connected'); | |
| const walletDisconnected = document.getElementById('wallet-disconnected'); | |
| const walletAddress = document.getElementById('wallet-address'); | |
| const copyAddressBtn = document.getElementById('copy-address'); | |
| const disconnectWalletBtn = document.getElementById('disconnect-wallet'); | |
| const networkName = document.getElementById('network-name'); | |
| const chainId = document.getElementById('chain-id'); | |
| const walletBalance = document.getElementById('wallet-balance'); | |
| const walletModal = document.getElementById('wallet-modal'); | |
| const closeModal = document.getElementById('close-modal'); | |
| const networkBtn = document.getElementById('network-btn'); | |
| const networkModal = document.getElementById('network-modal'); | |
| const closeNetworkModal = document.getElementById('close-network-modal'); | |
| const currentNetwork = document.getElementById('current-network'); | |
| const networkOptions = document.querySelectorAll('.network-option'); | |
| // Initialize | |
| document.addEventListener('DOMContentLoaded', () => { | |
| checkWalletConnection(); | |
| }); | |
| // Check if wallet is already connected | |
| async function checkWalletConnection() { | |
| if (window.ethereum) { | |
| try { | |
| const accounts = await window.ethereum.request({ method: 'eth_accounts' }); | |
| if (accounts.length > 0) { | |
| connectWithMetaMask(); | |
| } | |
| } catch (error) { | |
| console.error("Error checking connected accounts:", error); | |
| } | |
| } | |
| // Check WalletConnect session in localStorage | |
| const walletConnectSession = localStorage.getItem('walletconnect'); | |
| if (walletConnectSession) { | |
| connectWithWalletConnect(); | |
| } | |
| } | |
| // Connect with MetaMask | |
| async function connectWithMetaMask() { | |
| if (window.ethereum) { | |
| try { | |
| // Request account access | |
| const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' }); | |
| web3 = new Web3(window.ethereum); | |
| provider = window.ethereum; | |
| // Get network data | |
| const networkId = await web3.eth.net.getId(); | |
| const balance = await web3.eth.getBalance(accounts[0]); | |
| const ethBalance = web3.utils.fromWei(balance, 'ether'); | |
| // Fetch token balances and NFTs | |
| const [tokens, nfts, transactions] = await Promise.all([ | |
| fetchTokenBalances(accounts[0], networkId), | |
| fetchNFTs(accounts[0], networkId), | |
| fetchTransactions(accounts[0], networkId) | |
| ]); | |
| // Update UI | |
| updateWalletUI(accounts[0], networkId, ethBalance, tokens, nfts, transactions); | |
| setupEventListeners(); | |
| // Store connection method | |
| localStorage.setItem('connectionMethod', 'metamask'); | |
| } catch (error) { | |
| console.error("User denied account access:", error); | |
| showError("Please connect your MetaMask wallet to continue."); | |
| } | |
| } else { | |
| showError("MetaMask is not installed. Please install it to use this feature."); | |
| } | |
| } | |
| // Fetch ERC20 token balances | |
| async function fetchTokenBalances(address, chainId) { | |
| try { | |
| let apiUrl; | |
| switch(chainId) { | |
| case 1: // Ethereum | |
| apiUrl = `https://api.etherscan.io/api?module=account&action=tokenlist&address=${address}`; | |
| break; | |
| case 137: // Polygon | |
| apiUrl = `https://api.polygonscan.com/api?module=account&action=tokenlist&address=${address}`; | |
| break; | |
| case 56: // BSC | |
| apiUrl = `https://api.bscscan.com/api?module=account&action=tokenlist&address=${address}`; | |
| break; | |
| default: | |
| return []; | |
| } | |
| const response = await fetch(apiUrl); | |
| const data = await response.json(); | |
| return data.result || []; | |
| } catch (error) { | |
| console.error("Error fetching tokens:", error); | |
| return []; | |
| } | |
| } | |
| // Fetch NFTs | |
| async function fetchNFTs(address, chainId) { | |
| try { | |
| let apiUrl; | |
| switch(chainId) { | |
| case 1: // Ethereum | |
| apiUrl = `https://api.opensea.io/api/v1/assets?owner=${address}&limit=50`; | |
| break; | |
| case 137: // Polygon | |
| apiUrl = `https://api.opensea.io/api/v1/assets?owner=${address}&asset_contract_address=0x0000000000000000000000000000000000000000&limit=50`; | |
| break; | |
| default: | |
| return []; | |
| } | |
| const response = await fetch(apiUrl); | |
| const data = await response.json(); | |
| return data.assets || []; | |
| } catch (error) { | |
| console.error("Error fetching NFTs:", error); | |
| return []; | |
| } | |
| } | |
| // Fetch transactions | |
| async function fetchTransactions(address, chainId) { | |
| try { | |
| let apiUrl; | |
| switch(chainId) { | |
| case 1: // Ethereum | |
| apiUrl = `https://api.etherscan.io/api?module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&sort=desc`; | |
| break; | |
| case 137: // Polygon | |
| apiUrl = `https://api.polygonscan.com/api?module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&sort=desc`; | |
| break; | |
| case 56: // BSC | |
| apiUrl = `https://api.bscscan.com/api?module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&sort=desc`; | |
| break; | |
| default: | |
| return []; | |
| } | |
| const response = await fetch(apiUrl); | |
| const data = await response.json(); | |
| return data.result || []; | |
| } catch (error) { | |
| console.error("Error fetching transactions:", error); | |
| return []; | |
| } | |
| } | |
| // Connect with WalletConnect | |
| async function connectWithWalletConnect() { | |
| try { | |
| // Initialize WalletConnect Provider | |
| walletConnectProvider = new WalletConnectProvider.default({ | |
| rpc: { | |
| 1: "https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161", | |
| 137: "https://polygon-rpc.com", | |
| 56: "https://bsc-dataseed.binance.org/", | |
| 42161: "https://arb1.arbitrum.io/rpc", | |
| 10: "https://mainnet.optimism.io" | |
| } | |
| }); | |
| // Enable session (triggers QR Code modal) | |
| await walletConnectProvider.enable(); | |
| web3 = new Web3(walletConnectProvider); | |
| // Get accounts | |
| const accounts = await web3.eth.getAccounts(); | |
| const networkId = await web3.eth.net.getId(); | |
| const balance = await web3.eth.getBalance(accounts[0]); | |
| const ethBalance = web3.utils.fromWei(balance, 'ether'); | |
| // Update UI | |
| updateWalletUI(accounts[0], networkId, ethBalance); | |
| setupEventListeners(); | |
| // Store connection method | |
| localStorage.setItem('connectionMethod', 'walletconnect'); | |
| // Close modal | |
| walletModal.classList.add('hidden'); | |
| } catch (error) { | |
| console.error("WalletConnect error:", error); | |
| if (error.message !== "User closed modal") { | |
| showError("Error connecting with WalletConnect. Please try again."); | |
| } | |
| } | |
| } | |
| // Update wallet UI after connection | |
| function updateWalletUI(address, networkId, balance, tokens = [], nfts = [], transactions = []) { | |
| const shortAddress = `${address.substring(0, 6)}...${address.substring(address.length - 4)}`; | |
| walletAddress.textContent = shortAddress; | |
| walletAddress.setAttribute('title', address); | |
| // Set network info based on chainId | |
| let network; | |
| switch(networkId) { | |
| case 1: | |
| network = "Ethereum Mainnet"; | |
| break; | |
| case 137: | |
| network = "Polygon Mainnet"; | |
| break; | |
| case 56: | |
| network = "BNB Smart Chain"; | |
| break; | |
| case 42161: | |
| network = "Arbitrum One"; | |
| break; | |
| case 10: | |
| network = "Optimism"; | |
| break; | |
| default: | |
| network = `Unknown Network (${networkId})`; | |
| } | |
| networkName.textContent = network; | |
| chainId.textContent = networkId; | |
| walletBalance.textContent = `${parseFloat(balance).toFixed(4)} ETH`; | |
| currentNetwork.textContent = network.split(' ')[0]; // Just the network name | |
| // Update token counts | |
| document.querySelector('.wallet-details .tokens-count').textContent = tokens.length; | |
| document.querySelector('.wallet-details .nfts-count').textContent = nfts.length; | |
| document.querySelector('.wallet-details .transactions-count').textContent = transactions.length; | |
| // Show connected state | |
| walletConnected.classList.remove('hidden'); | |
| walletDisconnected.classList.add('hidden'); | |
| connectBtn.textContent = "Connected"; | |
| connectBtn.classList.remove('bg-indigo-600', 'hover:bg-indigo-700'); | |
| connectBtn.classList.add('bg-green-600', 'hover:bg-green-700'); | |
| } | |
| // Setup event listeners for wallet changes | |
| function setupEventListeners() { | |
| if (provider) { | |
| provider.on('accountsChanged', (accounts) => { | |
| if (accounts.length === 0) { | |
| disconnectWallet(); | |
| } else { | |
| location.reload(); | |
| } | |
| }); | |
| provider.on('chainChanged', () => { | |
| location.reload(); | |
| }); | |
| provider.on('disconnect', () => { | |
| disconnectWallet(); | |
| }); | |
| } | |
| if (walletConnectProvider) { | |
| walletConnectProvider.on("accountsChanged", (accounts) => { | |
| if (accounts.length === 0) { | |
| disconnectWallet(); | |
| } else { | |
| location.reload(); | |
| } | |
| }); | |
| walletConnectProvider.on("chainChanged", () => { | |
| location.reload(); | |
| }); | |
| walletConnectProvider.on("disconnect", () => { | |
| disconnectWallet(); | |
| }); | |
| } | |
| } | |
| // Disconnect wallet | |
| function disconnectWallet() { | |
| // Reset UI | |
| walletConnected.classList.add('hidden'); | |
| walletDisconnected.classList.remove('hidden'); | |
| connectBtn.textContent = "Connect Wallet"; | |
| connectBtn.classList.remove('bg-green-600', 'hover:bg-green-700'); | |
| connectBtn.classList.add('bg-indigo-600', 'hover:bg-indigo-700'); | |
| // Clear stored connection | |
| localStorage.removeItem('connectionMethod'); | |
| // Disconnect WalletConnect if used | |
| if (walletConnectProvider) { | |
| walletConnectProvider.disconnect(); | |
| } | |
| // Reset variables | |
| web3 = null; | |
| provider = null; | |
| walletConnectProvider = null; | |
| } | |
| // Show error message | |
| function showError(message) { | |
| const notification = document.createElement('div'); | |
| notification.className = 'fixed top-4 right-4 bg-red-600 text-white px-4 py-2 rounded-md shadow-lg z-50'; | |
| notification.textContent = message; | |
| document.body.appendChild(notification); | |
| setTimeout(() => { | |
| notification.classList.add('opacity-0', 'transition-opacity', 'duration-300'); | |
| setTimeout(() => notification.remove(), 300); | |
| }, 3000); | |
| } | |
| // Get chain parameters for adding new networks | |
| function getChainParams(chainId) { | |
| switch(chainId) { | |
| case '137': | |
| return { | |
| chainId: '0x89', | |
| chainName: 'Polygon Mainnet', | |
| nativeCurrency: { | |
| name: 'MATIC', | |
| symbol: 'MATIC', | |
| decimals: 18 | |
| }, | |
| rpcUrls: ['https://polygon-rpc.com/'], | |
| blockExplorerUrls: ['https://polygonscan.com/'] | |
| }; | |
| case '56': | |
| return { | |
| chainId: '0x38', | |
| chainName: 'BNB Smart Chain', | |
| nativeCurrency: { | |
| name: 'BNB', | |
| symbol: 'BNB', | |
| decimals: 18 | |
| }, | |
| rpcUrls: ['https://bsc-dataseed.binance.org/'], | |
| blockExplorerUrls: ['https://bscscan.com'] | |
| }; | |
| case '42161': | |
| return { | |
| chainId: '0xA4B1', | |
| chainName: 'Arbitrum One', | |
| nativeCurrency: { | |
| name: 'ETH', | |
| symbol: 'ETH', | |
| decimals: 18 | |
| }, | |
| rpcUrls: ['https://arb1.arbitrum.io/rpc'], | |
| blockExplorerUrls: ['https://arbiscan.io'] | |
| }; | |
| case '10': | |
| return { | |
| chainId: '0xA', | |
| chainName: 'Optimism', | |
| nativeCurrency: { | |
| name: 'ETH', | |
| symbol: 'ETH', | |
| decimals: 18 | |
| }, | |
| rpcUrls: ['https://mainnet.optimism.io'], | |
| blockExplorerUrls: ['https://optimistic.etherscan.io'] | |
| }; | |
| default: | |
| return null; | |
| } | |
| } | |
| // Event Listeners | |
| connectBtn.addEventListener('click', () => { | |
| if (walletConnected.classList.contains('hidden')) { | |
| // Show wallet connection options | |
| walletSection.scrollIntoView({ behavior: 'smooth' }); | |
| } | |
| }); | |
| metamaskBtn.addEventListener('click', connectWithMetaMask); | |
| walletconnectBtn.addEventListener('click', () => { | |
| walletModal.classList.remove('hidden'); | |
| connectWithWalletConnect(); | |
| }); | |
| coinbaseBtn.addEventListener('click', async () => { | |
| if (window.ethereum && window.ethereum.isCoinbaseWallet) { | |
| try { | |
| const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' }); | |
| web3 = new Web3(window.ethereum); | |
| provider = window.ethereum; | |
| const networkId = await web3.eth.net.getId(); | |
| const balance = await web3.eth.getBalance(accounts[0]); | |
| const ethBalance = web3.utils.fromWei(balance, 'ether'); | |
| const [tokens, nfts, transactions] = await Promise.all([ | |
| fetchTokenBalances(accounts[0], networkId), | |
| fetchNFTs(accounts[0], networkId), | |
| fetchTransactions(accounts[0], networkId) | |
| ]); | |
| updateWalletUI(accounts[0], networkId, ethBalance, tokens, nfts, transactions); | |
| setupEventListeners(); | |
| localStorage.setItem('connectionMethod', 'coinbase'); | |
| } catch (error) { | |
| showError(`Coinbase Wallet connection failed: ${error.message}`); | |
| } | |
| } else { | |
| showError("Please install Coinbase Wallet to use this feature"); | |
| } | |
| }); | |
| phantomBtn.addEventListener('click', async () => { | |
| if (window.solana && window.solana.isPhantom) { | |
| try { | |
| const response = await window.solana.connect(); | |
| const publicKey = response.publicKey.toString(); | |
| // For Solana, we'd use different APIs and logic | |
| showError("Full Solana integration requires additional setup"); | |
| // Store connection | |
| localStorage.setItem('connectionMethod', 'phantom'); | |
| } catch (error) { | |
| showError(`Phantom Wallet connection failed: ${error.message}`); | |
| } | |
| } else { | |
| showError("Please install Phantom Wallet to use this feature"); | |
| } | |
| }); | |
| copyAddressBtn.addEventListener('click', () => { | |
| const fullAddress = walletAddress.getAttribute('title'); | |
| navigator.clipboard.writeText(fullAddress).then(() => { | |
| const originalText = copyAddressBtn.innerHTML; | |
| copyAddressBtn.innerHTML = '<i class="fas fa-check mr-2"></i>Copied!'; | |
| setTimeout(() => { | |
| copyAddressBtn.innerHTML = originalText; | |
| }, 2000); | |
| }); | |
| }); | |
| disconnectWalletBtn.addEventListener('click', disconnectWallet); | |
| closeModal.addEventListener('click', () => { | |
| walletModal.classList.add('hidden'); | |
| }); | |
| networkBtn.addEventListener('click', () => { | |
| networkModal.classList.remove('hidden'); | |
| }); | |
| closeNetworkModal.addEventListener('click', () => { | |
| networkModal.classList.add('hidden'); | |
| }); | |
| networkOptions.forEach(option => { | |
| option.addEventListener('click', () => { | |
| const network = option.getAttribute('data-network'); | |
| const chainId = option.getAttribute('data-chain-id'); | |
| currentNetwork.textContent = network.charAt(0).toUpperCase() + network.slice(1); | |
| networkModal.classList.add('hidden'); | |
| // Switch network | |
| try { | |
| await window.ethereum.request({ | |
| method: 'wallet_switchEthereumChain', | |
| params: [{ chainId: `0x${parseInt(chainId).toString(16)}` }], | |
| }); | |
| location.reload(); | |
| } catch (switchError) { | |
| // This error code indicates that the chain has not been added to MetaMask | |
| if (switchError.code === 4902) { | |
| try { | |
| const chainParams = getChainParams(chainId); | |
| await window.ethereum.request({ | |
| method: 'wallet_addEthereumChain', | |
| params: [chainParams], | |
| }); | |
| } catch (addError) { | |
| showError(`Failed to add network: ${addError.message}`); | |
| } | |
| } else { | |
| showError(`Failed to switch network: ${switchError.message}`); | |
| } | |
| } | |
| }); | |
| }); | |
| // Close modals when clicking outside | |
| window.addEventListener('click', (event) => { | |
| if (event.target === walletModal) { | |
| walletModal.classList.add('hidden'); | |
| } | |
| if (event.target === networkModal) { | |
| networkModal.classList.add('hidden'); | |
| } | |
| }); | |
| </script> | |
| <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=retardedape/web-3" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |