-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
142 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
packages/widget/src/components/SwapInput/FormPriceHelperText.style.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { FormHelperText as MuiFormHelperText } from '@mui/material'; | ||
import { styled } from '@mui/material/styles'; | ||
|
||
export const FormHelperText = styled(MuiFormHelperText)(({ theme }) => ({ | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
margin: 0, | ||
})); |
59 changes: 59 additions & 0 deletions
59
packages/widget/src/components/SwapInput/FormPriceHelperText.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Skeleton } from '@mui/material'; | ||
import { useWatch } from 'react-hook-form'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useTokenBalance } from '../../hooks'; | ||
import { | ||
SwapFormKeyHelper, | ||
SwapFormTypeProps, | ||
} from '../../providers/SwapFormProvider'; | ||
import { formatTokenPrice } from '../../utils/format'; | ||
import { PriceTypography } from '../PriceTypography'; | ||
import { FormHelperText } from './FormPriceHelperText.style'; | ||
|
||
export const FormPriceHelperText: React.FC< | ||
SwapFormTypeProps & { selected: boolean } | ||
> = ({ formType, selected }) => { | ||
const { t } = useTranslation(); | ||
const [amount, chainId, tokenAddress] = useWatch({ | ||
name: [ | ||
SwapFormKeyHelper.getAmountKey(formType), | ||
SwapFormKeyHelper.getChainKey(formType), | ||
SwapFormKeyHelper.getTokenKey(formType), | ||
], | ||
}); | ||
const { token, isLoading, isFetching } = useTokenBalance( | ||
chainId, | ||
tokenAddress, | ||
); | ||
|
||
const fromAmountTokenPrice = formatTokenPrice(amount, token?.priceUSD); | ||
const maxAmountTokenPrice = formatTokenPrice(token?.amount, token?.priceUSD); | ||
|
||
return ( | ||
<FormHelperText> | ||
<PriceTypography | ||
color={fromAmountTokenPrice ? 'text.secondary' : 'grey.600'} | ||
marginLeft={selected ? 8 : 2} | ||
lineHeight={1.3334} | ||
> | ||
{t(`swap.currency`, { | ||
value: fromAmountTokenPrice, | ||
})} | ||
</PriceTypography> | ||
{isLoading && isFetching ? ( | ||
<Skeleton | ||
variant="text" | ||
width={48} | ||
height={16} | ||
sx={{ borderRadius: 0.5 }} | ||
/> | ||
) : maxAmountTokenPrice ? ( | ||
<PriceTypography color="text.secondary" lineHeight={1.3334}> | ||
{t(`swap.currency`, { | ||
value: maxAmountTokenPrice, | ||
})} | ||
</PriceTypography> | ||
) : null} | ||
</FormHelperText> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/widget/src/components/SwapInput/SwapInputAdornment.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { InputAdornment, Skeleton } from '@mui/material'; | ||
import { useFormContext, useWatch } from 'react-hook-form'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useTokenBalance } from '../../hooks'; | ||
import { | ||
SwapFormKeyHelper, | ||
SwapFormTypeProps, | ||
} from '../../providers/SwapFormProvider'; | ||
import { SwapMaxAmountTypography } from './SwapInputAdornment.style'; | ||
|
||
export const SwapInputAdornment: React.FC<SwapFormTypeProps> = ({ | ||
formType, | ||
}) => { | ||
const { t } = useTranslation(); | ||
const { setValue } = useFormContext(); | ||
const [chainId, tokenAddress] = useWatch({ | ||
name: [ | ||
SwapFormKeyHelper.getChainKey(formType), | ||
SwapFormKeyHelper.getTokenKey(formType), | ||
], | ||
}); | ||
const { token, isLoading, isFetching } = useTokenBalance( | ||
chainId, | ||
tokenAddress, | ||
); | ||
|
||
const handleMax = () => { | ||
setValue(SwapFormKeyHelper.getAmountKey(formType), token?.amount ?? ''); | ||
}; | ||
|
||
return ( | ||
<InputAdornment position="end"> | ||
{isLoading && isFetching ? ( | ||
<Skeleton | ||
variant="rectangular" | ||
width={96} | ||
height={24} | ||
sx={{ borderRadius: 1 }} | ||
/> | ||
) : formType === 'from' && token?.amount ? ( | ||
<SwapMaxAmountTypography | ||
onClick={handleMax} | ||
role="button" | ||
sx={{ | ||
userSelect: 'none', | ||
}} | ||
data-amount={token?.amount} | ||
> | ||
{t(`swap.maxAmount`, { | ||
amount: token?.amount, | ||
})} | ||
</SwapMaxAmountTypography> | ||
) : null} | ||
</InputAdornment> | ||
); | ||
}; |
79 changes: 0 additions & 79 deletions
79
packages/widget/src/components/SwapInputAdornment/SwapInputAdornment.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters