Skip to content

Commit b0e4eba

Browse files
committed
feat: Enhance webhook messages with clickable Solscan links for transactions, addresses, and tokens, and improve USD amount formatting.
1 parent 541e6c0 commit b0e4eba

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

apps/congrong-private-api/server/routes/hubble/webhook.post.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,39 +47,47 @@ function formatFlowMessage(payload: HubbleSignalPayload): string {
4747

4848
// Format numbers
4949
const amount = formatNumber(data.amount, 0, 4)
50-
const amountUsd = formatNumber(data.amount_usd)
50+
const amountUsdValue = Number(data.amount_usd) || 0
51+
const amountUsd = amountUsdValue.toLocaleString('en-US', { style: 'currency', currency: 'USD' })
52+
53+
// Solscan helpers
54+
const getTxLink = (sig: string) => `<a href="https://solscan.io/tx/${sig}">Solana Transaction</a>`
55+
const getAddrLink = (addr: string, label: string) => `<a href="https://solscan.io/account/${addr}">${label}</a>`
56+
const getTokenLink = (addr: string, symbol: string) => `<a href="https://solscan.io/token/${addr}">${symbol}</a>`
5157

5258
// Get address labels
5359
const getLabel = (address: string) => {
60+
let label = `${address.slice(0, 4)}...${address.slice(-4)}`
5461
if (tag && tag[address]) {
5562
const info = tag[address]
5663
const tags = info.tag.filter(t => t !== 'CEX' && t !== 'Deposit Address').join(', ')
5764
const source = info.source || ''
58-
// If we have source and tags, combine them.
59-
// Example: Binance (Deposit Address, CEX) -> We filtered out Deposit Address/CEX.
60-
// If tags is empty after filter, just return source.
61-
if (source && tags) { return `${source} (${tags})` }
62-
if (source) { return source }
63-
if (tags) { return tags }
65+
if (source && tags) { label = `${source} (${tags})` }
66+
else if (source) { label = source }
67+
else if (tags) { label = tags }
6468
}
65-
return `${address.slice(0, 4)}...${address.slice(-4)}`
69+
return getAddrLink(address, label)
6670
}
6771

6872
const senderLabel = getLabel(data.sender)
6973
const receiverLabel = getLabel(data.receiver)
7074

75+
// Handle Symbol display
76+
const displaySymbol = (data.symbol && data.symbol !== 'UNKNOWN') ? data.symbol : 'Token'
77+
const tokenLabel = getTokenLink(data.token, displaySymbol)
78+
7179
// Build message
7280
const emoji = isInflow ? '🟢' : '🔴'
7381
const action = isInflow ? '大额流入' : '大额流出'
7482

7583
const lines = [
7684
`${emoji} <b>${action}提醒</b>`,
7785
'',
78-
`💰 <b>金额:</b> ${amount} ${data.symbol} ($${amountUsd})`,
86+
`💰 <b>金额:</b> ${amount} ${tokenLabel} (${amountUsd})`,
7987
`📤 <b>发送方:</b> ${senderLabel}`,
8088
`📥 <b>接收方:</b> ${receiverLabel}`,
8189
'',
82-
`⛓️ ${payload.chain} | TX: <code>${payload.signature.slice(0, 16)}...</code>`,
90+
`🔗 ${getTxLink(payload.signature)}`,
8391
]
8492

8593
return lines.join('\n')

0 commit comments

Comments
 (0)