Skip to content

Commit

Permalink
feat: added indicator when currenct is being converted for individual…
Browse files Browse the repository at this point in the history
… quotes
  • Loading branch information
achannarasappa committed Feb 14, 2021
1 parent 590ee57 commit 5ba351a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
15 changes: 12 additions & 3 deletions internal/ui/component/watchlist/watchlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ type Model struct {
ExtraInfoExchange bool
ExtraInfoFundamentals bool
Sorter Sorter
Context c.Context
}

// NewModel returns a model with default values.
func NewModel(ctx c.Context) Model {
return Model{
Width: 80,
Context: ctx,
Separate: ctx.Config.Separate,
ExtraInfoExchange: ctx.Config.ExtraInfoExchange,
ExtraInfoFundamentals: ctx.Config.ExtraInfoFundamentals,
Expand All @@ -50,7 +52,7 @@ func (m Model) View() string {
[]string{
item(quote, m.Positions[quote.Symbol], m.Width),
extraInfoFundamentals(m.ExtraInfoFundamentals, quote, m.Width),
extraInfoExchange(m.ExtraInfoExchange, quote, m.Width),
extraInfoExchange(m.ExtraInfoExchange, quote, m.Context.Config.Currency, m.Width),
},
"",
),
Expand Down Expand Up @@ -116,14 +118,21 @@ func item(q Quote, p Position, width int) string {
)
}

func extraInfoExchange(show bool, q Quote, width int) string {
func extraInfoExchange(show bool, q Quote, targetCurrency string, width int) string {
if !show {
return ""
}

currencyText := q.Currency

if targetCurrency != "" && targetCurrency != q.Currency {
currencyText = q.Currency + " → " + targetCurrency
}

return "\n" + Line(
width,
Cell{
Text: tagText(q.Currency) + " " + tagText(exchangeDelayText(q.ExchangeDelay)) + " " + tagText(q.ExchangeName),
Text: tagText(currencyText) + " " + tagText(exchangeDelayText(q.ExchangeDelay)) + " " + tagText(q.ExchangeName),
},
)
}
Expand Down
35 changes: 35 additions & 0 deletions internal/ui/component/watchlist/watchlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,41 @@ var _ = Describe("Watchlist", func() {
Expect(removeFormatting(m.View())).To(Equal(expected))
})
})

When("the currency is being converted", func() {
It("should show an indicator with the to and from currency codes", func() {
m := NewModel(c.Context{
Config: c.Config{
ExtraInfoExchange: true,
Currency: "EUR",
},
})
m.Quotes = []Quote{
{
ResponseQuote: ResponseQuote{
Symbol: "APPL",
ShortName: "Apple, Inc",
Currency: "USD",
ExchangeName: "NASDAQ",
ExchangeDelay: 0,
},
Price: 5000.0,
Change: 1000.0,
ChangePercent: 20.0,
IsActive: true,
IsRegularTradingSession: true,
},
}
m.Context.Config.Currency = "EUR"
expected := strings.Join([]string{
"APPL ⦿ 5000.00",
"Apple, Inc ↑ 1000.00 (20.00%)",
" USD → EUR Real-Time NASDAQ ",
}, "\n")
Expect(removeFormatting(m.View())).To(Equal(expected))
})

})
})

When("the option for extra fundamental information is set", func() {
Expand Down

0 comments on commit 5ba351a

Please sign in to comment.