Skip to content

Commit a69fae9

Browse files
refactor: resolve merge conflicts with positions rename
2 parents 984a8aa + e8a8cc4 commit a69fae9

File tree

9 files changed

+295
-47
lines changed

9 files changed

+295
-47
lines changed

internal/ui/component/summary/summary.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ func (m *Model) View() string {
6262
m.styles.TextLabel("Change: ") + quoteChangeText(m.summary.TotalChange.Amount, m.summary.TotalChange.Percent, m.styles)
6363
widthChange := ansi.PrintableRuneWidth(textChange)
6464
textValue := m.styles.TextLabel(" • ") +
65-
m.styles.TextLabel("Value: ") + m.styles.TextLabel(u.ConvertFloatToString(m.summary.Value, false))
65+
m.styles.TextLabel("Value: ") + m.styles.TextLabel(u.ConvertFloatToStringWithCommas(m.summary.Value, false))
6666
widthValue := ansi.PrintableRuneWidth(textValue)
6767
textCost := m.styles.TextLabel(" • ") +
68-
m.styles.TextLabel("Cost: ") + m.styles.TextLabel(u.ConvertFloatToString(m.summary.Cost, false))
68+
m.styles.TextLabel("Cost: ") + m.styles.TextLabel(u.ConvertFloatToStringWithCommas(m.summary.Cost, false))
6969
widthCost := ansi.PrintableRuneWidth(textValue)
7070

7171
return grid.Render(grid.Grid{
@@ -103,12 +103,12 @@ func (m *Model) View() string {
103103

104104
func quoteChangeText(change float64, changePercent float64, styles c.Styles) string {
105105
if change == 0.0 {
106-
return styles.TextLabel(u.ConvertFloatToString(change, false) + " (" + u.ConvertFloatToString(changePercent, false) + "%)")
106+
return styles.TextLabel(u.ConvertFloatToStringWithCommas(change, false) + " (" + u.ConvertFloatToStringWithCommas(changePercent, false) + "%)")
107107
}
108108

109109
if change > 0.0 {
110-
return styles.TextPrice(changePercent, "↑ "+u.ConvertFloatToString(change, false)+" ("+u.ConvertFloatToString(changePercent, false)+"%)")
110+
return styles.TextPrice(changePercent, "↑ "+u.ConvertFloatToStringWithCommas(change, false)+" ("+u.ConvertFloatToStringWithCommas(changePercent, false)+"%)")
111111
}
112112

113-
return styles.TextPrice(changePercent, "↓ "+u.ConvertFloatToString(change, false)+" ("+u.ConvertFloatToString(changePercent, false)+"%)")
113+
return styles.TextPrice(changePercent, "↓ "+u.ConvertFloatToStringWithCommas(change, false)+" ("+u.ConvertFloatToStringWithCommas(changePercent, false)+"%)")
114114
}

internal/ui/component/summary/summary_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var _ = Describe("Summary", func() {
4646
},
4747
}))
4848
Expect(removeFormatting(m.View())).To(Equal(strings.Join([]string{
49-
"Day Change: ↑ 100.00 (10.00%) • Change: ↑ 9000.00 (1000.00%) • Value: 10000.00 • Cost: 1000.00 ",
49+
"Day Change: ↑ 100.00 (10.00%) • Change: ↑ 9,000.00 (1,000.00%) • Value: 10,000.00 • Cost: 1,000.00 ",
5050
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
5151
}, "\n")))
5252
})
@@ -69,7 +69,7 @@ var _ = Describe("Summary", func() {
6969
},
7070
}))
7171
Expect(removeFormatting(m.View())).To(Equal(strings.Join([]string{
72-
"Day Change: ↓ -100.00 (-10.00%) • Change: ↓ -9000.00 (-1000.00%) • Value: 1000.00 • Cost: 10000.00",
72+
"Day Change: ↓ -100.00 (-10.00%) • Change: ↓ -9,000.00 (-1,000.00%) • Value: 1,000.00 • Cost: 10,000.00",
7373
"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
7474
}, "\n")))
7575
})

