Skip to content

Commit

Permalink
fix rate source init panic
Browse files Browse the repository at this point in the history
  • Loading branch information
upright39 authored and dreacot committed Oct 24, 2023
1 parent 9cb9ff7 commit 9f91956
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions libwallet/assets_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/crypto-power/cryptopower/libwallet/instantswap"
"github.com/crypto-power/cryptopower/libwallet/internal/politeia"
"github.com/crypto-power/cryptopower/libwallet/utils"
"github.com/crypto-power/cryptopower/ui/values"
bolt "go.etcd.io/bbolt"

"github.com/crypto-power/cryptopower/libwallet/assets/btc"
Expand Down Expand Up @@ -190,13 +191,20 @@ func (mgr *AssetsManager) initRateSource() (err error) {
ctx, cancel := context.WithCancel(context.Background())
mgr.cancelFuncs = append(mgr.cancelFuncs, cancel)

rateSource := mgr.GetCurrencyConversionExchange()
rateSource := values.DefaultExchangeValue
disabled := true
// Check if database has been initialized. ATM, new setups need a wallet
// before mgr.db is initialized.
if mgr.db != nil {
rateSource = mgr.GetCurrencyConversionExchange()
disabled = mgr.IsPrivacyModeOn()
}

mgr.RateSource, err = ext.NewCommonRateSource(ctx, rateSource)
if err != nil {
return fmt.Errorf("ext.NewCommonRateSource error: %w", err)
}

disabled := mgr.IsPrivacyModeOn()
mgr.RateSource.ToggleStatus(disabled)

// Start the refresh goroutine even if rate source is disabled.
Expand Down
2 changes: 1 addition & 1 deletion libwallet/ext/rate_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ func (cs *CommonRateSource) GetTicker(market string) *Ticker {
return &t
}

// Used to initialize the embedding rate source.
// Used to initialize a rate source.
func NewCommonRateSource(ctx context.Context, source string) (*CommonRateSource, error) {
if source != binance && source != bittrex && source != none {
return nil, fmt.Errorf("New rate source %s is not supported", source)
Expand Down

0 comments on commit 9f91956

Please sign in to comment.