Spaces:
Running
Running
Download index.html from mottled/cyberlancer: direct link, hf CLI and curl.
- Browser
- Download file 41.2 kB
-
https://huggingface.co/spaces/mottled/cyberlancer/resolve/main/index.html
- Command line
-
hf download hf://spaces/mottled/cyberlancer/index.html
-
curl -L -o index.html https://huggingface.co/spaces/mottled/cyberlancer/resolve/main/index.html
41.2 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Polygon Token Escrow Platform</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.ethers.io/lib/ethers-5.7.umd.min.js" type="application/javascript"></script> | |
| <style> | |
| .gradient-bg { | |
| background: linear-gradient(135deg, #8e2de2 0%, #4a00e0 100%); | |
| } | |
| .token-logo { | |
| width: 40px; | |
| height: 40px; | |
| border-radius: 50%; | |
| object-fit: cover; | |
| border: 2px solid white; | |
| } | |
| .escrow-card { | |
| transition: all 0.3s ease; | |
| border-left: 4px solid #8e2de2; | |
| } | |
| .escrow-card:hover { | |
| transform: translateY(-5px); | |
| box-shadow: 0 10px 20px rgba(0,0,0,0.1); | |
| } | |
| .status-badge { | |
| padding: 4px 8px; | |
| border-radius: 12px; | |
| font-size: 12px; | |
| font-weight: 600; | |
| } | |
| .status-active { | |
| background-color: #d1fae5; | |
| color: #065f46; | |
| } | |
| .status-completed { | |
| background-color: #e0f2fe; | |
| color: #0369a1; | |
| } | |
| .status-disputed { | |
| background-color: #fee2e2; | |
| color: #b91c1c; | |
| } | |
| .connect-wallet-btn { | |
| transition: all 0.3s ease; | |
| } | |
| .connect-wallet-btn:hover { | |
| transform: scale(1.05); | |
| } | |
| .modal-overlay { | |
| background-color: rgba(0,0,0,0.5); | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-50 min-h-screen"> | |
| <!-- Header --> | |
| <header class="gradient-bg text-white shadow-lg"> | |
| <div class="container mx-auto px-4 py-6"> | |
| <div class="flex justify-between items-center"> | |
| <div class="flex items-center space-x-2"> | |
| <img src="https://cryptologos.cc/logos/polygon-matic-logo.png" alt="Polygon Logo" class="h-10"> | |
| <h1 class="text-2xl font-bold">Token Escrow</h1> | |
| </div> | |
| <button id="connectWalletBtn" class="connect-wallet-btn bg-white text-purple-700 px-6 py-2 rounded-full font-semibold flex items-center space-x-2"> | |
| <i class="fas fa-wallet"></i> | |
| <span>Connect Wallet</span> | |
| </button> | |
| </div> | |
| </div> | |
| </header> | |
| <!-- Main Content --> | |
| <main class="container mx-auto px-4 py-8"> | |
| <!-- Wallet Connected Info --> | |
| <div id="walletInfo" class="hidden bg-white rounded-lg shadow-md p-6 mb-8"> | |
| <div class="flex justify-between items-center"> | |
| <div class="flex items-center space-x-4"> | |
| <div class="bg-purple-100 p-3 rounded-full"> | |
| <i class="fas fa-wallet text-purple-700 text-xl"></i> | |
| </div> | |
| <div> | |
| <h3 class="font-semibold text-gray-800">Connected Wallet</h3> | |
| <p id="walletAddress" class="text-gray-500 text-sm truncate max-w-xs"></p> | |
| </div> | |
| </div> | |
| <div class="flex items-center space-x-4"> | |
| <div class="text-right"> | |
| <h3 class="font-semibold text-gray-800">Network</h3> | |
| <p id="networkInfo" class="text-gray-500 text-sm">Polygon Mainnet</p> | |
| </div> | |
| <div class="bg-blue-100 p-3 rounded-full"> | |
| <i class="fas fa-network-wired text-blue-700 text-xl"></i> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Token Balance Card --> | |
| <div id="tokenBalanceCard" class="hidden bg-white rounded-lg shadow-md p-6 mb-8"> | |
| <div class="flex justify-between items-center"> | |
| <div class="flex items-center space-x-4"> | |
| <img id="tokenLogo" src="https://cryptologos.cc/logos/polygon-matic-logo.png" alt="Token Logo" class="token-logo"> | |
| <div> | |
| <h3 class="font-semibold text-gray-800">Your Balance</h3> | |
| <div class="flex items-center space-x-2"> | |
| <p id="tokenBalance" class="text-2xl font-bold text-gray-900">0.00</p> | |
| <span id="tokenSymbol" class="text-gray-500">TOKEN</span> | |
| </div> | |
| </div> | |
| </div> | |
| <button id="createEscrowBtn" class="bg-purple-600 hover:bg-purple-700 text-white px-6 py-3 rounded-lg font-semibold flex items-center space-x-2"> | |
| <i class="fas fa-plus"></i> | |
| <span>Create Escrow</span> | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Tabs --> | |
| <div class="flex border-b border-gray-200 mb-8"> | |
| <button id="activeTab" class="tab-btn px-6 py-3 font-medium text-purple-700 border-b-2 border-purple-700">Active Escrows</button> | |
| <button id="completedTab" class="tab-btn px-6 py-3 font-medium text-gray-500 hover:text-purple-700">Completed</button> | |
| <button id="disputedTab" class="tab-btn px-6 py-3 font-medium text-gray-500 hover:text-purple-700">Disputed</button> | |
| </div> | |
| <!-- Escrow List --> | |
| <div id="escrowList" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"> | |
| <!-- Placeholder for escrow cards --> | |
| <div class="text-center py-12"> | |
| <i class="fas fa-lock text-gray-300 text-4xl mb-4"></i> | |
| <p class="text-gray-500">Connect your wallet to view escrow transactions</p> | |
| </div> | |
| </div> | |
| </main> | |
| <!-- Create Escrow Modal --> | |
| <div id="createEscrowModal" class="fixed inset-0 z-50 hidden items-center justify-center modal-overlay"> | |
| <div class="bg-white rounded-lg shadow-xl w-full max-w-md"> | |
| <div class="p-6"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h3 class="text-xl font-bold text-gray-800">Create New Escrow</h3> | |
| <button id="closeModalBtn" class="text-gray-500 hover:text-gray-700"> | |
| <i class="fas fa-times"></i> | |
| </button> | |
| </div> | |
| <form id="escrowForm" class="space-y-4"> | |
| <div> | |
| <label for="tokenSelect" class="block text-sm font-medium text-gray-700 mb-1">Token</label> | |
| <select id="tokenSelect" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-purple-500 focus:border-purple-500"> | |
| <option value="">Select Token</option> | |
| <!-- Tokens will be populated dynamically --> | |
| </select> | |
| </div> | |
| <div> | |
| <label for="receiverAddress" class="block text-sm font-medium text-gray-700 mb-1">Receiver Address</label> | |
| <input type="text" id="receiverAddress" placeholder="0x..." class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-purple-500 focus:border-purple-500"> | |
| </div> | |
| <div> | |
| <label for="amount" class="block text-sm font-medium text-gray-700 mb-1">Amount</label> | |
| <div class="relative"> | |
| <input type="number" id="amount" step="0.01" placeholder="0.00" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-purple-500 focus:border-purple-500 pr-16"> | |
| <div class="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none"> | |
| <span id="tokenSymbolModal" class="text-gray-500">TOKEN</span> | |
| </div> | |
| </div> | |
| </div> | |
| <div> | |
| <label for="releaseCondition" class="block text-sm font-medium text-gray-700 mb-1">Release Condition</label> | |
| <textarea id="releaseCondition" rows="3" placeholder="Describe the conditions for releasing the funds..." class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-purple-500 focus:border-purple-500"></textarea> | |
| </div> | |
| <div> | |
| <label for="arbitrator" class="block text-sm font-medium text-gray-700 mb-1">Arbitrator (Optional)</label> | |
| <input type="text" id="arbitrator" placeholder="0x..." class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-purple-500 focus:border-purple-500"> | |
| <p class="text-xs text-gray-500 mt-1">Address of a trusted third party to resolve disputes</p> | |
| </div> | |
| <div class="pt-4"> | |
| <button type="submit" class="w-full bg-purple-600 hover:bg-purple-700 text-white px-6 py-3 rounded-lg font-semibold"> | |
| Create Escrow Contract | |
| </button> | |
| </div> | |
| </form> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Escrow Detail Modal --> | |
| <div id="escrowDetailModal" class="fixed inset-0 z-50 hidden items-center justify-center modal-overlay"> | |
| <div class="bg-white rounded-lg shadow-xl w-full max-w-2xl"> | |
| <div class="p-6"> | |
| <div class="flex justify-between items-center mb-6"> | |
| <h3 class="text-xl font-bold text-gray-800">Escrow Details</h3> | |
| <button id="closeDetailModalBtn" class="text-gray-500 hover:text-gray-700"> | |
| <i class="fas fa-times"></i> | |
| </button> | |
| </div> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6"> | |
| <div class="bg-gray-50 p-4 rounded-lg"> | |
| <h4 class="font-medium text-gray-700 mb-2">Transaction Information</h4> | |
| <div class="space-y-3"> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-500">Escrow ID:</span> | |
| <span id="detailId" class="font-medium">#12345</span> | |
| </div> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-500">Status:</span> | |
| <span id="detailStatus" class="status-badge status-active">Active</span> | |
| </div> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-500">Created:</span> | |
| <span id="detailCreated" class="font-medium">2023-05-15</span> | |
| </div> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-500">Expires:</span> | |
| <span id="detailExpires" class="font-medium">2023-06-15</span> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="bg-gray-50 p-4 rounded-lg"> | |
| <h4 class="font-medium text-gray-700 mb-2">Token Information</h4> | |
| <div class="space-y-3"> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-500">Token:</span> | |
| <div class="flex items-center space-x-2"> | |
| <img id="detailTokenLogo" src="https://cryptologos.cc/logos/polygon-matic-logo.png" alt="Token Logo" class="h-5"> | |
| <span id="detailTokenSymbol" class="font-medium">MATIC</span> | |
| </div> | |
| </div> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-500">Amount:</span> | |
| <span id="detailAmount" class="font-medium">100.00</span> | |
| </div> | |
| <div class="flex justify-between"> | |
| <span class="text-gray-500">Value:</span> | |
| <span id="detailValue" class="font-medium">$85.00</span> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6"> | |
| <div class="bg-gray-50 p-4 rounded-lg"> | |
| <h4 class="font-medium text-gray-700 mb-2">Parties</h4> | |
| <div class="space-y-3"> | |
| <div> | |
| <p class="text-gray-500 text-sm">Sender</p> | |
| <p id="detailSender" class="font-medium truncate">0x123...4567</p> | |
| </div> | |
| <div> | |
| <p class="text-gray-500 text-sm">Receiver</p> | |
| <p id="detailReceiver" class="font-medium truncate">0x789...0123</p> | |
| </div> | |
| <div> | |
| <p class="text-gray-500 text-sm">Arbitrator</p> | |
| <p id="detailArbitrator" class="font-medium truncate">0x456...7890</p> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="bg-gray-50 p-4 rounded-lg"> | |
| <h4 class="font-medium text-gray-700 mb-2">Conditions</h4> | |
| <p id="detailConditions" class="text-gray-700">Funds will be released upon successful delivery of the product as described in the agreement.</p> | |
| </div> | |
| </div> | |
| <div class="bg-gray-50 p-4 rounded-lg mb-6"> | |
| <h4 class="font-medium text-gray-700 mb-2">Actions</h4> | |
| <div class="flex flex-wrap gap-3"> | |
| <button id="releaseFundsBtn" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg font-medium"> | |
| <i class="fas fa-check-circle mr-2"></i> Release Funds | |
| </button> | |
| <button id="disputeBtn" class="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-lg font-medium"> | |
| <i class="fas fa-exclamation-triangle mr-2"></i> Raise Dispute | |
| </button> | |
| <button id="cancelEscrowBtn" class="bg-gray-600 hover:bg-gray-700 text-white px-4 py-2 rounded-lg font-medium"> | |
| <i class="fas fa-times-circle mr-2"></i> Cancel Escrow | |
| </button> | |
| </div> | |
| </div> | |
| <div class="bg-gray-50 p-4 rounded-lg"> | |
| <h4 class="font-medium text-gray-700 mb-2">Transaction History</h4> | |
| <div class="space-y-3"> | |
| <div class="flex justify-between items-center border-b border-gray-200 pb-2"> | |
| <div class="flex items-center space-x-3"> | |
| <div class="bg-purple-100 p-2 rounded-full"> | |
| <i class="fas fa-file-contract text-purple-700"></i> | |
| </div> | |
| <div> | |
| <p class="font-medium">Escrow Created</p> | |
| <p class="text-xs text-gray-500">2023-05-15 14:30</p> | |
| </div> | |
| </div> | |
| <span class="text-purple-700 font-medium">+100 MATIC</span> | |
| </div> | |
| <!-- More history items would go here --> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Transaction Status Modal --> | |
| <div id="txStatusModal" class="fixed inset-0 z-50 hidden items-center justify-center modal-overlay"> | |
| <div class="bg-white rounded-lg shadow-xl w-full max-w-md p-6 text-center"> | |
| <div id="txLoading" class="py-8"> | |
| <div class="animate-spin rounded-full h-16 w-16 border-t-2 border-b-2 border-purple-500 mx-auto mb-4"></div> | |
| <h3 class="text-xl font-bold text-gray-800 mb-2">Processing Transaction</h3> | |
| <p class="text-gray-600">Please wait while we process your transaction on the Polygon network.</p> | |
| <p id="txHash" class="text-sm text-purple-600 mt-4 truncate"></p> | |
| </div> | |
| <div id="txSuccess" class="hidden py-8"> | |
| <div class="bg-green-100 p-4 rounded-full inline-block mb-4"> | |
| <i class="fas fa-check-circle text-green-600 text-4xl"></i> | |
| </div> | |
| <h3 class="text-xl font-bold text-gray-800 mb-2">Transaction Successful!</h3> | |
| <p class="text-gray-600">Your transaction has been confirmed on the Polygon network.</p> | |
| <p id="successTxHash" class="text-sm text-purple-600 mt-4 truncate"></p> | |
| <button id="closeTxModalBtn" class="mt-6 bg-purple-600 hover:bg-purple-700 text-white px-6 py-2 rounded-lg font-medium"> | |
| Close | |
| </button> | |
| </div> | |
| <div id="txError" class="hidden py-8"> | |
| <div class="bg-red-100 p-4 rounded-full inline-block mb-4"> | |
| <i class="fas fa-exclamation-circle text-red-600 text-4xl"></i> | |
| </div> | |
| <h3 class="text-xl font-bold text-gray-800 mb-2">Transaction Failed</h3> | |
| <p id="errorMessage" class="text-gray-600">There was an error processing your transaction.</p> | |
| <button id="closeErrorModalBtn" class="mt-6 bg-purple-600 hover:bg-purple-700 text-white px-6 py-2 rounded-lg font-medium"> | |
| Try Again | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| // DOM Elements | |
| const connectWalletBtn = document.getElementById('connectWalletBtn'); | |
| const walletInfo = document.getElementById('walletInfo'); | |
| const walletAddress = document.getElementById('walletAddress'); | |
| const tokenBalanceCard = document.getElementById('tokenBalanceCard'); | |
| const tokenBalance = document.getElementById('tokenBalance'); | |
| const tokenSymbol = document.getElementById('tokenSymbol'); | |
| const tokenLogo = document.getElementById('tokenLogo'); | |
| const createEscrowBtn = document.getElementById('createEscrowBtn'); | |
| const escrowList = document.getElementById('escrowList'); | |
| // Modal Elements | |
| const createEscrowModal = document.getElementById('createEscrowModal'); | |
| const closeModalBtn = document.getElementById('closeModalBtn'); | |
| const escrowForm = document.getElementById('escrowForm'); | |
| const tokenSelect = document.getElementById('tokenSelect'); | |
| const tokenSymbolModal = document.getElementById('tokenSymbolModal'); | |
| const escrowDetailModal = document.getElementById('escrowDetailModal'); | |
| const closeDetailModalBtn = document.getElementById('closeDetailModalBtn'); | |
| const txStatusModal = document.getElementById('txStatusModal'); | |
| const txLoading = document.getElementById('txLoading'); | |
| const txSuccess = document.getElementById('txSuccess'); | |
| const txError = document.getElementById('txError'); | |
| const txHash = document.getElementById('txHash'); | |
| const successTxHash = document.getElementById('successTxHash'); | |
| const errorMessage = document.getElementById('errorMessage'); | |
| const closeTxModalBtn = document.getElementById('closeTxModalBtn'); | |
| const closeErrorModalBtn = document.getElementById('closeErrorModalBtn'); | |
| // Tab Elements | |
| const activeTab = document.getElementById('activeTab'); | |
| const completedTab = document.getElementById('completedTab'); | |
| const disputedTab = document.getElementById('disputedTab'); | |
| // State | |
| let provider; | |
| let signer; | |
| let userAddress; | |
| let currentTab = 'active'; | |
| // Sample token data - replace with your actual token details | |
| const tokens = [ | |
| { | |
| address: '0xYourTokenAddressHere', | |
| symbol: 'YOURTOKEN', | |
| name: 'Your Token Name', | |
| decimals: 18, | |
| logo: 'https://placehold.co/100x100/purple/white?text=YT' | |
| }, | |
| { | |
| address: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', | |
| symbol: 'USDC', | |
| name: 'USD Coin', | |
| decimals: 6, | |
| logo: 'https://cryptologos.cc/logos/usd-coin-usdc-logo.png' | |
| }, | |
| { | |
| address: '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619', | |
| symbol: 'WETH', | |
| name: 'Wrapped Ether', | |
| decimals: 18, | |
| logo: 'https://cryptologos.cc/logos/ethereum-eth-logo.png' | |
| } | |
| ]; | |
| // Sample escrow data - replace with actual data from your contract | |
| const sampleEscrows = { | |
| active: [ | |
| { | |
| id: 'esc1', | |
| amount: '50.00', | |
| token: 'YOURTOKEN', | |
| sender: '0x123...4567', | |
| receiver: '0x789...0123', | |
| created: '2023-05-10', | |
| expires: '2023-06-10', | |
| status: 'active', | |
| conditions: 'Payment for website development services', | |
| arbitrator: '0x456...7890' | |
| }, | |
| { | |
| id: 'esc2', | |
| amount: '25.00', | |
| token: 'USDC', | |
| sender: '0x123...4567', | |
| receiver: '0x345...6789', | |
| created: '2023-05-15', | |
| expires: '2023-06-15', | |
| status: 'active', | |
| conditions: 'Freelance design work completion', | |
| arbitrator: null | |
| } | |
| ], | |
| completed: [ | |
| { | |
| id: 'esc3', | |
| amount: '100.00', | |
| token: 'YOURTOKEN', | |
| sender: '0x123...4567', | |
| receiver: '0x567...8901', | |
| created: '2023-04-01', | |
| completed: '2023-04-15', | |
| status: 'completed', | |
| conditions: 'Product purchase escrow', | |
| arbitrator: null | |
| } | |
| ], | |
| disputed: [ | |
| { | |
| id: 'esc4', | |
| amount: '75.00', | |
| token: 'WETH', | |
| sender: '0x123...4567', | |
| receiver: '0x234...5678', | |
| created: '2023-03-20', | |
| disputed: '2023-04-05', | |
| status: 'disputed', | |
| conditions: 'Service not delivered as agreed', | |
| arbitrator: '0x789...0123' | |
| } | |
| ] | |
| }; | |
| // Initialize the app | |
| function init() { | |
| // Event listeners | |
| connectWalletBtn.addEventListener('click', connectWallet); | |
| createEscrowBtn.addEventListener('click', () => { | |
| createEscrowModal.classList.remove('hidden'); | |
| createEscrowModal.classList.add('flex'); | |
| }); | |
| closeModalBtn.addEventListener('click', () => { | |
| createEscrowModal.classList.add('hidden'); | |
| createEscrowModal.classList.remove('flex'); | |
| }); | |
| closeDetailModalBtn.addEventListener('click', () => { | |
| escrowDetailModal.classList.add('hidden'); | |
| escrowDetailModal.classList.remove('flex'); | |
| }); | |
| closeTxModalBtn.addEventListener('click', () => { | |
| txStatusModal.classList.add('hidden'); | |
| txStatusModal.classList.remove('flex'); | |
| }); | |
| closeErrorModalBtn.addEventListener('click', () => { | |
| txStatusModal.classList.add('hidden'); | |
| txStatusModal.classList.remove('flex'); | |
| }); | |
| escrowForm.addEventListener('submit', handleEscrowCreation); | |
| // Tab switching | |
| activeTab.addEventListener('click', () => switchTab('active')); | |
| completedTab.addEventListener('click', () => switchTab('completed')); | |
| disputedTab.addEventListener('click', () => switchTab('disputed')); | |
| // Populate token select | |
| populateTokenSelect(); | |
| } | |
| // Connect wallet function | |
| async function connectWallet() { | |
| try { | |
| // Check if MetaMask is installed | |
| if (window.ethereum) { | |
| // Request account access | |
| const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' }); | |
| userAddress = accounts[0]; | |
| // Create Ethers provider and signer | |
| provider = new ethers.providers.Web3Provider(window.ethereum); | |
| signer = provider.getSigner(); | |
| // Update UI | |
| connectWalletBtn.innerHTML = `<i class="fas fa-check-circle"></i><span>Connected</span>`; | |
| connectWalletBtn.classList.remove('bg-white', 'text-purple-700'); | |
| connectWalletBtn.classList.add('bg-green-100', 'text-green-800'); | |
| walletInfo.classList.remove('hidden'); | |
| walletAddress.textContent = userAddress; | |
| tokenBalanceCard.classList.remove('hidden'); | |
| // Get network info | |
| const network = await provider.getNetwork(); | |
| document.getElementById('networkInfo').textContent = network.name.charAt(0).toUpperCase() + network.name.slice(1); | |
| // Load user data | |
| loadUserData(); | |
| // Listen for account changes | |
| window.ethereum.on('accountsChanged', (accounts) => { | |
| if (accounts.length === 0) { | |
| // Wallet disconnected | |
| resetWalletConnection(); | |
| } else { | |
| // Account changed | |
| userAddress = accounts[0]; | |
| walletAddress.textContent = userAddress; | |
| loadUserData(); | |
| } | |
| }); | |
| // Listen for chain changes | |
| window.ethereum.on('chainChanged', () => { | |
| window.location.reload(); | |
| }); | |
| } else { | |
| alert('Please install MetaMask or another Ethereum-compatible wallet to use this dApp.'); | |
| } | |
| } catch (error) { | |
| console.error('Error connecting wallet:', error); | |
| alert('Error connecting wallet. See console for details.'); | |
| } | |
| } | |
| // Reset wallet connection | |
| function resetWalletConnection() { | |
| connectWalletBtn.innerHTML = `<i class="fas fa-wallet"></i><span>Connect Wallet</span>`; | |
| connectWalletBtn.classList.remove('bg-green-100', 'text-green-800'); | |
| connectWalletBtn.classList.add('bg-white', 'text-purple-700'); | |
| walletInfo.classList.add('hidden'); | |
| tokenBalanceCard.classList.add('hidden'); | |
| escrowList.innerHTML = ` | |
| <div class="text-center py-12"> | |
| <i class="fas fa-lock text-gray-300 text-4xl mb-4"></i> | |
| <p class="text-gray-500">Connect your wallet to view escrow transactions</p> | |
| </div> | |
| `; | |
| } | |
| // Load user data | |
| async function loadUserData() { | |
| try { | |
| // In a real app, you would: | |
| // 1. Get token balances for the connected wallet | |
| // 2. Query your escrow contract for escrows involving this address | |
| // For now, we'll use sample data | |
| tokenBalance.textContent = '500.00'; | |
| tokenSymbol.textContent = 'YOURTOKEN'; | |
| tokenLogo.src = 'https://placehold.co/100x100/purple/white?text=YT'; | |
| // Load escrows | |
| loadEscrows(); | |
| } catch (error) { | |
| console.error('Error loading user data:', error); | |
| } | |
| } | |
| // Populate token select dropdown | |
| function populateTokenSelect() { | |
| tokens.forEach(token => { | |
| const option = document.createElement('option'); | |
| option.value = token.address; | |
| option.textContent = `${token.name} (${token.symbol})`; | |
| tokenSelect.appendChild(option); | |
| }); | |
| // Add event listener to update symbol display | |
| tokenSelect.addEventListener('change', (e) => { | |
| const selectedToken = tokens.find(t => t.address === e.target.value); | |
| if (selectedToken) { | |
| tokenSymbolModal.textContent = selectedToken.symbol; | |
| } | |
| }); | |
| } | |
| // Handle escrow creation form submission | |
| async function handleEscrowCreation(e) { | |
| e.preventDefault(); | |
| const tokenAddress = tokenSelect.value; | |
| const receiverAddress = document.getElementById('receiverAddress').value; | |
| const amount = document.getElementById('amount').value; | |
| const conditions = document.getElementById('releaseCondition').value; | |
| const arbitrator = document.getElementById('arbitrator').value; | |
| // Validate inputs | |
| if (!tokenAddress || !receiverAddress || !amount || !conditions) { | |
| alert('Please fill in all required fields'); | |
| return; | |
| } | |
| try { | |
| // Show loading modal | |
| txStatusModal.classList.remove('hidden'); | |
| txStatusModal.classList.add('flex'); | |
| txLoading.classList.remove('hidden'); | |
| txSuccess.classList.add('hidden'); | |
| txError.classList.add('hidden'); | |
| // In a real app, you would: | |
| // 1. Approve the token transfer to the escrow contract (if needed) | |
| // 2. Call the createEscrow function on your contract | |
| // Simulate transaction | |
| setTimeout(() => { | |
| txLoading.classList.add('hidden'); | |
| txSuccess.classList.remove('hidden'); | |
| txHash.textContent = '0x123...456 (simulated)'; | |
| successTxHash.textContent = '0x123...456 (simulated)'; | |
| // Close the create escrow modal | |
| createEscrowModal.classList.add('hidden'); | |
| createEscrowModal.classList.remove('flex'); | |
| // Reset form | |
| escrowForm.reset(); | |
| // Refresh escrows | |
| loadEscrows(); | |
| }, 2000); | |
| } catch (error) { | |
| console.error('Error creating escrow:', error); | |
| txLoading.classList.add('hidden'); | |
| txError.classList.remove('hidden'); | |
| errorMessage.textContent = error.message || 'Error creating escrow'; | |
| } | |
| } | |
| // Load escrows based on current tab | |
| function loadEscrows() { | |
| const escrows = sampleEscrows[currentTab]; | |
| if (escrows && escrows.length > 0) { | |
| escrowList.innerHTML = ''; | |
| escrows.forEach(escrow => { | |
| const escrowCard = document.createElement('div'); | |
| escrowCard.className = 'escrow-card bg-white rounded-lg shadow-md p-6 cursor-pointer'; | |
| escrowCard.innerHTML = ` | |
| <div class="flex justify-between items-start mb-4"> | |
| <div> | |
| <h3 class="font-bold text-lg text-gray-800">Escrow #${escrow.id}</h3> | |
| <p class="text-sm text-gray-500">Created: ${escrow.created}</p> | |
| </div> | |
| <span class="status-badge ${getStatusClass(escrow.status)}">${escrow.status.charAt(0).toUpperCase() + escrow.status.slice(1)}</span> | |
| </div> | |
| <div class="flex items-center justify-between mb-4"> | |
| <div class="flex items-center space-x-2"> | |
| <img src="${getTokenLogo(escrow.token)}" alt="${escrow.token}" class="h-6"> | |
| <span class="font-medium">${escrow.amount} ${escrow.token}</span> | |
| </div> | |
| <span class="text-sm text-gray-500">≈ $${(parseFloat(escrow.amount) * 1.7).toFixed(2)}</span> | |
| </div> | |
| <div class="mb-4"> | |
| <p class="text-sm text-gray-700 truncate">${escrow.conditions}</p> | |
| </div> | |
| <div class="flex justify-between items-center text-sm"> | |
| <div> | |
| <p class="text-gray-500">To:</p> | |
| <p class="font-medium">${escrow.receiver}</p> | |
| </div> | |
| <button class="text-purple-600 hover:text-purple-800 font-medium"> | |
| View Details <i class="fas fa-chevron-right ml-1"></i> | |
| </button> | |
| </div> | |
| `; | |
| escrowCard.addEventListener('click', () => showEscrowDetails(escrow)); | |
| escrowList.appendChild(escrowCard); | |
| }); | |
| } else { | |
| escrowList.innerHTML = ` | |
| <div class="col-span-3 text-center py-12"> | |
| <i class="fas fa-inbox text-gray-300 text-4xl mb-4"></i> | |
| <p class="text-gray-500">No ${currentTab} escrows found</p> | |
| </div> | |
| `; | |
| } | |
| } | |
| // Get token logo URL | |
| function getTokenLogo(symbol) { | |
| const token = tokens.find(t => t.symbol === symbol); | |
| return token ? token.logo : 'https://cryptologos.cc/logos/polygon-matic-logo.png'; | |
| } | |
| // Get status badge class | |
| function getStatusClass(status) { | |
| switch (status) { | |
| case 'active': return 'status-active'; | |
| case 'completed': return 'status-completed'; | |
| case 'disputed': return 'status-disputed'; | |
| default: return 'status-active'; | |
| } | |
| } | |
| // Show escrow details modal | |
| function showEscrowDetails(escrow) { | |
| // Populate details | |
| document.getElementById('detailId').textContent = `#${escrow.id}`; | |
| document.getElementById('detailStatus').textContent = escrow.status.charAt(0).toUpperCase() + escrow.status.slice(1); | |
| document.getElementById('detailStatus').className = `status-badge ${getStatusClass(escrow.status)}`; | |
| document.getElementById('detailCreated').textContent = escrow.created; | |
| document.getElementById('detailExpires').textContent = escrow.expires || 'N/A'; | |
| document.getElementById('detailTokenLogo').src = getTokenLogo(escrow.token); | |
| document.getElementById('detailTokenSymbol').textContent = escrow.token; | |
| document.getElementById('detailAmount').textContent = escrow.amount; | |
| document.getElementById('detailValue').textContent = `$${(parseFloat(escrow.amount) * 1.7).toFixed(2)}`; | |
| document.getElementById('detailSender').textContent = escrow.sender; | |
| document.getElementById('detailReceiver').textContent = escrow.receiver; | |
| document.getElementById('detailArbitrator').textContent = escrow.arbitrator || 'Not specified'; | |
| document.getElementById('detailConditions').textContent = escrow.conditions; | |
| // Show modal | |
| escrowDetailModal.classList.remove('hidden'); | |
| escrowDetailModal.classList.add('flex'); | |
| // Set up action buttons (in a real app, these would call contract functions) | |
| document.getElementById('releaseFundsBtn').addEventListener('click', () => { | |
| alert('In a real app, this would call the releaseFunds function on your escrow contract'); | |
| }); | |
| document.getElementById('disputeBtn').addEventListener('click', () => { | |
| alert('In a real app, this would call the raiseDispute function on your escrow contract'); | |
| }); | |
| document.getElementById('cancelEscrowBtn').addEventListener('click', () => { | |
| alert('In a real app, this would call the cancelEscrow function on your escrow contract'); | |
| }); | |
| } | |
| // Switch between tabs | |
| function switchTab(tab) { | |
| currentTab = tab; | |
| // Update tab styling | |
| activeTab.classList.remove('text-purple-700', 'border-purple-700'); | |
| activeTab.classList.add('text-gray-500', 'hover:text-purple-700', 'border-transparent'); | |
| completedTab.classList.remove('text-purple-700', 'border-purple-700'); | |
| completedTab.classList.add('text-gray-500', 'hover:text-purple-700', 'border-transparent'); | |
| disputedTab.classList.remove('text-purple-700', 'border-purple-700'); | |
| disputedTab.classList.add('text-gray-500', 'hover:text-purple-700', 'border-transparent'); | |
| // Highlight current tab | |
| if (tab === 'active') { | |
| activeTab.classList.remove('text-gray-500', 'hover:text-purple-700', 'border-transparent'); | |
| activeTab.classList.add('text-purple-700', 'border-purple-700'); | |
| } else if (tab === 'completed') { | |
| completedTab.classList.remove('text-gray-500', 'hover:text-purple-700', 'border-transparent'); | |
| completedTab.classList.add('text-purple-700', 'border-purple-700'); | |
| } else if (tab === 'disputed') { | |
| disputedTab.classList.remove('text-gray-500', 'hover:text-purple-700', 'border-transparent'); | |
| disputedTab.classList.add('text-purple-700', 'border-purple-700'); | |
| } | |
| // Load escrows for the selected tab | |
| loadEscrows(); | |
| } | |
| // Initialize the app when the DOM is loaded | |
| document.addEventListener('DOMContentLoaded', init); | |
| </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=mottled/cyberlancer" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |