From 20f43e46345266ed88ca7d72d2aff0f6b31c4c84 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 14 Nov 2024 12:15:52 +0800 Subject: [PATCH] types: attach explorer url to the deposit attachment --- pkg/types/deposit.go | 48 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/pkg/types/deposit.go b/pkg/types/deposit.go index dcd58e9c6..0a1853ec1 100644 --- a/pkg/types/deposit.go +++ b/pkg/types/deposit.go @@ -138,21 +138,59 @@ func (d *Deposit) SlackAttachment() slack.Attachment { }) return slack.Attachment{ - Color: depositStatusSlackColor(d.Status), - Title: fmt.Sprintf("Deposit %s %s To %s (%s)", d.Amount.String(), d.Asset, d.Address, d.Exchange), - // TitleLink: "", - Pretext: "", - Text: "", + Color: depositStatusSlackColor(d.Status), + Fallback: "", + ID: 0, + Title: fmt.Sprintf("Deposit %s %s To %s (%s)", d.Amount.String(), d.Asset, d.Address, d.Exchange), + TitleLink: getExplorerURL(d.Network, d.TransactionID), + Pretext: "", + Text: "", + ImageURL: "", + ThumbURL: "", + ServiceName: "", + ServiceIcon: "", + FromURL: "", + OriginalURL: "", // ServiceName: "", // ServiceIcon: "", // FromURL: "", // OriginalURL: "", Fields: fields, + Actions: nil, + MarkdownIn: nil, + Blocks: slack.Blocks{}, Footer: fmt.Sprintf("Apply Time: %s", d.Time.Time().Format(time.RFC3339)), FooterIcon: ExchangeFooterIcon(d.Exchange), + Ts: "", } } +func getExplorerURL(network string, txID string) string { + switch strings.ToUpper(network) { + case "BTC": + return getBitcoinNetworkExplorerURL(txID) + case "BSC": + return getBscNetworkExplorerURL(txID) + case "ETH": + return getEthNetworkExplorerURL(txID) + + } + + return "" +} + +func getEthNetworkExplorerURL(txID string) string { + return "https://etherscan.io/tx/" + txID +} + +func getBitcoinNetworkExplorerURL(txID string) string { + return "https://www.blockchain.com/explorer/transactions/btc/" + txID +} + +func getBscNetworkExplorerURL(txID string) string { + return "https://bscscan.com/tx/" + txID +} + func depositStatusSlackColor(status DepositStatus) string { switch status {