Skip to content

Commit

Permalink
feat: improve send to recipient form, add route priority select
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Jan 27, 2022
1 parent d674546 commit 52d91ca
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 56 deletions.
2 changes: 1 addition & 1 deletion libs/react-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"semver": "^7.3.5",
"source-map-loader": "^3.0.0",
"style-loader": "^3.3.1",
"tailwindcss": "^3.0.2",
"tailwindcss": "^3.0.17",
"terser-webpack-plugin": "^5.2.5",
"webpack": "^5.64.4",
"webpack-dev-server": "^4.6.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@emotion/styled": "^11.6.0",
"@mui/icons-material": "^5.3.1",
"@mui/material": "^5.3.0",
"i18next": "^21.6.9",
"i18next": "^21.6.10",
"react": "^18.0.0-rc.0",
"react-dom": "^18.0.0-rc.0",
"react-hook-form": "^7.25.1",
Expand Down
24 changes: 24 additions & 0 deletions packages/widget/src/components/Input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { InputBase } from '@mui/material';
import { inputBaseClasses } from '@mui/material/InputBase';
import { alpha, styled } from '@mui/material/styles';

export const Input = styled(InputBase)(({ theme }) => ({
backgroundColor: theme.palette.mode === 'light' ? theme.palette.common.white : theme.palette.grey[900],
borderRadius: 8,
borderWidth: 2,
borderStyle: 'solid',
borderColor: theme.palette.grey[300],
paddingRight: '14px',
transition: theme.transitions.create([
'border-color',
'background-color',
'box-shadow',
]),
[`& .${inputBaseClasses.input}`]: {
padding: '8.5px 0 8.5px 14px',
},
[`&.${inputBaseClasses.focused}`]: {
boxShadow: `${alpha(theme.palette.primary.main, 0.25)} 0 0 0 0.2rem`,
borderColor: theme.palette.primary.main,
},
}));
27 changes: 27 additions & 0 deletions packages/widget/src/components/Select.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Select as MuiSelect } from '@mui/material';
import { inputBaseClasses } from '@mui/material/InputBase';
import { outlinedInputClasses } from '@mui/material/OutlinedInput';
import { alpha, styled } from '@mui/material/styles';

export const Select = styled(MuiSelect)(({ theme }) => ({
backgroundColor: theme.palette.mode === 'light' ? theme.palette.common.white : theme.palette.grey[900],
borderRadius: 8,
borderWidth: 2,
borderStyle: 'solid',
borderColor: theme.palette.grey[300],
transition: theme.transitions.create([
'border-color',
'background-color',
'box-shadow',
]),
[`& .${inputBaseClasses.input}`]: {
padding: '8.5px 14px',
},
[`& .${outlinedInputClasses.notchedOutline}`]: {
display: 'none',
},
[`&.${inputBaseClasses.focused}`]: {
boxShadow: `${alpha(theme.palette.primary.main, 0.25)} 0 0 0 0.2rem`,
borderColor: theme.palette.primary.main,
},
}));
37 changes: 37 additions & 0 deletions packages/widget/src/components/SendToRecipientForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Box, Checkbox, FormControl, FormControlLabel } from '@mui/material';
import { useFormContext, useWatch } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { Input } from './Input';

