Skip to content

Commit

Permalink
FIX: add slackAttachment method on Deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
kbearXD committed Oct 23, 2024
1 parent c796606 commit 7ea8d0d
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions pkg/types/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/slack-go/slack"
)

type DepositStatus string
Expand Down Expand Up @@ -81,3 +82,53 @@ func (d Deposit) String() (o string) {

return o
}

func (d *Deposit) SlackAttachment() slack.Attachment {
var fields []slack.AttachmentField

if len(d.TransactionID) > 0 {
fields = append(fields, slack.AttachmentField{
Title: "TransactionID",
Value: d.TransactionID,
Short: false,
})
}

if len(d.Status) > 0 {
fields = append(fields, slack.AttachmentField{
Title: "Status",
Value: fmt.Sprintf("%s", d.Status),

Check failure on line 100 in pkg/types/deposit.go

View workflow job for this annotation

GitHub Actions / lint

S1025: the argument's underlying type is a string, should use a simple conversion instead of fmt.Sprintf (gosimple)
Short: false,
})
}

return slack.Attachment{
Color: depositStatusSlackColor(d.Status),
Title: fmt.Sprintf("Deposit %s %s To %s", d.Amount.String(), d.Asset, d.Address),
// TitleLink: "",
Pretext: "",
Text: "",
// ServiceName: "",
// ServiceIcon: "",
// FromURL: "",
// OriginalURL: "",
Fields: fields,
Footer: fmt.Sprintf("Apply Time: %s", d.Time.Time().Format(time.RFC3339)),
// FooterIcon: "",
}
}

func depositStatusSlackColor(status DepositStatus) string {
switch status {

case DepositSuccess:
return "good"

case DepositRejected:
return "red"

default:
return "gray"

}
}

0 comments on commit 7ea8d0d

Please sign in to comment.