Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeBoy committed Mar 16, 2024
2 parents f60215e + aecb2a3 commit 9720c30
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 100 deletions.
25 changes: 24 additions & 1 deletion libwallet/assets/dcr/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type SyncData struct {

synced bool
syncing bool
cancelCtx context.Context
cancelSync context.CancelFunc
cancelRescan context.CancelFunc
syncCanceled chan struct{}
Expand Down Expand Up @@ -90,6 +89,8 @@ type activeSyncData struct {
rescanStartTime int64

totalInactiveSeconds int64
isRescanning bool
isAddressDiscovery bool
}

const (
Expand Down Expand Up @@ -382,6 +383,28 @@ func (asset *Asset) CurrentSyncStage() utils.SyncStage {
return InvalidSyncStage
}

func (asset *Asset) IsAddressDiscovering() bool {
asset.syncData.mu.RLock()
defer asset.syncData.mu.RUnlock()

if asset.syncData != nil && asset.syncData.syncing {
return asset.syncData.isAddressDiscovery
}

return false
}

func (asset *Asset) IsSycnRescanning() bool {
asset.syncData.mu.RLock()
defer asset.syncData.mu.RUnlock()

if asset.syncData != nil && asset.syncData.syncing {
return asset.syncData.isRescanning
}

return false
}

func (asset *Asset) ConnectedPeers() int32 {
return asset.syncData.connectedPeers()
}
Expand Down
8 changes: 6 additions & 2 deletions libwallet/assets/dcr/syncnotification.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ func (asset *Asset) fetchCFiltersEnded() {
}

// Fetch Headers Callbacks

func (asset *Asset) fetchHeadersStarted() {
if !asset.IsSyncing() {
return
Expand Down Expand Up @@ -295,6 +294,7 @@ func (asset *Asset) discoverAddressesStarted() {
}

asset.syncData.mu.Lock()
asset.syncData.isAddressDiscovery = true
asset.syncData.syncStage = AddressDiscoverySyncStage
asset.syncData.addressDiscoveryProgress.AddressDiscoveryStartTime = time.Now().Unix()
asset.syncData.addressDiscoveryCompletedOrCanceled = make(chan bool)
Expand Down Expand Up @@ -402,6 +402,9 @@ func (asset *Asset) discoverAddressesFinished() {
if !asset.IsSyncing() {
return
}
asset.syncData.mu.Lock()
asset.syncData.isAddressDiscovery = false
asset.syncData.mu.Unlock()

asset.stopUpdatingAddressDiscoveryProgress()
}
Expand All @@ -417,7 +420,6 @@ func (asset *Asset) stopUpdatingAddressDiscoveryProgress() {
}

// Blocks Scan Callbacks

func (asset *Asset) rescanStarted() {
asset.stopUpdatingAddressDiscoveryProgress()

Expand All @@ -429,6 +431,7 @@ func (asset *Asset) rescanStarted() {
return
}

asset.syncData.isRescanning = true
asset.syncData.syncStage = HeadersRescanSyncStage
asset.syncData.rescanStartTime = time.Now().Unix()

Expand Down Expand Up @@ -518,6 +521,7 @@ func (asset *Asset) rescanFinished() {
}

asset.syncData.mu.Lock()
asset.syncData.isRescanning = false
asset.syncData.headersRescanProgress.TotalTimeRemainingSeconds = 0
asset.syncData.headersRescanProgress.TotalSyncProgress = 100

Expand Down
1 change: 1 addition & 0 deletions ui/cryptomaterial/dropdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ func (d *DropDown) itemLayout(gtx C, index int, clickable *Clickable, item *Drop

return bodyLayout.Layout2(gtx, func(gtx C) D {
lbl := d.theme.Body2(item.Text)
lbl.MaxLines = 1
if !d.expanded && len(item.Text) > d.maxTextLeng {
lbl.Text = item.Text[:d.maxTextLeng-3 /* subtract space for the ellipsis */] + "..."
}
Expand Down
12 changes: 6 additions & 6 deletions ui/cryptomaterial/modal.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (m *Modal) IsShown() bool {

// Layout renders the modal widget to screen. The modal assumes the size of
// its content plus padding.
func (m *Modal) Layout(gtx layout.Context, widgets []layout.Widget, width ...float32) layout.Dimensions {
func (m *Modal) Layout(gtx C, widgets []layout.Widget, width ...float32) D {
mGtx := gtx
if m.isDisabled {
mGtx = gtx.Disabled()
Expand All @@ -101,9 +101,9 @@ func (m *Modal) Layout(gtx layout.Context, widgets []layout.Widget, width ...flo
gtx.Constraints.Min.X = gtx.Constraints.Max.X
fillMax(gtx, m.overlayColor, CornerRadius{})

return m.button.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return m.button.Layout(gtx, func(gtx C) D {
semantic.Button.Add(gtx.Ops)
return layout.Dimensions{Size: gtx.Constraints.Min}
return D{Size: gtx.Constraints.Min}
})
}),
layout.Stacked(func(gtx C) D {
Expand All @@ -118,7 +118,7 @@ func (m *Modal) Layout(gtx layout.Context, widgets []layout.Widget, width ...flo
widgetFuncs = append(widgetFuncs, widgets...)
}

maxWidth := float32(360)
maxWidth := float32(450)
if len(width) > 0 && width[0] > 0 {
maxWidth = width[0]
} else if currentAppWidth := gtx.Metric.PxToDp(gtx.Constraints.Max.X); currentAppWidth <= values.StartMobileView {
Expand All @@ -138,8 +138,8 @@ func (m *Modal) Layout(gtx layout.Context, widgets []layout.Widget, width ...flo
return inset.Layout(gtx, func(gtx C) D {
return layout.Stack{Alignment: layout.Center}.Layout(gtx,
layout.Expanded(func(gtx C) D {
return m.overlayBlinder.Layout(gtx, func(gtx layout.Context) layout.Dimensions {
return layout.Dimensions{Size: gtx.Constraints.Min}
return m.overlayBlinder.Layout(gtx, func(gtx C) D {
return D{Size: gtx.Constraints.Min}
})
}),
layout.Stacked(func(gtx C) D {
Expand Down
6 changes: 3 additions & 3 deletions ui/page/components/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
"github.com/crypto-power/cryptopower/libwallet/instantswap"
"github.com/crypto-power/cryptopower/libwallet/txhelper"
"github.com/crypto-power/cryptopower/libwallet/utils"

libutils "github.com/crypto-power/cryptopower/libwallet/utils"
"github.com/crypto-power/cryptopower/ui/cryptomaterial"
"github.com/crypto-power/cryptopower/ui/load"
Expand Down Expand Up @@ -997,13 +997,13 @@ func GetServerIcon(theme *cryptomaterial.Theme, serverName string) *cryptomateri
// by comparing the current version with the latest release version
// available on GitHub.
func CheckForUpdate(l *load.Load) *ReleaseResponse {
req := &utils.ReqConfig{
req := &libutils.ReqConfig{
Method: http.MethodGet,
HTTPURL: releaseURL,
}

releaseResponse := new(ReleaseResponse)
if _, err := utils.HTTPRequest(req, &releaseResponse); err != nil {
if _, err := libutils.HTTPRequest(req, &releaseResponse); err != nil {
log.Error("checking for update failed:", err)
return nil
}
Expand Down
65 changes: 32 additions & 33 deletions ui/page/components/wallet_account_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,16 +291,19 @@ func (ws *WalletAndAccountSelector) Layout(window app.WindowNavigator, gtx C) D
}.Layout(gtx,
layout.Rigid(ws.setWalletLogo),
layout.Rigid(func(gtx C) D {
gtx.Constraints.Max.X = gtx.Constraints.Max.X / 2
if ws.accountSelector {
if ws.selectedAccount == nil {
return ws.Theme.Body1("").Layout(gtx)
}
lbl := ws.Theme.Body1(ws.SelectedAccount().Name)
lbl.MaxLines = 1
lbl.TextSize = textSize16
return lbl.Layout(gtx)
}

lbl := ws.Theme.SemiBoldLabel(ws.SelectedWallet().GetWalletName())
lbl.MaxLines = 1
lbl.TextSize = textSize16
return lbl.Layout(gtx)
}),
Expand Down Expand Up @@ -583,38 +586,30 @@ func (sm *selectorModal) Layout(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
if sm.accountSelector {
inset := layout.Inset{
Top: values.MarginPadding0,
}
return inset.Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(gtx,
layout.Rigid(func(gtx C) D {
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
if sm.infoModalOpen {
m := op.Record(gtx.Ops)
layout.Inset{Top: values.MarginPadding30}.Layout(gtx, func(gtx C) D {
card := sm.Theme.Card()
card.Color = sm.Theme.Color.Surface
return card.Layout(gtx, func(gtx C) D {
return layout.UniformInset(values.MarginPadding12).Layout(gtx, renderers.RenderHTML(sm.infoActionText, sm.Theme).Layout)
})
})
op.Defer(gtx.Ops, m.Stop())
}
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
if !sm.infoModalOpen {
return D{}
}

return D{}
}),
layout.Rigid(func(gtx C) D {
if sm.infoActionText != "" {
return sm.infoButton.Layout(gtx)
}
return D{}
}),
)
}),
)
})
m := op.Record(gtx.Ops)
dims := layout.Inset{Top: values.MarginPadding30}.Layout(gtx, func(gtx C) D {
card := sm.Theme.Card()
card.Color = sm.Theme.Color.Surface
return card.Layout(gtx, func(gtx C) D {
return layout.UniformInset(values.MarginPadding12).Layout(gtx, renderers.RenderHTML(sm.infoActionText, sm.Theme).Layout)
})
})
op.Defer(gtx.Ops, m.Stop())
return dims
}),
layout.Rigid(func(gtx C) D {
if sm.infoActionText == "" {
return D{}
}
return sm.infoButton.Layout(gtx)
}),
)
}
return D{}
}),
Expand Down Expand Up @@ -679,7 +674,7 @@ func (sm *selectorModal) modalListItemLayout(gtx C, selectorItem *SelectorItem)
Width: cryptomaterial.MatchParent,
Height: cryptomaterial.WrapContent,
Margin: layout.Inset{Bottom: values.MarginPadding4},
Padding: layout.Inset{Top: values.MarginPadding8, Bottom: values.MarginPadding8},
Padding: VerticalInset(values.MarginPadding8),
Clickable: selectorItem.clickable,
Alignment: layout.Middle,
}.Layout(gtx,
Expand All @@ -700,9 +695,13 @@ func (sm *selectorModal) modalListItemLayout(gtx C, selectorItem *SelectorItem)
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,
layout.Rigid(func(gtx C) D {
acct := sm.Theme.Label(values.TextSize18, name)
acct.MaxLines = 1
acct.Color = sm.Theme.Color.Text
acct.Font.Weight = font.Normal
return EndToEndRow(gtx, acct.Layout, func(gtx C) D {
return EndToEndRow(gtx, func(gtx C) D {
gtx.Constraints.Max.X = gtx.Constraints.Max.X / 2
return acct.Layout(gtx)
}, func(gtx C) D {
return LayoutBalance(gtx, sm.Load, totalBal)
})
}),
Expand Down
28 changes: 24 additions & 4 deletions ui/page/components/wallet_sync_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"gioui.org/font"
"gioui.org/layout"
"gioui.org/unit"
"github.com/crypto-power/cryptopower/libwallet/assets/dcr"
sharedW "github.com/crypto-power/cryptopower/libwallet/assets/wallet"
libutils "github.com/crypto-power/cryptopower/libwallet/utils"
"github.com/crypto-power/cryptopower/ui/cryptomaterial"
Expand Down Expand Up @@ -273,6 +274,12 @@ func (wsi *WalletSyncInfo) syncContent(gtx C, uniform layout.Inset) D {
isRescanning := wsi.wallet.IsRescanning() && !isSyncing
isInProgress := isSyncing || isRescanning
bestBlock := wsi.wallet.GetBestBlock()
isAddDiscovering := false
syncIsScanning := false
if !isBtcORLtcAsset {
isAddDiscovering = wsi.wallet.(*dcr.Asset).IsAddressDiscovering()
syncIsScanning = wsi.wallet.(*dcr.Asset).IsSycnRescanning()
}
dp8 := values.MarginPadding8
return uniform.Layout(gtx, func(gtx C) D {
return layout.Flex{Axis: layout.Horizontal}.Layout(gtx,
Expand All @@ -292,13 +299,13 @@ func (wsi *WalletSyncInfo) syncContent(gtx C, uniform layout.Inset) D {
return wsi.labelTexSize16Layout(values.String(values.StrSyncingProgress), dp8, true)(gtx)
}),
layout.Rigid(func(gtx C) D {
if !isInProgress || (isRescanning && (isBtcORLtcAsset)) {
if !isInProgress || (isRescanning && isBtcORLtcAsset) {
return D{}
}
return wsi.labelTexSize16Layout(values.String(values.StrSyncCompTime), dp8, true)(gtx)
}),
layout.Rigid(func(gtx C) D {
if !(isRescanning && (isBtcORLtcAsset)) {
if !(isRescanning && isBtcORLtcAsset) {
return D{}
}
return wsi.labelTexSize16Layout(values.String(values.StrAddressDiscoveryInProgress), dp8, true)(gtx)
Expand All @@ -316,7 +323,13 @@ func (wsi *WalletSyncInfo) syncContent(gtx C, uniform layout.Inset) D {
if !isInProgress || (isRescanning && (isBtcORLtcAsset)) {
return D{}
}
blockHeightFetched := values.StringF(values.StrBlockHeaderFetchedCount, bestBlock.Height, wsi.FetchSyncProgress().HeadersToFetchOrScan)
header := wsi.FetchSyncProgress().HeadersToFetchOrScan
// When progress's state is rescan header is a header of rescan and not fetch
// this is a workaround display block for user
if header < bestBlock.Height {
header = bestBlock.Height
}
blockHeightFetched := values.StringF(values.StrBlockHeaderFetchedCount, bestBlock.Height, header)
return wsi.labelTexSize16Layout(blockHeightFetched, dp8, false)(gtx)
}),
layout.Rigid(func(gtx C) D {
Expand All @@ -327,6 +340,13 @@ func (wsi *WalletSyncInfo) syncContent(gtx C, uniform layout.Inset) D {
syncProgress := values.String(values.StrWalletNotSynced)
if wsi.wallet.IsSyncing() {
syncProgress = values.StringF(values.StrSyncingProgressStat, daysBehind)
if !isBtcORLtcAsset {
if isAddDiscovering {
syncProgress = values.String(values.StrAddressDiscovering)
} else if syncIsScanning {
syncProgress = values.String(values.StrRescanningBlocks)
}
}
} else if wsi.wallet.IsRescanning() {
syncProgress = values.String(values.StrRescanningBlocks)
} else if wsi.wallet.IsSynced() {
Expand All @@ -336,7 +356,7 @@ func (wsi *WalletSyncInfo) syncContent(gtx C, uniform layout.Inset) D {
return wsi.labelTexSize16Layout(syncProgress, dp8, false)(gtx)
}),
layout.Rigid(func(gtx C) D {
if !isInProgress || (isRescanning && (isBtcORLtcAsset)) {
if !isInProgress || (isRescanning && isBtcORLtcAsset) {
return D{}
}
_, timeLeft := wsi.progressStatusDetails()
Expand Down
13 changes: 11 additions & 2 deletions ui/page/root/wallet_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,29 @@ func (pg *WalletSelectorPage) walletWrapper(gtx C, item *walletWithBalance) D {

func (pg *WalletSelectorPage) layoutNameAndBalance(gtx C, item *walletWithBalance) D {
return layout.Flex{
Axis: layout.Horizontal,
Alignment: layout.Middle,
}.Layout(gtx,
layout.Rigid(func(gtx C) D {
gtx.Constraints.Max.X = gtx.Constraints.Max.X / 2
txt := pg.Theme.Label(values.TextSize18, item.wallet.GetWalletName())
txt.Color = pg.Theme.Color.Text
txt.Font.Weight = font.SemiBold
txt.MaxLines = 1
return txt.Layout(gtx)
}),
layout.Rigid(func(gtx C) D {
if item.wallet.IsWatchingOnlyWallet() {
return layout.Inset{
Left: values.MarginPadding8,
}.Layout(gtx, func(gtx C) D {
return components.WalletHighlightLabel(pg.Theme, gtx, values.TextSize12, values.String(values.StrWatchOnly))
if !pg.IsMobileView() {
return components.WalletHighlightLabel(pg.Theme, gtx, values.TextSize12, values.String(values.StrWatchOnly))
}
image := components.CoinImageBySymbol(pg.Load, item.wallet.GetAssetType(), true)
if image == nil {
return D{}
}
return image.LayoutTransform(gtx, true, values.MarginPadding24)
})
}
return D{}
Expand Down
Loading

0 comments on commit 9720c30

Please sign in to comment.