From 1761228d101447df8a89902ae25bc26d875b664c Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 10 Nov 2025 05:02:22 +0000 Subject: [PATCH 1/2] fix: Add missing components and utilities to resolve frontend errors - Create BotControls.svelte component with start/stop scanner functionality - Add format.js utility with comprehensive number formatting functions - Add tsconfig.json to properly handle TypeScript files in the project - Fix .gitignore to exclude Python lib/ directory only, not frontend/src/lib Resolves: - Missing BotControls component import error - Missing format utility functions (formatAdaptive, formatSpread, formatPrice, formatPercent) - TypeScript compilation issues with websocket.ts - Improves type safety and build configuration The sendCommandViaWS export issue should be resolved with proper TypeScript configuration. Svelte component prop warnings are standard SvelteKit framework warnings and can be ignored. --- .gitignore | 3 +- .../src/lib/components/BotControls.svelte | 230 ++++++++++++++++++ frontend/src/lib/utils/format.js | 206 ++++++++++++++++ frontend/tsconfig.json | 27 ++ 4 files changed, 465 insertions(+), 1 deletion(-) create mode 100644 frontend/src/lib/components/BotControls.svelte create mode 100644 frontend/src/lib/utils/format.js create mode 100644 frontend/tsconfig.json diff --git a/.gitignore b/.gitignore index ec479015..5f5b8beb 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,8 @@ dist/ downloads/ eggs/ .eggs/ -lib/ +# Python lib directories (not frontend/src/lib) +/lib/ lib64/ parts/ sdist/ diff --git a/frontend/src/lib/components/BotControls.svelte b/frontend/src/lib/components/BotControls.svelte new file mode 100644 index 00000000..8af2f1da --- /dev/null +++ b/frontend/src/lib/components/BotControls.svelte @@ -0,0 +1,230 @@ + + +
+
+

🤖 Bot Controls