internal/ui/component/watchlist/row/row.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func New(config Config) *Model {
8484
id: id,
8585
width: 80,
8686
config: config,
87-
priceNoChangeSegment: u.ConvertFloatToString(config.Asset.QuotePrice.Price, config.Asset.Meta.IsVariablePrecision),
87+
priceNoChangeSegment: u.ConvertFloatToStringWithCommas(config.Asset.QuotePrice.Price, config.Asset.Meta.IsVariablePrecision),
8888
priceChangeSegment: "",
8989
}
9090
}
@@ -111,8 +111,8 @@ func (m *Model) Update(msg tea.Msg) (*Model, tea.Cmd) {
111111
m.priceStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("15")).Background(lipgloss.Color(""))
112112
m.frame = 0
113113

114-
oldPrice := u.ConvertFloatToString(m.config.Asset.QuotePrice.Price, m.config.Asset.Meta.IsVariablePrecision)
115-
newPrice := u.ConvertFloatToString(msg.QuotePrice.Price, msg.Meta.IsVariablePrecision)
114+
oldPrice := u.ConvertFloatToStringWithCommas(m.config.Asset.QuotePrice.Price, m.config.Asset.Meta.IsVariablePrecision)
115+
newPrice := u.ConvertFloatToStringWithCommas(msg.QuotePrice.Price, msg.Meta.IsVariablePrecision)
116116

