Skip to content

Commit 8f54fdd

Browse files
committed
FIX: add slackAttachment method on Deposit
1 parent c796606 commit 8f54fdd

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

pkg/types/deposit.go

+51
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/c9s/bbgo/pkg/fixedpoint"
10+
"github.com/slack-go/slack"
1011
)
1112

1213
type DepositStatus string
@@ -81,3 +82,53 @@ func (d Deposit) String() (o string) {
8182

8283
return o
8384
}
85+
86+
func (d *Deposit) SlackAttachment() slack.Attachment {
87+
var fields []slack.AttachmentField
88+
89+
if len(d.TransactionID) > 0 {
90+
fields = append(fields, slack.AttachmentField{
91+
Title: "TransactionID",
92+
Value: d.TransactionID,
93+
Short: false,
94+
})
95+
}
96+
97+
if len(d.Status) > 0 {
98+
fields = append(fields, slack.AttachmentField{
99+
Title: "Status",
100+
Value: string(d.Status),
101+
Short: false,
102+
})
103+
}
104+
105+
return slack.Attachment{
106+
Color: depositStatusSlackColor(d.Status),
107+
Title: fmt.Sprintf("Deposit %s %s To %s", d.Amount.String(), d.Asset, d.Address),
108+
// TitleLink: "",
109+
Pretext: "",
110+
Text: "",
111+
// ServiceName: "",
112+
// ServiceIcon: "",
113+
// FromURL: "",
114+
// OriginalURL: "",
115+
Fields: fields,
116+
Footer: fmt.Sprintf("Apply Time: %s", d.Time.Time().Format(time.RFC3339)),
117+
// FooterIcon: "",
118+
}
119+
}
120+
121+
func depositStatusSlackColor(status DepositStatus) string {
122+
switch status {
123+
124+
case DepositSuccess:
125+
return "good"
126+
127+
case DepositRejected:
128+
return "red"
129+
130+
default:
131+
return "gray"
132+
133+
}
134+
}

0 commit comments

Comments
 (0)