Skip to content

Commit 61fac50

Browse files
committed
frontend: refactor balance and amount-with-unit components
Amount component has text-overflow: ellipsis styling which does not work. Fixed text overflow should be shortened by an ellipsis.
1 parent 836fad6 commit 61fac50

27 files changed

+217
-225
lines changed

frontends/web/src/components/amount/amount-with-unit.module.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@
77

88
.unit {
99
font-weight: 400;
10+
flex-grow: 0;
11+
flex-shrink: 0;
1012
color: var(--color-secondary);
1113
font-variant: normal;
1214
position: relative;
1315
cursor: default;
1416
}
1517

1618
.availableFiatAmount {
17-
color: var(--color-default);
18-
padding-right: var(--space-quarter) !important;
19+
align-items: baseline;
20+
display: inline-flex;
21+
flex-grow: 0;
22+
justify-content: flex-start;
23+
gap: 0.4ch;
1924
text-align: right;
2025
}
2126

@@ -42,9 +47,4 @@
4247
.fiatRow {
4348
bottom: 0;
4449
}
45-
46-
.availableFiatAmount,
47-
.availableFiatUnit {
48-
line-height: 24px;
49-
}
5050
}

frontends/web/src/components/amount/amount-with-unit.tsx

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import style from './amount-with-unit.module.css';
2424

