Skip to content

Commit

Permalink
cleanup printing of large values
Browse files Browse the repository at this point in the history
  • Loading branch information
bonedaddy committed Jan 14, 2021
1 parent 764c888 commit f9f53a8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions discord/discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import (
"github.com/bonedaddy/go-indexed/bclient"
"github.com/bonedaddy/go-indexed/db"
"github.com/bwmarrin/discordgo"
"golang.org/x/text/message"
)

var (
rateLimitMsg = "You are being rate limited. Users are allowed 1 blockchain query per command every 60 seconds"
printer *message.Printer
)

// Client wraps bclient and discordgo to provide a discord bot for indexed finance
Expand All @@ -31,6 +33,10 @@ type Client struct {
wg *sync.WaitGroup
}

func init() {
printer = message.NewPrinter(message.MatchLanguage("en"))
}

// NewClient provides a wrapper around discordgo
func NewClient(ctx context.Context, cfg *Config, bc *bclient.Client, db *db.Database) (*Client, error) {
wg := &sync.WaitGroup{}
Expand Down
2 changes: 1 addition & 1 deletion discord/governance.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,5 @@ func (c *Client) governanceTokenTotalSupply(ctx *dgc.Ctx) {
return
}
supplyF, _ := utils.ToDecimal(supply, 18).Float64()
ctx.RespondText(fmt.Sprintf("ndx token total supply: %0.2f", supplyF))
ctx.RespondText(printer.Sprintf("ndx token total supply: %0.2f", supplyF))
}
4 changes: 2 additions & 2 deletions discord/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (c *Client) poolTotalValueLocked(ctx *dgc.Ctx) {
ctx.RespondText("failed to get total value locked")
return
}
ctx.RespondText(fmt.Sprintf("total value locked for %s: %0.2f", poolName, tvl))
ctx.RespondText(printer.Sprintf("total value locked for %s: $%0.2f", poolName, tvl))
}

func (c *Client) poolTotalSupply(ctx *dgc.Ctx) {
Expand All @@ -92,5 +92,5 @@ func (c *Client) poolTotalSupply(ctx *dgc.Ctx) {
return
}
supplyF, _ := utils.ToDecimal(supply, 18).Float64()
ctx.RespondText(fmt.Sprintf("total supply for %s: %0.2f", poolName, supplyF))
ctx.RespondText(printer.Sprintf("total supply for %s: %0.2f", poolName, supplyF))
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/wcharczuk/go-chart/v2 v2.1.0
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
golang.org/x/text v0.3.3
gopkg.in/yaml.v2 v2.3.0
gorm.io/driver/postgres v1.0.6
gorm.io/driver/sqlite v1.1.4
Expand Down

0 comments on commit f9f53a8

Please sign in to comment.