Skip to content
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: add mempool fee alerts #546

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frontend/src/components/CloseChannelDialogContent.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AlertTriangleIcon, CopyIcon, ExternalLinkIcon } from "lucide-react";
import React from "react";
import ExternalLink from "src/components/ExternalLink";
import { MempoolAlert } from "src/components/MempoolAlert";
import { Alert, AlertDescription, AlertTitle } from "src/components/ui/alert";
import { Button } from "src/components/ui/button";
import { Label } from "src/components/ui/label";
Expand Down Expand Up @@ -127,6 +128,9 @@ export function CloseChannelDialogContent({ alias, channel }: Props) {
<AlertDialogHeader>
<AlertDialogTitle>Select mode of channel closure</AlertDialogTitle>
<AlertDialogDescription className="text-left">
<div className="mb-4">
<MempoolAlert />
</div>
{closeType === "force" && (
<Alert className="mb-4">
<AlertTriangleIcon className="h-4 w-4" />
Expand Down
55 changes: 55 additions & 0 deletions frontend/src/components/MempoolAlert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { TriangleAlertIcon } from "lucide-react";
import { Alert, AlertDescription, AlertTitle } from "src/components/ui/alert";
import { ExternalLinkButton } from "src/components/ui/button";
import { useMempoolApi } from "src/hooks/useMempoolApi";

export function MempoolAlert() {
const { data: recommendedFees } = useMempoolApi<{ fastestFee: number }>(
"/v1/fees/recommended",
true
);

const fees = {
"EXTREMELY HIGH": 200,
"very high": 150,
high: 100,
"moderately high": 50,
};

const fee = recommendedFees?.fastestFee;
if (!fee) {
return null;
}
const matchedFee = Object.entries(fees).find((entry) => fee >= entry[1]);

if (!matchedFee) {
return null;
}
return (
<Alert>
<TriangleAlertIcon className="h-4 w-4" />
<AlertTitle>
Mempool Fees are currently{" "}
<span className="font-semibold">{matchedFee[0]}</span>
</AlertTitle>
<AlertDescription>
<p>Bitcoin transactions may be uneconomical at this time.</p>
<div className="flex gap-2 mt-2">
<ExternalLinkButton
to="https://guides.getalby.com/user-guide/v/alby-account-and-browser-extension/alby-hub/faq-alby-hub/what-to-do-during-times-of-high-onchain-fees"
size={"sm"}
>
Learn more
</ExternalLinkButton>
<ExternalLinkButton
to="https://mempool.space"
size={"sm"}
variant="secondary"
>
View fees on mempool
</ExternalLinkButton>
</div>
</AlertDescription>
</Alert>
);
}
2 changes: 2 additions & 0 deletions frontend/src/screens/channels/IncreaseIncomingCapacity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Link, useNavigate } from "react-router-dom";
import AppHeader from "src/components/AppHeader";
import ExternalLink from "src/components/ExternalLink";
import Loading from "src/components/Loading";
import { MempoolAlert } from "src/components/MempoolAlert";
import {
Button,
ExternalLinkButton,
Expand Down Expand Up @@ -202,6 +203,7 @@ function NewChannelInternal({
</div>
}
/>
<MempoolAlert />
<div className="md:max-w-md max-w-full flex flex-col gap-5 flex-1">
<form onSubmit={onSubmit} className="flex flex-col gap-5 flex-1">
<div className="grid gap-1.5">
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/screens/channels/IncreaseOutgoingCapacity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Link, useNavigate } from "react-router-dom";
import AppHeader from "src/components/AppHeader";
import ExternalLink from "src/components/ExternalLink";
import Loading from "src/components/Loading";
import { MempoolAlert } from "src/components/MempoolAlert";
import {
Button,
ExternalLinkButton,
Expand Down Expand Up @@ -225,6 +226,7 @@ function NewChannelInternal({ network }: { network: Network }) {
</div>
}
/>
<MempoolAlert />
<div className="md:max-w-md max-w-full flex flex-col gap-5 flex-1">
<form
onSubmit={onSubmit}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/screens/channels/first/FirstChannel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { useInfo } from "src/hooks/useInfo";
import { AutoChannelRequest, AutoChannelResponse } from "src/types";
import { request } from "src/utils/request";

import { MempoolAlert } from "src/components/MempoolAlert";
import {
ALBY_HIDE_HOSTED_BALANCE_BELOW,
ALBY_MIN_HOSTED_BALANCE_FOR_FIRST_CHANNEL,
Expand Down Expand Up @@ -94,6 +95,7 @@ export function FirstChannel() {
title="Open Your First Channel"
description="Open a channel to another lightning network node to join the lightning network"
/>
<MempoolAlert />
{invoice && channelSize && (
<div className="flex flex-col gap-4 items-center justify-center max-w-md">
<p className="text-muted-foreground">
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/screens/onchain/BuyBitcoin.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import AppHeader from "src/components/AppHeader";
import { MempoolAlert } from "src/components/MempoolAlert";
import { Input } from "src/components/ui/input";
import { Label } from "src/components/ui/label";
import { LoadingButton } from "src/components/ui/loading-button";
Expand Down Expand Up @@ -172,6 +173,7 @@ export default function BuyBitcoin() {
title="Buy Bitcoin"
description="Use one of our partner providers to buy bitcoin and deposit it to your savings balance."
/>
<MempoolAlert />
<div className="grid grid-cols-1 lg:grid-cols-2 gap-1 lg:gap-10">
<div className="flex max-w-lg flex-col gap-4">
<div className="grid gap-4">
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/screens/onchain/DepositBitcoin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Copy, CreditCard, RefreshCw } from "lucide-react";
import { Link } from "react-router-dom";
import AppHeader from "src/components/AppHeader";
import Loading from "src/components/Loading";
import { MempoolAlert } from "src/components/MempoolAlert";
import QRCode from "src/components/QRCode";
import { Button } from "src/components/ui/button";
import { Card, CardContent } from "src/components/ui/card";
Expand Down Expand Up @@ -40,6 +41,7 @@ export default function DepositBitcoin() {
</Link>
}
/>
<MempoolAlert />
<div className="w-80">
<Card>
<CardContent className="grid gap-6 p-8 justify-center border border-muted">
Expand Down
Loading