Skip to content

Commit

Permalink
add new layout for wallet selector (crypto-power#166)
Browse files Browse the repository at this point in the history
* add new layout for wallet selector

* update segmented control

* calculate usd balances for assets and wallets in the wallets tab

* cleaup code

* further code cleanup

* if a user is creating a wallet for the first time, take them to the overview page

* simplfy clickable list

* add back segmented control widget

* cleanup code
  • Loading branch information
dreacot authored Oct 24, 2023
1 parent 6679f2b commit 9cb9ff7
Show file tree
Hide file tree
Showing 17 changed files with 548 additions and 136 deletions.
25 changes: 25 additions & 0 deletions libwallet/assets/btc/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,28 @@ func (asset *Asset) AccountXPubMatches(account uint32, xPub string) (bool, error

return acctXPubKey.AccountPubKey.String() == xPub, nil
}

// GetWalletBalance returns the total balance across all accounts.
func (asset *Asset) GetWalletBalance() (*sharedW.Balance, error) {
if !asset.WalletOpened() {
return nil, utils.ErrBTCNotInitialized
}

accountsResult, err := asset.GetAccountsRaw()
if err != nil {
return nil, err
}

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

return &sharedW.Balance{
Total: Amount(totalBalance),
Spendable: Amount(totalSpendable),
ImmatureReward: Amount(totalImmatureReward),
}, nil
}
25 changes: 25 additions & 0 deletions libwallet/assets/dcr/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,28 @@ func (asset *Asset) SafelyCancelSync() {
func (asset *Asset) IsConnectedToNetwork() bool {
return asset.IsConnectedToDecredNetwork()
}

// GetWalletBalance returns the total balance across all accounts.
func (asset *Asset) GetWalletBalance() (*sharedW.Balance, error) {
if !asset.WalletOpened() {
return nil, utils.ErrDCRNotInitialized
}

accountsResult, err := asset.GetAccountsRaw()
if err != nil {
return nil, err
}

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

return &sharedW.Balance{
Total: Amount(totalBalance),
Spendable: Amount(totalSpendable),
ImmatureReward: Amount(totalImmatureReward),
}, nil
}
25 changes: 25 additions & 0 deletions libwallet/assets/ltc/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,3 +547,28 @@ func decodeAddress(s string, params *chaincfg.Params) (ltcutil.Address, error) {
}
return addr, nil
}

// GetWalletBalance returns the total balance across all accounts.
func (asset *Asset) GetWalletBalance() (*sharedW.Balance, error) {
if !asset.WalletOpened() {
return nil, utils.ErrLTCNotInitialized
}

accountsResult, err := asset.GetAccountsRaw()
if err != nil {
return nil, err
}

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

return &sharedW.Balance{
Total: Amount(totalBalance),
Spendable: Amount(totalSpendable),
ImmatureReward: Amount(totalImmatureReward),
}, nil
}
1 change: 1 addition & 0 deletions libwallet/assets/wallet/asset_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type Asset interface {
AccountNumber(accountName string) (int32, error)
AccountNameRaw(accountNumber uint32) (string, error)
GetAccountBalance(accountNumber int32) (*Balance, error)
GetWalletBalance() (*Balance, error)
UnspentOutputs(account int32) ([]*UnspentOutput, error)

AddSyncProgressListener(syncProgressListener SyncProgressListener, uniqueIdentifier string) error
Expand Down
Binary file modified ui/assets/decredicons/addNewWallet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ui/assets/decredicons/dot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion ui/cryptomaterial/icon_gallery.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Icons struct {
RevealIcon, InfoAction, LightMode, DarkMode, AddIcon, ChevronRight, AddExchange, FlypMeIcon, ChangellyIcon,
SimpleSwapIcon, SwapzoneIcon, ShapeShiftIcon, GodexIcon, CoinSwitchIcon, ChangeNowIcon, CaretUp, CaretDown,
LTCBackground, LTCGroupIcon, DCRBackground, DCRGroupIcon, BTCBackground, BTCGroupIcon, CrossPlatformIcon,
IntegratedExchangeIcon, MultiWalletIcon *Image
IntegratedExchangeIcon, MultiWalletIcon, Dot *Image

NewStakeIcon,
TicketImmatureIcon,
Expand Down Expand Up @@ -186,6 +186,7 @@ func (i *Icons) DefaultIcons() *Icons {
i.EllipseVert = NewImage(decredIcons["elipsis_vert"])
i.EllipseHoriz = NewImage(decredIcons["elipsis"])
i.Notification = NewImage(decredIcons["notification"])
i.Dot = NewImage(decredIcons["dot"])

/* Start exchange icons */
i.FlypMeIcon = NewImage(decredIcons["flypme"])
Expand Down
4 changes: 4 additions & 0 deletions ui/cryptomaterial/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func NewImage(src image.Image) *Image {
// reduced the image original scale of 1 by half to 0.5 fix blurry images
// this in turn reduced the image layout size by half. Multiplying the
// layout size by 2 to give the original image size to scale ratio.
func (img *Image) Layout8dp(gtx C) D {
return img.LayoutSize(gtx, values.MarginPadding8)
}

func (img *Image) Layout12dp(gtx C) D {
return img.LayoutSize(gtx, values.MarginPadding12)
}
Expand Down
4 changes: 4 additions & 0 deletions ui/cryptomaterial/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func (t *Theme) Label(size unit.Sp, txt string) Label {
return t.labelWithDefaultColor(Label{material.Label(t.Base, size, txt)})
}

func (t *Theme) Label2(size unit.Sp, txt string) Label {
return t.labelWithDefaultColor(Label{material.Label(t.Base, size, txt)})
}

func (t *Theme) labelWithDefaultColor(l Label) Label {
l.Color = t.Color.DeepBlue
return l
Expand Down
2 changes: 1 addition & 1 deletion ui/load/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

type WalletItem struct {
Wallet sharedW.Asset
TotalBalance string
TotalBalance sharedW.AssetAmount
}

type WalletLoad struct {
Expand Down
15 changes: 9 additions & 6 deletions ui/page/root/main_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ func (mp *MainPage) LayoutTopBar(gtx C) D {
return layout.Inset{
Left: values.MarginPadding10,
}.Layout(gtx, func(gtx C) D {
return walletHightlighLabel(mp.Theme, gtx, values.String(values.StrWatchOnly))
return walletHightlighLabel(mp.Theme, gtx, values.TextSize16, values.String(values.StrWatchOnly))
})
}
return D{}
Expand Down Expand Up @@ -1020,16 +1020,19 @@ func (mp *MainPage) showBackupInfo() {
mp.ParentWindow().ShowModal(backupNowOrLaterModal)
}

func walletHightlighLabel(theme *cryptomaterial.Theme, gtx C, content string) D {
indexLabel := theme.Label(values.TextSize16, content)
func walletHightlighLabel(theme *cryptomaterial.Theme, gtx C, textSize unit.Sp, content string) D {
indexLabel := theme.Label(textSize, content)
indexLabel.Color = theme.Color.PageNavText
indexLabel.Font.Weight = font.Medium
return cryptomaterial.LinearLayout{
Width: gtx.Dp(values.MarginPadding100),
Width: cryptomaterial.WrapContent,
Height: gtx.Dp(values.MarginPadding22),
Direction: layout.Center,
Background: theme.Color.Gray8,
Margin: layout.Inset{Right: values.MarginPadding8},
Border: cryptomaterial.Border{Radius: cryptomaterial.Radius(9), Color: theme.Color.Gray3, Width: values.MarginPadding1},
Padding: layout.Inset{
Left: values.MarginPadding8,
Right: values.MarginPadding8},
Margin: layout.Inset{Right: values.MarginPadding8},
Border: cryptomaterial.Border{Radius: cryptomaterial.Radius(9), Color: theme.Color.Gray3, Width: values.MarginPadding1},
}.Layout2(gtx, indexLabel.Layout)
}
Loading

0 comments on commit 9cb9ff7

Please sign in to comment.