Skip to content

Commit

Permalink
Option to hide mixing txs on UI
Browse files Browse the repository at this point in the history
  • Loading branch information
martonp committed Aug 2, 2024
1 parent 0006c35 commit 5eb658e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 4 deletions.
27 changes: 26 additions & 1 deletion client/asset/dcr/dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,8 @@ type ExchangeWallet struct {
txHistoryDB atomic.Value // *btc.BadgerTxDB
syncingTxHistory atomic.Bool

previouslySynced atomic.Bool

rescan struct {
sync.RWMutex
progress *rescanProgress // nil = no rescan in progress
Expand Down Expand Up @@ -4823,18 +4825,37 @@ func (dcr *ExchangeWallet) shutdown() {
}

// SyncStatus is information about the blockchain sync status.
func (dcr *ExchangeWallet) SyncStatus() (bool, float32, error) {
func (dcr *ExchangeWallet) SyncStatus() (synced bool, pct float32, err error) {
defer func() {
previouslySynced := dcr.previouslySynced.Load()
if err != nil {
dcr.previouslySynced.Store(false)
return
}
dcr.previouslySynced.Store(synced)

if !previouslySynced && synced {
dcr.tipMtx.RLock()
tip := dcr.currentTip
dcr.tipMtx.RUnlock()

dcr.syncTxHistory(dcr.ctx, uint64(tip.height))
}
}()

// If we have a rescan running, do different math.
dcr.rescan.RLock()
rescanProgress := dcr.rescan.progress
dcr.rescan.RUnlock()

if rescanProgress != nil {
height := dcr.cachedBestBlock().height
if height < rescanProgress.scannedThrough {
height = rescanProgress.scannedThrough
}
return false, float32(rescanProgress.scannedThrough) / float32(height), nil
}

// No rescan in progress. Ask wallet.
return dcr.wallet.SyncStatus(dcr.ctx)
}
Expand Down Expand Up @@ -6232,6 +6253,8 @@ func (dcr *ExchangeWallet) addUnknownTransactionsToHistory(tip uint64) {
return
}

dcr.log.Infof("LISTING SINCE BLOCK %d", len(txs))

for _, tx := range txs {
if dcr.ctx.Err() != nil {
return
Expand Down Expand Up @@ -6287,6 +6310,8 @@ func (dcr *ExchangeWallet) syncTxHistory(ctx context.Context, tip uint64) {
}
defer dcr.syncingTxHistory.Store(false)

dcr.log.Infof("Starting tx history sync to tip %d", tip)

txHistoryDB := dcr.txDB()
if txHistoryDB == nil {
return
Expand Down
4 changes: 4 additions & 0 deletions client/webserver/site/src/html/wallets.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@
{{- /* TRANSACTION HISTORY */ -}}
<section id="txHistoryBox" class="flex-stretch-column">
<h4 class="m-3">[[[asset_name tx_history]]]</h4>
<span class="mx-3" id="hideMixTxs">
<input type="checkbox" id="hideMixTxsCheckbox" class="form-check-input">
<label for="hideMixTxsCheckbox" class="form-check-label">[[[Hide Mixing Transactions]]]</label>
</span>
<div id="txHistoryTableContainer" class="flex-stretch-column pb-3">
<table id="txHistoryTable" class="row-border border-top">
<thead>
Expand Down
1 change: 1 addition & 0 deletions client/webserver/site/src/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,7 @@ export default class Application {
for (let i = startIndex; i < cachedTxHistory.txs.length && txs.length < n; i++) {
txs.push(cachedTxHistory.txs[i])
lastIndex = i
after = cachedTxHistory.txs[i].id
}
if (cachedTxHistory.lastTx && lastIndex === cachedTxHistory.txs.length - 1) {
lastTx = true
Expand Down
48 changes: 45 additions & 3 deletions client/webserver/site/src/js/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ export default class WalletsPage extends BasePage {
Doc.bind(page.copyRecipientBtn, 'click', () => { setupCopyBtn(this.currTx?.recipient || '', page.txDetailsRecipient, page.copyRecipientBtn, '#1e7d11') })
Doc.bind(page.copyBondIDBtn, 'click', () => { setupCopyBtn(this.currTx?.bondInfo?.bondID || '', page.txDetailsBondID, page.copyBondIDBtn, '#1e7d11') })
Doc.bind(page.copyBondAccountIDBtn, 'click', () => { setupCopyBtn(this.currTx?.bondInfo?.accountID || '', page.txDetailsBondAccountID, page.copyBondAccountIDBtn, '#1e7d11') })
Doc.bind(page.hideMixTxsCheckbox, 'change', () => { this.showTxHistory(this.selectedAssetID) })

// Bind the new wallet form.
this.newWalletForm = new NewWalletForm(page.newWalletForm, (assetID: number) => {
Expand Down Expand Up @@ -1819,6 +1820,9 @@ export default class WalletsPage extends BasePage {
}

handleTxNote (tx: WalletTransaction, newTx: boolean) {
const w = app().assets[this.selectedAssetID].wallet
const hideMixing = (w.traits & traitFundsMixer) !== 0 && !!this.page.hideMixTxs.checked
if (hideMixing && tx.type === txTypeMixing) return
if (newTx) {
if (!this.oldestTx) {
Doc.show(this.page.txHistoryTable)
Expand Down Expand Up @@ -1846,19 +1850,54 @@ export default class WalletsPage extends BasePage {
}
}

async getTxHistory (assetID: number, hideMixTxs: boolean, after?: string) : Promise<TxHistoryResult> {
let numToFetch = 10
if (hideMixTxs) numToFetch = 15

const res : TxHistoryResult = { txs: [], lastTx: false }
let ref = after

for (let i = 0; i < 40; i++) {
const currRes = await app().txHistory(assetID, numToFetch, ref)
if (currRes.txs.length > 0) {
ref = currRes.txs[currRes.txs.length - 1].id
}
let txs = currRes.txs
if (hideMixTxs) {
txs = txs.filter((tx) => tx.type !== txTypeMixing)
}
if (res.txs.length + txs.length > 10) {
const numToPush = 10 - res.txs.length
res.txs.push(...txs.slice(0, numToPush))
} else {
if (currRes.lastTx) res.lastTx = true
res.txs.push(...txs)
}
if (res.txs.length >= 10 || currRes.lastTx) break
}
return res
}

async showTxHistory (assetID: number) {
const page = this.page
let txRes : TxHistoryResult
Doc.hide(page.txHistoryTable, page.txHistoryBox, page.noTxHistory, page.earlierTxs, page.txHistoryNotAvailable)
Doc.hide(page.txHistoryTable, page.txHistoryBox, page.noTxHistory, page.earlierTxs, page.txHistoryNotAvailable, page.hideMixTxs)
Doc.empty(page.txHistoryTableBody)
const w = app().assets[assetID].wallet
if (!w || w.disabled || (w.traits & traitHistorian) === 0) {
Doc.show(page.txHistoryNotAvailable)
return
}

this.oldestTx = undefined

const isMixing = (w.traits & traitFundsMixer) !== 0
Doc.setVis(isMixing, page.hideMixTxs)
Doc.show(page.txHistoryBox)

try {
txRes = await app().txHistory(assetID, 10)
const hideMixing = isMixing && !!page.hideMixTxsCheckbox.checked
txRes = await this.getTxHistory(assetID, hideMixing)
} catch (err) {
Doc.show(page.noTxHistory)
return
Expand All @@ -1867,6 +1906,7 @@ export default class WalletsPage extends BasePage {
Doc.show(page.noTxHistory)
return
}

let oldestDate = this.txDate(txRes.txs[0])
page.txHistoryTableBody.appendChild(this.txHistoryDateRow(oldestDate))
for (const tx of txRes.txs) {
Expand All @@ -1887,8 +1927,10 @@ export default class WalletsPage extends BasePage {
if (!this.oldestTx) return
const page = this.page
let txRes : TxHistoryResult
const w = app().assets[this.selectedAssetID].wallet
const hideMixing = (w.traits & traitFundsMixer) !== 0 && !!page.hideMixTxsCheckbox.checked
try {
txRes = await app().txHistory(this.selectedAssetID, 10, this.oldestTx.id)
txRes = await this.getTxHistory(this.selectedAssetID, hideMixing, this.oldestTx.id)
} catch (err) {
console.error(err)
return
Expand Down

0 comments on commit 5eb658e

Please sign in to comment.