-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathAccountSelector.tsx
More file actions
89 lines (82 loc) · 2.48 KB
/
Copy pathAccountSelector.tsx
File metadata and controls
89 lines (82 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import type { Balance } from '@metamask/keyring-api';
import {
Address,
Card,
Field,
Selector,
SelectorOption,
type SnapComponent,
} from '@metamask/snaps-sdk/jsx';
import {
SolanaCaip19Tokens,
type Network,
} from '../../../../core/constants/solana';
import { addressToCaip10 } from '../../../../core/utils/addressToCaip10';
import { formatCrypto } from '../../../../core/utils/formatCrypto';
import { formatFiat } from '../../../../core/utils/formatFiat';
import type { Locale } from '../../../../core/utils/i18n';
import { i18n } from '../../../../core/utils/i18n';
import { tokenToFiat } from '../../../../core/utils/tokenToFiat';
import { truncateAddress } from '../../../../core/utils/truncateAddress';
import type { SolanaKeyringAccount } from '../../../../domain';
type AccountSelectorProps = {
name: string;
scope: Network;
accounts: SolanaKeyringAccount[];
balances: Record<string, Record<string, Balance>>;
price: number | null;
selectedAccountId: string;
locale: Locale;
currency: string;
error?: string;
};
export const AccountSelector: SnapComponent<AccountSelectorProps> = ({
accounts,
balances,
price,
name,
scope,
selectedAccountId,
error,
locale,
currency,
}) => {
const translate = i18n(locale);
const accountsList = Object.values(accounts);
return (
<Field label={translate('send.fromField')} error={error}>
<Selector name={name} value={selectedAccountId} title="From">
{accountsList.map((account) => {
const balance =
balances[account.id]?.[`${scope}/${SolanaCaip19Tokens.SOL}`];
const { amount, unit } = balance ?? {};
const value =
amount !== undefined && unit
? formatCrypto(amount, unit, locale)
: '';
const extra =
amount !== undefined && price !== null && currency
? formatFiat(tokenToFiat(amount, price), currency, locale)
: '-';
return (
<SelectorOption value={account.id}>
<Card
value={value}
extra={extra}
description={truncateAddress(account.address)}
title={
<Address
address={addressToCaip10(scope, account.address)}
truncate
displayName
avatar
/>
}
/>
</SelectorOption>
);
})}
</Selector>
</Field>
);
};