File size: 18,697 Bytes
612c504
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Global Trade Fin. Calculator</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">
    <style>
        /* Previous styles remain unchanged */
        .token-price-card {
            background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%);
            border-radius: 12px;
            padding: 1rem;
            position: relative;
            overflow: hidden;
            border: 1px solid #8b5cf6;
        }
        .token-price-change {
            display: inline-flex;
            align-items: center;
            padding: 0.25rem 0.5rem;
            border-radius: 9999px;
            font-size: 0.75rem;
            font-weight: 600;
        }
        .price-up {
            background-color: #10b981;
            color: white;
        }
        .price-down {
            background-color: #ef4444;
            color: white;
        }
        .price-neutral {
            background-color: #6b7280;
            color: white;
        }
        .token-refresh-btn {
            position: absolute;
            top: 0.5rem;
            right: 0.5rem;
            background: rgba(139, 92, 246, 0.1);
            border-radius: 50%;
            width: 24px;
            height: 24px;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        .token-refresh-btn:hover {
            background: rgba(139, 92, 246, 0.2);
            transform: rotate(180deg);
        }
        .token-price-loader {
            display: inline-block;
            width: 12px;
            height: 12px;
            border: 2px solid rgba(139, 92, 246, 0.3);
            border-radius: 50%;
            border-top-color: #8b5cf6;
            animation: spin 1s ease-in-out infinite;
        }
        @keyframes spin {
            to { transform: rotate(360deg); }
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <!-- Previous HTML content remains unchanged until the token minting modal -->

    <!-- Token Minting Modal -->
    <div id="tokenMintModal" class="modal fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4">
        <div class="bg-white rounded-xl shadow-xl p-6 max-w-md w-full">
            <div class="flex justify-between items-center mb-4">
                <h3 class="text-xl font-bold text-gray-800">Mint FFFUND Tokens</h3>
                <button id="closeTokenModal" class="text-gray-500 hover:text-gray-700">
                    <i class="fas fa-times"></i>
                </button>
            </div>
            
            <!-- Token Price Card -->
            <div class="token-price-card mb-4 relative">
                <div class="token-refresh-btn" id="refreshTokenPrice">
                    <i class="fas fa-sync-alt text-xs text-purple-600"></i>
                </div>
                <div class="flex items-center justify-between">
                    <div>
                        <span class="font-bold text-purple-700">FFFUND/USD</span>
                        <div class="flex items-center mt-1">
                            <span id="tokenLatestPrice" class="text-2xl font-bold mr-2">$1.00</span>
                            <span id="tokenPriceChange" class="token-price-change price-neutral">
                                <span id="tokenPriceChangeIcon"></span>
                                <span id="tokenPriceChangePercent">0.00%</span>
                            </span>
                        </div>
                    </div>
                    <div class="text-right">
                        <div class="text-xs text-gray-500">24h Range</div>
                        <div id="tokenPriceRange" class="text-sm font-medium">$1.00 - $1.00</div>
                        <div class="text-xs text-gray-500 mt-1">Last Updated</div>
                        <div id="tokenLastUpdated" class="text-xs">Just now</div>
                    </div>
                </div>
            </div>
            
            <div class="yield-farming-card mb-6">
                <div class="flex justify-between items-center mb-2">
                    <span class="font-bold text-purple-700">Fabric Flow Fund™ (FFFUND)</span>
                    <span class="bg-purple-100 text-purple-800 text-xs font-medium px-2.5 py-0.5 rounded">BRC-20</span>
                </div>
                <p class="text-sm text-gray-600 mb-3">Yield farming token to fund your business loan with competitive APY</p>
                
                <div class="grid grid-cols-2 gap-4 mb-3">
                    <div>
                        <p class="text-xs text-gray-500">Total Supply</p>
                        <p class="font-medium">50,000,000,000</p>
                    </div>
                    <div>
                        <p class="text-xs text-gray-500">Current Price</p>
                        <p id="currentTokenPrice" class="font-medium">$1.00</p>
                    </div>
                    <div>
                        <p class="text-xs text-gray-500">Current APY</p>
                        <p class="font-medium text-green-600">11.0%</p>
                    </div>
                    <div>
                        <p class="text-xs text-gray-500">Your Balance</p>
                        <p class="font-medium">0</p>
                    </div>
                </div>
                
                <div class="mb-2">
                    <p class="text-xs text-gray-500">Mint Progress</p>
                    <div class="token-progress">
                        <div id="tokenProgressBar" class="token-progress-bar" style="width: 0%"></div>
                    </div>
                    <p class="text-right text-xs mt-1"><span id="tokensMinted">0</span>/10,000</p>
                </div>
            </div>
            
            <div class="mb-4">
                <label class="block text-gray-700 font-medium mb-2">Amount to Mint</label>
                <div class="relative">
                    <input type="number" id="tokenAmount" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-purple-500 focus:border-purple-500" placeholder="e.g. 10000" min="10000" step="1000">
                    <div class="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none">
                        <span class="text-gray-500">FFFUND</span>
                    </div>
                </div>
                <p class="text-xs text-gray-500 mt-1">Minimum mint: 10,000 FFFUND</p>
            </div>
            
            <div class="bg-purple-50 p-4 rounded-lg mb-4">
                <div class="flex justify-between items-center mb-2">
                    <p class="text-sm text-purple-600 font-medium">Estimated Cost</p>
                    <p id="estimatedCost" class="text-lg font-bold text-purple-800">$0.00</p>
                </div>
                <div class="flex justify-between items-center mb-2">
                    <p class="text-sm text-purple-600 font-medium">Estimated Annual Yield</p>
                    <p id="estimatedYield" class="text-lg font-bold text-purple-800">0 FFFUND</p>
                </div>
                <div class="flex justify-between items-center">
                    <p class="text-sm text-purple-600 font-medium">Loan Impact</p>
                    <p id="tokenLoanImpact" class="text-lg font-bold text-purple-800">-$0</p>
                </div>
            </div>
            
            <button id="mintTokensBtn" class="w-full bg-purple-600 hover:bg-purple-700 text-white font-bold py-3 px-4 rounded-lg transition duration-300 flex items-center justify-center">
                <span id="mintBtnText">Mint Tokens</span>
                <span id="mintBtnLoader" class="ml-2 hidden">
                    <span class="token-price-loader"></span>
                </span>
            </button>
        </div>
    </div>

    <!-- Previous modals and scripts remain unchanged until the token minting script -->

    <script>
        // Previous JavaScript remains unchanged until the token minting functions

        // Token Minting Functions
        let lastTokenPrice = 1.00;
        let tokenPriceData = {
            askPrice: 1,
            bidPrice: 1,
            latestTradePrice: 1,
            timestamp: new Date().toISOString(),
            height: 1
        };

        // Function to mask API key
        function getMaskedApiKey() {
            const partialKey = 'ebc6d2b48db541a:im201to74ucouji';
            return '••••••••••••••••••••••••••••••••' + partialKey.slice(-4);
        }

        // Fetch token price from API
        async function fetchTokenPrice() {
            const loader = document.getElementById('mintBtnLoader');
            const btnText = document.getElementById('mintBtnText');
            const refreshBtn = document.getElementById('refreshTokenPrice');
            
            try {
                // Show loading state
                loader.classList.remove('hidden');
                btnText.textContent = 'Fetching Price...';
                refreshBtn.innerHTML = '<span class="token-price-loader"></span>';
                
                // In a real implementation, you would use the actual API key
                // const apiKey = 'ebc6d2b48db541a:im201to74ucouji';
                // const response = await fetch('https://open-api-fractal.unisat.io/v1/cat20-dex/getTokenPrice?tokenId=FFFUND', {
                //     method: 'GET',
                //     headers: {
                //         "Authorization": `Bearer ${apiKey}`,
                //         "Accept": "*/*"
                //     },
                // });
                
                // For demo purposes, we'll simulate the API response
                const mockResponse = {
                    "code": 1,
                    "msg": "OK",
                    "data": {
                        "askPrice": (1 + Math.random() * 0.2).toFixed(2),
                        "bidPrice": (1 - Math.random() * 0.1).toFixed(2),
                        "latestTradePrice": (1 + (Math.random() * 0.2 - 0.1)).toFixed(2),
                        "timestamp": new Date().toISOString(),
                        "height": Math.floor(Math.random() * 1000) + 1
                    }
                };
                
                // Simulate network delay
                await new Promise(resolve => setTimeout(resolve, 800));
                
                // Process response
                if (mockResponse.code === 1) {
                    tokenPriceData = mockResponse.data;
                    lastTokenPrice = parseFloat(tokenPriceData.latestTradePrice);
                    updateTokenPriceDisplay();
                    
                    // Show success message
                    const maskedKey = getMaskedApiKey();
                    console.log(`Successfully fetched token price using API key: ${maskedKey}`);
                } else {
                    throw new Error(mockResponse.msg || 'Failed to fetch token price');
                }
            } catch (error) {
                console.error('Error fetching token price:', error);
                // Fallback to last known price
                updateTokenPriceDisplay();
                
                // Show error message
                const toast = document.createElement('div');
                toast.className = 'fixed bottom-4 right-4 bg-red-500 text-white px-4 py-2 rounded-lg shadow-lg';
                toast.textContent = 'Price update failed. Using last known price.';
                document.body.appendChild(toast);
                setTimeout(() => toast.remove(), 3000);
            } finally {
                // Hide loading state
                loader.classList.add('hidden');
                btnText.textContent = 'Mint Tokens';
                refreshBtn.innerHTML = '<i class="fas fa-sync-alt text-xs text-purple-600"></i>';
            }
        }

        // Update token price display
        function updateTokenPriceDisplay() {
            const latestPrice = parseFloat(tokenPriceData.latestTradePrice);
            const askPrice = parseFloat(tokenPriceData.askPrice);
            const bidPrice = parseFloat(tokenPriceData.bidPrice);
            
            // Calculate price change
            const priceChange = latestPrice - lastTokenPrice;
            const priceChangePercent = (priceChange / lastTokenPrice) * 100;
            
            // Update price displays
            document.getElementById('tokenLatestPrice').textContent = `$${latestPrice.toFixed(2)}`;
            document.getElementById('currentTokenPrice').textContent = `$${latestPrice.toFixed(2)}`;
            document.getElementById('tokenPriceRange').textContent = `$${bidPrice.toFixed(2)} - $${askPrice.toFixed(2)}`;
            
            // Format timestamp
            const timestamp = new Date(tokenPriceData.timestamp);
            document.getElementById('tokenLastUpdated').textContent = timestamp.toLocaleTimeString();
            
            // Update price change indicator
            const priceChangeElement = document.getElementById('tokenPriceChange');
            const priceChangePercentElement = document.getElementById('tokenPriceChangePercent');
            const priceChangeIcon = document.getElementById('tokenPriceChangeIcon');
            
            priceChangePercentElement.textContent = `${Math.abs(priceChangePercent).toFixed(2)}%`;
            
            if (priceChange > 0) {
                priceChangeElement.className = 'token-price-change price-up';
                priceChangeIcon.innerHTML = '<i class="fas fa-caret-up mr-1"></i>';
            } else if (priceChange < 0) {
                priceChangeElement.className = 'token-price-change price-down';
                priceChangeIcon.innerHTML = '<i class="fas fa-caret-down mr-1"></i>';
            } else {
                priceChangeElement.className = 'token-price-change price-neutral';
                priceChangeIcon.innerHTML = '<i class="fas fa-minus mr-1"></i>';
            }
            
            // Update calculations based on new price
            updateTokenEstimate();
        }

        // Update token estimate calculations
        function updateTokenEstimate() {
            const amount = parseInt(document.getElementById('tokenAmount').value) || 0;
            const progress = Math.min((amount / 10000) * 100, 100);
            const currentPrice = parseFloat(tokenPriceData.latestTradePrice);
            
            document.getElementById('tokenProgressBar').style.width = `${progress}%`;
            document.getElementById('tokensMinted').textContent = amount.toLocaleString();
            
            // Calculate yield (11% APY)
            const annualYield = amount * 0.11;
            document.getElementById('estimatedYield').textContent = `${annualYield.toLocaleString()} FFFUND`;
            
            // Calculate cost
            const estimatedCost = amount * currentPrice;
            document.getElementById('estimatedCost').textContent = `$${estimatedCost.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2})}`;
            
            // Calculate loan impact ($0.10 per token)
            const loanImpact = amount * 0.10;
            document.getElementById('tokenLoanImpact').textContent = `-$${loanImpact.toLocaleString()}`;
        }

        // Mint tokens function
        function mintTokens() {
            const amount = parseInt(document.getElementById('tokenAmount').value) || 0;
            
            if (amount < 10000) {
                alert("Minimum mint amount is 10,000 FFFUND tokens");
                return;
            }
            
            const loader = document.getElementById('mintBtnLoader');
            const btnText = document.getElementById('mintBtnText');
            
            // Show loading state
            loader.classList.remove('hidden');
            btnText.textContent = 'Processing...';
            
            // Simulate transaction processing
            setTimeout(() => {
                // Show success message
                const currentPrice = parseFloat(tokenPriceData.latestTradePrice);
                const cost = amount * currentPrice;
                
                alert(`Successfully minted ${amount.toLocaleString()} FFFUND tokens at $${currentPrice.toFixed(2)} each (Total: $${cost.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2})}). Your annual yield will be approximately ${(amount * 0.11).toLocaleString()} FFFUND.`);
                
                // Reset form
                document.getElementById('tokenAmount').value = '';
                updateTokenEstimate();
                
                // Hide loading state
                loader.classList.add('hidden');
                btnText.textContent = 'Mint Tokens';
                
                // Close modal
                toggleModal(tokenMintModal);
            }, 1500);
        }

        // Event listeners for token minting
        document.getElementById('refreshTokenPrice').addEventListener('click', fetchTokenPrice);
        document.getElementById('tokenAmount').addEventListener('input', updateTokenEstimate);
        document.getElementById('mintTokensBtn').addEventListener('click', mintTokens);

        // Initialize token price on modal open
        document.getElementById('tokenMintBtn').addEventListener('click', () => {
            toggleModal(tokenMintModal);
            fetchTokenPrice();
        });

        // Rest of the JavaScript remains unchanged
    </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=privateuserh/privfin-vbeta1-05" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>