2525
type TAmountWithUnitProps = {
2626
amount: TAmountWithConversions | undefined;
27-
tableRow?: boolean;
2827
enableRotateUnit?: boolean;
2928
sign?: string;
3029
alwaysShowAmounts?: boolean;
@@ -34,12 +33,11 @@ type TAmountWithUnitProps = {
3433

3534
export const AmountWithUnit = ({
3635
amount,
37-
tableRow,
3836
enableRotateUnit: rotateUnit,
3937
sign,
4038
convertToFiat,
4139
alwaysShowAmounts = false,
42-
unitClassName = ''
40+
unitClassName = '',
4341
}: TAmountWithUnitProps) => {
4442
const { rotateDefaultCurrency, defaultCurrency, rotateBtcUnit } = useContext(RatesContext);
4543

@@ -64,35 +62,27 @@ export const AmountWithUnit = ({
6462
}
6563

6664
const enableClick = rotateUnit && (convertToFiat || isBitcoinCoin(amount.unit));
67-
const formattedAmount = !!displayedAmount ?
68-
(
69-
<Amount
70-
alwaysShowAmounts={alwaysShowAmounts}
71-
amount={displayedAmount}
72-
unit={displayedUnit}
73-
onMobileClick={enableClick ? onClick : undefined}
74-
/>
75-
) : '---';
76-
77-
const amountUnit = <AmountUnit unit={displayedUnit} rotateUnit={enableClick ? onClick : undefined} className={unitClassName}/>;
7865

79-
if (tableRow) {
80-
return (
81-
<tr className={style.fiatRow}>
82-
<td className={style.availableFiatAmount}>{formattedAmount}</td>
83-
<td>{amountUnit}</td>
84-
</tr>
85-
);
86-
}
8766
return (
8867
<span className={`
8968
${style.rates || ''}
69+
${style.availableFiatAmount || ''}
9070
${!displayedAmount && style.notAvailable || ''}
9171
`.trim()}>
9272
{!!displayedAmount ? sign : ''}
93-
{formattedAmount}
73+
{!!displayedAmount ? (
74+
<Amount
75+
alwaysShowAmounts={alwaysShowAmounts}
76+
amount={displayedAmount}
77+
unit={displayedUnit}
78+
onMobileClick={enableClick ? onClick : undefined}
79+
/>
80+
) : '---'}
9481
{' '}
95-
{amountUnit}
82+
<AmountUnit
83+
unit={displayedUnit}
84+
rotateUnit={enableClick ? onClick : undefined}
85+
className={unitClassName}/>
9686
</span>
9787
);
9888
};

frontends/web/src/components/amount/amount.module.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
.amount {
2+
align-items: baseline;
3+
display: inline-flex;
4+
display: flow-root; /* flow-root seems to work better on all-account. keeping inline-flex as fallback */
25
flex-shrink: 1;
6+
flex-basis: auto;
7+
flex-grow: 0;
38
font-variant: tabular-nums;
9+
max-width: 100%;
410
overflow: hidden;
511
text-overflow: ellipsis;
612
}

frontends/web/src/components/amount/conversion-amount.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
.txUnit {
1616
color: var(--color-secondary);
1717
font-size: var(--size-small);
18-
/* line-height: 1.285714; */
1918
white-space: nowrap;
2019
}
2120

2221
.txConversionAmount .txUnit {
2322
font-size: var(--size-smaller);
2423
flex-shrink: 0;
24+
max-width: 100%;
2525
}
2626

2727
.txSmallInlineIcon img {
Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
.balanceTable {
2-
align-items: flex-end;
3-
border-collapse: collapse;
4-
border-spacing: 0;
5-
display: flex;
6-
flex-direction: row;
7-
position: relative;
1+
.balanceContainer {
2+
color: var(--color-default);
3+
max-width: 100%;
84
}
95

10-
.balanceTable tr {
11-
display: inline-block;
12-
vertical-align: bottom;
13-
padding-right: var(--space-half);
6+
.availableBalanceTitle {
7+
color: var(--color-secondary);
8+
line-height: 1.5;
9+
margin-bottom: 10px;
1410
}
1511

16-
.balanceTable td {
12+
.balance {
13+
align-items: baseline;
14+
display: flex;
15+
flex-direction: row;
16+
flex-wrap: wrap;
1717
font-size: var(--size-large);
1818
font-weight: 400;
19-
line-height: 1.2;
20-
padding: 0;
21-
vertical-align: baseline;
19+
gap: var(--space-eight) var(--space-half);
20+
min-height: 37px;
21+
position: relative;
2222
}
2323

24-
.balanceTable td:last-child {
25-
font-size: var(--size-default);
24+
.unit {
25+
font-size: var(--size-header);
2626
}
2727

2828
.pendingBalance {
@@ -33,19 +33,21 @@
3333
padding-top: var(--space-half);
3434
}
3535

36-
@media (max-width: 768px) {
36+
.incomingBalance {
37+
display: inline-flex;
38+
flex-wrap: wrap;
39+
gap: .4ch;
40+
}
3741

38-
.balanceTable {
39-
display: inline-block;
40-
margin: 0 auto;
41-
}
42+
@media (max-width: 768px) {
4243

43-
.balanceTable td {
44+
.balance {
4445
font-size: var(--size-header);
45-
line-height: 1.5;
46+
min-height: auto;
4647
}
4748

4849
.pendingBalance {
4950
padding-top: var(--space-quarter);
5051
}
52+
5153
}

frontends/web/src/components/balance/balance.tsx

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
import { useTranslation } from 'react-i18next';
1919
import { TBalance } from '@/api/account';
20-
import { Amount } from '@/components/amount/amount';
2120
import { BalanceSkeleton } from '@/components/balance/balance-skeleton';
2221
import { AmountWithUnit } from '@/components/amount/amount-with-unit';
22+
import { SubTitle } from '@/components/title';
2323
import style from './balance.module.css';
2424

2525
type TProps = {
@@ -39,44 +39,41 @@ export const Balance = ({
3939
}
4040

4141
return (
42-
<header className={style.balance}>
43-
<table className={style.balanceTable}>
44-
<tbody data-testid="availableBalance">
45-
<AmountWithUnit
46-
amount={balance.available}
47-
tableRow
48-
enableRotateUnit={!noRotateFiat}
49-
/>
50-
<AmountWithUnit
51-
amount={balance.available}
52-
tableRow
53-
enableRotateUnit={!noRotateFiat}
54-
convertToFiat
55-
/>
56-
</tbody>
57-
</table>
58-
{
59-
balance.hasIncoming && (
60-
<p className={style.pendingBalance}>
61-
{t('account.incoming')}
62-
{' '}
63-
<span data-testid="incomingBalance">
64-
+<Amount
65-
amount={balance.incoming.amount}
66-
unit={balance.incoming.unit}
42+
<header className={style.balanceContainer}>
43+
<SubTitle className={style.availableBalanceTitle}>
44+
{t('accountSummary.availableBalance')}
45+
</SubTitle>
46+
<div className={style.balance} data-testid="availableBalance">
47+
<AmountWithUnit
48+
amount={balance.available}
49+
enableRotateUnit={!noRotateFiat}
50+
unitClassName={style.unit}
51+
/>
52+
<AmountWithUnit
53+
amount={balance.available}
54+
enableRotateUnit={!noRotateFiat}
55+
unitClassName={style.unit}
56+
convertToFiat
57+
/>
58+
</div>
59+
{balance.hasIncoming && (
60+
<p className={style.pendingBalance}>
61+
{t('account.incoming')}
62+
{' '}
63+
<span
64+
className={style.incomingBalance}
65+
data-testid="incomingBalance">
66+
+<AmountWithUnit amount={balance.incoming} />
67+
<span className={style.incomingConversion}>
68+
/&nbsp;
69+
<AmountWithUnit
70+
amount={balance.incoming}
71+
convertToFiat
6772
/>
68-
{' '}{balance.incoming.unit} /
69-
<span className={style.incomingConversion}>
70-
{' '}
71-
<AmountWithUnit
72-
amount={balance.incoming}
73-
convertToFiat
74-
/>
75-
</span>
7673
</span>
77-
</p>
78-
)
79-
}
74+
</span>
75+
</p>
76+
)}
8077
</header>
8178
);
8279
};

frontends/web/src/components/transactions/components/tx-detail-dialog/tx-detail-dialog.module.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
.amount {
5959
font-size: var(--size-header);
6060
margin: var(--space-quarter) 0;
61+
max-width: 100%;
62+
white-space: nowrap;
6163
}
6264

6365
.headerAmountUnit {
@@ -92,6 +94,7 @@
9294
display: flex;
9395
flex-direction: column;
9496
justify-content: center;
97+
max-width: 100%;
9598
}
9699

97100
.amountFiat {

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { useMediaQuery } from '@/hooks/mediaquery';
2020
import { Loupe } from '@/components/icon/icon';
2121
import { parseTimeLong, parseTimeShort } from '@/utils/date';
2222
import { ProgressRing } from '@/components/progressRing/progressRing';
23-
import { Amount } from '@/components/amount/amount';
23+
import { AmountWithUnit } from '../amount/amount-with-unit';
2424
import { ConversionAmount } from '@/components/amount/conversion-amount';
2525
import { Arrow } from './components/arrows';
2626
import { getTxSign } from '@/utils/transaction';
@@ -162,7 +162,6 @@ const Amounts = ({
162162
const txTypeClass = `txAmount-${type}`;
163163
const recv = type === 'receive';
164164
const displayAmount = recv ? amount.amount : deductedAmount.amount;
165-
const displayUnit = recv ? amount.unit : deductedAmount.unit;
166165
const sign = displayAmount ? getTxSign(type) : '';
167166

168167
return (
@@ -172,14 +171,10 @@ const Amounts = ({
172171
`}>
173172
<span className={styles.txAmount}>
174173
{sign}
175-
<Amount
176-
amount={displayAmount}
177-
unit={displayUnit}
174+
<AmountWithUnit
175+
amount={amount}
176+
unitClassName={styles.txUnit}
178177
/>
179-
<span className={styles.txUnit}>
180-
{' '}
181-
{displayUnit}
182-
</span>
183178
</span>
184179
<ConversionAmount amount={amount} deductedAmount={deductedAmount} type={type} />
185180
</span>

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
width: var(--size-default);
3636
}
3737

38+
.button {
39+
height: 37px;
40+
min-height: auto;
41+
}
42+
3843
@media (max-width: 768px) {
3944
.accountHeader {
4045
padding: 0 var(--space-half);
@@ -46,22 +51,24 @@
4651
}
4752

4853
.subTitle {
54+
color: var(--color-secondary);
4955
font-size: var(--size-subheader);
5056
font-weight: normal;
51-
margin-bottom: var(--space-quarter);
52-
margin-top: 0;
57+
margin: 0;
5358
}
5459

5560
.balanceHeader {
56-
align-items: flex-start;
61+
align-items: flex-end;
62+
color: var(--color-default);
5763
display: flex;
5864
flex-direction: row;
5965
flex-wrap: wrap;
60-
margin-bottom: var(--space-half);
66+
gap: var(--space-half);
6167
min-height: var(--button-height);
6268
}
6369

6470
.actionsContainer {
71+
--size-default: var(--size-small);
6572
display: flex;
6673
flex-grow: 1;
6774
flex-shrink: 0;

0 commit comments

Comments
 (0)