-
Notifications
You must be signed in to change notification settings - Fork 91
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: Buy Token #249
Open
KeneePatel
wants to merge
4
commits into
keep-starknet-strange:main
Choose a base branch
from
KeneePatel:frontend/buy_page
base: main
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
Frontend: Buy Token #249
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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,21 @@ | ||
import { forwardRef, useCallback } from 'react' | ||
|
||
import { FormattableInput, FormattableInputProps } from '.' | ||
|
||
type FloatInputProps = Omit<FormattableInputProps, 'formatInput'> | ||
|
||
const FloatInput = forwardRef<HTMLInputElement, FloatInputProps>(({ ...props }, ref) => { | ||
const formatNumber = useCallback((value: string) => { | ||
if (!value.length) return '' | ||
|
||
if (!/^([0-9]+([.][0-9]{0,6})?|[0-9]+)$/.test(value)) return | ||
|
||
return value | ||
}, []) | ||
|
||
return <FormattableInput {...props} formatInput={formatNumber} ref={ref} /> | ||
}) | ||
|
||
FloatInput.displayName = 'FloatInput' | ||
|
||
export default FloatInput |
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,78 @@ | ||
import { useQuoteToken } from 'hooks' | ||
import { BaseSyntheticEvent, useState } from 'react' | ||
import { useParams } from 'react-router-dom' | ||
import { PrimaryButton, SecondaryButton } from 'src/components/Button' | ||
import FloatInput from 'src/components/Input/FloatInput' | ||
import PercentInput from 'src/components/Input/PercentInput' | ||
import useMemecoin from 'src/hooks/useMemecoin' | ||
import Box from 'src/theme/components/Box' | ||
import { Column, Row } from 'src/theme/components/Flex' | ||
import * as Text from 'src/theme/components/Text' | ||
|
||
import * as styles from './style.css' | ||
|
||
const DEFAULT_SLIPPAGE = 0.5 | ||
const DEFAULT_AMOUNT = 0 | ||
|
||
export default function TokenBuyer() { | ||
const [slippage, setSlippage] = useState(DEFAULT_SLIPPAGE) | ||
const [amount, setAmount] = useState(DEFAULT_AMOUNT) | ||
|
||
// memecoin | ||
const { address: tokenAddress } = useParams() | ||
const { data: memecoin } = useMemecoin(tokenAddress) | ||
|
||
// quote token | ||
const quoteToken = useQuoteToken(memecoin?.isLaunched ? memecoin?.liquidity?.quoteToken : undefined) | ||
|
||
// function to handle change of input in Amount | ||
function handleAmount(event: BaseSyntheticEvent) { | ||
if (event.target.value == '') { | ||
setAmount(0) | ||
return | ||
} | ||
setAmount(parseFloat(event.target.value)) | ||
} | ||
|
||
// function to handle change of input in Amount | ||
function handleSlippage(event: BaseSyntheticEvent) { | ||
if (event.target.value == '') { | ||
setAmount(0) | ||
return | ||
} | ||
setSlippage(parseFloat(event.target.value)) | ||
} | ||
|
||
return ( | ||
<Column marginTop="10" gap="16"> | ||
<Row> | ||
<Text.HeadlineMedium marginBottom="12">Buy Token</Text.HeadlineMedium> | ||
</Row> | ||
<Row justifyContent="space-between" gap="16"> | ||
<Box marginRight="24" className={styles.container2}> | ||
<Text.HeadlineSmall paddingRight="1">{quoteToken?.name}</Text.HeadlineSmall> | ||
</Box> | ||
<Row width="full" justifyContent="flex-end"> | ||
<Box marginRight="24" className={styles.container2}> | ||
<Text.HeadlineSmall>Amount: </Text.HeadlineSmall> | ||
</Box> | ||
<FloatInput value={amount} onChange={handleAmount} width="full" maxWidth="180" minWidth="42" /> | ||
</Row> | ||
</Row> | ||
<Row justifyContent="space-between" gap="16"> | ||
<Box marginRight="24" className={styles.container2}> | ||
<Text.HeadlineSmall paddingRight="1">Slippage</Text.HeadlineSmall> | ||
</Box> | ||
<Row gap="8" width="auto"> | ||
<SecondaryButton onClick={() => setSlippage(0.1)}>0.1%</SecondaryButton> | ||
<SecondaryButton onClick={() => setSlippage(0.5)}>0.5%</SecondaryButton> | ||
<SecondaryButton onClick={() => setSlippage(1)} marginRight="18"> | ||
1% | ||
</SecondaryButton> | ||
<PercentInput value={slippage} onChange={handleSlippage} width="full" maxWidth="180" minWidth="42" /> | ||
</Row> | ||
</Row> | ||
<PrimaryButton onClick={() => console.log('TODO: implement the buying functionality here')}>Buy</PrimaryButton> | ||
</Column> | ||
) | ||
} |
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
Oops, something went wrong.
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.
These can be moved to the
constants