Skip to content

Commit c731db3

Browse files
committed
frontend: align send-to-self tx display with other txs
Keep the first row in BTC/sats and switch the second row to fiat for consistency. Since the sent amount is no longer shown on the right for send-to-self transactions, the left-side label now includes amount to keep it visible.
1 parent 83b81ff commit c731db3

File tree

6 files changed

+77
-36
lines changed

6 files changed

+77
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- iOS: Add haptic feedback on toggle component
77
- Apply rounded corners in several places and components of the app
88
- Send: enable rotating currencies in send window.
9+
- Show the fee's fiat value in send-to-self txs for consistency with others, and include the send-to-self amount in the left-side label
910

1011
## v4.50.1
1112
- Fix a bug that would delay showing watch-only accounts.

frontends/web/src/components/amount/conversion-amount.tsx

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import { useContext } from 'react';
44
import type { TAmountWithConversions, TTransactionType } from '@/api/account';
55
import { RatesContext } from '@/contexts/RatesContext';
6-
import { Arrow } from '@/components/transactions/components/arrows';
76
import { Amount } from '@/components/amount/amount';
87
import { getTxSign } from '@/utils/transaction';
98
import styles from './conversion-amount.module.css';
@@ -17,41 +16,35 @@ type TConversionAmountProps = {
1716
const btcUnits: Readonly<string[]> = ['BTC', 'TBTC', 'sat', 'tsat'];
1817

1918
/**
20-
* Renders a formattted conversion amount optionally with send-to-self icon or estimate symbol
19+
* Renders a formatted conversion amount, optionally with an estimate symbol.
2120
*/
2221
export const ConversionAmount = ({
2322
amount,
2423
deductedAmount,
2524
type,
2625
}: TConversionAmountProps) => {
2726
const { defaultCurrency } = useContext(RatesContext);
28-
const conversion = amount?.conversions && amount?.conversions[defaultCurrency];
2927

3028
const sign = getTxSign(type);
3129
const estimatedPrefix = '\u2248'; // ≈
32-
const sendToSelf = type === 'send_to_self';
3330
const recv = type === 'receive';
34-
const amountToShow = recv || sendToSelf ? amount : deductedAmount;
35-
const conversionUnit = sendToSelf ? amountToShow.unit : defaultCurrency;
31+
const amountToShow = recv ? amount : deductedAmount;
32+
const conversionUnit = defaultCurrency;
33+
const conversion = amountToShow?.conversions && amountToShow?.conversions[defaultCurrency];
3634

37-
// we skip the estimated conversion prefix when the Tx is send to self, or both coin and conversion are in BTC units.
38-
const skipEstimatedPrefix = sendToSelf || (btcUnits.includes(conversionUnit) && btcUnits.includes(amountToShow.unit));
35+
// we skip the estimated conversion prefix when both coin and conversion are in BTC units.
36+
const skipEstimatedPrefix = btcUnits.includes(conversionUnit) && btcUnits.includes(amountToShow.unit);
3937

4038
return (
4139
<span className={styles.txConversionAmount}>
42-
{(conversion || sendToSelf) && amountToShow ? (
40+
{conversion && amountToShow ? (
4341
<>
44-
{sendToSelf && (
45-
<span className={styles.txSmallInlineIcon}>
46-
<Arrow type="send_to_self" />
47-
</span>
48-
)}
4942
{amountToShow.estimated && !skipEstimatedPrefix && (
5043
<span className={styles.txPrefix}>{estimatedPrefix}{' '}</span>
5144
)}
52-
{conversion && conversion !== '0' && !sendToSelf ? sign : null}
45+
{conversion !== '0' ? sign : null}
5346
<Amount
54-
amount={sendToSelf ? amountToShow.amount : conversion || ''}
47+
amount={conversion || ''}
5548
unit={conversionUnit}
5649
/>
5750
<span className={styles.txUnit}>

frontends/web/src/components/transactions/transaction.module.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@
190190
color: var(--color-default);
191191
font-size: var(--size-default);
192192
line-height: 1.25;
193+
max-width: 100%;
194+
text-overflow: ellipsis;
193195
}
194196

195197
.txDateLong {
@@ -228,8 +230,7 @@
228230
}
229231

230232
.addresses {
231-
opacity: 0;
232-
pointer-events: none;
233+
display: none;
233234
}
234235

235236
.txNoteWithAddress {
@@ -239,4 +240,4 @@
239240
.iconLoupe {
240241
width: 28px;
241242
vertical-align: text-bottom;
242-
}
243+
}

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

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22

3-
import { useTranslation } from 'react-i18next';
3+
import { Trans, useTranslation } from 'react-i18next';
44
import type { TAmountWithConversions, TTransactionStatus, TTransactionType, TTransaction } from '@/api/account';
55
import { useMediaQuery } from '@/hooks/mediaquery';
66
import { Loupe } from '@/components/icon/icon';
@@ -44,6 +44,7 @@ export const Transaction = ({
4444
</span>
4545
<Status
4646
addresses={addresses}
47+
amount={amountAtTime}
4748
note={note}
4849
numConfirmations={numConfirmations}
4950
numConfirmationsComplete={numConfirmationsComplete}
@@ -70,6 +71,7 @@ export const Transaction = ({
7071

7172
type TStatus = {
7273
addresses: string[];
74+
amount: TAmountWithConversions;
7375
note?: TTransaction['note'];
7476
numConfirmations: number;
7577
numConfirmationsComplete: number;
@@ -80,6 +82,7 @@ type TStatus = {
8082

8183
const Status = ({
8284
addresses,
85+
amount,
8386
note,
8487
numConfirmations,
8588
numConfirmationsComplete,
@@ -102,6 +105,7 @@ const Status = ({
102105
) : (
103106
<Addresses
104107
addresses={addresses}
108+
amount={amount}
105109
status={status}
106110
type={type}
107111
/>
@@ -151,10 +155,13 @@ const Amounts = ({
151155
const displayAmount = recv ? amount : deductedAmount;
152156

153157
return (
154-
<span className={`
158+
<span
159+
className={`
155160
${styles.txAmountsColumn || ''}
156161
${styles[txTypeClass] || ''}
157-
`}>
162+
`}
163+
data-testid="tx-amounts"
164+
>
158165
<span className={styles.txAmount}>
159166
{displayAmount.amount !== '0' && getTxSign(type)}
160167
<AmountWithUnit
@@ -171,6 +178,22 @@ type TDateProps = {
171178
time: string | null;
172179
};
173180

181+
type TAddressListProps = {
182+
values: string[];
183+
};
184+
185+
const AddressList = ({ values }: TAddressListProps) => (
186+
<span className={styles.addresses}>
187+
{values[0]}
188+
{values.length > 1 && (
189+
<span>
190+
{' '}
191+
(+{values.length - 1})
192+
</span>
193+
)}
194+
</span>
195+
);
196+
174197
const Date = ({
175198
time,
176199
}: TDateProps) => {
@@ -192,39 +215,59 @@ const Date = ({
192215

193216
type TAddresses = {
194217
addresses: TTransaction['addresses'];
218+
amount: TAmountWithConversions;
195219
status: TTransactionStatus;
196220
type: TTransactionType;
197221
};
198222

199223
const Addresses = ({
200224
addresses,
225+
amount,
201226
status,
202227
type,
203228
}: TAddresses) => {
204229
const { t } = useTranslation();
205230
const isMobile = useMediaQuery('(max-width: 768px)');
231+
232+
if (type === 'send_to_self') {
233+
const labelKey = status === 'failed'
234+
? 'transaction.tx.send_to_self_failed'
235+
: 'transaction.tx.send_to_self';
236+
return (
237+
<span className={styles.txNoteWithAddress}>
238+
<span className={styles.txType}>
239+
<Trans
240+
i18nKey={labelKey}
241+
components={{
242+
amount: (
243+
<AmountWithUnit
244+
amount={amount}
245+
unitClassName={styles.txUnit}
246+
/>
247+
),
248+
}}
249+
/>
250+
</span>
251+
{' '}
252+
<AddressList values={addresses} />
253+
</span>
254+
);
255+
}
256+
206257
const label = isMobile
207258
? (type === 'receive' ? t('generic.received') : t('generic.sent'))
208259
: (type === 'receive'
209260
? t('transaction.tx.receive', { context: status })
210261
: t('transaction.tx.send', { context: status })
211-
// send_to_self will currently show the send message
212262
);
213263

214264
return (
215265
<span className={styles.txNoteWithAddress}>
216266
<span className={styles.txType}>
217267
{label}
218268
</span>
219-
<span className={styles.addresses}>
220-
{addresses[0]}
221-
{addresses.length > 1 && (
222-
<span>
223-
{' '}
224-
(+{addresses.length - 1})
225-
</span>
226-
)}
227-
</span>
269+
{' '}
270+
<AddressList values={addresses} />
228271
</span>
229272
);
230273
};

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,9 @@
19611961
"receive_pending": "Received to",
19621962
"send_complete": "Sent to",
19631963
"send_failed": "Failed sending to",
1964-
"send_pending": "Sent to"
1964+
"send_pending": "Sent to",
1965+
"send_to_self": "Sent <amount /> to self",
1966+
"send_to_self_failed": "Failed sending <amount /> to self"
19651967
},
19661968
"vsize": "Virtual size",
19671969
"weight": "Weight"

frontends/web/tests/send.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,12 @@ test('Send BTC', async ({ page, host, frontendPort, servewalletPort }, testInfo)
200200
await page.getByTestId('close-button').click();
201201

202202
// Verify that the values displayed are correctly
203-
const shownDetractedAmount = await newTx.getByTestId('amountBlocks').nth(0).textContent();
204-
const shownSentToSelfAmount = await newTx.getByTestId('amountBlocks').nth(1).textContent();
203+
const labelAmount = await newTx.getByTestId('amountBlocks').first().textContent();
204+
const amountsColumn = newTx.getByTestId('tx-amounts');
205+
const shownDetractedAmount = await amountsColumn.getByTestId('amountBlocks').nth(0).textContent();
205206

207+
expect(labelAmount).toBe(amount);
206208
expect(shownDetractedAmount).toBe(fee);
207-
expect(shownSentToSelfAmount).toBe(amount);
208209

209210
});
210211

0 commit comments

Comments
 (0)