Spaces:
Running

File size: 4,263 Bytes
9d340cc
 
8feb975
 
 
9d340cc
 
8feb975
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9d340cc
8feb975
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

// Main JavaScript for Aziz Contracts

// Initialize application
document.addEventListener('DOMContentLoaded', function() {
    console.log('Aziz Contracts initialized');
// Check if Web3 is available
    if (typeof window.ethereum !== 'undefined') {
        console.log('MetaMask is installed!');
        initializeWeb3();
    } else {
        console.log('Please install MetaMask!');
        showMetaMaskAlert();
    }
    
    // Initialize any interactive elements
    initializeInteractiveElements();
});

// Web3 initialization
async function initializeWeb3() {
    try {
        // Request account access
        const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
        const account = accounts[0];
        
        console.log('Connected account:', account);
        
        // Update UI with connected account
        updateWalletStatus(account);
        
        // Listen for account changes
        window.ethereum.on('accountsChanged', function (accounts) {
            if (accounts.length === 0) {
                console.log('Please connect to MetaMask.');
                updateWalletStatus(null);
            } else {
                console.log('Account changed to:', accounts[0]);
                updateWalletStatus(accounts[0]);
            }
        });
        
    } catch (error) {
        console.error('User denied account access:', error);
    }
}

// Update wallet connection status in UI
function updateWalletStatus(account) {
    const walletElements = document.querySelectorAll('.wallet-status');
    
    walletElements.forEach(element => {
        if (account) {
            element.innerHTML = `
                <div class="flex items-center space-x-2">
                    <div class="w-2 h-2 bg-green-500 rounded-full"></div>
                    <span class="text-sm font-medium">Connected: ${account.substring(0, 6)}...${account.substring(38)}</span>
                </div>
            `;
        } else {
            element.innerHTML = `
                <div class="flex items-center space-x-2">
                    <div class="w-2 h-2 bg-red-500 rounded-full"></div>
                    <span class="text-sm font-medium">Not Connected</span>
                </div>
            `;
        }
    });
}

// Show MetaMask installation alert
function showMetaMaskAlert() {
    // This would typically show a modal or notification
        console.log('Please install MetaMask to use Aziz Contracts');
}

// Initialize interactive elements
function initializeInteractiveElements() {
    // Add click handlers for demo buttons
    const demoButtons = document.querySelectorAll('button');
    demoButtons.forEach(button => {
        button.addEventListener('click', function(e) {
            if (!this.textContent.includes('Connect')) {
                e.preventDefault();
                showFeatureComingSoon();
            }
        });
    });
}

// Show feature coming soon message
function showFeatureComingSoon() {
    // Create a temporary notification
    const notification = document.createElement('div');
    notification.className = 'fixed top-4 right-4 bg-blue-500 text-white px-6 py-3 rounded-lg shadow-lg z-50';
    notification.textContent = 'Feature coming soon! 🚀';
    
    document.body.appendChild(notification);
    
    // Remove after 3 seconds
    setTimeout(() => {
        notification.remove();
    }, 3000);
}

// Contract interaction functions (placeholder for actual implementation)
class ContractManager {
    constructor() {
        this.contractAddress = null;
        this.provider = null;
        this.signer = null;
        this.contract = null;
    }
    
    async connectContract(contractAddress, abi) {
        // This would be implemented with ethers.js
        console.log('Connecting to contract at:', contractAddress);
    }
    
    async proposeContract(clubAddress, playerAddress, salary, startDate, endDate) {
        // Implementation for proposing a contract
        console.log('Proposing contract...');
    }
    
    async signContract(contractId, isClub) {
        // Implementation for signing a contract
        console.log('Signing contract...');
    }
}

// Initialize contract manager
window.contractManager = new ContractManager();