diff --git a/apps/laboratory/src/components/Bitcoin/BitcoinSendTransferTest.tsx b/apps/laboratory/src/components/Bitcoin/BitcoinSendTransferTest.tsx index fb2d2c7006..59646ca416 100644 --- a/apps/laboratory/src/components/Bitcoin/BitcoinSendTransferTest.tsx +++ b/apps/laboratory/src/components/Bitcoin/BitcoinSendTransferTest.tsx @@ -1,67 +1,67 @@ -import { Box, Button, Input, InputGroup, InputLeftAddon, useToast } from '@chakra-ui/react' -import type { BitcoinConnector } from '@reown/appkit-adapter-bitcoin' -import { useAppKitAccount, useAppKitProvider } from '@reown/appkit/react' -import { useState } from 'react' - -export function BitcoinSendTransferTest() { - const { walletProvider } = useAppKitProvider('bip122') - const { address } = useAppKitAccount() - - const toast = useToast() - const [loading, setLoading] = useState(false) - const [recipient, setRecipient] = useState(address || '') - const [amount, setAmount] = useState('1500') - - async function onSendTransfer() { - if (!walletProvider) { - toast({ - title: 'No wallet provider', - status: 'error', - isClosable: true - }) - } - - try { - setLoading(true) - const signature = await walletProvider.sendTransfer({ - recipient, - amount - }) - - toast({ - title: `Transfer sent: ${signature}`, - status: 'success', - isClosable: true - }) - } catch (error) { - toast({ title: 'Error', description: (error as Error).message, status: 'error' }) - } finally { - setLoading(false) - } - } - - return ( - <> - - - Recipient - setRecipient(e.currentTarget.value)} /> - - - - Amount - setAmount(e.currentTarget.value)} type="number" /> - - - - - - ) -} +import { Box, Button, Input, InputGroup, InputLeftAddon, useToast } from '@chakra-ui/react' +import type { BitcoinConnector } from '@reown/appkit-adapter-bitcoin' +import { useAppKitAccount, useAppKitProvider } from '@reown/appkit/react' +import { useState } from 'react' + +export function BitcoinSendTransferTest() { + const { walletProvider } = useAppKitProvider('bip122') + const { address } = useAppKitAccount() + + const toast = useToast() + const [loading, setLoading] = useState(false) + const [recipient, setRecipient] = useState(address || '') + const [amount, setAmount] = useState('1500') + + async function onSendTransfer() { + if (!walletProvider) { + toast({ + title: 'No wallet provider', + status: 'error', + isClosable: true + }) + } + + try { + setLoading(true) + const signature = await walletProvider.sendTransfer({ + recipient, + amount + }) + + toast({ + title: `Transfer sent: ${signature}`, + status: 'success', + isClosable: true + }) + } catch (error) { + toast({ title: 'Error', description: (error as Error).message, status: 'error' }) + } finally { + setLoading(false) + } + } + + return ( + <> + + + Recipient + setRecipient(e.currentTarget.value)} /> + + + + Amount + setAmount(e.currentTarget.value)} type="number" /> + + + + + + ) +} diff --git a/apps/laboratory/src/components/Bitcoin/BitcoinSignMessageTest.tsx b/apps/laboratory/src/components/Bitcoin/BitcoinSignMessageTest.tsx index b076c8b7d6..0df09218f3 100644 --- a/apps/laboratory/src/components/Bitcoin/BitcoinSignMessageTest.tsx +++ b/apps/laboratory/src/components/Bitcoin/BitcoinSignMessageTest.tsx @@ -1,59 +1,59 @@ -import { Box, Button, Input, InputGroup, InputLeftAddon, useToast } from '@chakra-ui/react' -import type { BitcoinConnector } from '@reown/appkit-adapter-bitcoin' -import { useAppKitAccount, useAppKitProvider } from '@reown/appkit/react' -import { useState } from 'react' - -export function BitcoinSignMessageTest() { - const { walletProvider } = useAppKitProvider('bip122') - const { address } = useAppKitAccount() - - const toast = useToast() - const [loading, setLoading] = useState(false) - const [message, setMessage] = useState('Hello, World!') - - async function onSignMessage() { - if (!walletProvider || !address) { - toast({ - title: 'No connection detected', - status: 'error', - isClosable: true - }) - - return - } - - setLoading(true) - - try { - const signature = await walletProvider.signMessage({ - address, - message - }) - toast({ title: 'Signature', description: signature, status: 'success' }) - } catch (error) { - toast({ title: 'Error', description: (error as Error).message, status: 'error' }) - } finally { - setLoading(false) - } - } - - return ( - <> - - - Message - setMessage(e.currentTarget.value)} /> - - - - - - ) -} +import { Box, Button, Input, InputGroup, InputLeftAddon, useToast } from '@chakra-ui/react' +import type { BitcoinConnector } from '@reown/appkit-adapter-bitcoin' +import { useAppKitAccount, useAppKitProvider } from '@reown/appkit/react' +import { useState } from 'react' + +export function BitcoinSignMessageTest() { + const { walletProvider } = useAppKitProvider('bip122') + const { address } = useAppKitAccount() + + const toast = useToast() + const [loading, setLoading] = useState(false) + const [message, setMessage] = useState('Hello, World!') + + async function onSignMessage() { + if (!walletProvider || !address) { + toast({ + title: 'No connection detected', + status: 'error', + isClosable: true + }) + + return + } + + setLoading(true) + + try { + const signature = await walletProvider.signMessage({ + address, + message + }) + toast({ title: 'Signature', description: signature, status: 'success' }) + } catch (error) { + toast({ title: 'Error', description: (error as Error).message, status: 'error' }) + } finally { + setLoading(false) + } + } + + return ( + <> + + + Message + setMessage(e.currentTarget.value)} /> + + + + + + ) +} diff --git a/apps/laboratory/src/components/Bitcoin/BitcoinSignPSBTTest.tsx b/apps/laboratory/src/components/Bitcoin/BitcoinSignPSBTTest.tsx index 55df912c94..66616cff00 100644 --- a/apps/laboratory/src/components/Bitcoin/BitcoinSignPSBTTest.tsx +++ b/apps/laboratory/src/components/Bitcoin/BitcoinSignPSBTTest.tsx @@ -1,79 +1,79 @@ -import { Box, Button, Input, InputGroup, InputLeftAddon, useToast } from '@chakra-ui/react' -import type { BitcoinConnector } from '@reown/appkit-adapter-bitcoin' -import { useAppKitAccount, useAppKitNetwork, useAppKitProvider } from '@reown/appkit/react' -import { useState } from 'react' -import { BitcoinUtil } from '../../utils/BitcoinUtil' - -export function BitcoinSignPSBTTest() { - const { walletProvider } = useAppKitProvider('bip122') - const { address } = useAppKitAccount() - const { caipNetwork } = useAppKitNetwork() - - const toast = useToast() - const [loading, setLoading] = useState(false) - const [recipient, setRecipient] = useState(address || '') - const [amount, setAmount] = useState('1500') - - async function onSignPSBT() { - if (!walletProvider || !address || !caipNetwork) { - toast({ - title: 'No connection detected', - status: 'error', - isClosable: true - }) - - return - } - - if (caipNetwork.chainNamespace !== 'bip122') { - toast({ - title: 'The selected chain is not bip122', - status: 'error', - isClosable: true - }) - - return - } - - try { - const utxos = await BitcoinUtil.getUTXOs(address, caipNetwork.caipNetworkId) - const feeRate = await BitcoinUtil.getFeeRate() - - const params = BitcoinUtil.createSignPSBTParams({ - amount: Number(amount), - feeRate, - network: caipNetwork, - recipientAddress: recipient, - senderAddress: address, - utxos - }) - - const signature = await walletProvider.signPSBT(params) - toast({ title: 'PSBT Signature', description: signature.psbt, status: 'success' }) - } catch (error) { - toast({ title: 'Error', description: (error as Error).message, status: 'error' }) - } finally { - setLoading(false) - } - } - - return ( - <> - - - Recipient - setRecipient(e.currentTarget.value)} /> - - - - Amount - setAmount(e.currentTarget.value)} type="number" /> - - - - - - ) -} +import { Box, Button, Input, InputGroup, InputLeftAddon, useToast } from '@chakra-ui/react' +import type { BitcoinConnector } from '@reown/appkit-adapter-bitcoin' +import { useAppKitAccount, useAppKitNetwork, useAppKitProvider } from '@reown/appkit/react' +import { useState } from 'react' +import { BitcoinUtil } from '../../utils/BitcoinUtil' + +export function BitcoinSignPSBTTest() { + const { walletProvider } = useAppKitProvider('bip122') + const { address } = useAppKitAccount() + const { caipNetwork } = useAppKitNetwork() + + const toast = useToast() + const [loading, setLoading] = useState(false) + const [recipient, setRecipient] = useState(address || '') + const [amount, setAmount] = useState('1500') + + async function onSignPSBT() { + if (!walletProvider || !address || !caipNetwork) { + toast({ + title: 'No connection detected', + status: 'error', + isClosable: true + }) + + return + } + + if (caipNetwork.chainNamespace !== 'bip122') { + toast({ + title: 'The selected chain is not bip122', + status: 'error', + isClosable: true + }) + + return + } + + try { + const utxos = await BitcoinUtil.getUTXOs(address, caipNetwork.caipNetworkId) + const feeRate = await BitcoinUtil.getFeeRate() + + const params = BitcoinUtil.createSignPSBTParams({ + amount: Number(amount), + feeRate, + network: caipNetwork, + recipientAddress: recipient, + senderAddress: address, + utxos + }) + + const signature = await walletProvider.signPSBT(params) + toast({ title: 'PSBT Signature', description: signature.psbt, status: 'success' }) + } catch (error) { + toast({ title: 'Error', description: (error as Error).message, status: 'error' }) + } finally { + setLoading(false) + } + } + + return ( + <> + + + Recipient + setRecipient(e.currentTarget.value)} /> + + + + Amount + setAmount(e.currentTarget.value)} type="number" /> + + + + + + ) +} diff --git a/apps/laboratory/src/components/Bitcoin/BitcoinTests.tsx b/apps/laboratory/src/components/Bitcoin/BitcoinTests.tsx index ebf6a21623..8de3acab82 100644 --- a/apps/laboratory/src/components/Bitcoin/BitcoinTests.tsx +++ b/apps/laboratory/src/components/Bitcoin/BitcoinTests.tsx @@ -1,53 +1,53 @@ -import * as React from 'react' -import { useAppKitAccount } from '@reown/appkit/react' -import { StackDivider, Card, CardHeader, Heading, CardBody, Box, Stack } from '@chakra-ui/react' -import { BitcoinSignMessageTest } from './BitcoinSignMessageTest' -import { BitcoinSendTransferTest } from './BitcoinSendTransferTest' -import { BitcoinSignPSBTTest } from './BitcoinSignPSBTTest' - -export function BitcoinTests() { - const [ready, setReady] = React.useState(false) - - const { isConnected } = useAppKitAccount() - - React.useEffect(() => { - setReady(true) - }, []) - - if (!ready || !isConnected) { - return null - } - - return ( - - - Test Interactions - - - - } spacing="4"> - - - Sign Message Test - - - - - - - Sign PSBT Test - - - - - - - Send Transfer Test - - - - - - - ) -} +import * as React from 'react' +import { useAppKitAccount } from '@reown/appkit/react' +import { StackDivider, Card, CardHeader, Heading, CardBody, Box, Stack } from '@chakra-ui/react' +import { BitcoinSignMessageTest } from './BitcoinSignMessageTest' +import { BitcoinSendTransferTest } from './BitcoinSendTransferTest' +import { BitcoinSignPSBTTest } from './BitcoinSignPSBTTest' + +export function BitcoinTests() { + const [ready, setReady] = React.useState(false) + + const { isConnected } = useAppKitAccount() + + React.useEffect(() => { + setReady(true) + }, []) + + if (!ready || !isConnected) { + return null + } + + return ( + + + Test Interactions + + + + } spacing="4"> + + + Sign Message Test + + + + + + + Sign PSBT Test + + + + + + + Send Transfer Test + + + + + + + ) +}