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: show podcasting info in transactions #146

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"buffer": "^6.0.3",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"crypto-js": "^4.2.0",
"currency-list": "^1.0.8",
"dayjs": "^1.11.10",
"expo": "~51.0.34",
Expand Down Expand Up @@ -67,6 +68,7 @@
"@babel/preset-typescript": "^7.24.7",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/react-native": "^12.7.2",
"@types/crypto-js": "^4.2.2",
"@types/jest": "^29.5.13",
"@types/react": "~18.2.45",
"jest": "^29.7.0",
Expand Down
222 changes: 160 additions & 62 deletions pages/Transaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,90 +2,129 @@ import { Nip47Transaction } from "@getalby/sdk/dist/NWCClient";
import dayjs from "dayjs";
import { useLocalSearchParams } from "expo-router";
import React from "react";
import { View, TouchableOpacity } from "react-native";
import { View, TouchableOpacity, ScrollView } 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";
import Hex from "crypto-js/enc-hex";
import Utf8 from "crypto-js/enc-utf8";

type TLVRecord = {
type: number;
value: string;
};

type Boostagram = {
app_name: string;
name: string;
podcast: string;
url: string;
episode?: string;
itemID?: string;
ts?: string;
message?: string;
sender_id: string;
sender_name: string;
time: string;
action: string;
value_msat_total: number;
}

export function Transaction() {
const { transactionJSON } = useLocalSearchParams() as unknown as {
transactionJSON: string;
};
const transaction: Nip47Transaction = JSON.parse(transactionJSON);
const getFiatAmount = useGetFiatAmount();
const rawMetadata = transaction.metadata;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part could potentially be memoized. Otherwise the records are parsed with every render...

let boostagram: Boostagram | undefined;

try {
const tlvRecord = (rawMetadata?.tlv_records as TLVRecord[])?.find(record => record.type === 7629169);
if (tlvRecord) {
boostagram = JSON.parse(Utf8.stringify(Hex.parse(tlvRecord.value)))
}
} catch (e) {
console.error(e);
}

return (
<View className="flex-1 flex flex-col p-6 gap-3">
<View className="flex-1 flex flex-col gap-3">
<Screen
title="Transaction"
/>
<View className="flex flex-col gap-5 justify-center items-center">
<View
className="my-8 bg-muted rounded-full p-8"
style={{ elevation: 2 }}>
{transaction.type === "incoming" && (
<MoveDownLeft
className="text-receive"
width={100}
height={100}
<ScrollView className="p-6">
<View className="flex flex-col gap-5 justify-center items-center mb-12">
<View
className="my-8 bg-muted rounded-full p-8"
style={{ elevation: 2 }}>
{transaction.type === "incoming" && (
<MoveDownLeft
className="text-receive"
width={100}
height={100}
/>
)}
{transaction.type === "outgoing" && (
<MoveUpRight className="text-send" width={100} height={100} />
)}
</View>
<Text className="text-3xl font-bold2 text-foreground">
{transaction.type === "incoming" ? "Received" : "Sent"}
</Text>
<View className="flex flex-col items-center justify-center gap-2">
<View className="flex flex-row items-end mt-5">
<Text
className={cn(
"text-4xl gap-2 font-semibold2",
transaction.type === "incoming" ? "text-receive" : "text-foreground"
)}
>
{transaction.type === "incoming" ? "+" : "-"} {Math.floor(transaction.amount / 1000)}
</Text>
<Text className="text-2xl font-semibold2 text-muted-foreground"> sats</Text>
</View>
{getFiatAmount && (
<Text className="text-2xl font-semibold2 text-muted-foreground ">
{getFiatAmount(Math.floor(transaction.amount / 1000))}
</Text>
)}
</View>
<View className="flex flex-col gap-2 w-full mt-8">
<TransactionDetailRow
title="Date & Time"
content={dayjs.unix(transaction.settled_at).fromNow()}
/>
<TransactionDetailRow
title="Description"
content={transaction.description || "-"}
/>

{boostagram && <PodcastingInfo boost={boostagram} />}

<TransactionDetailRow
title="Payment Hash"
content={transaction.payment_hash}
copy
/>
<TransactionDetailRow
title="Preimage"
content={transaction.preimage}
copy
/>
<TransactionDetailRow
title="Fee"
content={
Math.floor(transaction.fees_paid / 1000).toString() + " sats (" + (transaction.fees_paid / transaction.amount * 100).toFixed(2) + "%)"
}
/>
)}
{transaction.type === "outgoing" && (
<MoveUpRight className="text-send" width={100} height={100} />
)}
</View>
<Text className="text-3xl font-bold2 text-foreground">
{transaction.type === "incoming" ? "Received" : "Sent"}
</Text>
<View className="flex flex-col items-center justify-center gap-2">
<View className="flex flex-row items-end mt-5">
<Text
className={cn(
"text-4xl gap-2 font-semibold2",
transaction.type === "incoming" ? "text-receive" : "text-foreground"
)}
>
{transaction.type === "incoming" ? "+" : "-"} {Math.floor(transaction.amount / 1000)}
</Text>
<Text className="text-2xl font-semibold2 text-muted-foreground"> sats</Text>
</View>
{getFiatAmount && (
<Text className="text-2xl font-semibold2 text-muted-foreground ">
{getFiatAmount(Math.floor(transaction.amount / 1000))}
</Text>
)}
</View>
<View className="flex flex-col gap-2 w-full mt-8">
<TransactionDetailRow
title="Date & Time"
content={dayjs.unix(transaction.settled_at).fromNow()}
/>
<TransactionDetailRow
title="Description"
content={transaction.description || "-"}
/>
<TransactionDetailRow
title="Payment Hash"
content={transaction.payment_hash}
copy
/>
<TransactionDetailRow
title="Preimage"
content={transaction.preimage}
copy
/>
<TransactionDetailRow
title="Fee"
content={
Math.floor(transaction.fees_paid / 1000).toString() + " sats (" + (transaction.fees_paid / transaction.amount * 100).toFixed(2) + "%)"
}
/>
</View>
</View>
</ScrollView>
</View>
);
}
Expand Down Expand Up @@ -117,3 +156,62 @@ function TransactionDetailRow(props: {
</View>
);
}

