File size: 3,121 Bytes
417f2e4
4a4f586
 
417f2e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// API Configuration – replace with actual endpoint from the Hugging Face Space
const API_URL = 'https://megatron11722-bearbrute-ai-crypto-wallet-recovery.static.hf.space/index.html#';


// DOM Elements
const form = document.getElementById('recoveryForm');
const walletAddress = document.getElementById('walletAddress');
const extraInfo = document.getElementById('extraInfo');
const recoverBtn = document.getElementById('recoverBtn');
const btnText = document.getElementById('btnText');
const loadingSpinner = document.getElementById('loadingSpinner');
const errorMsg = document.getElementById('errorMsg');
const resultContainer = document.getElementById('resultContainer');
const resultContent = document.getElementById('resultContent');
const copyBtn = document.getElementById('copyBtn');

// Form Submit
form.addEventListener('submit', async (e) => {
  e.preventDefault();
  
  // Basic validation
  if (!walletAddress.value.trim()) {
    showError('Please enter a wallet address.');
    return;
  }

  // UI loading state
  setLoading(true);
  hideError();
  hideResult();

  try {
    // Build payload according to Gradio API (data array of inputs)
    const payload = {
      data: [
        walletAddress.value.trim(),
        extraInfo.value.trim() || 'no extra info'
      ]
    };

    const response = await fetch(API_URL, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(payload),
    });

    if (!response.ok) {
      throw new Error(`API error: ${response.status} ${response.statusText}`);
    }

    const result = await response.json();
    
    // Gradio returns { data: [...] }
    if (result && result.data && result.data.length > 0) {
      const recovered = result.data[0];
      displayResult(typeof recovered === 'string' ? recovered : JSON.stringify(recovered, null, 2));
    } else {
      throw new Error('Unexpected response structure');
    }
  } catch (err) {
    showError(`Failed to recover wallet: ${err.message}`);
  } finally {
    setLoading(false);
  }
});

// Copy to clipboard
copyBtn.addEventListener('click', async () => {
  const text = resultContent.textContent;
  if (!text) return;
  
  try {
    await navigator.clipboard.writeText(text);
    copyBtn.innerHTML = '<i data-lucide="check" class="w-4 h-4"></i> Copied!';
    lucide.createIcons();
    setTimeout(() => {
      copyBtn.innerHTML = '<i data-lucide="copy" class="w-4 h-4"></i> Copy to Clipboard';
      lucide.createIcons();
    }, 2000);
  } catch (err) {
    alert('Copy failed. Please copy manually.');
  }
});

// Helper functions
function setLoading(isLoading) {
  recoverBtn.disabled = isLoading;
  btnText.classList.toggle('hidden', isLoading);
  loadingSpinner.classList.toggle('hidden', !isLoading);
}

function showError(msg) {
  errorMsg.textContent = msg;
  errorMsg.classList.remove('hidden');
}

function hideError() {
  errorMsg.classList.add('hidden');
}

function displayResult(text) {
  resultContent.textContent = text;
  resultContainer.classList.remove('hidden');
}

function hideResult() {
  resultContainer.classList.add('hidden');
}