Skip to content

Commit

Permalink
fix: receiver component
Browse files Browse the repository at this point in the history
  • Loading branch information
reneaaron committed Sep 24, 2024
1 parent 4ef17b3 commit 31e59f9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 44 deletions.
29 changes: 29 additions & 0 deletions components/Receiver.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from "react";
import { View } from "react-native";
import { Text } from "~/components/ui/text";

interface ReceiverProps {
originalText: string;
invoice?: string;
}

export function Receiver({ originalText, invoice }: ReceiverProps) {
const shouldShowReceiver =
originalText !== invoice &&
originalText.toLowerCase().replace("lightning:", "").includes("@");

if (!shouldShowReceiver) {
return null;
}

return (
<View className="flex flex-col gap-2">
<Text className="text-muted-foreground text-center font-semibold2">
To
</Text>
<Text className="text-center text-foreground text-2xl font-medium2">
{originalText.toLowerCase().replace("lightning:", "")}
</Text>
</View>
);
}
19 changes: 2 additions & 17 deletions pages/send/ConfirmPayment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React from "react";
import { View } from "react-native";
import { ZapIcon } from "~/components/Icons";
import Loading from "~/components/Loading";
import { Receiver } from "~/components/Receiver";
import Screen from "~/components/Screen";
import { Button } from "~/components/ui/button";
import { Text } from "~/components/ui/text";
Expand Down Expand Up @@ -94,23 +95,7 @@ export function ConfirmPayment() {
</View>
)
)}
{
/* only show "To" for lightning addresses */ originalText !==
invoice &&
originalText
.toLowerCase()
.replace("lightning:", "")
.includes("@") && (
<View className="flex flex-col gap-2">
<Text className="text-muted-foreground text-center font-semibold2">
To
</Text>
<Text className="text-center text-foreground text-2xl font-medium2">
{originalText.toLowerCase().replace("lightning:", "")}
</Text>
</View>
)
}
<Receiver originalText={originalText} invoice={invoice} />
</View>
<View className="p-6">
<Button
Expand Down
13 changes: 3 additions & 10 deletions pages/send/LNURLPay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { errorToast } from "~/lib/errorToast";
import Loading from "~/components/Loading";
import { DualCurrencyInput } from "~/components/DualCurrencyInput";
import DismissableKeyboardView from "~/components/DismissableKeyboardView";
import { Receiver } from "~/components/Receiver";

export function LNURLPay() {
const { lnurlDetailsJSON, originalText, humanReadablePaymentInfo } =
const { lnurlDetailsJSON, originalText } =
useLocalSearchParams() as unknown as {
lnurlDetailsJSON: string;
originalText: string;
humanReadablePaymentInfo: string;
};
const lnurlDetails: LNURLPayServiceResponse = JSON.parse(lnurlDetailsJSON);
const [isLoading, setLoading] = React.useState(false);
Expand Down Expand Up @@ -68,14 +68,7 @@ export function LNURLPay() {
returnKeyType="done"
/>
</View>
<View>
<Text className="text-muted-foreground text-center font-semibold2">
To
</Text>
<Text className="text-center text-foreground text-2xl font-medium2">
{humanReadablePaymentInfo}
</Text>
</View>
<Receiver originalText={originalText} />
</View>
<View className="p-6">
<Button
Expand Down
12 changes: 2 additions & 10 deletions pages/send/PaymentSuccess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Button } from "~/components/ui/button";
import { Text } from "~/components/ui/text";
import Screen from "~/components/Screen";
import { useGetFiatAmount } from "~/hooks/useGetFiatAmount";
import { Receiver } from "~/components/Receiver";

export function PaymentSuccess() {
const getFiatAmount = useGetFiatAmount();
Expand All @@ -30,16 +31,7 @@ export function PaymentSuccess() {
<Text className="text-2xl text-muted-foreground font-semibold2">{getFiatAmount(+amount)}</Text>
}
</View>
{originalText !== invoice &&
<View>
<Text className="text-muted-foreground text-center font-semibold2">
Sent to
</Text>
<Text className="text-foreground text-center text-2xl font-medium2">
{originalText.toLowerCase().replace("lightning:", "")}
</Text>
</View>
}
<Receiver originalText={originalText} invoice={invoice} />
</View>
<View className="p-6">
<Button
Expand Down
8 changes: 1 addition & 7 deletions pages/send/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export function Send() {
}
console.log("loading payment", text);
const originalText = text;
let humanReadablePaymentInfo = text;
setLoading(true);
try {
if (text.startsWith("bitcoin:")) {
Expand All @@ -99,29 +98,24 @@ export function Send() {
throw new Error("LNURL tag " + lnurlDetails.tag + " not supported");
}

humanReadablePaymentInfo = lnurlValue;

router.replace({
pathname: "/send/lnurl-pay",
params: {
lnurlDetailsJSON: JSON.stringify(lnurlDetails),
originalText,
humanReadablePaymentInfo
},
});

return true;
} else {
humanReadablePaymentInfo = text;

// Check if this is a valid invoice
new Invoice({
pr: text,
});

router.replace({
pathname: "/send/confirm",
params: { invoice: text, originalText, humanReadablePaymentInfo },
params: { invoice: text, originalText },
});

return true;
Expand Down

0 comments on commit 31e59f9

Please sign in to comment.