Skip to content

Commit

Permalink
Merge branch 'master' into mb_staking
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeBoy committed Dec 18, 2023
2 parents ab60c2f + dfe8bd1 commit 7ed802a
Show file tree
Hide file tree
Showing 24 changed files with 488 additions and 362 deletions.
14 changes: 13 additions & 1 deletion libwallet/assets/btc/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"sort"
"strings"
"sync"

"github.com/btcsuite/btcwallet/wallet"
Expand Down Expand Up @@ -104,15 +105,26 @@ func (asset *Asset) GetTransactions(offset, limit, txFilter int32, newestFirst b
// get all transactions then return transactions that match the input limit and offset.
// If offset and limit are 0, it will return all transactions
// If newestFirst is true, it will return transactions from newest to oldest
func (asset *Asset) GetTransactionsRaw(offset, limit, txFilter int32, newestFirst bool) ([]*sharedW.Transaction, error) {
func (asset *Asset) GetTransactionsRaw(offset, limit, txFilter int32, newestFirst bool, txHashSearch string) ([]*sharedW.Transaction, error) {
if !asset.WalletOpened() {
return nil, utils.ErrBTCNotInitialized
}

txHashSearch = strings.TrimSpace(txHashSearch)
transactions, err := asset.filterTxs(0, 0, txFilter, newestFirst)
if err != nil {
return nil, err
}

if txHashSearch != "" {
for _, tx := range transactions {
if tx.Hash == txHashSearch {
return []*sharedW.Transaction{tx}, nil
}
}
return []*sharedW.Transaction{}, nil
}

if offset == 0 && limit == 0 {
return transactions, nil
}
Expand Down
4 changes: 2 additions & 2 deletions libwallet/assets/dcr/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

func (asset *Asset) TotalStakingRewards() (int64, error) {
voteTransactions, err := asset.GetTransactionsRaw(0, 0, TxFilterVoted, true)
voteTransactions, err := asset.GetTransactionsRaw(0, 0, TxFilterVoted, true, "")
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -568,7 +568,7 @@ func (asset *Asset) NextTicketPriceRemaining() (secs int64, err error) {
func (asset *Asset) UnspentUnexpiredTickets() ([]*sharedW.Transaction, error) {
var tickets []*sharedW.Transaction
for _, filter := range []int32{TxFilterUnmined, TxFilterImmature, TxFilterLive} {
tx, err := asset.GetTransactionsRaw(0, 0, filter, true)
tx, err := asset.GetTransactionsRaw(0, 0, filter, true, "")
if err != nil {
return nil, err
}
Expand Down
11 changes: 9 additions & 2 deletions libwallet/assets/dcr/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package dcr

import (
"encoding/json"
"strings"

"github.com/asdine/storm"
"github.com/asdine/storm/q"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
"github.com/crypto-power/cryptopower/libwallet/txhelper"
"github.com/crypto-power/cryptopower/libwallet/utils"
Expand Down Expand Up @@ -100,7 +102,7 @@ func (asset *Asset) GetTransactionRaw(txHash string) (*sharedW.Transaction, erro
}

func (asset *Asset) GetTransactions(offset, limit, txFilter int32, newestFirst bool) (string, error) {
transactions, err := asset.GetTransactionsRaw(offset, limit, txFilter, newestFirst)
transactions, err := asset.GetTransactionsRaw(offset, limit, txFilter, newestFirst, "")
if err != nil {
return "", err
}
Expand All @@ -113,7 +115,12 @@ func (asset *Asset) GetTransactions(offset, limit, txFilter int32, newestFirst b
return string(jsonEncodedTransactions), nil
}

func (asset *Asset) GetTransactionsRaw(offset, limit, txFilter int32, newestFirst bool) (transactions []*sharedW.Transaction, err error) {
func (asset *Asset) GetTransactionsRaw(offset, limit, txFilter int32, newestFirst bool, txHashSearch string) (transactions []*sharedW.Transaction, err error) {
txHashSearch = strings.TrimSpace(txHashSearch)
if txHashSearch != "" {
err = asset.GetWalletDataDb().Find(q.Eq("Hash", txHashSearch), &transactions)
return
}
err = asset.GetWalletDataDb().Read(offset, limit, txFilter, newestFirst, asset.RequiredConfirmations(), asset.GetBestBlockHeight(), &transactions)
return
}
Expand Down
15 changes: 13 additions & 2 deletions libwallet/assets/ltc/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"sort"
"strings"
"sync"

sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
Expand Down Expand Up @@ -104,15 +105,25 @@ func (asset *Asset) GetTransactions(offset, limit, txFilter int32, newestFirst b
// get all transactions then return transactions that match the input limit and offset.
// If offset and limit are 0, it will return all transactions
// If newestFirst is true, it will return transactions from newest to oldest
func (asset *Asset) GetTransactionsRaw(offset, limit, txFilter int32, newestFirst bool) ([]*sharedW.Transaction, error) {
func (asset *Asset) GetTransactionsRaw(offset, limit, txFilter int32, newestFirst bool, txHashSearch string) ([]*sharedW.Transaction, error) {
if !asset.WalletOpened() {
return nil, utils.ErrLTCNotInitialized
}

txHashSearch = strings.TrimSpace(txHashSearch)
transactions, err := asset.filterTxs(0, 0, txFilter, newestFirst)
if err != nil {
return nil, err
}

if txHashSearch != "" {
for _, tx := range transactions {
if tx.Hash == txHashSearch {
return []*sharedW.Transaction{tx}, nil
}
}
return []*sharedW.Transaction{}, nil
}

if offset == 0 && limit == 0 {
return transactions, nil
}
Expand Down
2 changes: 1 addition & 1 deletion libwallet/assets/wallet/asset_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Asset interface {
CountTransactions(txFilter int32) (int, error)
GetTransactionRaw(txHash string) (*Transaction, error)
TxMatchesFilter(tx *Transaction, txFilter int32) bool
GetTransactionsRaw(offset, limit, txFilter int32, newestFirst bool) ([]*Transaction, error)
GetTransactionsRaw(offset, limit, txFilter int32, newestFirst bool, txHashSearch string) ([]*Transaction, error)

GetBestBlock() *BlockInfo
GetBestBlockHeight() int32
Expand Down
Binary file added ui/assets/decredicons/ic_share.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added ui/assets/decredicons/ic_ticket_voted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions ui/cryptomaterial/dropdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ func (d *DropDown) Changed() bool {
if item.PreventSelection {
return false
}

oldSelected := d.selectedIndex
d.selectedIndex = index
return true
return oldSelected != index
}
}
}
Expand Down Expand Up @@ -400,15 +400,15 @@ func (d *DropDown) drawLayout(gtx C, body layout.Widget) D {
d.linearLayout.Padding = d.padding
d.linearLayout.Shadow = d.shadow
} else {
d.linearLayout.Background = d.theme.Color.Gray2
if d.Background != nil {
d.linearLayout.Background = *d.Background
} else {
d.linearLayout.Background = d.theme.Color.Gray2
}
d.linearLayout.Padding = layout.Inset{}
d.linearLayout.Shadow = nil
}

if d.Background != nil {
d.linearLayout.Background = *d.Background
}

if d.BorderWidth > 0 {
d.linearLayout.Border.Width = d.BorderWidth
}
Expand Down
5 changes: 3 additions & 2 deletions 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, TrocadorIcon, CaretUp, CaretDown,
LTCBackground, LTCGroupIcon, DCRBackground, DCRGroupIcon, BTCBackground, BTCGroupIcon, CrossPlatformIcon,
IntegratedExchangeIcon, MultiWalletIcon, Dot, TradeExchangeIcon, FilterImgIcon, FilterOffImgIcon *Image
IntegratedExchangeIcon, MultiWalletIcon, Dot, TradeExchangeIcon, FilterImgIcon, FilterOffImgIcon, ShareIcon *Image

NewStakeIcon,
TicketImmatureIcon,
Expand Down Expand Up @@ -124,7 +124,7 @@ func (i *Icons) DefaultIcons() *Icons {
i.TicketImmatureIcon = NewImage(decredIcons["ticket_immature"])
i.TicketUnminedIcon = NewImage(decredIcons["ticket_unmined"])
i.TicketLiveIcon = NewImage(decredIcons["ticket_live"])
i.TicketVotedIcon = NewImage(decredIcons["ticket_voted"])
i.TicketVotedIcon = NewImage(decredIcons["ic_ticket_voted"])
i.TicketMissedIcon = NewImage(decredIcons["ticket_missed"])
i.TicketExpiredIcon = NewImage(decredIcons["ticket_expired"])
i.TicketRevokedIcon = NewImage(decredIcons["ticket_revoked"])
Expand Down Expand Up @@ -207,6 +207,7 @@ func (i *Icons) DefaultIcons() *Icons {
i.CrossPlatformIcon = NewImage(decredIcons["crossPlatformIcon"])
i.FilterImgIcon = NewImage(decredIcons["ic_filter"])
i.FilterOffImgIcon = NewImage(decredIcons["ic_filter_off"])
i.ShareIcon = NewImage(decredIcons["ic_share"])

return i
}
Expand Down
21 changes: 16 additions & 5 deletions ui/cryptomaterial/segmented_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ type SegmentedControl struct {
slideActionTitle *SlideAction
segmentType SegmentType

allowCycle bool
isMobileView bool
allowCycle bool
isMobileView bool
disableUniformPadding bool
}

// Segmented control is a linear set of two or more segments, each of which functions as a button.
Expand All @@ -61,6 +62,7 @@ func (t *Theme) SegmentedControl(segmentTitles []string, segmentType SegmentType
sc.slideAction.Draged(func(dragDirection SwipeDirection) {
isNext := dragDirection == SwipeLeft
sc.handleActionEvent(isNext)
sc.list.ScrollTo(sc.selectedIndex)
})

sc.slideActionTitle.SetDragEffect(50)
Expand All @@ -73,6 +75,10 @@ func (t *Theme) SegmentedControl(segmentTitles []string, segmentType SegmentType
return sc
}

func (sc *SegmentedControl) DisableUniform(disable bool) {
sc.disableUniformPadding = disable
}

func (sc *SegmentedControl) SetEnableSwipe(enable bool) {
sc.isSwipeActionEnabled = enable
}
Expand All @@ -82,8 +88,7 @@ func (sc *SegmentedControl) SetEnableSwipe(enable bool) {
// or not. If the parameter is not provided, isMobileView defaults to false.
func (sc *SegmentedControl) Layout(gtx C, body func(gtx C) D, isMobileView ...bool) D {
sc.isMobileView = len(isMobileView) > 0 && isMobileView[0]

return UniformPadding(gtx, func(gtx C) D {
widget := func(gtx C) D {
return layout.Flex{
Axis: layout.Vertical,
Alignment: layout.Middle,
Expand All @@ -105,7 +110,13 @@ func (sc *SegmentedControl) Layout(gtx C, body func(gtx C) D, isMobileView ...bo
})
}),
)
}, true)
}

if sc.disableUniformPadding {
return widget(gtx)
}

return UniformPadding(gtx, widget, sc.isMobileView)
}

func (sc *SegmentedControl) GroupTileLayout(gtx C) D {
Expand Down
4 changes: 4 additions & 0 deletions ui/page/components/coinformat.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ func LayoutBalanceSize(gtx layout.Context, l *load.Load, amount string, mainText
return formatBalance(gtx, l, amount, mainTextSize, l.Theme.Color.Text, false, false)
}

func LayoutBalanceCustom(gtx layout.Context, l *load.Load, amount string, mainTextSize unit.Sp, isBold bool) layout.Dimensions {
return formatBalance(gtx, l, amount, mainTextSize, l.Theme.Color.Text, isBold, false)
}

func LayoutBalanceColor(gtx layout.Context, l *load.Load, amount string, color color.NRGBA) layout.Dimensions {
return formatBalance(gtx, l, amount, values.TextSize20, color, false, false)
}
Expand Down
Loading

0 comments on commit 7ed802a

Please sign in to comment.