Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend for Opening a New Position with 1-Click-LP #710

Open
wants to merge 60 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
55417f5
feat: TokenInput component
nikkaroraa Oct 31, 2022
4397329
feat: styling done, still very messy
nikkaroraa Nov 2, 2022
8b4cab2
refactor: separated into individual components
nikkaroraa Nov 3, 2022
968f105
feat: modal stepper ready, also ready for demo
nikkaroraa Nov 3, 2022
31cb944
fix: redirect to the "/new-lp" page
nikkaroraa Nov 5, 2022
39282fa
feat: change ETH input to oSQTH input
nikkaroraa Nov 5, 2022
19c2e94
feat: showing data now on the preview modal + refactor
nikkaroraa Nov 7, 2022
0167172
feat: calc ticks from custom price range
nikkaroraa Nov 9, 2022
b5e2be2
feat: send open-position transaction on confirm
nikkaroraa Nov 9, 2022
e50718e
fix: fix collatRatio and slippage values
nikkaroraa Nov 9, 2022
5e76eca
feat: add disabled state for preview button
nikkaroraa Nov 9, 2022
c8994ec
refactor: move most of the logic into hooks
nikkaroraa Nov 9, 2022
fffd953
feat: enforce toggle value
nikkaroraa Nov 10, 2022
9b5f480
feat: add loading state for TokenInput
nikkaroraa Nov 10, 2022
426ee91
feat: add loading state
nikkaroraa Nov 10, 2022
fa1e43b
refactor: use getDepositAmounts directly
nikkaroraa Nov 10, 2022
d963f56
feat: handle tx success and error states
nikkaroraa Nov 10, 2022
e81de40
refactor: making PR ready for review
nikkaroraa Nov 10, 2022
647fc20
feat: switch input to ETH -- UI part
nikkaroraa Nov 11, 2022
1abce78
refactor: refactor different Input types
nikkaroraa Nov 11, 2022
754f55a
feat: calculate ticks from ETH price range
nikkaroraa Nov 11, 2022
8489e58
feat: figure out the calcs part, finally!!!!
nikkaroraa Nov 15, 2022
ab85a4b
feat: improve formatters
nikkaroraa Nov 15, 2022
f105273
refactor: very minor refactor
nikkaroraa Nov 15, 2022
976f91c
fix: fix type not found
nikkaroraa Nov 16, 2022
24b8731
refactor: put action hooks together
nikkaroraa Nov 16, 2022
52b7074
fix: fix type not found
nikkaroraa Nov 16, 2022
834f84d
feat: remove "Projected APY" section for now
nikkaroraa Nov 16, 2022
dde109f
fix: handle the case of NaN values
nikkaroraa Nov 16, 2022
c5d1a05
feat: set min collatRatioPercent value
nikkaroraa Nov 17, 2022
4a605cb
refactor: use constants value
nikkaroraa Nov 17, 2022
26b3d1b
feat: calculate liquidation price
nikkaroraa Nov 18, 2022
e21eae6
refactor
nikkaroraa Nov 18, 2022
fce4f05
fix: fix openLPDeposit tick conversion and refactor
nikkaroraa Nov 18, 2022
80b0137
chore: use correct controller helper deployment address on goerli
nikkaroraa Nov 18, 2022
921efe4
fix: make maxCollatRatio dynamic as well
nikkaroraa Nov 18, 2022
d07649b
feat: make the input in the modal editable
nikkaroraa Nov 20, 2022
645fc5b
feat: debounce ethToDeposit for better performance
nikkaroraa Nov 20, 2022
ee47657
refactor: pull everything to one subdir up
nikkaroraa Nov 20, 2022
13efe06
style: change input width based on input length
nikkaroraa Nov 20, 2022
431a9de
refactor: general refactor for better reusability
nikkaroraa Nov 20, 2022
34d3148
feat: work on showing input errors
nikkaroraa Nov 21, 2022
dc79b30
refactor: no need to use TokenPrice component
nikkaroraa Nov 21, 2022
e7bca00
style: use mono font for numbers
nikkaroraa Nov 21, 2022
b897377
fix: remove lpPriceError on setting to default
nikkaroraa Nov 21, 2022
85b9c28
style: input width changing based on number of chars
nikkaroraa Nov 21, 2022
cfc1ecd
feat: add uniswap lp nft warning
nikkaroraa Nov 21, 2022
dda22c0
feat: show minCollat error
nikkaroraa Nov 21, 2022
96bfab3
typo: add fullstop to error messages
nikkaroraa Nov 21, 2022
3317f13
feat: collateral ratio slider optimizations
nikkaroraa Nov 21, 2022
dda0ea0
feat: change collat ratio value based on min value
nikkaroraa Nov 21, 2022
86f1bdc
feat: min collatRatio error
nikkaroraa Nov 21, 2022
df26fbe
PR reviews
nikkaroraa Nov 21, 2022
a276f68
typo
nikkaroraa Nov 21, 2022
5327386
feat: add footer
nikkaroraa Nov 21, 2022
b3971ca
very minor
nikkaroraa Nov 21, 2022
8d129be
style: hide modal scrollbar
nikkaroraa Nov 21, 2022
c165f2f
fix: handle the case of single asset LP position
nikkaroraa Nov 21, 2022
9f43c4f
style: minor style changes
nikkaroraa Nov 21, 2022
1dc55e8
fix: handle the case of invalid initial bracketing for liquidation price
nikkaroraa Nov 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"react-use": "^17.3.2",
"set-interval-async": "^2.0.3",
"subscriptions-transport-ws": "^0.11.0",
"use-debounce": "^8.0.4",
"web3": "^1.5.2"
},
"devDependencies": {
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export default class MyDocument extends Document {
href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@100;300;400;500;700&display=swap"
rel="stylesheet"
/>
{/* new font introduced with the new lp page */}
<link
href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&family=DM+Mono:wght@300;400;500&display=swap"
rel="stylesheet"
/>
</Head>
<body>
<Main />
Expand Down
132 changes: 132 additions & 0 deletions packages/frontend/pages/new-lp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import Nav from '@components/Nav'
import { createStyles, makeStyles, ThemeProvider } from '@material-ui/core/styles'
import { Grid, Typography } from '@material-ui/core'
import React, { useState, useCallback, useEffect } from 'react'
import { useAtomValue } from 'jotai'
import BigNumber from 'bignumber.js'

import { AltPrimaryButton } from '@components/Button'
import { PageHeader, PreviewModal, InputToken, Footer } from '@components/Lp'
import { useWalletBalance } from '@state/wallet/hooks'
import { connectedWalletAtom } from '@state/wallet/atoms'
import { useETHPrice } from '@hooks/useETHPrice'
import { BIG_ZERO } from '@constants/index'
import { toTokenAmount } from '@utils/calculations'
import ethLogo from 'public/images/eth-logo.svg'
import getTheme, { Mode } from '../src/theme'

const useStyles = makeStyles((theme) =>
createStyles({
container: {
padding: theme.spacing(9, 10),
maxWidth: '1500px',
width: '95%',
marginLeft: 'auto',
marginRight: 'auto',
},
title: {
fontSize: '24px',
fontWeight: 700,
letterSpacing: '-0.02em',
},
subtitle: {
fontSize: '18px',
fontWeight: 400,
color: theme.palette.grey[400],
},
margin: {
marginTop: theme.spacing(4),
},
}),
)

const LPPage: React.FC = () => {
const { data: walletBalance } = useWalletBalance()
const ethPrice = useETHPrice()
const connectedWallet = useAtomValue(connectedWalletAtom)

const [ethToDeposit, setETHToDeposit] = useState('0')
const [isPreviewModalOpen, setPreviewModalOpen] = useState(false)
const [inputError, setInputError] = useState('')

const ethBalance = toTokenAmount(walletBalance ?? BIG_ZERO, 18)
const classes = useStyles()
const isPreviewButtonDisabled = !connectedWallet || Number(ethToDeposit) === 0 || inputError !== ''

useEffect(() => {
if (ethBalance.lt(ethToDeposit)) {
setInputError('Insufficient balance')
} else {
setInputError('')
}
}, [ethToDeposit, ethBalance])

const handleBalanceClick = useCallback(
() => setETHToDeposit(ethBalance.toFixed(4, BigNumber.ROUND_DOWN)),
[ethBalance],
)

return (
<>
<Nav />
<PageHeader />

<Grid container spacing={10} justifyContent="center" className={classes.container}>
<Grid item xs={12} md={8}>
<Typography variant="h3" className={classes.title}>
Pool returns
</Typography>
<Typography variant="subtitle1" className={classes.subtitle}>
Total return combines fees and funding.
</Typography>
</Grid>

<Grid item xs md>
<Typography variant="h3" className={classes.title}>
Deposit ETH
</Typography>

<InputToken
id="eth-deposit-amount"
value={ethToDeposit}
onInputChange={setETHToDeposit}
error={!!inputError}
helperText={inputError}
symbol="ETH"
logo={ethLogo}
usdPrice={ethPrice}
balance={ethBalance}
onBalanceClick={handleBalanceClick}
/>

<AltPrimaryButton
className={classes.margin}
id="preview-deposit-btn"
onClick={() => setPreviewModalOpen(true)}
disabled={isPreviewButtonDisabled}
fullWidth
>
{connectedWallet ? 'Preview deposit' : 'Connect wallet to deposit'}
</AltPrimaryButton>
</Grid>
</Grid>

<Footer />

<PreviewModal
ethToDeposit={ethToDeposit}
setETHToDeposit={setETHToDeposit}
isOpen={isPreviewModalOpen}
onClose={() => setPreviewModalOpen(false)}
/>
</>
)
}

const ThemeWrapper: React.FC = () => (
<ThemeProvider theme={getTheme(Mode.NEW_DARK)}>
<LPPage />
</ThemeProvider>
)

export default ThemeWrapper
21 changes: 21 additions & 0 deletions packages/frontend/public/images/eth-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading