-
Notifications
You must be signed in to change notification settings - Fork 2
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
autoswap frontend #481
Open
matepal00
wants to merge
94
commits into
dev
Choose a base branch
from
autoswap-frontend
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
autoswap frontend #481
Changes from 79 commits
Commits
Show all changes
94 commits
Select commit
Hold shift + click to select a range
cc2339b
Implement sagas
Sniezka1927 61f87c3
autoswap frontend
matepal00 102088a
different simulation
matepal00 588fac6
bump
matepal00 306b35e
options modal
matepal00 90a88bb
change simulate function
matepal00 3eabdb2
fix modal
matepal00 d88dd34
lookup table addresses and fixed
matepal00 320553a
Merge remote-tracking branch 'origin/autoswap-frontend' into create-a…
matepal00 491a426
selectors and sagas refirement
matepal00 e344575
Merge pull request #482 from invariant-labs/create-and-swap-position-…
matepal00 c55655c
simulation configuration
matepal00 6a9fbef
Align settings modal popover
Sniezka1927 f9d6020
Add check for settings button
Sniezka1927 60dfbe7
Price impact warning on autoswap
Sniezka1927 ff1184a
fix modal
matepal00 ee717d5
Merge pull request #489 from invariant-labs/align-autoswap-settings-m…
matepal00 057ce83
bump
matepal00 d9d1e31
connect sagas
matepal00 e6c08f8
Merge pull request #492 from invariant-labs/connect-sagas
matepal00 bb65847
Split deposit options
Sniezka1927 1cdc606
modal state and fixes
matepal00 a0c814d
bump
matepal00 642f32e
align with base
matepal00 6ecd200
Merge pull request #493 from invariant-labs/split-deposit-options
matepal00 9e3d18e
bump
matepal00 23f0ae7
check values
matepal00 4a1376c
modal adjustmet
matepal00 e486628
Merge branch 'autoswap-frontend' of github.com:invariant-labs/webapp-…
Sniezka1927 47119a1
Add error styles to price impact
Sniezka1927 83a5131
refactor code
matepal00 011d721
bump
matepal00 f523a54
bump
matepal00 c75c772
bump
matepal00 14dd337
align with dev
matepal00 ab433ca
Merge branch 'autoswap-frontend' into price-impact-warning-on-autoswap
matepal00 7360ae2
price impact refactor
matepal00 988098d
Merge pull request #491 from invariant-labs/price-impact-warning-on-a…
matepal00 0c583ee
transaction cache and fixes
matepal00 4c67c38
Merge pull request #498 from invariant-labs/price-impact-warning-on-a…
matepal00 5801d3f
bump package
matepal00 4135714
bump package
matepal00 4b17127
final adjustment
matepal00 fe2f046
price impact fix
matepal00 34f5771
bump sdk and code refactor
matepal00 525d4bc
bump
matepal00 a35ebc2
Show second token value on single checkbox selected
Sniezka1927 60430ca
Merge pull request #500 from invariant-labs/show-second-token-amount-…
matepal00 18e845a
fix swap and create position
matepal00 4133935
both inputs support, code refactor
matepal00 a1b4146
bump sdk and fixes / corrects
matepal00 fd214e9
Show amount of assets transferred from wallet in deposit inputs
Sniezka1927 286a688
error handling and decimal fix
matepal00 91a8685
error changes
matepal00 4645079
Use auto as default when possible
Sniezka1927 39c9c6f
error adjustment
matepal00 029e225
code refactor in autoswap and code fixes
matepal00 749b54d
Merge pull request #509 from invariant-labs/autoswap-refactor-fixes
matepal00 b51d9fd
style correct
matepal00 fec7483
added error
matepal00 82689d8
variable refactor
matepal00 f1ae894
saga refactor
matepal00 c907e9c
code refactor and optimization
matepal00 237a04a
change loading state
matepal00 caa8088
no price from pool check
matepal00 c241516
requested changes
matepal00 8803c6e
correct both inputs on
matepal00 b1b937c
style adjustment part 1
matepal00 3f3f2d9
bump
matepal00 72c8e96
deposit options header
matepal00 d0b749d
checkbox styles
matepal00 1e39ad5
input width animation
matepal00 98f4eed
bump
matepal00 abfa127
consolelog
matepal00 496898a
price impact change
matepal00 0d241a3
Merge branch 'dev' of github.com:invariant-labs/webapp-eclipse into a…
wojciech-cichocki 1c1e597
requested changes
matepal00 2a15ca7
update error handling with setting simulation to null when error
matepal00 19a3878
requested changes
matepal00 3389a93
req changes
matepal00 7cc7682
Merge remote-tracking branch 'origin/dev' into autoswap-frontend
matepal00 0644644
add pool
matepal00 e665258
bump
matepal00 7d706e9
bump2
matepal00 7b9e647
conole log
matepal00 f4d4b59
bump v3
matepal00 04a36b3
query ticks and tickmap optimalization
matepal00 4d0032f
bump
matepal00 38647cd
bump package
matepal00 1cfd6eb
min weth
matepal00 3303bda
Merge remote-tracking branch 'origin/dev' into autoswap-frontend
matepal00 ad01bb4
ticks query refactor
matepal00 56f7cb6
bump limit
matepal00 b4bd32e
console log
matepal00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
207 changes: 207 additions & 0 deletions
207
src/components/Modals/DepositOptionsModal/DepositOption.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,207 @@ | ||
import React, { useRef, useState } from 'react' | ||
import useStyles from './style' | ||
import { Box, Button, Divider, Grid, Input, Tooltip, Typography } from '@mui/material' | ||
import classNames from 'classnames' | ||
import icons from '@static/icons' | ||
|
||
interface Props { | ||
value: string | ||
valueIndex: number | ||
setValue: (value: string) => void | ||
saveValue: (value: string) => void | ||
options: { | ||
value: string | ||
label: string | ||
message: string | ||
}[] | ||
upperValueTreshHold: string | ||
lowerValueTreshHold: string | ||
label: string | ||
description: string | ||
divider?: boolean | ||
} | ||
|
||
const DepositOption: React.FC<Props> = ({ | ||
value, | ||
setValue, | ||
saveValue, | ||
valueIndex, | ||
description, | ||
label, | ||
options, | ||
upperValueTreshHold, | ||
lowerValueTreshHold, | ||
divider | ||
}) => { | ||
const { classes } = useStyles() | ||
const inputRef = useRef<HTMLInputElement>(null) | ||
const [temp, setTemp] = useState<string>(valueIndex === -1 ? value : '') | ||
const allowOnlyDigitsAndTrimUnnecessaryZeros: React.ChangeEventHandler< | ||
HTMLInputElement | HTMLTextAreaElement | ||
> = e => { | ||
const value = e.target.value | ||
|
||
const regex = /^\d*\.?\d*$/ | ||
if (value === '' || regex.test(value)) { | ||
const startValue = value | ||
const caretPosition = e.target.selectionStart | ||
|
||
let parsed = value | ||
const zerosRegex = /^0+\d+\.?\d*$/ | ||
if (zerosRegex.test(parsed)) { | ||
parsed = parsed.replace(/^0+/, '') | ||
} | ||
const dotRegex = /^\.\d*$/ | ||
if (dotRegex.test(parsed)) { | ||
parsed = `0${parsed}` | ||
} | ||
|
||
const diff = startValue.length - parsed.length | ||
|
||
setTemp(parsed) | ||
|
||
if (caretPosition !== null && parsed !== startValue) { | ||
setTimeout(() => { | ||
if (inputRef.current) { | ||
inputRef.current.selectionStart = Math.max(caretPosition - diff, 0) | ||
inputRef.current.selectionEnd = Math.max(caretPosition - diff, 0) | ||
} | ||
}, 0) | ||
} | ||
} else if (!regex.test(value)) { | ||
setTemp('0.00') | ||
} | ||
} | ||
|
||
const checkValue: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement> = e => { | ||
const value = e.target.value | ||
if (Number(value) > Number(upperValueTreshHold)) { | ||
setTemp(upperValueTreshHold) | ||
} else if (Number(value) < Number(lowerValueTreshHold) || isNaN(Number(value))) { | ||
setTemp(lowerValueTreshHold) | ||
} else { | ||
const onlyTwoDigits = '^\\d*\\.?\\d{0,2}$' | ||
const regex = new RegExp(onlyTwoDigits, 'g') | ||
if (regex.test(value)) { | ||
setTemp(value) | ||
} else { | ||
setTemp(Number(value).toFixed(2)) | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
{divider && <Divider className={classes.divider} />} | ||
<Typography className={classes.label}>{label}</Typography> | ||
<Grid container gap='9px'> | ||
{options.map((tier, index) => ( | ||
<Button | ||
className={classNames( | ||
classes.slippagePercentageButton, | ||
valueIndex === index && classes.slippagePercentageButtonActive | ||
)} | ||
key={tier.value} | ||
onClick={e => { | ||
e.preventDefault() | ||
setValue(Number(options[index].value).toFixed(2)) | ||
saveValue(Number(options[index].value).toFixed(2)) | ||
}}> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: 'center', | ||
height: '100%', | ||
gap: '2px' | ||
}}> | ||
<Box | ||
sx={{ | ||
fontWeight: 700, | ||
fontSize: 14, | ||
marginTop: '-8px' | ||
}}> | ||
{tier.value}% | ||
</Box> | ||
<Tooltip | ||
title={ | ||
<Box | ||
style={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
gap: '6px', | ||
flexDirection: 'row', | ||
justifyContent: 'center' | ||
}}> | ||
<Box width={'12px'}> | ||
<img src={icons.goldenInfoCircle} alt='' width={'12px'} height={'12px'} /> | ||
</Box> | ||
<span style={{ width: '141px' }}>{tier.message}</span> | ||
</Box> | ||
} | ||
classes={{ tooltip: classes.tooltip }}> | ||
<Typography | ||
style={{ | ||
fontWeight: 400, | ||
fontSize: 10, | ||
letterSpacing: '-0.03%', | ||
textTransform: 'none', | ||
marginLeft: '-4px' | ||
}}> | ||
{tier.label} | ||
{tier.message !== '' ? ( | ||
<img | ||
src={icons.infoCircle} | ||
alt='' | ||
width='8px' | ||
style={{ marginTop: '0px', marginLeft: '2px' }} | ||
className={classes.grayscaleIcon} | ||
/> | ||
) : null} | ||
</Typography> | ||
</Tooltip> | ||
</Box> | ||
</Button> | ||
))} | ||
</Grid> | ||
<Box marginTop='6px'> | ||
<Input | ||
disableUnderline | ||
placeholder='0.00' | ||
className={classNames( | ||
classes.detailsInfoForm, | ||
valueIndex === -1 && classes.customSlippageActive | ||
)} | ||
type={'text'} | ||
value={temp} | ||
onChange={e => { | ||
allowOnlyDigitsAndTrimUnnecessaryZeros(e) | ||
checkValue(e) | ||
}} | ||
ref={inputRef} | ||
startAdornment='Custom' | ||
endAdornment={ | ||
<> | ||
% | ||
<button | ||
className={classes.detailsInfoBtn} | ||
onClick={() => { | ||
setValue(Number(temp).toFixed(2)) | ||
saveValue(Number(temp).toFixed(2)) | ||
}}> | ||
Save | ||
</button> | ||
</> | ||
} | ||
classes={{ | ||
input: classes.innerInput, | ||
inputAdornedEnd: classes.inputAdornedEnd | ||
}} | ||
/> | ||
</Box> | ||
<Typography className={classes.info}>{description}</Typography> | ||
</> | ||
) | ||
} | ||
|
||
export default DepositOption |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should put styles like that in style files instead of directly inline