Skip to content

Commit ab0d45c

Browse files
committed
extend overpayment warning to discountCT (liquid) txes
- when calculating overpayment, consider liquid transactions for which discount CT rates were or are available - extract calculations for fee rates and overpayment into functions - generalize fee rate calculation by computing an effective fee rate which will use discount fee rate if available
1 parent 6a32119 commit ab0d45c

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

client/src/app.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,24 @@ import {setAdapt} from '@cycle/run/lib/adapt';
55
import { getMempoolDepth, getConfEstimate, calcSegwitFeeGains } from './lib/fees'
66
import getPrivacyAnalysis from './lib/privacy-analysis'
77
import { nativeAssetId, blockTxsPerPage, blocksPerPage } from './const'
8-
import { dbg, combine, extractErrors, dropErrors, last, updateQuery, notNully, processGoAddr, parseHashes, isHash256, makeAddressQR, tickWhileFocused, tickWhileViewing, updateBlocks } from './util'
8+
import {
9+
dbg,
10+
combine,
11+
extractErrors,
12+
dropErrors,
13+
last,
14+
updateQuery,
15+
notNully,
16+
processGoAddr,
17+
parseHashes,
18+
isHash256,
19+
makeAddressQR,
20+
tickWhileFocused,
21+
tickWhileViewing,
22+
updateBlocks,
23+
calculateFeerates,
24+
calculateOverpayment,
25+
} from './util'
926
import l10n, { defaultLang } from './l10n'
1027
import * as views from './views'
1128

@@ -191,15 +208,14 @@ export default function main({ DOM, HTTP, route, storage, scanner: scan$, search
191208

192209
// Transaction analysis
193210
, txAnalysis$ = tx$.filter(Boolean)
194-
.combineLatest(mempool$, feeEst$, (tx, mempool, feeEst) =>
195-
({ tx, mempool, feeEst, feerate: tx.fee ? tx.fee / tx.weight * 4 : null }))
196-
.map(({ tx, feerate, mempool, feeEst }) => ({
211+
.combineLatest(mempool$, feeEst$, calculateFeerates)
212+
.map(({ tx, feerate, mempool, feeEst, effectiveFeerate}) => ({
197213
feerate
198214
, privacyAnalysis: getPrivacyAnalysis(tx)
199215
, segwitGains: calcSegwitFeeGains(tx)
200-
, mempoolDepth: !tx.status.confirmed && feerate != null && mempool ? getMempoolDepth(mempool.fee_histogram, feerate) : null
201-
, confEstimate: !tx.status.confirmed && feerate != null && feeEst ? getConfEstimate(feeEst, feerate) : null
202-
, overpaying: !tx.status.confirmed && feerate != null && feeEst && feeEst[2] != null ? feerate/feeEst[2] : null
216+
, mempoolDepth: !tx.status.confirmed && feerate != null && mempool ? getMempoolDepth(mempool.fee_histogram, effectiveFeerate) : null
217+
, confEstimate: !tx.status.confirmed && feerate != null && feeEst ? getConfEstimate(feeEst, effectiveFeerate) : null
218+
, overpaying: !tx.status.confirmed && feerate != null && feeEst ? calculateOverpayment(effectiveFeerate, feeEst) : null
203219
}))
204220

205221
// Asset and associated txs (elements only)

client/src/util.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ export const outTotal = tx => tx.vout.reduce((N, vout) => N + (vout.value || 0),
6060

6161
export const isNativeOut = vout => (!vout.asset && !vout.assetcommitment) || vout.asset === nativeAssetId
6262

63+
export const calculateFeerates = (tx, mempool, feeEst) => {
64+
const feerate = tx.fee ? tx.fee / tx.weight * 4 : null;
65+
const discountFeerate = tx.fee && tx.discount_vsize ? tx.fee / tx.discount_vsize : null;
66+
const effectiveFeerate = discountFeerate ? discountFeerate : feerate;
67+
return { tx, mempool, feeEst, feerate, discountFeerate, effectiveFeerate };
68+
}
69+
70+
export const calculateOverpayment = (feerate, feeEst) => {
71+
const feeEstValid = feeEst != null && feeEst[2] != null;
72+
return feeEstValid ? feerate / feeEst[2] : null;
73+
}
74+
6375
// Address helpers
6476

6577
// Try removing blinding key from confidential address and return in standard address encoding

client/src/views/tx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const txHeader = (tx, { tipHeight, mempool, feeEst, t
142142
<div>
143143
<span className="amount">{t`${formatSat(tx.fee)} (${feerate.toFixed(2)} sat/vB)`}</span>
144144
{ overpaying > OVERPAYMENT_WARN &&
145-
<p className={`text-${ overpaying > OVERPAYMENT_WARN*1.5 ? 'danger' : 'warning' } mb-0`} title={t`compared to bitcoind's suggested fee of ${feeEst[2].toFixed(1)} sat/vB for confirmation within 2 blocks`}>
145+
<p className={`text-${ overpaying > OVERPAYMENT_WARN*1.5 ? 'danger' : 'warning' } mb-0`} title={t`compared to the suggested fee of ${feeEst[2].toFixed(1)} sat/vB for confirmation within 2 blocks`}>
146146
{t`overpaying by ${Math.round((overpaying-1)*100)}%`}
147147
</p>
148148
}

0 commit comments

Comments
 (0)