From 620a3a94895c0e2cde7045bfec5942adeb291dba Mon Sep 17 00:00:00 2001 From: Mahmoud Aboelenein Date: Thu, 18 Jul 2024 19:19:01 +0300 Subject: [PATCH 1/2] added sendInscriptions example --- example/package-lock.json | 2 +- example/src/App.tsx | 2 + .../src/components/sendInscriptions/index.tsx | 128 ++++++++++++++++++ package-lock.json | 8 +- package.json | 2 +- 5 files changed, 136 insertions(+), 6 deletions(-) create mode 100644 example/src/components/sendInscriptions/index.tsx diff --git a/example/package-lock.json b/example/package-lock.json index c4d16c2..c3af5f2 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -35,7 +35,7 @@ "version": "2.5.0", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.1.1", + "@sats-connect/core": "0.1.1-1478519", "@sats-connect/make-default-provider-config": "0.0.5", "@sats-connect/ui": "0.0.6" }, diff --git a/example/src/App.tsx b/example/src/App.tsx index b76c07c..fb836c4 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -17,6 +17,7 @@ import { QueryClient, QueryClientProvider, useQueryClient } from '@tanstack/reac import { WalletType } from './components/wallet/WalletType'; import { GetAccounts } from './components/bitcoin/GetAccounts'; import { SignMessage } from './components/SignMessage'; +import SendInscription from './components/sendInscriptions'; function AppWithProviders() { const queryClient = useQueryClient(); @@ -121,6 +122,7 @@ function AppWithProviders() { + diff --git a/example/src/components/sendInscriptions/index.tsx b/example/src/components/sendInscriptions/index.tsx new file mode 100644 index 0000000..2554a72 --- /dev/null +++ b/example/src/components/sendInscriptions/index.tsx @@ -0,0 +1,128 @@ +import { useCallback, useMemo, useState } from 'react'; +import Wallet, { BitcoinNetworkType } from 'sats-connect'; +import { Button, Card, Input, Success } from '../../App.styles'; + +interface Props { + network: BitcoinNetworkType; +} + +interface Recipient { + address: string; + inscriptionId: string; +} + +const SendInscription = ({ network }: Props) => { + const [recipients, setRecipients] = useState([{ address: '', inscriptionId: '' }]); + const [txnId, setTxnId] = useState(''); + + const addRecipient = () => { + setRecipients([...recipients, { address: '', inscriptionId: '' }]); + }; + + const updateRecipient = (index: number, field: keyof Recipient, value: string) => { + const updatedRecipients = [...recipients]; + updatedRecipients[index][field] = value; + setRecipients(updatedRecipients); + }; + + const removeRecipient = (index: number) => { + if (recipients.length > 1) { + const updatedRecipients = recipients.filter((_, i) => i !== index); + setRecipients(updatedRecipients); + } + }; + + const onClick = useCallback(() => { + (async () => { + const response = await Wallet.request('ord_sendInscriptions', { + transfers: recipients.map((r) => ({ + address: r.address, + inscriptionId: r.inscriptionId, + })), + }); + + if (response.status === 'error') { + console.error(response.error); + alert('Error sending BTC. See console for details.'); + return; + } + + setTxnId(response.result.txid); + setRecipients([{ address: '', inscriptionId: '' }]); + })().catch(console.error); + }, [recipients]); + + const explorerUrl = useMemo( + () => + network === BitcoinNetworkType.Mainnet + ? `https://mempool.space/tx/${txnId}` + : `https://mempool.space/testnet/tx/${txnId}`, + [network, txnId] + ); + + return ( + +

Send Inscriptions

+ {!txnId && ( + <> + {recipients.map((recipient, index) => ( +
+ {index > 0 &&
} +

Recipient {index + 1}

+
+
Inscription Id
+ updateRecipient(index, 'inscriptionId', e.target.value)} + /> +
+
+
Address
+ updateRecipient(index, 'address', e.target.value)} + /> +
+
+ ))} +
+ + {recipients.length > 1 && ( + + )} +
+ + + )} + {txnId && ( + + Success! Click{' '} + + here + {' '} + to see your transaction + + )} +
+ ); +}; + +export default SendInscription; diff --git a/package-lock.json b/package-lock.json index 1771da2..0155c22 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.5.0", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.1.1", + "@sats-connect/core": "0.1.1-1478519", "@sats-connect/make-default-provider-config": "0.0.5", "@sats-connect/ui": "0.0.6" }, @@ -1715,9 +1715,9 @@ ] }, "node_modules/@sats-connect/core": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.1.1.tgz", - "integrity": "sha512-ZkLwa3mxHjxAN9HVT7tLOvqkHwwoeIgzul9dMTLAzg2kJ2+GnP9LWg7UedgHRgIjrXGwQ0KVIh9kzBXgDvWi5A==", + "version": "0.1.1-1478519", + "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.1.1-1478519.tgz", + "integrity": "sha512-zuZu6YGV5w4SHWjkTw/Jn4/D7DtZh0XU4XiiX1Jmn+tY9fqOKG3qj85DxetbJMg4wNU0/dBUpejyJlhI3ANFIA==", "dependencies": { "axios": "1.6.8", "bitcoin-address-validation": "2.2.3", diff --git a/package.json b/package.json index f4c8185..3820995 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ ] }, "dependencies": { - "@sats-connect/core": "0.1.1", + "@sats-connect/core": "0.1.1-1478519", "@sats-connect/make-default-provider-config": "0.0.5", "@sats-connect/ui": "0.0.6" }, From fb847383bb6715449c702e1d24484cc858acacc5 Mon Sep 17 00:00:00 2001 From: Mahmoud Aboelenein Date: Mon, 22 Jul 2024 12:14:53 +0300 Subject: [PATCH 2/2] update @sats-connect/core --- example/package-lock.json | 2 +- package-lock.json | 8 ++++---- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/example/package-lock.json b/example/package-lock.json index c3af5f2..1f05c59 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -35,7 +35,7 @@ "version": "2.5.0", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.1.1-1478519", + "@sats-connect/core": "0.1.2", "@sats-connect/make-default-provider-config": "0.0.5", "@sats-connect/ui": "0.0.6" }, diff --git a/package-lock.json b/package-lock.json index 0155c22..8c5bde6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "2.5.0", "license": "ISC", "dependencies": { - "@sats-connect/core": "0.1.1-1478519", + "@sats-connect/core": "0.1.2", "@sats-connect/make-default-provider-config": "0.0.5", "@sats-connect/ui": "0.0.6" }, @@ -1715,9 +1715,9 @@ ] }, "node_modules/@sats-connect/core": { - "version": "0.1.1-1478519", - "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.1.1-1478519.tgz", - "integrity": "sha512-zuZu6YGV5w4SHWjkTw/Jn4/D7DtZh0XU4XiiX1Jmn+tY9fqOKG3qj85DxetbJMg4wNU0/dBUpejyJlhI3ANFIA==", + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/@sats-connect/core/-/core-0.1.2.tgz", + "integrity": "sha512-SM8U7Bcp5PdtAXw0CNFP3QloU0/xMSupH0FOw65YzWGSklFRoQBq+YCrCZ/shB7fIg1wPFgEFvY5MLQjANl+gw==", "dependencies": { "axios": "1.6.8", "bitcoin-address-validation": "2.2.3", diff --git a/package.json b/package.json index 3820995..6debeca 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ ] }, "dependencies": { - "@sats-connect/core": "0.1.1-1478519", + "@sats-connect/core": "0.1.2", "@sats-connect/make-default-provider-config": "0.0.5", "@sats-connect/ui": "0.0.6" },