export const SendToRecipientForm: React.FC = () => {
const { t } = useTranslation();
const { register, formState: { isSubmitting } } = useFormContext();
const sendToRecipientChecked = useWatch({
name: 'isSendToRecipient',
defaultValue: false,
});

if (!sendToRecipientChecked) {
return null;
}

return (
<Box>
<FormControl variant="standard" fullWidth disabled={isSubmitting}>
<Input
size="small"
placeholder={t(`swap.form.recipientsAddress`, { chain: 'ETH' })}
inputProps={{ ...register('recipientsAddress') }}
required
/>
</FormControl>
<Box my={1}>
<FormControlLabel
control={<Checkbox required {...register('isAddressConfirmed')} />}
label={t(`swap.form.correctnessConfirmation`) as string}
disabled={isSubmitting}
/>
</Box>
</Box>
);
};
53 changes: 40 additions & 13 deletions packages/widget/src/components/SwapForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { HelpOutline as HelpOutlineIcon, KeyboardArrowDown as KeyboardArrowDownIcon, SwapVert as SwapVertIcon } from '@mui/icons-material';
import { Box, FormControl, Typography } from '@mui/material';
import { Box, FormControl, MenuItem, Typography } from '@mui/material';
import { useFormContext } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { Select } from './Select';
import { SendToRecipientForm } from './SendToRecipientForm';
import { SwapChainButton } from './SwapChainButton';
import { SwapInput } from './SwapInput';
import { SwapFromInputAdornment, SwapToInputAdornment } from './SwapInputAdornment';
Expand All @@ -17,15 +19,21 @@ export const SwapForm: React.FC = () => {
{t(`swap.form.from`)}
</Typography>
<Box my={1}>
<SwapChainButton fullWidth disableElevation disableRipple variant="outlined" endIcon={<KeyboardArrowDownIcon />}>
<SwapChainButton
variant="outlined"
endIcon={<KeyboardArrowDownIcon />}
disabled={isSubmitting}
disableElevation
disableRipple
fullWidth
>
MATIC on ETH
</SwapChainButton>
<FormControl variant="standard" fullWidth>
<FormControl variant="standard" fullWidth disabled={isSubmitting}>
<SwapInput
type="number"
size="small"
defaultValue={0}
disabled={isSubmitting}
autoComplete="off"
endAdornment={(<SwapFromInputAdornment maxAmount={98700.30} price={1300.00} />)}
aria-describedby=""
Expand All @@ -48,15 +56,21 @@ export const SwapForm: React.FC = () => {
<SwapVertIcon sx={{ alignSelf: 'center', padding: '0 16px' }} />
</Box>
<Box my={1}>
<SwapChainButton fullWidth disableElevation disableRipple variant="outlined" endIcon={<KeyboardArrowDownIcon />}>
<SwapChainButton
variant="outlined"
endIcon={<KeyboardArrowDownIcon />}
disabled={isSubmitting}
disableElevation
disableRipple
fullWidth
>
MATIC on ETH
</SwapChainButton>
<FormControl variant="standard" fullWidth>
<FormControl variant="standard" fullWidth disabled={isSubmitting}>
<SwapInput
type="number"
size="small"
defaultValue={0}
disabled={isSubmitting}
autoComplete="off"
endAdornment={(<SwapToInputAdornment price={1300.00} />)}
aria-describedby=""
Expand All @@ -72,22 +86,35 @@ export const SwapForm: React.FC = () => {
{/* <FormHelperText id="swap-to-helper-text">Text</FormHelperText> */}
</FormControl>
</Box>
<Box my={3} sx={{ display: 'flex', justifyContent: 'space-between' }}>
<Box sx={{ display: 'flex' }}>
<Box mt={3} mb={2} sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<HelpOutlineIcon sx={{ color: 'grey.500' }} />
<Typography ml={2} variant="subtitle1" color="text.primary" sx={{ alignSelf: 'end' }}>
{t(`swap.form.sendToRecipient`)}
</Typography>
</Box>
<Switch />
<Switch {...register('isSendToRecipient')} />
</Box>
<Box my={3} sx={{ display: 'flex', justifyContent: 'space-between' }}>
<Box sx={{ display: 'flex' }}>
<SendToRecipientForm />
<Box my={2} sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<HelpOutlineIcon sx={{ color: 'grey.500' }} />
<Typography ml={2} variant="subtitle1" color="text.primary" sx={{ alignSelf: 'end' }}>
{t(`swap.form.routePriority`)}
{t(`swap.form.routePriority.title`)}
</Typography>
</Box>
<FormControl sx={{ width: '50%' }}>
<Select
defaultValue={1}
inputProps={{
'aria-label': '',
...register('routePriority'),
}}
MenuProps={{ elevation: 2 }}
>
<MenuItem value={1}>{t(`swap.form.routePriority.recommended`)}</MenuItem>
</Select>
</FormControl>
</Box>
</Box>
);
Expand Down
25 changes: 4 additions & 21 deletions packages/widget/src/components/SwapInput.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
import { InputBase } from '@mui/material';
import { inputBaseClasses } from '@mui/material/InputBase';
import { alpha, styled } from '@mui/material/styles';
import { styled } from '@mui/material/styles';
import { Input } from './Input';

export const SwapInput = styled(InputBase)(({ theme }) => ({
export const SwapInput = styled(Input)({
borderRadius: '0 0 8px 8px',
backgroundColor: theme.palette.mode === 'light' ? theme.palette.common.white : theme.palette.grey[900],
borderWidth: '1px 2px 2px 2px',
borderStyle: 'solid',
borderColor: theme.palette.grey[300],
paddingRight: '14px',
transition: theme.transitions.create([
'border-color',
'background-color',
'box-shadow',
]),
[`& .${inputBaseClasses.input}`]: {
padding: '8.5px 0 8.5px 14px',
},
[`&.${inputBaseClasses.focused}`]: {
boxShadow: `${alpha(theme.palette.primary.main, 0.25)} 0 0 0 0.2rem`,
borderColor: theme.palette.primary.main,
},
'& input[type="number"]::-webkit-outer-spin-button, & input[type="number"]::-webkit-inner-spin-button': {
WebkitAppearance: 'none',
margin: 0,
},
'& input[type="number"]': {
MozAppearance: 'textfield',
},
}));
});
7 changes: 6 additions & 1 deletion packages/widget/src/i18n/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
"maxAmount": "({{value, number(minimumFractionDigits: 2)}})",
"price": "\u2248 {{value, currency(currency: USD)}}",
"sendToRecipient": "Send to recipient",
"routePriority": "Route priority"
"routePriority": {
"title": "Route priority",
"recommended": "Recommended"
},
"recipientsAddress": "Recipient's {{chain}} address",
"correctnessConfirmation": "I confirm the address above is correct"
},
"button": "Swap"
}
Expand Down
18 changes: 9 additions & 9 deletions packages/widget/src/pages/SwapPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ export function SwapPage() {
<MainContainer maxWidth="sm" disableGutters>
<WalletHeader />
<MainHeader />
<FormContainer maxWidth="sm">
<SwapFormProvider>
<SwapFormProvider>
<FormContainer maxWidth="sm">
<SwapForm />
</SwapFormProvider>
</FormContainer>
<Box>
<SwapButton variant="contained" disableElevation fullWidth>
{t(`swap.button`)}
</SwapButton>
</Box>
</FormContainer>
<Box>
<SwapButton variant="contained" disableElevation fullWidth>
{t(`swap.button`)}
</SwapButton>
</Box>
</SwapFormProvider>
</MainContainer>
);
}
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4010,7 +4010,7 @@ check-types@^11.1.1:
resolved "https://registry.yarnpkg.com/check-types/-/check-types-11.1.2.tgz#86a7c12bf5539f6324eb0e70ca8896c0e38f3e2f"
integrity sha512-tzWzvgePgLORb9/3a0YenggReLKAIb2owL03H2Xdoe5pKcUyWRSEQ8xfCar8t2SIAuEDwtmx2da1YB52YuHQMQ==

