Skip to content

Commit

Permalink
Fix issue printing correct currency values in set and card
Browse files Browse the repository at this point in the history
  • Loading branch information
noqqe committed Jun 30, 2023
1 parent 884fbdf commit b4f0067
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/serra/card.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func Cards(rarity, set, sortby, name, oracle, cardType string, reserved, foil bo
var sortStage bson.D
switch sortby {
case "value":
if getCurrency() == "EUR" {
if getCurrency() == EUR {
sortStage = bson.D{{"prices.eur", 1}}
} else {
sortStage = bson.D{{"prices.usd", 1}}
Expand Down
13 changes: 7 additions & 6 deletions src/serra/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"os"
)

const EUR = "€"
const USD = "$"

func getMongoDBURI() string {
uri := os.Getenv("MONGODB_URI")
if uri == "" {
Expand All @@ -19,13 +22,11 @@ func getMongoDBURI() string {
func getCurrency() string {
switch os.Getenv("SERRA_CURRENCY") {
case "EUR":
return "€"
return EUR
case "USD":
return USD
default:
LogMessage("Warning: You did not configure SERRA_CURRENCY. Assuming \"USD\"", "yellow")
return "$"
}

// default
LogMessage("Warning: You did not configure SERRA_CURRENCY. Assuming \"USD\"", "yellow")

return "USD"
}
2 changes: 1 addition & 1 deletion src/serra/gains.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Gains(limit float64, sort int) error {
}

currencyField := "$serra_prices.usd"
if getCurrency() == "EUR" {
if getCurrency() == EUR {
currencyField = "$serra_prices.eur"
}

Expand Down
10 changes: 6 additions & 4 deletions src/serra/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,16 @@ func showPriceHistory(prices []PriceEntry, prefix string, total bool) {

var value float64
if total {
value = e.Usd + e.UsdFoil + e.UsdEtched
if getCurrency() == "EUR" {
if getCurrency() == EUR {
value = e.Eur + e.EurFoil
} else {
value = e.Usd + e.UsdFoil
}
} else {
value = e.Usd
if getCurrency() == "EUR" {
if getCurrency() == EUR {
value = e.Eur
} else {
value = e.Usd
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/serra/scryfall.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type Card struct {

// Getter for currency specific value
func (c Card) getValue(foil bool) float64 {
if getCurrency() == "EUR" {
if getCurrency() == EUR {
if foil {
return c.Prices.EurFoil
}
Expand Down
2 changes: 1 addition & 1 deletion src/serra/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func ShowSet(setname string) error {

// fetch all cards in set ordered by currently used currency
cardSortCurrency := bson.D{{"prices.usd", -1}}
if getCurrency() == "EUR" {
if getCurrency() == EUR {
cardSortCurrency = bson.D{{"prices.eur", -1}}
}
cards, err := coll.storageFind(bson.D{{"set", setname}}, cardSortCurrency, 0, 0)
Expand Down

0 comments on commit b4f0067

Please sign in to comment.