function PodcastingInfo({ boost }: { boost: Boostagram }) {
return (
<>
{boost.message && (
<TransactionDetailRow
title="Message"
content={boost.message}
/>
)}
{boost.podcast && (
<TransactionDetailRow
title="Podcast"
content={boost.podcast}
/>
)}
{boost.episode && (
<TransactionDetailRow
title="Episode"
content={boost.episode}
/>
)}
{boost.action && (
<TransactionDetailRow
title="Action"
content={boost.action}
/>
)}
{boost.ts && (
<TransactionDetailRow
title="Timestamp"
content={boost.ts}
/>
)}
{boost.value_msat_total && (
<TransactionDetailRow
title="Total amount"
content={
Math.floor(boost.value_msat_total / 1000) + (Math.floor(boost.value_msat_total / 1000) == 1 ? " sat" : " sats")
}
/>
)}
{boost.sender_name && (
<TransactionDetailRow
title="Sender"
content={boost.sender_name}
/>
)}
{boost.app_name && (
<TransactionDetailRow
title="App"
content={boost.app_name}
/>
)}
</>
);
}

export default PodcastingInfo;
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2797,6 +2797,11 @@
resolved "https://registry.yarnpkg.com/@types/cookie/-/cookie-0.6.0.tgz#eac397f28bf1d6ae0ae081363eca2f425bedf0d5"
integrity sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==

"@types/crypto-js@^4.2.2":
version "4.2.2"
resolved "https://registry.yarnpkg.com/@types/crypto-js/-/crypto-js-4.2.2.tgz#771c4a768d94eb5922cc202a3009558204df0cea"
integrity sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ==

"@types/graceful-fs@^4.1.3":
version "4.1.9"
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.9.tgz#2a06bc0f68a20ab37b3e36aa238be6abdf49e8b4"
Expand Down Expand Up @@ -4010,6 +4015,11 @@ [email protected], crypt@~0.0.1:
resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b"
integrity sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==

crypto-js@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.2.0.tgz#4d931639ecdfd12ff80e8186dba6af2c2e856631"
integrity sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==

crypto-random-string@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e"
Expand Down
Loading