-
Notifications
You must be signed in to change notification settings - Fork 26
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
feat: withdraw custom amount from savings #597
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 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
Next
Next commit
feat: withdraw custom amount from savings
- Loading branch information
commit 629bb61f74973827935b5cc0431c57b373eff465
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ export default function WithdrawOnchainFunds() { | |
const [onchainAddress, setOnchainAddress] = React.useState(""); | ||
const [confirmOnchainAddress, setConfirmOnchainAddress] = React.useState(""); | ||
const [checkedConfirmation, setCheckedConfirmation] = React.useState(false); | ||
const [amount, setAmount] = React.useState(""); | ||
const [sendAll, setSendAll] = React.useState(false); | ||
const [transactionId, setTransactionId] = React.useState(""); | ||
|
||
const copy = (text: string) => { | ||
|
@@ -67,7 +69,11 @@ export default function WithdrawOnchainFunds() { | |
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ toAddress: onchainAddress }), | ||
body: JSON.stringify({ | ||
toAddress: onchainAddress, | ||
amount: +amount, | ||
sendAll, | ||
}), | ||
} | ||
); | ||
console.info("Redeemed onchain funds", response); | ||
|
@@ -85,7 +91,14 @@ export default function WithdrawOnchainFunds() { | |
} | ||
setLoading(false); | ||
}, | ||
[checkedConfirmation, confirmOnchainAddress, onchainAddress, toast] | ||
[ | ||
amount, | ||
checkedConfirmation, | ||
confirmOnchainAddress, | ||
onchainAddress, | ||
sendAll, | ||
toast, | ||
] | ||
); | ||
|
||
if (transactionId) { | ||
|
@@ -139,18 +152,19 @@ export default function WithdrawOnchainFunds() { | |
/> | ||
|
||
<div className="max-w-lg"> | ||
{!!balances?.onchain.reserved && ( | ||
<Alert className="mb-4"> | ||
<AlertTriangleIcon className="h-4 w-4" /> | ||
<AlertTitle>Channel Anchor Reserves will be depleted</AlertTitle> | ||
<AlertDescription> | ||
You have channels open and this withdrawal will use some or all of | ||
your anchor reserves to publish the transaction, which may make it | ||
harder to close channels without depositing additional onchain | ||
funds to your savings balance. | ||
</AlertDescription> | ||
</Alert> | ||
)} | ||
{!!balances?.onchain.reserved && | ||
(sendAll || +amount > balances.onchain.total * 0.9) && ( | ||
<Alert className="mb-4"> | ||
<AlertTriangleIcon className="h-4 w-4" /> | ||
<AlertTitle>Channel Anchor Reserves may be depleted</AlertTitle> | ||
<AlertDescription> | ||
You have channels open and this withdrawal may deplete your | ||
anchor reserves, which may make it harder to close channels | ||
without depositing additional onchain funds to your savings | ||
balance. | ||
</AlertDescription> | ||
</Alert> | ||
)} | ||
<p> | ||
Your savings balance will be withdrawn to the onchain bitcoin wallet | ||
address you specify below. Please make sure you are the owner of this | ||
|
@@ -159,6 +173,34 @@ export default function WithdrawOnchainFunds() { | |
and have the seed phrase for. | ||
</p> | ||
<form onSubmit={redeemFunds} className="grid gap-5 mt-4"> | ||
<div className=""> | ||
<Label htmlFor="amount">Amount</Label> | ||
<div className="flex justify-between items-center mb-1"> | ||
<p className="text-sm text-muted-foreground"> | ||
Current onchain balance:{" "} | ||
{new Intl.NumberFormat().format(balances.onchain.total)} sats | ||
</p> | ||
<div className="flex items-center gap-1"> | ||
<Checkbox | ||
id="send-all" | ||
onCheckedChange={() => setSendAll(!sendAll)} | ||
/> | ||
<Label htmlFor="send-all" className="text-xs"> | ||
Send All | ||
</Label> | ||
</div> | ||
</div> | ||
<Input | ||
id="amount" | ||
type="number" | ||
value={sendAll ? balances.onchain.total : amount} | ||
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. are we sure "send all" will be that amount? 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. No, good catch! |
||
disabled={sendAll} | ||
required | ||
onChange={(e) => { | ||
setAmount(e.target.value); | ||
}} | ||
/> | ||
</div> | ||
<div className=""> | ||
<Label htmlFor="onchain-address">Onchain Address</Label> | ||
<Input | ||
|
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
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
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
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.
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.
use spendable instead of total