@omnisat/lasereyes 0.0.17 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -176,14 +176,19 @@ declare const useInscriber: ({ inscribeApiUrl, }: {
176
176
  isFetchingCommitPsbt: boolean;
177
177
  commitPsbtHex: string;
178
178
  commitPsbtBase64: string;
179
- handleSignCommit: (tx: string) => Promise<string | undefined>;
179
+ handleSignCommit: (tx?: string) => Promise<string | undefined>;
180
180
  commitTxId: string;
181
181
  setCommitTxId: react.Dispatch<react.SetStateAction<string>>;
182
182
  feeRate: number;
183
183
  setFeeRate: react.Dispatch<react.SetStateAction<number>>;
184
184
  totalFees: number;
185
185
  inscriberAddress: string;
186
- inscribe: () => Promise<string>;
186
+ inscribe: ({ content: providedContent, mimeType: providedMimeType, ordinalAddress: providedAddress, commitTxId: providedCommitTxId, }: {
187
+ content?: any;
188
+ mimeType?: string | undefined;
189
+ ordinalAddress?: string | undefined;
190
+ commitTxId?: string | undefined;
191
+ }) => Promise<string>;
187
192
  isInscribing: boolean;
188
193
  inscriptionTxId: string;
189
194
  reset: () => void;
package/dist/index.js CHANGED
@@ -1355,6 +1355,8 @@ var LaserEyesProvider = ({
1355
1355
  let psbtHex, psbtBase64;
1356
1356
  if (!library)
1357
1357
  return;
1358
+ if (!psbt)
1359
+ throw new Error("No PSBT provided");
1358
1360
  if (isHex(psbt)) {
1359
1361
  psbtBase64 = bitcoin2.Psbt.fromHex(psbt).toBase64();
1360
1362
  psbtHex = psbt;
@@ -1466,9 +1468,7 @@ var LaserEyesProvider = ({
1466
1468
  const signedPsbt = yield library == null ? void 0 : library.signPsbt(psbtHex, true, true);
1467
1469
  console.log({ signedPsbt });
1468
1470
  const psbtSignedPsbt = bitcoin2.Psbt.fromHex(signedPsbt);
1469
- console.log("psbtSignedPsbt", psbtSignedPsbt.toBase64());
1470
1471
  if (broadcast) {
1471
- console.log("broadcastin");
1472
1472
  const txId = yield pushPsbt(psbtSignedPsbt.toHex());
1473
1473
  return {
1474
1474
  signedPsbtHex: psbtSignedPsbt.toHex(),
@@ -1751,6 +1751,11 @@ var useInscriber = ({
1751
1751
  const [previewUrl, setPreviewUrl] = (0, import_react2.useState)("");
1752
1752
  const [isFetchingCommitPsbt, setIsFetchingCommitPsbt] = (0, import_react2.useState)(false);
1753
1753
  const [isInscribing, setIsInscribing] = (0, import_react2.useState)(false);
1754
+ (0, import_react2.useEffect)(() => {
1755
+ setCommitPsbtHex("");
1756
+ setCommitPsbtBase64("");
1757
+ setCommitTxId("");
1758
+ }, [content, address2, mimeType, feeRate]);
1754
1759
  const getCommitPsbt = (0, import_react2.useCallback)(() => __async(void 0, null, function* () {
1755
1760
  try {
1756
1761
  if (!content)
@@ -1780,14 +1785,17 @@ var useInscriber = ({
1780
1785
  });
1781
1786
  } catch (e) {
1782
1787
  console.error(e);
1783
- throw e;
1788
+ throw new Error(e.response.data);
1784
1789
  } finally {
1785
1790
  setIsFetchingCommitPsbt(false);
1786
1791
  }
1787
1792
  }), [paymentAddress, paymentPublicKey, content, feeRate, mimeType, publicKey]);
1788
1793
  const handleSignCommit = (tx) => __async(void 0, null, function* () {
1789
1794
  try {
1790
- const signedResponse = yield signPsbt(tx, true, true);
1795
+ const toBeSigned = tx != null ? tx : commitPsbtHex;
1796
+ if (!toBeSigned)
1797
+ throw new Error("missing tx");
1798
+ const signedResponse = yield signPsbt(toBeSigned, true, true);
1791
1799
  setCommitTxId(signedResponse == null ? void 0 : signedResponse.txId);
1792
1800
  return signedResponse == null ? void 0 : signedResponse.txId;
1793
1801
  } catch (e) {
@@ -1795,38 +1803,53 @@ var useInscriber = ({
1795
1803
  throw e;
1796
1804
  }
1797
1805
  });
1798
- const inscribe = (0, import_react2.useCallback)(() => __async(void 0, null, function* () {
1799
- try {
1800
- setIsInscribing(true);
1801
- if (!content)
1802
- throw new Error("missing content");
1803
- if (!address2)
1804
- throw new Error("missing address");
1805
- if (!mimeType)
1806
- throw new Error("missing mimeType");
1807
- if (!commitTxId) {
1808
- console.log("commitTxId not found, getting commit psbt");
1809
- const signed = yield getCommitPsbt();
1810
- console.log({ signed });
1811
- yield handleSignCommit(signed.psbtBase64);
1806
+ const inscribe = (0, import_react2.useCallback)(
1807
+ (_0) => __async(void 0, [_0], function* ({
1808
+ content: providedContent,
1809
+ mimeType: providedMimeType,
1810
+ ordinalAddress: providedAddress,
1811
+ commitTxId: providedCommitTxId
1812
+ }) {
1813
+ try {
1814
+ const inscribeContent = providedContent != null ? providedContent : content;
1815
+ const inscribeMimeType = providedMimeType != null ? providedMimeType : mimeType;
1816
+ const inscribeOutputAddress = providedAddress != null ? providedAddress : address2;
1817
+ let inscribeCommitTxId = providedCommitTxId != null ? providedCommitTxId : commitTxId;
1818
+ if (!inscribeContent)
1819
+ throw new Error("missing content");
1820
+ if (!inscribeMimeType)
1821
+ throw new Error("missing mimeType");
1822
+ if (!inscribeOutputAddress)
1823
+ throw new Error("missing address");
1824
+ setIsInscribing(true);
1825
+ if (!inscribeCommitTxId) {
1826
+ const signed = yield getCommitPsbt();
1827
+ inscribeCommitTxId = yield handleSignCommit(signed.psbtBase64);
1828
+ if (!inscribeCommitTxId)
1829
+ throw new Error("failed to broadcast commit");
1830
+ console.log("tempCommitTxId", inscribeCommitTxId);
1831
+ }
1832
+ yield delay(1e4);
1833
+ if (!inscribeCommitTxId)
1834
+ throw new Error("missing commitTxId");
1835
+ return yield import_axios3.default.post(`${inscribeApiUrl}/inscribe`, {
1836
+ content,
1837
+ mimeType,
1838
+ ordinalAddress: address2,
1839
+ commitTxId: inscribeCommitTxId
1840
+ }).then((res) => res.data).then((data) => {
1841
+ setInscriptionTxId(data);
1842
+ return data;
1843
+ });
1844
+ } catch (e) {
1845
+ console.error(e);
1846
+ throw e;
1847
+ } finally {
1848
+ setIsInscribing(false);
1812
1849
  }
1813
- yield delay(1e4);
1814
- return yield import_axios3.default.post(`${inscribeApiUrl}/inscribe`, {
1815
- content,
1816
- mimeType,
1817
- ordinalAddress: address2,
1818
- commitTxId
1819
- }).then((res) => res.data).then((data) => {
1820
- setInscriptionTxId(data);
1821
- return data;
1822
- });
1823
- } catch (e) {
1824
- console.error(e);
1825
- throw e;
1826
- } finally {
1827
- setIsInscribing(false);
1828
- }
1829
- }), [address2, commitTxId, content, mimeType]);
1850
+ }),
1851
+ [address2, commitTxId, content, mimeType]
1852
+ );
1830
1853
  const reset = () => {
1831
1854
  setContent("");
1832
1855
  setMimeType(MIME_TYPE_TEXT);
@@ -1839,11 +1862,6 @@ var useInscriber = ({
1839
1862
  setInscriptionTxId("");
1840
1863
  setPreviewUrl("");
1841
1864
  };
1842
- (0, import_react2.useEffect)(() => {
1843
- if (commitTxId && !inscriptionTxId) {
1844
- inscribe();
1845
- }
1846
- }, [commitTxId, inscribe, inscriptionTxId]);
1847
1865
  return {
1848
1866
  content,
1849
1867
  setContent,
package/dist/index.mjs CHANGED
@@ -1277,6 +1277,8 @@ var LaserEyesProvider = ({
1277
1277
  let psbtHex, psbtBase64;
1278
1278
  if (!library)
1279
1279
  return;
1280
+ if (!psbt)
1281
+ throw new Error("No PSBT provided");
1280
1282
  if (isHex(psbt)) {
1281
1283
  psbtBase64 = bitcoin2.Psbt.fromHex(psbt).toBase64();
1282
1284
  psbtHex = psbt;
@@ -1388,9 +1390,7 @@ var LaserEyesProvider = ({
1388
1390
  const signedPsbt = yield library == null ? void 0 : library.signPsbt(psbtHex, true, true);
1389
1391
  console.log({ signedPsbt });
1390
1392
  const psbtSignedPsbt = bitcoin2.Psbt.fromHex(signedPsbt);
1391
- console.log("psbtSignedPsbt", psbtSignedPsbt.toBase64());
1392
1393
  if (broadcast) {
1393
- console.log("broadcastin");
1394
1394
  const txId = yield pushPsbt(psbtSignedPsbt.toHex());
1395
1395
  return {
1396
1396
  signedPsbtHex: psbtSignedPsbt.toHex(),
@@ -1673,6 +1673,11 @@ var useInscriber = ({
1673
1673
  const [previewUrl, setPreviewUrl] = useState2("");
1674
1674
  const [isFetchingCommitPsbt, setIsFetchingCommitPsbt] = useState2(false);
1675
1675
  const [isInscribing, setIsInscribing] = useState2(false);
1676
+ useEffect2(() => {
1677
+ setCommitPsbtHex("");
1678
+ setCommitPsbtBase64("");
1679
+ setCommitTxId("");
1680
+ }, [content, address2, mimeType, feeRate]);
1676
1681
  const getCommitPsbt = useCallback(() => __async(void 0, null, function* () {
1677
1682
  try {
1678
1683
  if (!content)
@@ -1702,14 +1707,17 @@ var useInscriber = ({
1702
1707
  });
1703
1708
  } catch (e) {
1704
1709
  console.error(e);
1705
- throw e;
1710
+ throw new Error(e.response.data);
1706
1711
  } finally {
1707
1712
  setIsFetchingCommitPsbt(false);
1708
1713
  }
1709
1714
  }), [paymentAddress, paymentPublicKey, content, feeRate, mimeType, publicKey]);
1710
1715
  const handleSignCommit = (tx) => __async(void 0, null, function* () {
1711
1716
  try {
1712
- const signedResponse = yield signPsbt(tx, true, true);
1717
+ const toBeSigned = tx != null ? tx : commitPsbtHex;
1718
+ if (!toBeSigned)
1719
+ throw new Error("missing tx");
1720
+ const signedResponse = yield signPsbt(toBeSigned, true, true);
1713
1721
  setCommitTxId(signedResponse == null ? void 0 : signedResponse.txId);
1714
1722
  return signedResponse == null ? void 0 : signedResponse.txId;
1715
1723
  } catch (e) {
@@ -1717,38 +1725,53 @@ var useInscriber = ({
1717
1725
  throw e;
1718
1726
  }
1719
1727
  });
1720
- const inscribe = useCallback(() => __async(void 0, null, function* () {
1721
- try {
1722
- setIsInscribing(true);
1723
- if (!content)
1724
- throw new Error("missing content");
1725
- if (!address2)
1726
- throw new Error("missing address");
1727
- if (!mimeType)
1728
- throw new Error("missing mimeType");
1729
- if (!commitTxId) {
1730
- console.log("commitTxId not found, getting commit psbt");
1731
- const signed = yield getCommitPsbt();
1732
- console.log({ signed });
1733
- yield handleSignCommit(signed.psbtBase64);
1728
+ const inscribe = useCallback(
1729
+ (_0) => __async(void 0, [_0], function* ({
1730
+ content: providedContent,
1731
+ mimeType: providedMimeType,
1732
+ ordinalAddress: providedAddress,
1733
+ commitTxId: providedCommitTxId
1734
+ }) {
1735
+ try {
1736
+ const inscribeContent = providedContent != null ? providedContent : content;
1737
+ const inscribeMimeType = providedMimeType != null ? providedMimeType : mimeType;
1738
+ const inscribeOutputAddress = providedAddress != null ? providedAddress : address2;
1739
+ let inscribeCommitTxId = providedCommitTxId != null ? providedCommitTxId : commitTxId;
1740
+ if (!inscribeContent)
1741
+ throw new Error("missing content");
1742
+ if (!inscribeMimeType)
1743
+ throw new Error("missing mimeType");
1744
+ if (!inscribeOutputAddress)
1745
+ throw new Error("missing address");
1746
+ setIsInscribing(true);
1747
+ if (!inscribeCommitTxId) {
1748
+ const signed = yield getCommitPsbt();
1749
+ inscribeCommitTxId = yield handleSignCommit(signed.psbtBase64);
1750
+ if (!inscribeCommitTxId)
1751
+ throw new Error("failed to broadcast commit");
1752
+ console.log("tempCommitTxId", inscribeCommitTxId);
1753
+ }
1754
+ yield delay(1e4);
1755
+ if (!inscribeCommitTxId)
1756
+ throw new Error("missing commitTxId");
1757
+ return yield axios3.post(`${inscribeApiUrl}/inscribe`, {
1758
+ content,
1759
+ mimeType,
1760
+ ordinalAddress: address2,
1761
+ commitTxId: inscribeCommitTxId
1762
+ }).then((res) => res.data).then((data) => {
1763
+ setInscriptionTxId(data);
1764
+ return data;
1765
+ });
1766
+ } catch (e) {
1767
+ console.error(e);
1768
+ throw e;
1769
+ } finally {
1770
+ setIsInscribing(false);
1734
1771
  }
1735
- yield delay(1e4);
1736
- return yield axios3.post(`${inscribeApiUrl}/inscribe`, {
1737
- content,
1738
- mimeType,
1739
- ordinalAddress: address2,
1740
- commitTxId
1741
- }).then((res) => res.data).then((data) => {
1742
- setInscriptionTxId(data);
1743
- return data;
1744
- });
1745
- } catch (e) {
1746
- console.error(e);
1747
- throw e;
1748
- } finally {
1749
- setIsInscribing(false);
1750
- }
1751
- }), [address2, commitTxId, content, mimeType]);
1772
+ }),
1773
+ [address2, commitTxId, content, mimeType]
1774
+ );
1752
1775
  const reset = () => {
1753
1776
  setContent("");
1754
1777
  setMimeType(MIME_TYPE_TEXT);
@@ -1761,11 +1784,6 @@ var useInscriber = ({
1761
1784
  setInscriptionTxId("");
1762
1785
  setPreviewUrl("");
1763
1786
  };
1764
- useEffect2(() => {
1765
- if (commitTxId && !inscriptionTxId) {
1766
- inscribe();
1767
- }
1768
- }, [commitTxId, inscribe, inscriptionTxId]);
1769
1787
  return {
1770
1788
  content,
1771
1789
  setContent,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnisat/lasereyes",
3
- "version": "0.0.17",
3
+ "version": "0.0.19",
4
4
  "sideEffects": false,
5
5
  "private": false,
6
6
  "license": "MIT",