chokidar@^3.4.2, chokidar@^3.5.2:
chokidar@^3.4.2, chokidar@^3.5.2, chokidar@^3.5.3:
version "3.5.3"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd"
integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==
Expand Down Expand Up @@ -6327,10 +6327,10 @@ humanize-ms@^1.2.1:
dependencies:
ms "^2.0.0"

i18next@^21.6.9:
version "21.6.9"
resolved "https://registry.yarnpkg.com/i18next/-/i18next-21.6.9.tgz#854bbcf8a3f47e4af9a5a92e0df6a546f4370841"
integrity sha512-oS82WMEwBFLGzq18RGwm7XRkRUMngXr92LqOjC1Z1txfueotPBPcN2bU2GWC3010fgjdhsQMFqrEqEf8a+R/oQ==
i18next@^21.6.10:
version "21.6.10"
resolved "https://registry.yarnpkg.com/i18next/-/i18next-21.6.10.tgz#aa503831d42213ae2f05eaede29ca07c2d6fbb6f"
integrity sha512-Xw+tEGQ61BF6SXtBlFffhM/YhJKHZf2cyDrcNK/l2dE6yVbkPkSasC3VhkAsHXX30vUJ0yG04WIUtf7UvwjOxg==
dependencies:
"@babel/runtime" "^7.12.0"

Expand Down Expand Up @@ -10743,14 +10743,14 @@ symbol-tree@^3.2.4:
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2"
integrity sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==

tailwindcss@^3.0.2:
version "3.0.16"
resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-3.0.16.tgz#eb6e7a0ecec56e43b9dad439b8cb3a5da1e0c1a3"
integrity sha512-1L8E5Wr+o1c4kxxObNz2owJe94a7BLEMV+2Lz6wzprJdcs3ENSRR9t4OZf2OqtRNS/q/zFPuOKoLtQoy3Lrhhw==
tailwindcss@^3.0.17:
version "3.0.17"
resolved "https://registry.yarnpkg.com/tailwindcss/-/tailwindcss-3.0.17.tgz#2c5fe6c364d76ec54644347c6f09befe0113b06f"
integrity sha512-OiHUsmOKQQEg/ocXaLIjk/kOz8EK2jF6iPuc1bQ4NsmhYl7sk70UDsGV02AJvBAAiJhinPCkDR8egT9qY+ulCw==
dependencies:
arg "^5.0.1"
chalk "^4.1.2"
chokidar "^3.5.2"
chokidar "^3.5.3"
color-name "^1.1.4"
cosmiconfig "^7.0.1"
detective "^5.2.0"
Expand Down

0 comments on commit 52d91ca

Please sign in to comment.