${domains.map(d => {
const name = typeof d === 'string' ? d : (d.domain || d.name || String(d));
const isFav = favourite && name === favourite;
return `
${esc(name)}.sol
${isFav ? '
★ FAVOURITE
' : ''}
`;
}).join('')}
`;
} catch(err) {
results.innerHTML = errorHTML(`Network error: ${err.message}`);
}
}
// ─── WALLET ─────────────────────────────────────────────────
let connectedProvider = null;
// ── Wallet Standard Discovery ──
// MetaMask Solana and modern wallets register via the Wallet Standard protocol
const walletStandardWallets = [];
let walletStandardReady = false;
function initWalletStandard() {
// Listen for wallets that register AFTER us
window.addEventListener('wallet-standard:register-wallet', (event) => {
try {
const callback = event.detail;
if (typeof callback === 'function') {
callback({
register: (...wallets) => {
for (const w of wallets) {
if (!walletStandardWallets.some(existing => existing.name === w.name)) {
walletStandardWallets.push(w);
}
}
}
});
}
} catch(e) { console.warn('WS register error:', e); }
});
// Announce that the app is ready — catches wallets that loaded BEFORE us
try {
const appReadyEvent = new CustomEvent('wallet-standard:app-ready', {
detail: {
register: (...wallets) => {
for (const w of wallets) {
if (!walletStandardWallets.some(existing => existing.name === w.name)) {
walletStandardWallets.push(w);
}
}
}
}
});
window.dispatchEvent(appReadyEvent);
} catch(e) { console.warn('WS app-ready error:', e); }
walletStandardReady = true;
}
// Initialise Wallet Standard immediately
initWalletStandard();
function getAvailableWallets() {
const found = [];
const seen = new Set();
function add(name, icon, provider, url, isWalletStandard) {
if (!provider || seen.has(name)) return;
seen.add(name);
found.push({ name, icon, provider, url, isWalletStandard: !!isWalletStandard });
}
// ── 1. Wallet Standard wallets (MetaMask Solana, etc.) ──
for (const w of walletStandardWallets) {
try {
const hasConnect = w.features?.['standard:connect'];
if (!hasConnect) continue;
const name = (w.name || 'WALLET').toUpperCase();
// Use wallet's icon (base64 data URI) or fallback emoji
let icon = '◈';
if (name.includes('METAMASK')) icon = '🦊';
else if (name.includes('PHANTOM')) icon = '👻';
else if (name.includes('SOLFLARE')) icon = '🔆';
else if (name.includes('BACKPACK')) icon = '🎒';
else if (name.includes('COINBASE')) icon = '🔵';
else if (name.includes('TRUST')) icon = '🛡️';
else if (name.includes('JUPITER')) icon = '🪐';
const url = w.url || '#';
add(name, icon, w, url, true);
} catch(e) {}
}
// ── 2. Legacy injection points ──
// Phantom
try {
const p = window.phantom?.solana;
if (p && p.isPhantom) add('PHANTOM', '👻', p, 'https://phantom.app');
} catch(e) {}
// Solflare
try {
const s = window.solflare;
if (s && s.isSolflare) add('SOLFLARE', '🔆', s, 'https://solflare.com');
} catch(e) {}
// Backpack
try {
const b = window.backpack;
if (b && b.isBackpack) add('BACKPACK', '🎒', b, 'https://backpack.app');
} catch(e) {}
// Coinbase
try {
if (window.coinbaseSolana) add('COINBASE', '🔵', window.coinbaseSolana, 'https://coinbase.com/wallet');
} catch(e) {}
// Trust
try {
const t = window.trustwallet?.solana;
if (t) add('TRUST', '🛡️', t, 'https://trustwallet.com');
} catch(e) {}
// ── 3. Generic window.solana ──
try {
const ws = window.solana;
if (ws && !seen.has('SOLANA WALLET')) {
if (ws.isJupiter && !seen.has('JUPITER')) add('JUPITER', '🪐', ws, 'https://jup.ag');
else if (ws.isMetaMask && !seen.has('METAMASK')) add('METAMASK', '🦊', ws, 'https://metamask.io');
else if (ws.isPhantom && !seen.has('PHANTOM')) { /* skip */ }
else if (ws.isSolflare && !seen.has('SOLFLARE')){ /* skip */ }
else if (ws.isBackpack && !seen.has('BACKPACK')){ /* skip */ }
else if (!seen.has('PHANTOM') && !seen.has('METAMASK')) add('SOLANA WALLET', '◈', ws, '#');
}
} catch(e) {}
// ── 4. Jupiter specific ──
try {
const j = window.jupiter?.solana;
if (j) add('JUPITER', '🪐', j, 'https://jup.ag');
} catch(e) {}
// ── 5. Multi-provider array ──
try {
const providers = window.solana?.providers;
if (Array.isArray(providers)) {
for (const p of providers) {
if (p.isPhantom) add('PHANTOM', '👻', p, 'https://phantom.app');
else if (p.isJupiter) add('JUPITER', '🪐', p, 'https://jup.ag');
else if (p.isSolflare) add('SOLFLARE', '🔆', p, 'https://solflare.com');
else if (p.isBackpack) add('BACKPACK', '🎒', p, 'https://backpack.app');
else if (p.isMetaMask) add('METAMASK', '🦊', p, 'https://metamask.io');
}
}
} catch(e) {}
return found;
}
const KNOWN_WALLETS = [
{ name: 'PHANTOM', icon: '👻', url: 'https://phantom.app' },
{ name: 'JUPITER', icon: '🪐', url: 'https://jup.ag' },
{ name: 'SOLFLARE', icon: '🔆', url: 'https://solflare.com' },
{ name: 'BACKPACK', icon: '🎒', url: 'https://backpack.app' },
{ name: 'COINBASE', icon: '🔵', url: 'https://coinbase.com/wallet' },
{ name: 'TRUST', icon: '🛡️', url: 'https://trustwallet.com' },
{ name: 'METAMASK', icon: '🦊', url: 'https://metamask.io' },
];
function initWallet() {
const btn = $('#wallet-btn');
if (!btn) return;
btn.addEventListener('click', toggleWallet);
createWalletModal();
}
function createWalletModal() {
const modal = document.createElement('div');
modal.id = 'wallet-modal';
modal.className = 'sol-modal hidden';
modal.innerHTML = `
SELECT WALLET
`;
document.body.appendChild(modal);
modal.querySelector('.sol-modal-backdrop').addEventListener('click', closeModal);
modal.querySelector('#modal-close').addEventListener('click', closeModal);
}
function openModal() {
const modal = $('#wallet-modal');
const list = $('#wallet-list');
// Small delay to let async provider injection complete
setTimeout(() => {
const available = getAvailableWallets();
const detectedNames = new Set(available.map(w => w.name));
let html = '';
if (available.length > 0) {
html += '
DETECTED
';
html += available.map(w => `
`).join('');
}
const notInstalled = KNOWN_WALLETS.filter(w => !detectedNames.has(w.name));
if (notInstalled.length > 0) {
html += '
NOT INSTALLED
';
html += notInstalled.map(w => `
${w.icon}${w.name}INSTALL ↗
`).join('');
}
if (available.length === 0) {
html = `
NO SOLANA WALLETS DETECTED
Install a Solana wallet extension to connect. If you just installed one, refresh the page.