-
Notifications
You must be signed in to change notification settings - Fork 127
feat: add FeeRateField component to set fee rates for swaps #2432
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
Open
im-adithya
wants to merge
10
commits into
master
Choose a base branch
from
fix/onchain-fee-rate-field
base: master
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
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
76767c9
feat: add FeeRateField component to set fee rates for swaps
im-adithya 7879e12
chore: extract toggle into FeeRateField component
im-adithya e678952
chore: remove redundant info message
im-adithya cc4577a
chore: use on-chain wording everywhere
im-adithya 0d1e794
chore: only pass fee rate if it exists
im-adithya d97a5bf
chore: shift onchain payment to backend
im-adithya e6354d1
chore: remove unnecessary backendType check
im-adithya 1f888e0
chore: minor changes
im-adithya 2d8f09e
chore: split InitiateSwapRequest struct
im-adithya 031a16a
chore: show + onchain fees for internal swap ins too
im-adithya 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,131 @@ | ||
| import { AlertTriangleIcon, ExternalLinkIcon, PencilIcon } from "lucide-react"; | ||
| import { useEffect, useRef, useState } from "react"; | ||
| import ExternalLink from "src/components/ExternalLink"; | ||
| import Loading from "src/components/Loading"; | ||
| import { Button } from "src/components/ui/button"; | ||
| import { Input } from "src/components/ui/input"; | ||
| import { Label } from "src/components/ui/label"; | ||
| import { useInfo } from "src/hooks/useInfo"; | ||
| import { useMempoolApi } from "src/hooks/useMempoolApi"; | ||
|
|
||
| type RecommendedFees = { | ||
| fastestFee: number; | ||
| halfHourFee: number; | ||
| economyFee: number; | ||
| minimumFee: number; | ||
| }; | ||
|
|
||
| type FeeRateFieldProps = { | ||
| feeRate: string; | ||
| onFeeRateChange: (value: string) => void; | ||
| }; | ||
|
|
||
| export function FeeRateField({ feeRate, onFeeRateChange }: FeeRateFieldProps) { | ||
| const { data: info } = useInfo(); | ||
| const { data: recommendedFees, error: mempoolError } = | ||
| useMempoolApi<RecommendedFees>("/v1/fees/recommended"); | ||
| const [isEditing, setIsEditing] = useState(false); | ||
| const hasInitializedDefaultFee = useRef(false); | ||
|
|
||
| useEffect(() => { | ||
| if ( | ||
| recommendedFees?.fastestFee && | ||
| !hasInitializedDefaultFee.current && | ||
| !feeRate | ||
| ) { | ||
| hasInitializedDefaultFee.current = true; | ||
| onFeeRateChange(recommendedFees.fastestFee.toString()); | ||
| } | ||
| }, [feeRate, onFeeRateChange, recommendedFees]); | ||
|
|
||
| useEffect(() => { | ||
| if (mempoolError) { | ||
| setIsEditing(true); | ||
| } | ||
| }, [mempoolError]); | ||
|
|
||
| if (!info || (!recommendedFees && !mempoolError)) { | ||
| return ( | ||
| <div className="flex items-center justify-between"> | ||
| <Label>On-chain Fee Rate (sat/vB)</Label> | ||
| <Loading className="w-4 h-4" /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| if (!isEditing) { | ||
| return ( | ||
| <div className="flex items-center justify-between"> | ||
| <Label>On-chain Fee Rate (sat/vB)</Label> | ||
| {feeRate ? ( | ||
| <button | ||
| type="button" | ||
| className="flex items-center gap-2 cursor-pointer" | ||
| onClick={() => setIsEditing(true)} | ||
| > | ||
| <p className="text-sm">{feeRate} sat/vB</p> | ||
| <PencilIcon className="w-4 h-4" /> | ||
| </button> | ||
| ) : ( | ||
| <Loading className="w-4 h-4" /> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div className="grid gap-2"> | ||
| <Label htmlFor="fee-rate">On-chain Fee Rate (sat/vB)</Label> | ||
| {mempoolError && ( | ||
| <div className="text-muted-foreground text-xs flex gap-1 items-center"> | ||
| <AlertTriangleIcon className="h-3 w-3" /> | ||
| Failed to fetch fee estimates. Try refreshing the page. | ||
| </div> | ||
| )} | ||
| <Input | ||
| id="fee-rate" | ||
| type="number" | ||
| value={feeRate} | ||
| step={1} | ||
| required | ||
| min={recommendedFees?.minimumFee || 1} | ||
| onChange={(e) => { | ||
| onFeeRateChange(e.target.value); | ||
| }} | ||
| /> | ||
| {recommendedFees && ( | ||
| <div className="flex items-center mt-2 gap-4"> | ||
| <Button | ||
| variant="positive" | ||
| className="rounded-full" | ||
| type="button" | ||
| onClick={() => | ||
| onFeeRateChange(recommendedFees.economyFee.toString()) | ||
| } | ||
| > | ||
| Low priority: {recommendedFees.economyFee} | ||
| </Button> | ||
| <Button | ||
| variant="positive" | ||
| className="rounded-full" | ||
| type="button" | ||
| onClick={() => | ||
| onFeeRateChange(recommendedFees.fastestFee.toString()) | ||
| } | ||
| > | ||
| High priority: {recommendedFees.fastestFee} | ||
| </Button> | ||
| {info.mempoolUrl && ( | ||
| <ExternalLink | ||
| to={info.mempoolUrl} | ||
| className="text-muted-foreground text-sm underline flex items-center gap-2" | ||
| > | ||
| View on Mempool | ||
| <ExternalLinkIcon className="w-4 h-4" /> | ||
| </ExternalLink> | ||
| )} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.