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: swap fallbacks #2877

Merged
merged 2 commits into from
Nov 21, 2023
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
18 changes: 3 additions & 15 deletions src/app/screens/Send/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import { useTranslation } from "react-i18next";
import { useLocation, useNavigate } from "react-router-dom";
import QrcodeAdornment from "~/app/components/QrcodeAdornment";
import toast from "~/app/components/Toast";
import { useAccount } from "~/app/context/AccountContext";
import {
extractLightningTagData,
isAlbyOAuthAccount,
isBitcoinAddress,
} from "~/app/utils";
import { extractLightningTagData, isBitcoinAddress } from "~/app/utils";
import lnurlLib from "~/common/lib/lnurl";
import { isLNURLDetailsError } from "~/common/utils/typeHelpers";

Expand All @@ -27,10 +22,6 @@ function Send() {
const [invoice, setInvoice] = useState(location.state?.decodedQR || "");
const navigate = useNavigate();
const [loading, setLoading] = useState(false);
const auth = useAccount();
const hint = !isAlbyOAuthAccount(auth.account?.connectorType)
? t("input.hint")
: t("input.hint_with_bitcoin_address");

function isPubKey(str: string) {
return str.length == 66 && (str.startsWith("02") || str.startsWith("03"));
Expand Down Expand Up @@ -100,10 +91,7 @@ function Send() {
},
},
});
} else if (
isAlbyOAuthAccount(auth.account?.connectorType) &&
isBitcoinAddress(invoice)
) {
} else if (isBitcoinAddress(invoice)) {
navigate("/sendToBitcoinAddress", {
state: { args: { bitcoinAddress: invoice } },
});
Expand Down Expand Up @@ -144,7 +132,7 @@ function Send() {
<TextField
id="invoice"
label={t("input.label")}
hint={hint}
hint={t("input.hint_with_bitcoin_address")}
value={invoice}
disabled={loading}
autoFocus
Expand Down
72 changes: 70 additions & 2 deletions src/app/screens/SendToBitcoinAddress/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function SendToBitcoinAddress() {
}
} catch (e) {
console.error(e);
if (e instanceof Error) toast.error(t("service_unavailable"));
setStep("unavailable");
} finally {
setFeesLoading(false);
}
Expand Down Expand Up @@ -358,7 +358,6 @@ function SendToBitcoinAddress() {
</Container>
</form>
)}

{step == "success" && (
<Container justifyBetween maxWidth="sm">
<ResultCard
Expand Down Expand Up @@ -392,13 +391,82 @@ function SendToBitcoinAddress() {
</div>
</Container>
)}
{step == "unavailable" && (
<Container justifyBetween maxWidth="sm">
<Alert type="info">
Built-in swaps are currently unavailable. You can use one of the
following swap providers in the meantime:
</Alert>
<ExchangeLink
href="https://boltz.exchange/"
imageSrc="/assets/icons/swap/boltz.png"
title="Boltz Exchange"
description="Privacy first, non-Custodial bitcoin exchange"
/>
<ExchangeLink
href="https://swap.deezy.io/"
imageSrc="/assets/icons/swap/deezy.svg"
title="Deezy"
description="Swap instantly between lightning and on-chain bitcoin"
/>
<ExchangeLink
href="https://fixedfloat.com/BTCLN/BTC/?ref=qnnjvywb"
imageSrc="/assets/icons/swap/fixedfloat.png"
title="FixedFloat"
description="Instant cryptocurrency exchange"
/>
<ExchangeLink
href="https://sideshift.ai/ln/btc"
imageSrc="/assets/icons/swap/sideshift.svg"
title="sideshift.ai"
description="No sign-up crypto exchange"
/>
</Container>
)}
</div>
</div>
);
}

export default SendToBitcoinAddress;

// Define the types for the component props
interface ExchangeLinkProps {
href: string;
imageSrc: string;
title: string;
description: string;
}

const ExchangeLink: React.FC<ExchangeLinkProps> = ({
href,
imageSrc,
title,
description,
}) => {
return (
<a key={href} href={href} target="_blank" rel="noreferrer" className="mt-4">
<div className="bg-white dark:bg-surface-01dp shadow flex p-4 rounded-lg hover:bg-gray-50 dark:hover:bg-neutral-800 cursor-pointer w-full">
<div className="flex space-x-3 items-center ">
<img
src={imageSrc}
alt="image"
className="h-14 w-14 rounded-lg object-cover"
/>
<div>
<h2 className="font-medium font-serif text-base dark:text-white">
{title}
</h2>
<p className="font-serif text-sm font-normal text-gray-500 dark:text-neutral-400 line-clamp-3">
{description}
</p>
</div>
</div>
</div>
</a>
);
};

type BitcoinAddressProps = {
address: string;
};
Expand Down
Binary file added static/assets/icons/swap/boltz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions static/assets/icons/swap/deezy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/assets/icons/swap/fixedfloat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions static/assets/icons/swap/sideshift.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading