From 8ecc2deec5af4ef8e353ad3e51b937c91eaffc6c Mon Sep 17 00:00:00 2001
From: mintdart <96025197+mintdart@users.noreply.github.com>
Date: Thu, 27 Jul 2023 04:12:35 -0500
Subject: [PATCH] add input amounts in borrow page
---
src/pages/borrow.tsx | 161 +++++++++++++++++++++++++++++++++++--------
1 file changed, 134 insertions(+), 27 deletions(-)
diff --git a/src/pages/borrow.tsx b/src/pages/borrow.tsx
index c06797424..1d87c5f78 100644
--- a/src/pages/borrow.tsx
+++ b/src/pages/borrow.tsx
@@ -15,6 +15,7 @@ import TokenLogo from '~/components/TokenLogo'
import { ComboboxSelectPopover, SelectItem } from '~/components/Filters'
import { Tab, TabList } from '~/components'
import { chainIconUrl, formattedNum, tokenIconUrl } from '~/utils'
+import { useDebounce } from '~/hooks'
export const getStaticProps = withPerformanceLogging('borrow', async () => {
const {
@@ -79,30 +80,66 @@ export default function YieldBorrow(data) {
: router.query['collateral'][0]
: null
- const filteredPools = findOptimizerPools({
- pools: data.pools,
- tokenToLend: collateralToken,
- tokenToBorrow: borrowToken,
- cdpRoutes: data.cdpPools
- })
+ const filteredPools = React.useMemo(
+ () =>
+ findOptimizerPools({
+ pools: data.pools,
+ tokenToLend: collateralToken,
+ tokenToBorrow: borrowToken,
+ cdpRoutes: data.cdpPools
+ }),
+ [data, collateralToken, borrowToken]
+ )
+
+ const [borrowAmount, setBorrowAmount] = React.useState('')
+ const [collateralAmount, setCollateralAmount] = React.useState('')
+
+ const finalBorrowAmount = useDebounce(borrowAmount, 500)
+ const finalCollateralAmount = useDebounce(collateralAmount, 500)
return (
{disclaimer}
-
-
-
+
{borrowToken || collateralToken ? (
) : null}
- {(borrowToken || collateralToken) && }
+ {(borrowToken || collateralToken) && (
+
+ )}
)
@@ -185,7 +224,18 @@ const FormWrapper = styled(Content)`
margin-top: 2px;
}
- height: 252px;
+ height: 18rem;
+`
+
+const FormField = styled.div`
+ display: flex;
+ flex-direction: column;
+ gap: 4px;
+
+ h1 {
+ font-size: 1rem;
+ font-weight: 400;
+ }
`
const PoolsWrapper = styled(Content)`
@@ -197,25 +247,38 @@ const PoolsWrapper = styled(Content)`
}
`
+const InputWrapper = styled.span`
+ display: flex;
+ flex-direction: row;
+ gap: 8px;
+ background: ${({ theme }) => (theme.mode === 'dark' ? '#17181c' : '#eff0f3')};
+ color: ${({ theme }) => theme.text1};
+ padding: 8px;
+ border-radius: 12px;
+
+ :focus-within {
+ outline: ${({ theme }) => '1px solid ' + theme.text1};
+ }
+`
+
const Menu = styled(AriaSelect)`
display: flex;
align-items: center;
justify-content: space-between;
- gap: 8px;
- background: ${({ theme }) => (theme.mode === 'dark' ? '#17181c' : '#eff0f3')};
+ gap: 4px;
+ background: ${({ theme }) => (theme.mode === 'dark' ? 'rgba(0, 0, 0, 1)' : 'rgba(246, 246, 246, 1)')};
color: ${({ theme }) => theme.text1};
padding: 12px;
border-radius: 12px;
border: none;
margin: 0;
- width: 100%;
+ width: 180px;
font-weight: 500;
font-size: 1rem;
+ overflow: hidden;
- & > *:first-child {
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
+ & > *:last-child {
+ flex-shrink: 0;
}
:focus-visible,
@@ -228,10 +291,45 @@ const Menu = styled(AriaSelect)`
}
& > *[data-name] {
+ max-width: 90px;
+ overflow: hidden;
+ white-space: nowrap;
+ text-overflow: ellipsis;
margin-right: auto;
}
`
+const InputAmount = styled.input`
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 8px;
+ background: ${({ theme }) => (theme.mode === 'dark' ? '#17181c' : '#eff0f3')};
+ color: ${({ theme }) => theme.text1};
+ padding: 12px;
+ border-radius: 12px;
+ border: none;
+ margin: 0;
+ width: 100%;
+ font-weight: 500;
+ font-size: 1.25rem;
+
+ &::-webkit-outer-spin-button,
+ &::-webkit-inner-spin-button {
+ -webkit-appearance: none;
+ margin: 0;
+ }
+
+ &[type='number'] {
+ -moz-appearance: textfield;
+ }
+
+ :focus-visible,
+ &[data-focus-visible] {
+ outline: none;
+ }
+`
+
const Popover = styled(ComboboxSelectPopover)`
@media screen and (min-width: 640px) {
max-width: 448px;
@@ -290,7 +388,7 @@ const TokensSelect = ({
@@ -351,9 +450,17 @@ interface IPool {
ltv?: number | null
}
-const PoolsList = ({ pools }: { pools: Array }) => {
+const PoolsList = ({
+ pools,
+ borrowAmount,
+ collateralAmount
+}: {
+ pools: Array
+ borrowAmount: string
+ collateralAmount: string
+}) => {
const [tab, setTab] = React.useState('safe')
-
+ console.log({ borrowAmount })
const filteredPools = pools
.filter(
(pool) =>