Skip to content

Commit c616f0f

Browse files
committed
frontend: use sat spacing in all-accounts
This also simplifes and remove some dry code in all-accounts comp.
1 parent 164b1e2 commit c616f0f

File tree

4 files changed

+15
-27
lines changed

4 files changed

+15
-27
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
cursor: default;
33
line-height: 1;
44
margin: 0;
5+
max-width: 100%;
56
white-space: nowrap;
67
}
78

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
1718
import { useContext } from 'react';
1819
import { CoinUnit, ConversionUnit, TAmountWithConversions } from '@/api/account';
1920
import { RatesContext } from '@/contexts/RatesContext';
@@ -22,7 +23,7 @@ import { isBitcoinCoin } from '@/routes/account/utils';
2223
import style from './amount-with-unit.module.css';
2324

2425
type TAmountWithUnitProps = {
25-
amount: TAmountWithConversions;
26+
amount: TAmountWithConversions | undefined;
2627
tableRow?: boolean;
2728
enableRotateUnit?: boolean;
2829
sign?: string;
@@ -42,6 +43,9 @@ export const AmountWithUnit = ({
4243
}: TAmountWithUnitProps) => {
4344
const { rotateDefaultCurrency, defaultCurrency, rotateBtcUnit } = useContext(RatesContext);
4445

46+
if (!amount) {
47+
return null;
48+
}
4549
let displayedAmount: string = '';
4650
let displayedUnit: CoinUnit | ConversionUnit;
4751
let onClick: () => Promise<void>;

frontends/web/src/routes/accounts/all-accounts.module.css

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,6 @@
6262
justify-content: flex-end;
6363
}
6464

65-
.accountBalance {
66-
overflow: hidden;
67-
white-space: nowrap;
68-
text-overflow: ellipsis;
69-
margin-right: 4px;
70-
}
71-
72-
.coinUnit {
73-
flex-shrink: 0;
74-
white-space: nowrap;
75-
}
76-
7765
.chevron {
7866
margin-top: 6px;
7967
color: var(--color-mediumgray);

frontends/web/src/routes/accounts/all-accounts.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { useState, useEffect } from 'react';
1718
import { useTranslation } from 'react-i18next';
1819
import { Link } from 'react-router-dom';
19-
import { useState, useEffect, useContext } from 'react';
2020
import { useOnlyVisitableOnMobile } from '@/hooks/onlyvisitableonmobile';
2121
import * as accountApi from '@/api/account';
2222
import { getBalance } from '@/api/account';
@@ -27,16 +27,20 @@ import { HideAmountsButton } from '@/components/hideamountsbutton/hideamountsbut
2727
import { Main, Header } from '@/components/layout';
2828
import { Badge } from '@/components/badge/badge';
2929
import { ChevronRightDark, USBSuccess } from '@/components/icon/icon';
30-
import { AppContext } from '@/contexts/AppContext';
3130
import { AllAccountsGuide } from '@/routes/accounts/all-accounts-guide';
3231
import { useMountedRef } from '@/hooks/mount';
32+
import { AmountWithUnit } from '@/components/amount/amount-with-unit';
3333
import styles from './all-accounts.module.css';
3434

3535
type AllAccountsProps = {
3636
accounts?: accountApi.IAccount[];
3737
};
3838

39-
const AccountItem = ({ account, hideAmounts }: { account: accountApi.IAccount, hideAmounts: boolean }) => {
39+
type TAccountItemProp = {
40+
account: accountApi.IAccount;
41+
};
42+
43+
const AccountItem = ({ account }: TAccountItemProp) => {
4044
const [balance, setBalance] = useState<accountApi.TAmountWithConversions>();
4145
const mounted = useMountedRef();
4246

@@ -70,12 +74,7 @@ const AccountItem = ({ account, hideAmounts }: { account: accountApi.IAccount, h
7074
</p>
7175

7276
<div className={styles.accountBalanceContainer}>
73-
<div className={styles.accountBalance}>
74-
{balance ? (hideAmounts ? '***' : balance.amount) : '...'}
75-
</div>
76-
<div className={styles.coinUnit}>
77-
{balance ? balance.unit : ''}
78-
</div>
77+
<AmountWithUnit amount={balance} />
7978
</div>
8079
<div className={styles.chevron}>
8180
<ChevronRightDark />
@@ -84,18 +83,15 @@ const AccountItem = ({ account, hideAmounts }: { account: accountApi.IAccount, h
8483
);
8584
};
8685

87-
8886
/**
8987
* This component will only be shown on mobile.
9088
**/
9189
export const AllAccounts = ({ accounts = [] }: AllAccountsProps) => {
9290
const { t } = useTranslation();
93-
const { hideAmounts } = useContext(AppContext);
9491
const accountsByKeystore = getAccountsByKeystore(accounts);
9592
useOnlyVisitableOnMobile('/settings/manage-accounts');
9693

9794
return (
98-
9995
<Main>
10096
<Header title={<h2>{t('settings.accounts')}</h2>}>
10197
<HideAmountsButton />
@@ -124,7 +120,7 @@ export const AllAccounts = ({ accounts = [] }: AllAccountsProps) => {
124120
</div>
125121
<div className={styles.accountsList}>
126122
{keystore.accounts.map(account => (
127-
<AccountItem hideAmounts={hideAmounts} key={`account-${account.code}`} account={account} />
123+
<AccountItem key={`account-${account.code}`} account={account} />
128124
))}
129125
</div>
130126
</div>
@@ -134,6 +130,5 @@ export const AllAccounts = ({ accounts = [] }: AllAccountsProps) => {
134130
</View>
135131
<AllAccountsGuide />
136132
</Main >
137-
138133
);
139134
};

0 commit comments

Comments
 (0)