-
Notifications
You must be signed in to change notification settings - Fork 555
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
Pre-populating the Deposit Max Amount #1875
Closed
Closed
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
7506fda
Prepolutaing the Deposit Max Amount
kirksgithub 5b4578f
Added minor error handling for input value being parsed
kirksgithub 115a516
adjusted setAmount using humanReadableMax string
kirksgithub d98afe6
Added one more check in case of undefined humanReadableMax
kirksgithub 8da4cd4
Reduced a few lines of code
kirksgithub f865635
Reduced a few more lines of code
kirksgithub b0f53ae
Added Max button in case the user clears out the input field
kirksgithub 4e5357f
Minor code cleanup
kirksgithub 8da110b
Added additional check in case humanReadableMax is 0
kirksgithub e767022
Additional Error Checking
kirksgithub 1c15f3c
Fixed if/else syntax
kirksgithub fac3f43
Minor fix
kirksgithub 1607801
Remove label prop to outside of Input
kirksgithub 1922acc
checking if humanReadable is set
kirksgithub 7e0d4d6
Added effect for async humanReadableMax & setting setAmount
kirksgithub 42f9c4f
Added error checking when custom amount is greater than Max available
kirksgithub 0f6e1f7
Added additional undefined check for humanReadableMax
kirksgithub 3f7aff2
Added disabled Confirm button
kirksgithub e0fbd43
Code cleanup
kirksgithub eb273d8
Added Confirm disabled in case criteria is not met for wallet holdings
kirksgithub 131eae6
Persistent Max button
kirksgithub 6412bdf
Improved disable button & small code cleanup
kirksgithub 6498f4d
Fixed conditional statement for confirm
kirksgithub 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 |
---|---|---|
|
@@ -5,7 +5,7 @@ import useUserGovTokenAccountQuery from '@hooks/useUserGovTokenAccount' | |
import { useDepositCallback } from './GovernancePower/Vanilla/useDepositCallback' | ||
import useWalletOnePointOh from '@hooks/useWalletOnePointOh' | ||
import Modal from './Modal' | ||
import { useState } from 'react' | ||
import { useState, useEffect } from 'react' | ||
import useGoverningTokenMint from '@hooks/selectedRealm/useGoverningTokenMint' | ||
import { useMintInfoByPubkeyQuery } from '@hooks/queries/mintInfo' | ||
import Input from './inputs/Input' | ||
|
@@ -30,12 +30,11 @@ export const DepositTokensButton = ({ | |
const depositTooltipContent = !connected | ||
? 'Connect your wallet to deposit' | ||
: !hasTokensInWallet | ||
? "You don't have any governance tokens in your wallet to deposit." | ||
: undefined | ||
? "You don't have any governance tokens in your wallet to deposit." | ||
: undefined | ||
|
||
const ButtonToUse = as === 'primary' ? Button : SecondaryButton | ||
const [openModal, setOpenModal] = useState(false) | ||
const [amount, setAmount] = useState('') | ||
const mint = useGoverningTokenMint(role) | ||
const mintInfo = useMintInfoByPubkeyQuery(mint).data?.result | ||
|
||
|
@@ -44,7 +43,15 @@ export const DepositTokensButton = ({ | |
? undefined | ||
: depositAmount.shiftedBy(-mintInfo.decimals).toNumber() | ||
|
||
const [amount, setAmount] = useState('') | ||
|
||
useEffect(() => { | ||
if (humanReadableMax && humanReadableMax > 0) | ||
setAmount(humanReadableMax ? humanReadableMax.toString() : '') | ||
}, [humanReadableMax]) | ||
|
||
const deposit = useDepositCallback(role) | ||
|
||
return ( | ||
<> | ||
<ButtonToUse | ||
|
@@ -59,12 +66,17 @@ export const DepositTokensButton = ({ | |
<Modal isOpen={openModal} onClose={() => setOpenModal(false)}> | ||
<div className="flex flex-col gap-y-4"> | ||
<h2>Deposit tokens</h2> | ||
<label> | ||
Amount to deposit | ||
<span> | ||
- <a href="#" onClick={() => { setAmount(humanReadableMax ? humanReadableMax.toString() : '') }}>Max</a> | ||
</span> | ||
</label> | ||
<Input | ||
placeholder={humanReadableMax?.toString() + ' (max)'} | ||
type="number" | ||
label="Amount to deposit" | ||
value={amount} | ||
onChange={(e) => setAmount(e.target.value)} | ||
onChange={(e) => { setAmount(e.target.value) }} | ||
max={humanReadableMax} | ||
/> | ||
<Button | ||
|
@@ -76,6 +88,7 @@ export const DepositTokensButton = ({ | |
await deposit(nativeAmount) | ||
setOpenModal(false) | ||
}} | ||
disabled={humanReadableMax !== undefined && (parseInt(amount) > humanReadableMax || parseInt(amount) > 0)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems wrong? if |
||
> | ||
Confirm | ||
</Button> | ||
|
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.
it seems like you're using a different code formatter, any idea what's going on? FWIW I prefer this way of formatting ternaries
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.
using codespace
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.
as in, using the codespace associated with the repo? interesting. how did you find that btw? I'm new to codespaces and just set it up for personal use.