Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeBoy committed May 29, 2024
1 parent fa9de0d commit 317c98c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
17 changes: 9 additions & 8 deletions libwallet/ext/rate_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ const (
kucoinExchange = values.KucoinExchange
none = values.DefaultExchangeValue

// These are method names for expected bittrex specific websocket messages.
BittrexMsgHeartbeat = "heartbeat"
BittrexMarketSummary = "marketSummary"
BittrexTicker = "ticker"

// MktSep is used repo wide to separate market symbols.
MktSep = "-"
)
Expand Down Expand Up @@ -166,7 +161,7 @@ func NewCommonRateSource(ctx context.Context, source string, disableConversionEx
sourceChanged: make(chan *struct{}),
disableConversionExchange: disableConversionExchange,
}
s.getTicker = s.getFuncSource(source)
s.getTicker = s.sourceGetTickerFunc(source)
s.cond = sync.NewCond(&s.mtx)

return s, nil
Expand Down Expand Up @@ -227,7 +222,7 @@ func (cs *CommonRateSource) ToggleSource(newSource string) error {
refresh = false /* none is the dummy rate source for when user disables rates */
}

getTickerFn := cs.getFuncSource(newSource)
getTickerFn := cs.sourceGetTickerFunc(newSource)
if getTickerFn == nil {
return fmt.Errorf("new rate source %s is not supported", newSource)
}
Expand Down Expand Up @@ -603,7 +598,7 @@ func isValidSource(source string) bool {
}
}

func (cs *CommonRateSource) getFuncSource(source string) func(values.Market) (*Ticker, error) {
func (cs *CommonRateSource) sourceGetTickerFunc(source string) func(values.Market) (*Ticker, error) {
switch source {
case binance, binanceUS:
return cs.binanceGetTicker
Expand All @@ -615,7 +610,13 @@ func (cs *CommonRateSource) getFuncSource(source string) func(values.Market) (*T
return kucoinGetTicker
case coinpaprika:
return cs.coinpaprikaGetTicker
case none:
return dummyGetTickerFunc
default:
return nil
}
}

func dummyGetTickerFunc(values.Market) (*Ticker, error) {
return &Ticker{}, nil
}
2 changes: 1 addition & 1 deletion ui/page/accounts/accounts_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (pg *Page) OnNavigatedTo() {
func (pg *Page) OnNavigatedFrom() {}

func (pg *Page) fetchExchangeRate() {
market, err := utils.MarketFromAsset(pg.wallet.GetAssetType())
market, err := utils.USDMarketFromAsset(pg.wallet.GetAssetType())
if err != nil {
log.Errorf("Unsupported asset type: %s", pg.wallet.GetAssetType())
return
Expand Down
2 changes: 1 addition & 1 deletion ui/page/send/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (pg *Page) fetchExchangeRate() {
return
}
pg.isFetchingExchangeRate = true
market, err := utils.MarketFromAsset(pg.selectedWallet.GetAssetType())
market, err := utils.USDMarketFromAsset(pg.selectedWallet.GetAssetType())
if err != nil {
log.Errorf("Unsupported asset type: %s", pg.selectedWallet.GetAssetType())
pg.isFetchingExchangeRate = false
Expand Down
2 changes: 1 addition & 1 deletion ui/page/wallet/single_wallet_main_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (swmp *SingleWalletMasterPage) fetchExchangeRate() {
}

swmp.isFetchingExchangeRate = true
market, err := utils.MarketFromAsset(swmp.selectedWallet.GetAssetType())
market, err := utils.USDMarketFromAsset(swmp.selectedWallet.GetAssetType())
if err != nil {
log.Errorf("Asset type %q is not supported for exchange rate fetching", swmp.selectedWallet.GetAssetType())
swmp.isFetchingExchangeRate = false
Expand Down
2 changes: 1 addition & 1 deletion ui/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func RadiusLayout(gtx layout.Context, radius int, w layout.Widget) layout.Dimens
return dims
}

func MarketFromAsset(asset utils.AssetType) (values.Market, error) {
func USDMarketFromAsset(asset utils.AssetType) (values.Market, error) {
switch asset {
case utils.DCRWalletAsset:
return values.DCRUSDTMarket, nil
Expand Down

0 comments on commit 317c98c

Please sign in to comment.