From e68309ada0dd00b526536cd1daa403cf0af8880e Mon Sep 17 00:00:00 2001 From: WrBug Date: Fri, 5 Dec 2025 02:59:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Telegram=20?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E6=B6=88=E6=81=AF=E5=AF=B9=E9=BD=90=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E5=92=8C=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=E8=B4=A6?= =?UTF-8?q?=E6=88=B7=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 Telegram 订单成功/失败消息的左对齐问题,移除前导空格 - 在导入钱包时,如果未提供账户名,自动生成使用钱包地址后四位的名称 - 优化消息格式,确保在 Telegram 中正确显示 --- .../polymarketbot/service/AccountService.kt | 22 +++++++- .../service/TelegramNotificationService.kt | 56 +++++++++---------- 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/AccountService.kt b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/AccountService.kt index ff98215..ae13c0b 100644 --- a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/AccountService.kt +++ b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/AccountService.kt @@ -111,7 +111,25 @@ class AccountService( val encryptedApiSecret = apiKeyCreds.secret?.let { cryptoUtils.encrypt(it) } val encryptedApiPassphrase = apiKeyCreds.passphrase?.let { cryptoUtils.encrypt(it) } - // 8. 创建账户 + // 8. 生成账户名称(如果未提供,使用钱包地址后四位) + val accountName = if (request.accountName.isNullOrBlank()) { + val walletAddress = request.walletAddress.trim() + // 取地址后四位(去掉 0x 前缀后取后四位) + val addressWithoutPrefix = if (walletAddress.startsWith("0x") || walletAddress.startsWith("0X")) { + walletAddress.substring(2) + } else { + walletAddress + } + if (addressWithoutPrefix.length >= 4) { + addressWithoutPrefix.substring(addressWithoutPrefix.length - 4).uppercase() + } else { + addressWithoutPrefix.uppercase() + } + } else { + request.accountName.trim() + } + + // 9. 创建账户 val account = Account( privateKey = encryptedPrivateKey, // 存储加密后的私钥 walletAddress = request.walletAddress, @@ -119,7 +137,7 @@ class AccountService( apiKey = apiKeyCreds.apiKey, apiSecret = encryptedApiSecret, // 存储加密后的 API Secret apiPassphrase = encryptedApiPassphrase, // 存储加密后的 API Passphrase - accountName = request.accountName, + accountName = accountName, isDefault = false, // 不再支持默认账户 isEnabled = request.isEnabled, createdAt = System.currentTimeMillis(), diff --git a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/TelegramNotificationService.kt b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/TelegramNotificationService.kt index 39b5ee0..7e631d4 100644 --- a/backend/src/main/kotlin/com/wrbug/polymarketbot/service/TelegramNotificationService.kt +++ b/backend/src/main/kotlin/com/wrbug/polymarketbot/service/TelegramNotificationService.kt @@ -479,20 +479,18 @@ class TelegramNotificationService( "" } - return """ - ✅ $orderCreatedSuccess - - 📊 $orderInfo: - • $orderIdLabel: ${orderId ?: unknown} - • $marketLabel: $marketDisplay$outcomeDisplay - • $sideLabel: $sideDisplay - • $priceLabel: $price - • $quantityLabel: $size shares - • $amountLabel: $amountDisplay USDC - • $accountLabel: $escapedAccountInfo - - ⏰ $timeLabel: $time - """.trimIndent() + return """✅ $orderCreatedSuccess + +📊 $orderInfo: +• $orderIdLabel: ${orderId ?: unknown} +• $marketLabel: $marketDisplay$outcomeDisplay +• $sideLabel: $sideDisplay +• $priceLabel: $price +• $quantityLabel: $size shares +• $amountLabel: $amountDisplay USDC +• $accountLabel: $escapedAccountInfo + +⏰ $timeLabel: $time""" } /** @@ -605,22 +603,20 @@ class TelegramNotificationService( "" } - return """ - ❌ $orderCreatedFailed - - 📊 $orderInfo: - • $marketLabel: $marketDisplay$outcomeDisplay - • $sideLabel: $sideDisplay - • $priceLabel: $price - • $quantityLabel: $size shares - • $amountLabel: $amountDisplay USDC - • $accountLabel: $escapedAccountInfo - - ⚠️ $errorInfo: - $escapedErrorMessage - - ⏰ $timeLabel: $time - """.trimIndent() + return """❌ $orderCreatedFailed + +📊 $orderInfo: +• $marketLabel: $marketDisplay$outcomeDisplay +• $sideLabel: $sideDisplay +• $priceLabel: $price +• $quantityLabel: $size shares +• $amountLabel: $amountDisplay USDC +• $accountLabel: $escapedAccountInfo + +⚠️ $errorInfo: +$escapedErrorMessage + +⏰ $timeLabel: $time""" } /**