File size: 3,322 Bytes
e40e246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// Mining simulation logic
let miningInterval;
let minedAmount = 0;
let miningPower = 1; // Default mining power
let isMining = false;

function initMiningSimulation() {
    // Load saved data if exists
    const savedData = localStorage.getItem('pocketMinerData');
    if (savedData) {
        const data = JSON.parse(savedData);
        minedAmount = data.minedAmount || 0;
        miningPower = data.miningPower || 1;
        updateMiningStats();
    }
}

function startMining() {
    if (isMining) return;
    
    isMining = true;
    document.getElementById('miningStatus').classList.add('mining-active');
    document.getElementById('startMiningBtn').classList.add('hidden');
    document.getElementById('stopMiningBtn').classList.remove('hidden');
    
    miningInterval = setInterval(() => {
        // Simulate mining with random variance
        const variance = 0.8 + Math.random() * 0.4; // 0.8-1.2 multiplier
        minedAmount += (0.000001 * miningPower * variance);
        updateMiningStats();
        saveToLocalStorage();
    }, 1000);
}

function stopMining() {
    isMining = false;
    clearInterval(miningInterval);
    document.getElementById('miningStatus').classList.remove('mining-active');
    document.getElementById('startMiningBtn').classList.remove('hidden');
    document.getElementById('stopMiningBtn').classList.add('hidden');
    saveToLocalStorage();
}

function updateMiningStats() {
    document.getElementById('minedAmount').textContent = minedAmount.toFixed(8);
    document.getElementById('miningPowerValue').textContent = miningPower.toFixed(2);
    document.getElementById('walletBalance').textContent = minedAmount.toFixed(8);
}

function upgradeMiningPower() {
    const cost = miningPower * 0.0001;
    if (minedAmount >= cost) {
        minedAmount -= cost;
        miningPower += 0.25;
        updateMiningStats();
        saveToLocalStorage();
        
        // Show upgrade notification
        showNotification('Mining power upgraded to ' + miningPower.toFixed(2) + ' TH/s!');
    } else {
        showNotification('Not enough BTC to upgrade mining power!', 'error');
    }
}

function withdrawToWallet() {
    if (minedAmount > 0.00005) { // Minimum withdrawal amount
        showNotification(`${minedAmount.toFixed(8)} BTC withdrawn to your wallet!`, 'success');
        minedAmount = 0;
        updateMiningStats();
        saveToLocalStorage();
    } else {
        showNotification('Minimum withdrawal amount is 0.00005 BTC', 'error');
    }
}

function showNotification(message, type = 'info') {
    const notification = document.createElement('div');
    notification.className = `fixed top-4 right-4 px-4 py-2 rounded-md shadow-lg text-white ${
        type === 'error' ? 'bg-red-500' : 
        type === 'success' ? 'bg-green-500' : 'bg-blue-500'
    }`;
    notification.textContent = message;
    document.body.appendChild(notification);
    
    setTimeout(() => {
        notification.classList.add('opacity-0', 'transition-opacity', 'duration-300');
        setTimeout(() => notification.remove(), 300);
    }, 3000);
}

function saveToLocalStorage() {
    localStorage.setItem('pocketMinerData', JSON.stringify({
        minedAmount,
        miningPower
    }));
}

// Navigation function
function navigateTo(page) {
    window.location.href = page;
}