diff --git a/.golangci.yml b/.golangci.yml index 0c88ae9..e4fd8b9 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -44,3 +44,7 @@ linters: - ifshort - gci - musttag + - structcheck + - varcheck + - deadcode + - depguard diff --git a/pkg/config/toml_config/chain.go b/pkg/config/toml_config/chain.go index d7f8c4f..af7a90a 100644 --- a/pkg/config/toml_config/chain.go +++ b/pkg/config/toml_config/chain.go @@ -17,13 +17,13 @@ type Chain struct { Filters []string `toml:"filters"` MintscanPrefix string `toml:"mintscan-prefix"` PingPrefix string `toml:"ping-prefix"` - PingBaseUrl string `toml:"ping-base-url" default:"https://ping.pub"` + PingBaseUrl string `default:"https://ping.pub" toml:"ping-base-url"` Explorer *Explorer `toml:"explorer"` - LogUnknownMessages null.Bool `toml:"log-unknown-messages" default:"false"` - LogUnparsedMessages null.Bool `toml:"log-unparsed-messages" default:"true"` - LogFailedTransactions null.Bool `toml:"log-failed-transactions" default:"true"` - LogNodeErrors null.Bool `toml:"log-node-errors" default:"true"` - FilterInternalMessages null.Bool `toml:"filter-internal-messages" default:"true"` + LogUnknownMessages null.Bool `default:"false" toml:"log-unknown-messages"` + LogUnparsedMessages null.Bool `default:"true" toml:"log-unparsed-messages"` + LogFailedTransactions null.Bool `default:"true" toml:"log-failed-transactions"` + LogNodeErrors null.Bool `default:"true" toml:"log-node-errors"` + FilterInternalMessages null.Bool `default:"true" toml:"filter-internal-messages"` Denoms DenomInfos `toml:"denoms"` } diff --git a/pkg/config/toml_config/denom.go b/pkg/config/toml_config/denom.go index 937ac1b..30be142 100644 --- a/pkg/config/toml_config/denom.go +++ b/pkg/config/toml_config/denom.go @@ -7,8 +7,8 @@ import ( type DenomInfo struct { Denom string `toml:"denom"` - DisplayDenom string `toml:"display-denom" default:""` - DenomCoefficient int64 `toml:"denom-coefficient" default:"1000000"` + DisplayDenom string `default:"" toml:"display-denom"` + DenomCoefficient int64 `default:"1000000" toml:"denom-coefficient"` CoingeckoCurrency string `toml:"coingecko-currency"` } diff --git a/pkg/config/toml_config/toml_config.go b/pkg/config/toml_config/toml_config.go index c0cdfa1..427f404 100644 --- a/pkg/config/toml_config/toml_config.go +++ b/pkg/config/toml_config/toml_config.go @@ -20,8 +20,8 @@ type TelegramConfig struct { } type LogConfig struct { - LogLevel string `toml:"level" default:"info"` - JSONOutput null.Bool `toml:"json" default:"false"` + LogLevel string `default:"info" toml:"level"` + JSONOutput null.Bool `default:"false" toml:"json"` } func (c *TomlConfig) Validate() error { diff --git a/pkg/reporters/telegram/telegram.go b/pkg/reporters/telegram/telegram.go index d431542..8a18273 100644 --- a/pkg/reporters/telegram/telegram.go +++ b/pkg/reporters/telegram/telegram.go @@ -8,6 +8,9 @@ import ( "main/pkg/types/amount" "time" + "github.com/dustin/go-humanize" + "gopkg.in/telebot.v3/middleware" + "main/pkg/alias_manager" "main/pkg/config" configTypes "main/pkg/config/types" @@ -18,7 +21,6 @@ import ( "github.com/rs/zerolog" tele "gopkg.in/telebot.v3" - "gopkg.in/telebot.v3/middleware" ) type TelegramReporter struct { @@ -232,17 +234,17 @@ func (reporter *TelegramReporter) SerializeLink(link configTypes.Link) template. func (reporter *TelegramReporter) SerializeAmount(amount amount.Amount) template.HTML { if amount.PriceUSD == nil { return template.HTML(fmt.Sprintf( - "%.6f%s", - amount.Value, + "%s %s", + humanize.BigCommaf(amount.Value), amount.Denom, )) } return template.HTML(fmt.Sprintf( - "%.6f%s ($%.2f)", - amount.Value, + "%s %s ($%s)", + humanize.BigCommaf(amount.Value), amount.Denom, - amount.PriceUSD, + utils.StripTrailingDigits(humanize.BigCommaf(amount.PriceUSD), 3), )) } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index b47aa33..90068a0 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -44,3 +44,17 @@ func SplitStringIntoChunks(msg string, maxLineLength int) []string { outMessages = append(outMessages, sb.String()) return outMessages } + +func StripTrailingDigits(s string, digits int) string { + if i := strings.Index(s, "."); i >= 0 { + if digits <= 0 { + return s[:i] + } + i++ + if i+digits >= len(s) { + return s + } + return s[:i+digits] + } + return s +}