Skip to content

Commit

Permalink
New format for exchange rate for WOC
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Nov 14, 2022
1 parent 6693b06 commit 6d8320c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
6 changes: 1 addition & 5 deletions conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package bsvrates
import (
"context"
"fmt"
"strconv"

"github.com/mrz1836/go-whatsonchain"
)
Expand Down Expand Up @@ -32,10 +31,7 @@ func (c *Client) GetConversion(ctx context.Context, currency Currency, amount fl
case ProviderWhatsOnChain:
var response *whatsonchain.ExchangeRate
if response, err = c.WhatsOnChain().GetExchangeRate(ctx); err == nil && response != nil {
var rate float64
if rate, err = strconv.ParseFloat(response.Rate, 64); err == nil {
satoshis, err = ConvertPriceToSatoshis(rate, amount)
}
satoshis, err = ConvertPriceToSatoshis(response.Rate, amount)
}
case providerLast:
err = fmt.Errorf("provider unknown")
Expand Down
4 changes: 3 additions & 1 deletion mock_whatsonchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bsvrates
import (
"context"
"errors"
"time"

"github.com/mrz1836/go-whatsonchain"
)
Expand Down Expand Up @@ -34,7 +35,8 @@ type mockWOCValid struct {
func (m *mockWOCValid) GetExchangeRate(_ context.Context) (rate *whatsonchain.ExchangeRate, err error) {

rate = &whatsonchain.ExchangeRate{
Rate: "159.01",
Rate: 159.01,
Time: time.Now().Unix(),
Currency: CurrencyToName(CurrencyDollars),
}

Expand Down
3 changes: 1 addition & 2 deletions rates.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package bsvrates
import (
"context"
"fmt"
"strconv"

"github.com/mrz1836/go-whatsonchain"
)
Expand All @@ -33,7 +32,7 @@ func (c *Client) GetRate(ctx context.Context, currency Currency) (rate float64,
case ProviderWhatsOnChain:
var response *whatsonchain.ExchangeRate
if response, err = c.WhatsOnChain().GetExchangeRate(ctx); err == nil && response != nil {
rate, err = strconv.ParseFloat(response.Rate, 64)
rate = response.Rate
}
case providerLast:
err = fmt.Errorf("provider unknown")
Expand Down

0 comments on commit 6d8320c

Please sign in to comment.