Skip to content

Commit

Permalink
multi: retire load.WalletLoad
Browse files Browse the repository at this point in the history
  • Loading branch information
itswisdomagain committed Nov 8, 2023
1 parent 4e64334 commit 4a30d1f
Show file tree
Hide file tree
Showing 78 changed files with 1,092 additions and 1,391 deletions.
16 changes: 16 additions & 0 deletions libwallet/assets/wallet/wallet_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,19 @@ func backupFile(fileName string, suffix int) (newName string, err error) {

return newName, nil
}

// Balances returns the spendable balance and total balance of the wallet.
func Balances(w Asset) (AssetAmount, AssetAmount, error) {
accountsResult, err := w.GetAccountsRaw()
if err != nil {
return w.ToAmount(0), w.ToAmount(0), err
}

var totalSpendable, totalBalance int64
for _, account := range accountsResult.Accounts {
totalSpendable += account.Balance.Spendable.ToInt()
totalBalance += account.Balance.Total.ToInt()
}

return w.ToAmount(totalSpendable), w.ToAmount(totalBalance), nil
}
10 changes: 10 additions & 0 deletions libwallet/assets_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ func (mgr *AssetsManager) SetCurrencyConversionExchange(xc string) {
}()
}

// ExchangeRateFetchingEnabled returns true if privacy mode isn't turned on and
// a valid exchange rate source is configured.
func (mgr *AssetsManager) ExchangeRateFetchingEnabled() bool {
if mgr.IsPrivacyModeOn() {
return false
}
xc := mgr.GetCurrencyConversionExchange()
return xc != "" && xc != values.DefaultExchangeValue
}

// GetLanguagePreference returns the language preference.
func (mgr *AssetsManager) GetLanguagePreference() string {
var lang string
Expand Down
44 changes: 44 additions & 0 deletions libwallet/assets_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"sort"
"strconv"
"time"

Expand Down Expand Up @@ -490,6 +491,15 @@ func (mgr *AssetsManager) sortWallets(assetType utils.AssetType) []sharedW.Asset
normalWallets = append(normalWallets, wallet)
}
}

// Sort both lists by wallet ID.
sort.Slice(normalWallets, func(i, j int) bool {
return normalWallets[i].GetWalletID() < normalWallets[j].GetWalletID()
})
sort.Slice(watchOnlyWallets, func(i, j int) bool {
return watchOnlyWallets[i].GetWalletID() < watchOnlyWallets[j].GetWalletID()
})

return append(normalWallets, watchOnlyWallets...)
}

Expand Down Expand Up @@ -780,3 +790,37 @@ func (mgr *AssetsManager) BlockExplorerURLForTx(assetType utils.AssetType, txHas
func (mgr *AssetsManager) LogFile() string {
return filepath.Join(mgr.params.LogDir, LogFilename)
}

func (mgr *AssetsManager) DCRHDPrefix() string {
switch mgr.NetType() {
case utils.Testnet:
return dcr.TestnetHDPath
case utils.Mainnet:
return dcr.MainnetHDPath
default:
return ""
}
}

func (mgr *AssetsManager) BTCHDPrefix() string {
switch mgr.NetType() {
case utils.Testnet:
return btc.TestnetHDPath
case utils.Mainnet:
return btc.MainnetHDPath
default:
return ""
}
}

// LTC HDPrefix returns the HD path prefix for the Litecoin wallet network.
func (mgr *AssetsManager) LTCHDPrefix() string {
switch mgr.NetType() {
case utils.Testnet:
return ltc.TestnetHDPath
case utils.Mainnet:
return ltc.MainnetHDPath
default:
return ""
}
}
17 changes: 12 additions & 5 deletions ui/load/appinfo.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package load

import "time"
import (
"time"

"github.com/crypto-power/cryptopower/libwallet"
)

// TODO: This should ultimately replace Load, acting as the container for all
// properties and methods that every app page and window relies on. Should
Expand All @@ -9,14 +13,17 @@ type AppInfo struct {
version string
buildDate time.Time
startUpTime time.Time

AssetsManager *libwallet.AssetsManager
}

// StartApp returns an instance of AppInfo with the startUpTime set to the current time.
func StartApp(version string, buildDate time.Time) *AppInfo {
func StartApp(version string, buildDate time.Time, assetsManager *libwallet.AssetsManager) *AppInfo {
return &AppInfo{
version: version,
buildDate: buildDate,
startUpTime: time.Now(),
version: version,
buildDate: buildDate,
startUpTime: time.Now(),
AssetsManager: assetsManager,
}
}

Expand Down
8 changes: 5 additions & 3 deletions ui/load/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"golang.org/x/text/message"

"github.com/crypto-power/cryptopower/app"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
"github.com/crypto-power/cryptopower/ui/assets"
"github.com/crypto-power/cryptopower/ui/cryptomaterial"
"github.com/crypto-power/cryptopower/ui/notification"
Expand All @@ -29,7 +30,6 @@ type Load struct {

Theme *cryptomaterial.Theme

WL *WalletLoad
Printer *message.Printer
Network string
CurrentAppWidth int
Expand All @@ -39,11 +39,13 @@ type Load struct {
DarkModeSettingChanged func(bool)
LanguageSettingChanged func()
CurrencySettingChanged func()
ToggleSync func(NeedUnlockRestore)

// TODO: Kill this property!
ToggleSync func(sharedW.Asset, NeedUnlockRestore)
}

func (l *Load) RefreshTheme(window app.WindowNavigator) {
isDarkModeOn := l.WL.AssetsManager.IsDarkModeOn()
isDarkModeOn := l.AssetsManager.IsDarkModeOn()
l.Theme.SwitchDarkMode(isDarkModeOn, assets.DecredIcons)
l.DarkModeSettingChanged(isDarkModeOn)
l.LanguageSettingChanged()
Expand Down
188 changes: 0 additions & 188 deletions ui/load/wallet.go

This file was deleted.

Loading

0 comments on commit 4a30d1f

Please sign in to comment.