Skip to content

Commit

Permalink
extract transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
gbarkhatov committed Dec 18, 2024
1 parent 8bbd034 commit f1172c4
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/components/WalletProvider/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Button, ScrollLocker, Text } from "@babylonlabs-io/bbn-core-ui";
import type { Meta, StoryObj } from "@storybook/react";
import { Psbt } from "bitcoinjs-lib";
import { useEffect, useState } from "react";

import { useChainProviders } from "@/context/Chain.context";
Expand Down Expand Up @@ -137,14 +138,15 @@ export const WithBTCSigningFeatures: Story = {
],
render: () => {
const { open } = useWidgetState();
const [messageToSign, setMessageToSign] = useState<string>("");
const [psbtToSign, setPsbtToSign] = useState<string>("");
const [messageToSign, setMessageToSign] = useState("");
const [psbtToSign, setPsbtToSign] = useState("");
const connectors = useChainProviders();
const [walletData, setWalletData] = useState<{
btcWallet?: IBTCProvider;
signedMessage?: string;
signedPsbt?: string;
}>({});
const [transaction, setTransaction] = useState("");

useEffect(() => {
const btcUnsub = connectors.BTC?.on("connect", async (wallet) => {
Expand Down Expand Up @@ -236,11 +238,37 @@ export const WithBTCSigningFeatures: Story = {
<Text variant="body2" className="b-flex-1 b-truncate">
Signed PSBT: {walletData.signedPsbt}
</Text>
<Button onClick={() => setWalletData((prev) => ({ ...prev, signedPsbt: undefined }))}>
<Button
onClick={() => {
setTransaction("");
setWalletData((prev) => ({ ...prev, signedPsbt: undefined }));
}}
>
Delete
</Button>
</div>
)}
{walletData.signedPsbt && (
<div className="b-mt-2 b-flex b-items-center b-gap-2">
<Text variant="body2" className="b-flex-1 b-truncate">
Transaction: {transaction}
</Text>
<Button
onClick={() => {
if (!walletData.signedPsbt) return;
try {
const tx = Psbt.fromHex(walletData.signedPsbt).extractTransaction().toHex();
console.log("Extracted transaction:", tx);
setTransaction(tx);
} catch (error) {
console.error("Failed to extract transaction:", error);
}
}}
>
Extract transaction
</Button>
</div>
)}
</div>
</div>
)}
Expand Down

0 comments on commit f1172c4

Please sign in to comment.