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

fix: copy preimage & payment hash #117

Merged
merged 2 commits into from
Sep 12, 2024
Merged
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
29 changes: 26 additions & 3 deletions pages/Transaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { Nip47Transaction } from "@getalby/sdk/dist/NWCClient";
import dayjs from "dayjs";
import { useLocalSearchParams } from "expo-router";
import React from "react";
import { View } from "react-native";
import { View, TouchableOpacity } from "react-native";
import Screen from "~/components/Screen";
import { MoveDownLeft, MoveUpRight } from "~/components/Icons";
import { Text } from "~/components/ui/text";
import { useGetFiatAmount } from "~/hooks/useGetFiatAmount";
import { cn } from "~/lib/utils";
import * as Clipboard from "expo-clipboard";
import Toast from "react-native-toast-message";

export function Transaction() {
const { transactionJSON } = useLocalSearchParams() as unknown as {
Expand Down Expand Up @@ -69,10 +71,12 @@ export function Transaction() {
<TransactionDetailRow
title="Payment Hash"
content={transaction.payment_hash}
copy
/>
<TransactionDetailRow
title="Preimage"
content={transaction.preimage}
copy
/>
<TransactionDetailRow
title="Fee"
Expand All @@ -86,11 +90,30 @@ export function Transaction() {
);
}

function TransactionDetailRow(props: { title: string; content: string }) {
function TransactionDetailRow(props: {
title: string;
content: string;
copy?: boolean;
}) {
return (
<View className="flex flex-row gap-3">
<Text className="w-32 text-muted-foreground">{props.title}</Text>
<Text className="flex-1 text-foreground font-medium2">{props.content}</Text>
{props.copy ? (
<TouchableOpacity
className="flex-1"
onPress={() => {
Clipboard.setStringAsync(props.content);
Toast.show({
type: "success",
text1: "Copied to clipboard",
});
}}
>
<Text className="text-foreground font-medium2">{props.content}</Text>
</TouchableOpacity>
) : (
<Text className="flex-1 text-foreground font-medium2">{props.content}</Text>
)}
</View>
);
}
Loading