117117
if msg.QuotePrice.Price > m.config.Asset.QuotePrice.Price {
118118
m.priceChangeDirection = 1
@@ -147,7 +147,7 @@ func (m *Model) Update(msg tea.Msg) (*Model, tea.Cmd) {
147147

148148
// If symbol has changed or price has not changed then just update the asset
149149
m.config.Asset = msg
150-
m.priceNoChangeSegment = u.ConvertFloatToString(msg.QuotePrice.Price, msg.Meta.IsVariablePrecision)
150+
m.priceNoChangeSegment = u.ConvertFloatToStringWithCommas(msg.QuotePrice.Price, msg.Meta.IsVariablePrecision)
151151
m.priceChangeSegment = ""
152152

153153
return m, nil
@@ -366,7 +366,7 @@ func textPosition(asset *c.Asset, styles c.Styles) string {
366366
positionValue = u.ValueText(asset.Position.Value, styles) +
367367
styles.TextLight(
368368
" ("+
369-
u.ConvertFloatToString(asset.Position.Weight, asset.Meta.IsVariablePrecision)+"%"+
369+
u.ConvertFloatToStringWithCommas(asset.Position.Weight, asset.Meta.IsVariablePrecision)+"%"+
370370
")")
371371
}
372372
if asset.Position.TotalChange.Amount != 0.0 {
@@ -385,19 +385,19 @@ func textQuoteExtended(asset *c.Asset, styles c.Styles) string {
385385
}
386386

387387
if asset.Class == c.AssetClassFuturesContract {
388-
return styles.Text(u.ConvertFloatToString(asset.QuoteFutures.IndexPrice, asset.Meta.IsVariablePrecision)) +
388+
return styles.Text(u.ConvertFloatToStringWithCommas(asset.QuoteFutures.IndexPrice, asset.Meta.IsVariablePrecision)) +
389389
"\n" +
390-
styles.Text(u.ConvertFloatToString(asset.QuoteFutures.Basis, false)) + "%"
390+
styles.Text(u.ConvertFloatToStringWithCommas(asset.QuoteFutures.Basis, false)) + "%"
391391
}
392392

393393
if asset.QuotePrice.PriceOpen == 0.0 {
394-
return styles.Text(u.ConvertFloatToString(asset.QuotePrice.PricePrevClose, asset.Meta.IsVariablePrecision)) +
394+
return styles.Text(u.ConvertFloatToStringWithCommas(asset.QuotePrice.PricePrevClose, asset.Meta.IsVariablePrecision)) +
395395
"\n"
396396
}
397397

398-
return styles.Text(u.ConvertFloatToString(asset.QuotePrice.PricePrevClose, asset.Meta.IsVariablePrecision)) +
398+
return styles.Text(u.ConvertFloatToStringWithCommas(asset.QuotePrice.PricePrevClose, asset.Meta.IsVariablePrecision)) +
399399
"\n" +
400-
styles.Text(u.ConvertFloatToString(asset.QuotePrice.PriceOpen, asset.Meta.IsVariablePrecision))
400+
styles.Text(u.ConvertFloatToStringWithCommas(asset.QuotePrice.PriceOpen, asset.Meta.IsVariablePrecision))
401401

402402
}
403403

@@ -429,9 +429,9 @@ func textPositionExtended(asset *c.Asset, styles c.Styles) string {
429429
return ""
430430
}
431431

432-
return styles.Text(u.ConvertFloatToString(asset.Position.UnitCost, asset.Meta.IsVariablePrecision)) +
432+
return styles.Text(u.ConvertFloatToStringWithCommas(asset.Position.UnitCost, asset.Meta.IsVariablePrecision)) +
433433
"\n" +
434-
styles.Text(u.ConvertFloatToString(asset.Position.Quantity, asset.Meta.IsVariablePrecision))
434+
styles.Text(u.ConvertFloatToStringWithCommas(asset.Position.Quantity, asset.Meta.IsVariablePrecision))
435435

436436
}
437437

@@ -451,9 +451,9 @@ func textQuoteRange(asset *c.Asset, styles c.Styles) string {
451451
if asset.Class == c.AssetClassFuturesContract {
452452

453453
if asset.QuotePrice.PriceDayHigh != 0.0 && asset.QuotePrice.PriceDayLow != 0.0 {
454-
return u.ConvertFloatToString(asset.QuotePrice.PriceDayLow, asset.Meta.IsVariablePrecision) +
454+
return u.ConvertFloatToStringWithCommas(asset.QuotePrice.PriceDayLow, asset.Meta.IsVariablePrecision) +
455455
styles.Text(" - ") +
456-
u.ConvertFloatToString(asset.QuotePrice.PriceDayHigh, asset.Meta.IsVariablePrecision) +
456+
u.ConvertFloatToStringWithCommas(asset.QuotePrice.PriceDayHigh, asset.Meta.IsVariablePrecision) +
457457
"\n" +
458458
asset.QuoteFutures.Expiry
459459
}
@@ -463,13 +463,13 @@ func textQuoteRange(asset *c.Asset, styles c.Styles) string {
463463
}
464464

465465
if asset.QuotePrice.PriceDayHigh != 0.0 && asset.QuotePrice.PriceDayLow != 0.0 {
466-
return u.ConvertFloatToString(asset.QuotePrice.PriceDayLow, asset.Meta.IsVariablePrecision) +
466+
return u.ConvertFloatToStringWithCommas(asset.QuotePrice.PriceDayLow, asset.Meta.IsVariablePrecision) +
467467
styles.Text(" - ") +
468-
u.ConvertFloatToString(asset.QuotePrice.PriceDayHigh, asset.Meta.IsVariablePrecision) +
468+
u.ConvertFloatToStringWithCommas(asset.QuotePrice.PriceDayHigh, asset.Meta.IsVariablePrecision) +
469469
"\n" +
470-
u.ConvertFloatToString(asset.QuoteExtended.FiftyTwoWeekLow, asset.Meta.IsVariablePrecision) +
470+
u.ConvertFloatToStringWithCommas(asset.QuoteExtended.FiftyTwoWeekLow, asset.Meta.IsVariablePrecision) +
471471
styles.Text(" - ") +
472-
u.ConvertFloatToString(asset.QuoteExtended.FiftyTwoWeekHigh, asset.Meta.IsVariablePrecision)
472+
u.ConvertFloatToStringWithCommas(asset.QuoteExtended.FiftyTwoWeekHigh, asset.Meta.IsVariablePrecision)
473473
}
474474

475475
return ""
@@ -501,14 +501,14 @@ func textQuoteRangeLabels(asset *c.Asset, styles c.Styles) string {
501501
func textVolumeMarketCap(asset *c.Asset) string {
502502

503503
if asset.Class == c.AssetClassFuturesContract {
504-
return u.ConvertFloatToString(asset.QuoteFutures.OpenInterest, true) +
504+
return u.ConvertFloatToStringWithCommas(asset.QuoteFutures.OpenInterest, true) +
505505
"\n" +
506-
u.ConvertFloatToString(asset.QuoteExtended.Volume, true)
506+
u.ConvertFloatToStringWithCommas(asset.QuoteExtended.Volume, true)
507507
}
508508

509-
return u.ConvertFloatToString(asset.QuoteExtended.MarketCap, true) +
509+
return u.ConvertFloatToStringWithCommas(asset.QuoteExtended.MarketCap, true) +
510510
"\n" +
511-
u.ConvertFloatToString(asset.QuoteExtended.Volume, true)
511+
u.ConvertFloatToStringWithCommas(asset.QuoteExtended.Volume, true)
512512
}
513513
func textVolumeMarketCapLabels(asset *c.Asset, styles c.Styles) string {
514514

@@ -537,14 +537,14 @@ func textMarketState(asset *c.Asset, styles c.Styles) string {
537537

538538
func quoteChangeText(change float64, changePercent float64, isVariablePrecision bool, styles c.Styles) string {
539539
if change == 0.0 {
540-
return styles.TextPrice(changePercent, " "+u.ConvertFloatToString(change, isVariablePrecision)+" ("+u.ConvertFloatToString(changePercent, false)+"%)")
540+
return styles.TextPrice(changePercent, " "+u.ConvertFloatToStringWithCommas(change, isVariablePrecision)+" ("+u.ConvertFloatToStringWithCommas(changePercent, false)+"%)")
541541
}
542542

543543
if change > 0.0 {
544-
return styles.TextPrice(changePercent, "↑ "+u.ConvertFloatToString(change, isVariablePrecision)+" ("+u.ConvertFloatToString(changePercent, false)+"%)")
544+
return styles.TextPrice(changePercent, "↑ "+u.ConvertFloatToStringWithCommas(change, isVariablePrecision)+" ("+u.ConvertFloatToStringWithCommas(changePercent, false)+"%)")
545545
}
546546

547-
return styles.TextPrice(changePercent, "↓ "+u.ConvertFloatToString(change, isVariablePrecision)+" ("+u.ConvertFloatToString(changePercent, false)+"%)")
547+
return styles.TextPrice(changePercent, "↓ "+u.ConvertFloatToStringWithCommas(change, isVariablePrecision)+" ("+u.ConvertFloatToStringWithCommas(changePercent, false)+"%)")
548548
}
549549

550550
func textSeparator(width int, styles c.Styles) string {

internal/ui/component/watchlist/row/row_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ var _ = Describe("Row", func() {
181181

182182
view := stripANSI(outputRow.View())
183183
Expect(view).To(ContainSubstring("AAPL"), "output was: %q", view)
184-
Expect(view).To(ContainSubstring("1500.00"), "output was: %q", view)
184+
Expect(view).To(ContainSubstring("1,500.00"), "output was: %q", view)
185185
Expect(cmd).ToNot(BeNil())
186186

187187
// Simulate frame updates
@@ -196,7 +196,7 @@ var _ = Describe("Row", func() {
196196
view = stripANSI(outputRow.View())
197197
Expect(cmd).To(BeNil(), "expected cmd to be nil after final frame, got: %v", cmd)
198198
Expect(view).To(ContainSubstring("AAPL"), "output was: %q", view)
199-
Expect(view).To(ContainSubstring("1500.00"), "output was: %q", view)
199+
Expect(view).To(ContainSubstring("1,500.00"), "output was: %q", view)
200200
})
201201

202202
})

internal/ui/component/watchlist/watchlist.go

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ type SetAssetsMsg []c.Asset
4040
// Messages for updating assets
4141
type UpdateAssetsMsg []c.Asset
4242

43+
// Messages for changing sort
44+
type ChangeSortMsg string
45+
4346
// NewModel returns a model with default values
4447
func NewModel(config Config) *Model {
4548
return &Model{
@@ -138,6 +141,44 @@ func (m *Model) Update(msg tea.Msg) (*Model, tea.Cmd) {
138141

139142
return m, tea.Batch(cmds...)
140143

144+
case ChangeSortMsg:
145+
146+
var cmd tea.Cmd
147+
cmds := make([]tea.Cmd, 0)
148+
149+
// Update the sorter with the new sort option
150+
m.config.Sort = string(msg)
151+
m.sorter = s.NewSorter(m.config.Sort)
152+
153+
// Re-sort and update the assets
154+
assets := m.sorter(m.assets)
155+
m.assets = assets
156+
157+
// Update rows with the new order (similar to SetAssetsMsg)
158+
for i, asset := range assets {
159+
if i < len(m.rows) {
160+
m.rows[i], cmd = m.rows[i].Update(row.UpdateAssetMsg(asset))
161+
cmds = append(cmds, cmd)
162+
} else {
163+
// Create new row if needed
164+
m.rows = append(m.rows, row.New(row.Config{
165+
Separate: m.config.Separate,
166+
ExtraInfoExchange: m.config.ExtraInfoExchange,
167+
ExtraInfoFundamentals: m.config.ExtraInfoFundamentals,
168+
ShowPositions: m.config.ShowPositions,
169+
Styles: m.config.Styles,
170+
Asset: asset,
171+
}))
172+
}
173+
}
174+
175+
// Remove extra rows if needed
176+
if len(assets) < len(m.rows) {
177+
m.rows = m.rows[:len(assets)]
178+
}
179+
180+
return m, tea.Batch(cmds...)
181+
141182
}
142183

143184
return m, nil
@@ -165,14 +206,14 @@ func getCellWidths(assets []*c.Asset) row.CellWidthsContainer {
165206
for _, asset := range assets {
166207
var quoteLength int
167208

168-
volumeMarketCapLength := len(u.ConvertFloatToString(asset.QuoteExtended.MarketCap, true))
209+
volumeMarketCapLength := len(u.ConvertFloatToStringWithCommas(asset.QuoteExtended.MarketCap, true))
169210

170211
if asset.QuoteExtended.FiftyTwoWeekHigh == 0.0 {
171-
quoteLength = len(u.ConvertFloatToString(asset.QuotePrice.Price, asset.Meta.IsVariablePrecision))
212+
quoteLength = len(u.ConvertFloatToStringWithCommas(asset.QuotePrice.Price, asset.Meta.IsVariablePrecision))
172213
}
173214

174215
if asset.QuoteExtended.FiftyTwoWeekHigh != 0.0 {
175-
quoteLength = len(u.ConvertFloatToString(asset.QuoteExtended.FiftyTwoWeekHigh, asset.Meta.IsVariablePrecision))
216+
quoteLength = len(u.ConvertFloatToStringWithCommas(asset.QuoteExtended.FiftyTwoWeekHigh, asset.Meta.IsVariablePrecision))
176217
}
177218

178219
if volumeMarketCapLength > cellMaxWidths.WidthVolumeMarketCap {
@@ -187,8 +228,8 @@ func getCellWidths(assets []*c.Asset) row.CellWidthsContainer {
187228
}
188229

189230
if asset.Position != (c.Position{}) {
190-
positionLength := len(u.ConvertFloatToString(asset.Position.Value, asset.Meta.IsVariablePrecision))
191-
positionQuantityLength := len(u.ConvertFloatToString(asset.Position.Quantity, asset.Meta.IsVariablePrecision))
231+
positionLength := len(u.ConvertFloatToStringWithCommas(asset.Position.Value, asset.Meta.IsVariablePrecision))
232+
positionQuantityLength := len(u.ConvertFloatToStringWithCommas(asset.Position.Quantity, asset.Meta.IsVariablePrecision))
192233

193234
if positionLength > cellMaxWidths.PositionLength {
194235
cellMaxWidths.PositionLength = positionLength

0 commit comments

Comments
 (0)