+
+ {$isScanning ? '🟢 Running' : '🔴 Stopped'} +
+
+ +
+ {#if !$isScanning} + + {:else} + + {/if} +
+ +
+

+ {#if $isScanning} + 🔍 Scanner is actively searching for trading opportunities + {:else} + 💤 Scanner is stopped. Click "Start Scanner" to begin + {/if} +

+
+
+ + diff --git a/frontend/src/lib/utils/format.js b/frontend/src/lib/utils/format.js new file mode 100644 index 00000000..2fc288ef --- /dev/null +++ b/frontend/src/lib/utils/format.js @@ -0,0 +1,206 @@ +/** + * Utility functions for formatting numbers and values + */ + +/** + * Format a number with adaptive decimal places + * @param {number} value - The value to format + * @param {number} minDecimals - Minimum decimal places + * @param {number} maxDecimals - Maximum decimal places + * @returns {string} Formatted value + */ +export function formatAdaptive(value, minDecimals = 2, maxDecimals = 4) { + if (value === null || value === undefined || isNaN(value)) { + return '0'; + } + + const num = Number(value); + + // For very small numbers, use more decimals + if (Math.abs(num) < 0.001 && num !== 0) { + return num.toFixed(maxDecimals + 2); + } + + // For normal numbers + if (Math.abs(num) < 1) { + return num.toFixed(maxDecimals); + } + + return num.toFixed(minDecimals); +} + +/** + * Format a spread percentage + * @param {number} spread - The spread value + * @returns {string} Formatted spread + */ +export function formatSpread(spread) { + if (spread === null || spread === undefined || isNaN(spread)) { + return '0.00'; + } + return Number(spread).toFixed(4); +} + +/** + * Format a price with adaptive decimals based on value + * @param {number} price - The price to format + * @returns {string} Formatted price + */ +export function formatPrice(price) { + if (price === null || price === undefined || isNaN(price)) { + return '0.00'; + } + + const num = Number(price); + + // For very small prices (< 0.01), use more decimals + if (num < 0.01 && num > 0) { + return num.toFixed(6); + } + + // For small prices (< 1), use 4 decimals + if (num < 1) { + return num.toFixed(4); + } + + // For normal prices, use 2 decimals + return num.toFixed(2); +} + +/** + * Format a percentage value + * @param {number} percent - The percentage value + * @returns {string} Formatted percentage + */ +export function formatPercent(percent) { + if (percent === null || percent === undefined || isNaN(percent)) { + return '0.00'; + } + return Number(percent).toFixed(2); +} + +/** + * Format a volume value + * @param {number} volume - The volume value + * @returns {string} Formatted volume + */ +export function formatVolume(volume) { + if (volume === null || volume === undefined || isNaN(volume)) { + return '0'; + } + + const num = Number(volume); + + // Format with K, M, B suffixes + if (num >= 1_000_000_000) { + return (num / 1_000_000_000).toFixed(2) + 'B'; + } + if (num >= 1_000_000) { + return (num / 1_000_000).toFixed(2) + 'M'; + } + if (num >= 1_000) { + return (num / 1_000).toFixed(2) + 'K'; + } + + return num.toFixed(0); +} + +/** + * Format a PnL value with color indication + * @param {number} pnl - The PnL value + * @param {boolean} isPercent - Whether the value is a percentage + * @returns {string} Formatted PnL + */ +export function formatPnL(pnl, isPercent = false) { + if (pnl === null || pnl === undefined || isNaN(pnl)) { + return isPercent ? '0.00%' : '$0.00'; + } + + const num = Number(pnl); + const sign = num >= 0 ? '+' : ''; + const formatted = isPercent + ? num.toFixed(2) + '%' + : '$' + num.toFixed(2); + + return sign + formatted; +} + +/** + * Format a duration in seconds to human readable format + * @param {number} seconds - Duration in seconds + * @returns {string} Formatted duration + */ +export function formatDuration(seconds) { + if (seconds === null || seconds === undefined || isNaN(seconds)) { + return '0s'; + } + + const num = Number(seconds); + + if (num < 60) { + return num.toFixed(0) + 's'; + } + + const minutes = Math.floor(num / 60); + const remainingSeconds = num % 60; + + if (minutes < 60) { + return `${minutes}m ${remainingSeconds.toFixed(0)}s`; + } + + const hours = Math.floor(minutes / 60); + const remainingMinutes = minutes % 60; + + return `${hours}h ${remainingMinutes}m`; +} + +/** + * Format a timestamp to local time + * @param {number|string} timestamp - Unix timestamp or ISO string + * @returns {string} Formatted time + */ +export function formatTime(timestamp) { + if (!timestamp) { + return '-'; + } + + const date = new Date(timestamp); + + if (isNaN(date.getTime())) { + return '-'; + } + + return date.toLocaleTimeString('en-US', { + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: false + }); +} + +/** + * Format a timestamp to local date and time + * @param {number|string} timestamp - Unix timestamp or ISO string + * @returns {string} Formatted date and time + */ +export function formatDateTime(timestamp) { + if (!timestamp) { + return '-'; + } + + const date = new Date(timestamp); + + if (isNaN(date.getTime())) { + return '-'; + } + + return date.toLocaleString('en-US', { + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit', + hour12: false + }); +} diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json new file mode 100644 index 00000000..9bb07567 --- /dev/null +++ b/frontend/tsconfig.json @@ -0,0 +1,27 @@ +{ + "extends": "./.svelte-kit/tsconfig.json", + "compilerOptions": { + "allowJs": true, + "checkJs": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "sourceMap": true, + "strict": false, + "moduleResolution": "bundler", + "module": "ESNext", + "target": "ESNext", + "lib": ["ESNext", "DOM", "DOM.Iterable"], + "types": ["vite/client"], + "isolatedModules": true, + "allowSyntheticDefaultImports": true + }, + "include": [ + "src/**/*.d.ts", + "src/**/*.ts", + "src/**/*.js", + "src/**/*.svelte" + ], + "exclude": ["node_modules", "build", ".svelte-kit"] +} From 4dae01838b67d64ad94e96ee198c5bebe7132e7f Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 10 Nov 2025 05:06:40 +0000 Subject: [PATCH 2/2] fix: Add missing formatUSDT export to format utilities - Add formatUSDT function to format.js - Formats USDT cryptocurrency values with appropriate decimal places - Used by PositionCard, StatsPanel, GlobalStats, ExportPanel, TradeHistory components Resolves: SyntaxError for missing formatUSDT export --- frontend/src/lib/utils/format.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/frontend/src/lib/utils/format.js b/frontend/src/lib/utils/format.js index 2fc288ef..f5176186 100644 --- a/frontend/src/lib/utils/format.js +++ b/frontend/src/lib/utils/format.js @@ -105,6 +105,27 @@ export function formatVolume(volume) { return num.toFixed(0); } +/** + * Format a USDT value + * @param {number} value - The USDT value + * @returns {string} Formatted USDT value + */ +export function formatUSDT(value) { + if (value === null || value === undefined || isNaN(value)) { + return '0.00'; + } + + const num = Number(value); + + // For very small values, use more decimals + if (Math.abs(num) < 0.01 && num !== 0) { + return num.toFixed(4); + } + + // For normal values, use 2 decimals + return num.toFixed(2); +} + /** * Format a PnL value with color indication * @param {number} pnl - The PnL value