on master help sign in
Polish custom gwei dropdown (#846)
commit2bd4b280ad2647bb83d2f2b739486c849de0aeee authorWill Galebach <willbach@gmail.com> dateTue 14 Dec 2021, 09:03 (5 years ago) parent30bb32b
3 files changed+62−21
src/components/L2/Dropdowns/FeeDropdown.scss+31−7 src/components/L2/Dropdowns/FeeDropdown.tsx+30−13 src/style/shared/variables.scss+1−1
src/components/L2/Dropdowns/FeeDropdown.scss+31−7
@@ -4,6 +4,31 @@
44 font-size: 14px;
55 position: relative;
66
7+ &.custom {
8+ background-color: $washed-gray;
9+ padding: 4px;
10+ border-radius: $medium-border-radius;
11+ display: flex;
12+ flex-direction: row;
13+ justify-content: space-between;
14+ align-items: center;
15+ cursor: pointer;
16+
17+ .custom-input {
18+ font-family: "Inter", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji";
19+ height: 24px;
20+ width: 134px;
21+ border: none;
22+ background-color: $washed-gray;
23+ }
24+
25+ svg {
26+ width: 16px;
27+ height: 14px;
28+ margin-right: 6px;
29+ }
30+ }
31+
732 .selector {
833 min-width: 150px;
934 }
@@ -16,7 +41,6 @@
1641 .price {
1742 display: flex;
1843 flex-direction: row;
19− justify-content: space-between;
2044 align-items: center;
2145 cursor: pointer;
2246 line-height: 20px;
@@ -27,14 +51,14 @@
2751 opacity: 0.8;
2852 }
2953
30− .label {
31− margin-right: 8px;
54+ .speed {
55+ font-weight: 600;
56+ margin-right: 4px;
3257 }
3358
34− .custom-input {
35− font-family: "Inter", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji";
36− text-align: right;
37− height: 24px;
59+ .time {
60+ color: $dark-gray;
61+ font-weight: 600;
3862 }
3963
4064 .unit {
src/components/L2/Dropdowns/FeeDropdown.tsx+30−13
@@ -1,12 +1,12 @@
11import React, { useCallback, useEffect, useState, FormEvent } from 'react';
2−import { Box, Row, StatelessTextInput } from '@tlon/indigo-react';
2+import { Box, Row, Icon, StatelessTextInput } from '@tlon/indigo-react';
33import { DEFAULT_GAS_PRICE_GWEI } from 'lib/constants';
44import useGasPrice from 'lib/useGasPrice';
55
66import Dropdown from './Dropdown';
77import './FeeDropdown.scss';
88
9−const PRICE_LABELS = ['Fast', 'Average', 'Slow'];
9+const PRICE_LABELS = ['Fast', 'Normal', 'Slow'];
1010
1111export interface GasPrice {
1212 price: number;
@@ -25,7 +25,8 @@ export default function FeeDropdown({
2525 const { suggestedGasPrices } = useGasPrice(DEFAULT_GAS_PRICE_GWEI);
2626
2727 const [open, setOpen] = useState(false);
28− const [custom, setCustom] = useState<string>('0');
28+ const [useCustom, setUseCustom] = useState(false);
29+ const [custom, setCustom] = useState<string | undefined>();
2930 const [selected, setSelected] = useState<GasPrice>(
3031 suggestedGasPrices.average
3132 );
@@ -66,6 +67,28 @@ export default function FeeDropdown({
6667 [setGasPrice, setSelected, setOpen]
6768 );
6869
70+ if (useCustom) {
71+ return (
72+ <Row className="fee-dropdown custom">
73+ <StatelessTextInput
74+ value={custom}
75+ className="custom-input"
76+ placeholder="Custom gwei"
77+ onChange={handleCustom}
78+ autoFocus
79+ />
80+ <Icon
81+ icon="ChevronSouth"
82+ onClick={() => {
83+ setOpen(true);
84+ setUseCustom(false);
85+ setCustom('');
86+ }}
87+ />
88+ </Row>
89+ );
90+ }
91+
6992 return (
7093 <Dropdown
7194 className="fee-dropdown"
@@ -79,19 +102,13 @@ export default function FeeDropdown({
79102 className="price"
80103 onClick={selectPrice(value)}
81104 key={`gas-price-${ind}`}>
82− {PRICE_LABELS[ind]}: {formatDisplay(value)}
105+ <Box className="speed">{PRICE_LABELS[ind]}</Box>
106+ <Box className="time">{formatDisplay(value)}</Box>
83107 </Row>
84108 )
85109 )}
86− <Row className="price">
87− <Box className="label">Custom:</Box>
88− <StatelessTextInput
89− value={custom}
90− className="custom-input"
91− placeholder="0"
92− onChange={handleCustom}
93− />
94− <Box className="unit">gwei</Box>
110+ <Row className="price" onClick={() => setUseCustom(true)}>
111+ <Box className="time">Custom...</Box>
95112 </Row>
96113 </Box>
97114 </Dropdown>
src/style/shared/variables.scss+1−1
@@ -1,6 +1,6 @@
11$default-font: "Inter", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji";
22
3−$washed-gray: rgba(0, 0, 0, 0.04);
3+$washed-gray: rgba(245, 245, 245, 1);
44$small-border-radius: 2px;
55$medium-border-radius: 4px;
66$large-border-radius: 8px;