-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSpotOrderSettingsSheet.tsx
110 lines (94 loc) · 2.62 KB
/
SpotOrderSettingsSheet.tsx
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import React from "react";
import styled from "@emotion/styled";
import { BN } from "@compolabs/spark-orderbook-ts-sdk";
import Sheet from "../Sheet";
import { SmartFlex } from "../SmartFlex";
import Text from "../Text";
interface Props {
filterIcons: string[];
decimals: number[];
selectedFilter: number;
selectedDecimal: string;
isOpen: boolean;
onFilterSelect: (index: number) => void;
onDecimalSelect: (index: string) => void;
onClose: () => void;
}
const SpotOrderSettingsSheet: React.FC<Props> = ({
decimals,
filterIcons,
selectedFilter,
selectedDecimal,
onFilterSelect,
onDecimalSelect,
isOpen,
onClose,
}) => {
const handleFilterSelect = (index: number) => {
onFilterSelect(index);
onClose();
};
const handleDecimalsSelect = (index: string) => {
onDecimalSelect(index);
onClose();
};
const renderButtons = () => {
return filterIcons.map((icon, index) => (
<SettingIcon
key={index}
alt="filter"
isActive={selectedFilter === index}
src={icon}
onClick={() => handleFilterSelect(index)}
/>
));
};
const renderDecimals = () => {
return decimals.map((decimal, index) => (
<DecimalItem
key={index}
isActive={selectedDecimal === index.toString()}
onClick={() => handleDecimalsSelect(index.toString())}
>
<Text primary>{new BN(10).pow(-decimal).toString()}</Text>
</DecimalItem>
));
};
return (
<Sheet isOpen={isOpen} header onClose={onClose}>
<SmartFlex margin="0 0 40px 0" column>
<FilterContainer center="y">{renderButtons()}</FilterContainer>
<DecimalsContainer center="y" column>
{renderDecimals()}
</DecimalsContainer>
</SmartFlex>
</Sheet>
);
};
export default SpotOrderSettingsSheet;
const SettingIcon = styled.img<{ isActive?: boolean }>`
cursor: pointer;
transition: 0.4s;
border-radius: 4px;
border: 1px solid ${({ isActive, theme }) => (isActive ? theme.colors.borderAccent : "transparent")};
&:hover {
border: 1px solid ${({ isActive, theme }) => (isActive ? theme.colors.borderAccent : theme.colors.borderPrimary)};
}
`;
const FilterContainer = styled(SmartFlex)`
padding: 8px 24px;
gap: 12px;
`;
const DecimalsContainer = styled(SmartFlex)``;
const DecimalItem = styled(SmartFlex)<{ isActive?: boolean }>`
padding: 8px 24px;
height: 40px;
background-color: ${({ isActive, theme }) => (isActive ? theme.colors.borderPrimary : "unset")};
${Text} {
display: flex;
align-items: center;
}
&:hover {
background-color: ${({ theme }) => theme.colors.borderPrimary};
}
`;