Skip to content

Commit

Permalink
fix: support for lnurl success action
Browse files Browse the repository at this point in the history
  • Loading branch information
reneaaron committed Sep 27, 2024
1 parent 54153de commit 24c92e0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/lnurl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ type LNURLDetails = LNURLPayServiceResponse;
//| LNURLAuthServiceResponse
//| LNURLWithdrawServiceResponse;

interface LNURLPaymentSuccessAction {
export interface LNURLPaymentSuccessAction {
tag: string;
description?: string;
message?: string;
url?: string;
}

interface LNURLPaymentInfo {
export interface LNURLPaymentInfo {
pr: string;
successAction?: LNURLPaymentSuccessAction;
}
Expand Down
4 changes: 3 additions & 1 deletion pages/send/ConfirmPayment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import { errorToast } from "~/lib/errorToast";
import { useAppStore } from "~/lib/state/appStore";

export function ConfirmPayment() {
const { invoice, originalText, comment } = useLocalSearchParams() as {
const { invoice, originalText, comment, successAction } = useLocalSearchParams() as {
invoice: string;
originalText: string;
comment: string;
successAction: string;
};
const getFiatAmount = useGetFiatAmount();
const [isLoading, setLoading] = React.useState(false);
Expand All @@ -43,6 +44,7 @@ export function ConfirmPayment() {
originalText,
invoice,
amount: decodedInvoice.satoshi,
successAction,
},
});
} catch (error) {
Expand Down
7 changes: 6 additions & 1 deletion pages/send/LNURLPay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ export function LNURLPay() {
//console.log("Got pay request", lnurlPayInfo.pr);
router.push({
pathname: "/send/confirm",
params: { invoice: lnurlPayInfo.pr, originalText, comment },
params: {
invoice: lnurlPayInfo.pr,
originalText,
comment,
successAction: lnurlPayInfo.successAction ? JSON.stringify(lnurlPayInfo.successAction) : undefined,
},
});
} catch (error) {
console.error(error);
Expand Down
36 changes: 34 additions & 2 deletions pages/send/PaymentSuccess.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { router, useLocalSearchParams } from "expo-router";
import { Link, router, useLocalSearchParams } from "expo-router";
import { View } from "react-native";
import { Paid } from "~/animations/Paid";
import { Button } from "~/components/ui/button";
import { Text } from "~/components/ui/text";
import Screen from "~/components/Screen";
import { useGetFiatAmount } from "~/hooks/useGetFiatAmount";
import { LNURLPaymentSuccessAction } from "lib/lnurl";
import { Receiver } from "~/components/Receiver";

export function PaymentSuccess() {
const getFiatAmount = useGetFiatAmount();
const { preimage, originalText, invoice, amount } = useLocalSearchParams() as {
const { preimage, originalText, invoice, amount, successAction } = useLocalSearchParams() as {
preimage: string;
originalText: string;
invoice: string;
amount: string;
successAction: string;
};

const lnurlSuccessAction: LNURLPaymentSuccessAction = successAction ? JSON.parse(successAction) : undefined;

return (
<View className="flex-1 flex flex-col">
<Screen
Expand All @@ -32,6 +37,33 @@ export function PaymentSuccess() {
}
</View>
<Receiver originalText={originalText} invoice={invoice} />
{lnurlSuccessAction &&
<View className="flex flex-col gap-2 items-center">
<Text className="text-muted-foreground text-center font-semibold2">
Message From Receiver
</Text>
{lnurlSuccessAction.tag == "message" &&
<Text className="text-foreground text-center text-2xl font-medium2">
{lnurlSuccessAction.message}
</Text>
}
{lnurlSuccessAction.tag == "url" &&
<>
<Text className="text-foreground text-center text-2xl font-medium2">
{lnurlSuccessAction.description}
</Text>
{lnurlSuccessAction.url &&
<Link href={lnurlSuccessAction.url}>
<Button variant="secondary">
<Text>Open Link</Text>
</Button>
</Link>
}
</>
}
</View>
}

</View>
<View className="p-6">
<Button
Expand Down

0 comments on commit 24c92e0

Please sign in to comment.