Skip to content

Commit 2593b72

Browse files
authored
Merge pull request #74 from QuickSwap/feature/update-recipient-input
Update inputs and pool card
2 parents 895fbed + 42c9df9 commit 2593b72

File tree

7 files changed

+116
-53
lines changed

7 files changed

+116
-53
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import React from 'react';
2+
import { Box, Typography } from '@material-ui/core';
3+
import { makeStyles } from '@material-ui/core/styles';
4+
import useENS from 'hooks/useENS';
5+
import { useActiveWeb3React } from 'hooks';
6+
import { getEtherscanLink } from 'utils';
7+
8+
const useStyles = makeStyles(({ palette }) => ({
9+
addressInput: {
10+
border: (props: any) =>
11+
`1px solid ${props.error ? palette.error.main : palette.primary.dark}`,
12+
borderRadius: 20,
13+
padding: '12px 24px',
14+
textAlign: 'left',
15+
'& input': {
16+
width: '100%',
17+
fontSize: 20,
18+
fontWeight: 'bold',
19+
color: (props: any) =>
20+
props.error ? palette.error.main : palette.text.primary,
21+
background: 'transparent',
22+
border: 'none',
23+
boxShadow: 'none',
24+
outline: 'none',
25+
marginTop: 16,
26+
},
27+
'& a': {
28+
color: palette.text.primary,
29+
textDecoration: 'none',
30+
},
31+
},
32+
}));
33+
34+
interface AddressInputProps {
35+
value: string;
36+
onChange: (val: string) => void;
37+
placeholder: string;
38+
label: string;
39+
}
40+
41+
const AddressInput: React.FC<AddressInputProps> = ({
42+
value,
43+
onChange,
44+
placeholder,
45+
label,
46+
}) => {
47+
const { chainId } = useActiveWeb3React();
48+
const { address, loading, name } = useENS(value);
49+
const error = Boolean(value.length > 0 && !loading && !address);
50+
const classes = useStyles({ error });
51+
52+
return (
53+
<Box className={classes.addressInput}>
54+
<Box display='flex' justifyContent='space-between' alignItems='center'>
55+
<Typography>{label}</Typography>
56+
{address && chainId && (
57+
<a
58+
href={getEtherscanLink(chainId, name ?? address, 'address')}
59+
target='_blank'
60+
rel='noreferrer'
61+
>
62+
(View on Block Explorer)
63+
</a>
64+
)}
65+
</Box>
66+
<input
67+
value={value}
68+
placeholder={placeholder}
69+
onChange={(evt) => {
70+
const input = evt.target.value;
71+
const withoutSpaces = input.replace(/\s+/g, '');
72+
onChange(withoutSpaces);
73+
}}
74+
/>
75+
</Box>
76+
);
77+
};
78+
79+
export default AddressInput;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './AddressInput';

src/components/PoolPositionCard/PoolPositionCard.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import { useTheme } from '@material-ui/core/styles';
44
import { ChevronDown, ChevronUp } from 'react-feather';
55
import { Pair } from '@uniswap/sdk';
66
import { unwrappedToken } from 'utils/wrappedCurrency';
7-
import { useStakingInfo, getBulkPairData } from 'state/stake/hooks';
7+
import {
8+
useStakingInfo,
9+
getBulkPairData,
10+
useDualStakingInfo,
11+
} from 'state/stake/hooks';
812
import { DoubleCurrencyLogo } from 'components';
913
import { getAPYWithFee, getOneYearFee } from 'utils';
1014
import PoolPositionCardDetails from './PoolPositionCardDetails';
1115

