Skip to content

Commit a29ba3c

Browse files
committed
frontend: Add received date to coin control UTXO list
Add the received date (block header timestamp) to the UTXO detail in the coin control view. This makes it easier for users to view the date, which can be helpful for various reasons, without having to open each UTXO individually in the block explorer.
1 parent 45f54df commit a29ba3c

File tree

9 files changed

+48
-13
lines changed

9 files changed

+48
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44
- Reduced support for BitBox01
55
- Fix a bug that would prevent the app to perform firmware upgrade when offline.
6+
- Add received date to coin control transaction details
67

78
# v4.47.2
89
- Linux: fix compatiblity with some versions of Mesa that are incompatible with the bundled wayland libraries

backend/coins/btc/account.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"path"
2424
"sort"
2525
"sync/atomic"
26+
"time"
2627

2728
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/accounts"
2829
accountsTypes "github.com/BitBoxSwiss/bitbox-wallet-app/backend/accounts/types"
@@ -840,9 +841,10 @@ func sortByAddresses(result []*SpendableOutput) []*SpendableOutput {
840841
// SpendableOutput is an unspent coin.
841842
type SpendableOutput struct {
842843
*transactions.SpendableOutput
843-
OutPoint wire.OutPoint
844-
Address *addresses.AccountAddress
845-
IsChange bool
844+
OutPoint wire.OutPoint
845+
Address *addresses.AccountAddress
846+
IsChange bool
847+
HeaderTimestamp *time.Time
846848
}
847849

848850
// SpendableOutputs returns the utxo set, sorted by the value descending.
@@ -856,13 +858,18 @@ func (account *Account) SpendableOutputs() []*SpendableOutput {
856858
}
857859
for outPoint, txOut := range utxos {
858860
scriptHashHex := blockchain.NewScriptHashHex(txOut.TxOut.PkScript)
861+
headerTimestamp, err := account.transactions.GetHeaderTimestamp(outPoint.Hash)
862+
if err != nil {
863+
headerTimestamp = nil
864+
}
859865
result = append(
860866
result,
861867
&SpendableOutput{
862868
OutPoint: outPoint,
863869
SpendableOutput: txOut,
864870
Address: account.getAddress(scriptHashHex),
865871
IsChange: account.IsChange(scriptHashHex),
872+
HeaderTimestamp: headerTimestamp,
866873
})
867874
}
868875
return sortByAddresses(result)

backend/coins/btc/handlers/handlers.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,16 @@ func (handlers *Handlers) getUTXOs(*http.Request) (interface{}, error) {
357357

358358
result = append(result,
359359
map[string]interface{}{
360-
"outPoint": output.OutPoint.String(),
361-
"txId": output.OutPoint.Hash.String(),
362-
"txOutput": output.OutPoint.Index,
363-
"amount": handlers.formatBTCAmountAsJSON(btcutil.Amount(output.TxOut.Value), false),
364-
"address": address,
365-
"scriptType": output.Address.Configuration.ScriptType(),
366-
"note": handlers.account.TxNote(output.OutPoint.Hash.String()),
367-
"addressReused": addressReused,
368-
"isChange": output.IsChange,
360+
"outPoint": output.OutPoint.String(),
361+
"txId": output.OutPoint.Hash.String(),
362+
"txOutput": output.OutPoint.Index,
363+
"amount": handlers.formatBTCAmountAsJSON(btcutil.Amount(output.TxOut.Value), false),
364+
"address": address,
365+
"scriptType": output.Address.Configuration.ScriptType(),
366+
"note": handlers.account.TxNote(output.OutPoint.Hash.String()),
367+
"addressReused": addressReused,
368+
"isChange": output.IsChange,
369+
"headerTimestamp": output.HeaderTimestamp,
369370
})
370371
}
371372

backend/coins/btc/transactions/transactions.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package transactions
1616

1717
import (
18+
"time"
19+
1820
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/accounts"
1921
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc/blockchain"
2022
"github.com/BitBoxSwiss/bitbox-wallet-app/backend/coins/btc/headers"
@@ -221,6 +223,18 @@ func (transactions *Transactions) SpendableOutputs() (map[wire.OutPoint]*Spendab
221223
})
222224
}
223225

226+
// GetHeaderTimestamp retrieves the header timestamp for a given transaction hash.
227+
func (transactions *Transactions) GetHeaderTimestamp(txHash chainhash.Hash) (*time.Time, error) {
228+
transactions.synchronizer.WaitSynchronized()
229+
return DBView(transactions.db, func(dbTx DBTxInterface) (*time.Time, error) {
230+
txInfo, err := dbTx.TxInfo(txHash)
231+
if err != nil {
232+
return nil, err
233+
}
234+
return txInfo.HeaderTimestamp, nil
235+
})
236+
}
237+
224238
func (transactions *Transactions) isInputSpent(dbTx DBTxInterface, outPoint wire.OutPoint) bool {
225239
input, err := dbTx.Input(outPoint)
226240
if err != nil {

frontends/web/src/api/account.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ export type TUTXO = {
408408
scriptType: ScriptType;
409409
addressReused: boolean;
410410
isChange: boolean;
411+
headerTimestamp: string;
411412
};
412413

413414
export const getUTXOs = (code: AccountCode): Promise<TUTXO[]> => {

frontends/web/src/components/transactions/transaction.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ type TDateProps = {
190190
time: string | null;
191191
}
192192

193-
const Date = ({
193+
export const Date = ({
194194
time,
195195
}: TDateProps) => {
196196
const { i18n } = useTranslation();

frontends/web/src/locales/en/app.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,7 @@
16591659
"addressReused": "Address re-used",
16601660
"change": "Change",
16611661
"outpoint": "Outpoint",
1662+
"receivedDate": "Received date",
16621663
"title": "Send from output"
16631664
},
16641665
"confirm": {

frontends/web/src/routes/account/send/utxos.module.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
}
7070

7171
.address,
72+
.date,
7273
.transaction {
7374
display: flex;
7475
font-size: var(--size-default);

frontends/web/src/routes/account/send/utxos.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { FiatConversion } from '@/components/rates/rates';
3434
import { getScriptName } from '@/routes/account/utils';
3535
import { Message } from '@/components/message/message';
3636
import { Badge } from '@/components/badge/badge';
37+
import { Date } from '@/components/transactions/transaction';
3738
import style from './utxos.module.css';
3839

3940
export type TSelectedUTXOs = {
@@ -127,6 +128,14 @@ export const UTXOs = ({
127128
</span>
128129
<FiatConversion alwaysShowAmounts amount={utxo.amount} unstyled noAction/>
129130
</div>
131+
<div className={style.date}>
132+
<span className={style.label}>
133+
{t('send.coincontrol.receivedDate')}:
134+
</span>
135+
<span className={style.shrink}>
136+
<Date time={utxo.headerTimestamp} />
137+
</span>
138+
</div>
130139
<div className={style.address}>
131140
<span className={style.label}>
132141
{t('send.coincontrol.address')}:

0 commit comments

Comments
 (0)