forked from decred/decrediton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AccountsSelect.jsx
86 lines (80 loc) · 2.03 KB
/
AccountsSelect.jsx
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
import Select from "react-select";
import { useAccountsSelect } from "./hooks";
import { Balance } from "shared";
import styles from "./AccountsSelect.module.css";
import { classNames } from "pi-ui";
import LinkToAccounts from "./LinkToAccounts";
const AccountsSelect = ({
accountsType,
className,
selectClassName,
showAccountsButton,
disabled,
hideSpendable,
filterAccounts,
account: accountProp,
onChange,
onKeyDown,
valueRenderer,
optionRenderer,
searchable
}) => {
const { account, accounts, placeholder } = useAccountsSelect({
accountProp,
accountsType,
filterAccounts,
onChange
});
const selectKeyDown = (e) => {
switch (e.keyCode) {
case 8:
case 46:
e.preventDefault();
break;
}
onKeyDown?.(e);
};
if (!valueRenderer) {
valueRenderer = (option) => (
<div className={styles.value}>
<div className={styles.name}>{option.name}</div>
{!hideSpendable && (
<div className={styles.spendable}>
<Balance flat amount={option.spendable} />
</div>
)}
</div>
);
}
return (
<div
className={classNames(styles.isRow, className)}
data-testid="accountsSelect">
<Select
disabled={disabled}
clearable={false}
style={{ zIndex: "9" }}
placeholder={placeholder}
multi={false}
value={account}
valueKey="value"
labelKey="label"
options={accounts}
valueRenderer={valueRenderer}
optionRenderer={optionRenderer ?? valueRenderer}
onChange={(acc) => onChange?.(acc)}
className={classNames(styles.select, selectClassName)}
onInputKeyDown={selectKeyDown}
searchable={searchable}
/>
{showAccountsButton && <LinkToAccounts />}
</div>
);
};
AccountsSelect.propTypes = {
accountsType: PropTypes.oneOf(["spending", "visible"]),
className: PropTypes.string,
showAccountsButton: PropTypes.bool,
getAddressForSelected: PropTypes.bool
};
export default AccountsSelect;