12-
interface PoolPositionCardProps {
13-
pair: Pair;
14-
}
15-
16-
const PoolPositionCard: React.FC<PoolPositionCardProps> = ({ pair }) => {
16+
const PoolPositionCard: React.FC<{ pair: Pair }> = ({ pair }) => {
1717
const [bulkPairData, setBulkPairData] = useState<any>(null);
1818
const { palette, breakpoints } = useTheme();
1919
const isMobile = useMediaQuery(breakpoints.down('xs'));
@@ -22,15 +22,21 @@ const PoolPositionCard: React.FC<PoolPositionCardProps> = ({ pair }) => {
2222
const currency1 = unwrappedToken(pair.token1);
2323

2424
const stakingInfos = useStakingInfo(pair);
25+
const dualStakingInfos = useDualStakingInfo(pair);
2526
const stakingInfo = useMemo(
26-
() => (stakingInfos && stakingInfos.length > 0 ? stakingInfos[0] : null),
27-
[stakingInfos],
27+
() =>
28+
stakingInfos && stakingInfos.length > 0
29+
? stakingInfos[0]
30+
: dualStakingInfos && dualStakingInfos.length > 0
31+
? dualStakingInfos[0]
32+
: null,
33+
[stakingInfos, dualStakingInfos],
2834
);
2935

30-
const pairId = stakingInfo ? stakingInfo.pair : null;
36+
const pairId = pair.liquidityToken.address;
3137

3238
useEffect(() => {
33-
const pairLists = pairId ? [pairId] : [];
39+
const pairLists = [pairId];
3440
getBulkPairData(pairLists).then((data) => setBulkPairData(data));
3541
return () => setBulkPairData(null);
3642
}, [pairId]);
@@ -101,7 +107,7 @@ const PoolPositionCard: React.FC<PoolPositionCardProps> = ({ pair }) => {
101107
</Box>
102108
</Box>
103109

104-
{showMore && <PoolPositionCardDetails pair={pair} pairId={pairId} />}
110+
{showMore && <PoolPositionCardDetails pair={pair} />}
105111
{stakingInfo && apyWithFee && (
106112
<Box bgcolor='#404557' paddingY={0.75} paddingX={isMobile ? 2 : 3}>
107113
<Typography variant='body2'>

src/components/PoolPositionCard/PoolPositionCardDetails.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,7 @@ const useStyles = makeStyles(({ palette }) => ({
5252
},
5353
}));
5454

55-
interface PoolPositionCardProps {
56-
pair: Pair;
57-
pairId: string | null;
58-
}
59-
60-
const PoolPositionCardDetails: React.FC<PoolPositionCardProps> = ({
61-
pair,
62-
pairId,
63-
}) => {
55+
const PoolPositionCardDetails: React.FC<{ pair: Pair }> = ({ pair }) => {
6456
const classes = useStyles();
6557
const history = useHistory();
6658
const { breakpoints } = useTheme();
@@ -156,7 +148,9 @@ const PoolPositionCardDetails: React.FC<PoolPositionCardProps> = ({
156148
<Box className={classes.poolButtonRow}>
157149
<Button
158150
variant='outlined'
159-
onClick={() => history.push(`/analytics/pair/${pairId}`)}
151+
onClick={() =>
152+
history.push(`/analytics/pair/${pair.liquidityToken.address}`)
153+
}
160154
>
161155
<Typography variant='body2'>View Analytics</Typography>
162156
</Button>

src/components/SettingsModal/SettingsModal.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,16 @@ const SettingsModal: React.FC<SettingsModalProps> = ({ open, onClose }) => {
331331
border={`1px solid ${palette.secondary.light}`}
332332
maxWidth={168}
333333
>
334-
<input
335-
style={{ textAlign: 'left' }}
336-
className={classes.settingsInput}
334+
<NumericalInput
335+
placeholder={(ttl / 60).toString()}
336+
value={deadlineInput}
337+
fontSize={14}
338+
fontWeight={500}
339+
color='rgba(212, 229, 255, 0.8)'
337340
onBlur={() => {
338341
parseCustomDeadline((ttl / 60).toString());
339342
}}
340-
placeholder={(ttl / 60).toString()}
341-
value={deadlineInput}
342-
onChange={(e: any) => parseCustomDeadline(e.target.value)}
343+
onUserInput={(value) => parseCustomDeadline(value)}
343344
/>
344345
</Box>
345346
<Typography variant='body2' style={{ marginLeft: 8 }}>

src/components/Swap/Swap.tsx

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
AdvancedSwapDetails,
2323
QuestionHelper,
2424
SettingsModal,
25+
AddressInput,
2526
} from 'components';
2627
import { useActiveWeb3React } from 'hooks';
2728
import {
@@ -111,23 +112,6 @@ const useStyles = makeStyles(({ palette }) => ({
111112
background: 'transparent',
112113
},
113114
},
114-
'& .content': {
115-
border: `1px solid ${palette.primary.dark}`,
116-
borderRadius: 20,
117-
padding: '12px 24px',
118-
textAlign: 'left',
119-
'& input': {
120-
width: '100%',
121-
fontSize: 20,
122-
fontWeight: 'bold',
123-
color: 'white',
124-
background: 'transparent',
125-
border: 'none',
126-
boxShadow: 'none',
127-
outline: 'none',
128-
marginTop: 16,
129-
},
130-
},
131115
},
132116
slippageRow: {
133117
color: palette.text.secondary,
@@ -628,21 +612,18 @@ const Swap: React.FC<{
628612
<Box />
629613
)}
630614
<Button
631-
id='remove-recipient-button'
632615
onClick={() => onChangeRecipient(recipient !== null ? null : '')}
633616
>
634617
{recipient !== null ? '- Remove send' : '+ Add a send (optional)'}
635618
</Button>
636619
</Box>
637620
{recipient !== null && (
638-
<Box className='content'>
639-
<Typography>Recipient</Typography>
640-
<input
641-
value={recipient}
642-
placeholder='Wallet Address or ENS name'
643-
onChange={(evt) => onChangeRecipient(evt.target.value)}
644-
/>
645-
</Box>
621+
<AddressInput
622+
label='Recipient'
623+
placeholder='Wallet Address or ENS name'
624+
value={recipient}
625+
onChange={onChangeRecipient}
626+
/>
646627
)}
647628
</Box>
648629
)}

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export { default as Header } from './Header';
22
export { default as Footer } from './Footer';
33
export { default as ListLogo } from './ListLogo';
4+
export { default as AddressInput } from './AddressInput';
45
export { default as AreaChart } from './AreaChart';
56
export { default as BarChart } from './BarChart';
67
export { default as BetaWarningBanner } from './BetaWarningBanner';

0 commit comments

Comments
 (0)