@gardenfi/react-hooks 0.0.1-beta.1 → 0.0.1-beta.3
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/index2.cjs +1 -1
- package/dist/index2.js +24 -22
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +14 -11
- package/dist/src/lib/hooks/useOrderbook.d.ts +2 -1
- package/package.json +4 -4
package/dist/index2.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),q=require("wagmi"),C=require("./index4.cjs"),M=require("./index3.cjs"),G=require("@gardenfi/core"),a=require("@catalogfi/utils"),p=require("@gardenfi/orderbook"),P=require("@catalogfi/wallets"),O=t.createContext({}),y=({children:w,config:r})=>{const[o,S]=t.useState(),[c,E]=t.useState(),[f,g]=t.useState(),{data:i}=q.useWalletClient(),{initializeSecretManager:h}=C.useSecretManager(S),{orderbook:s}=M.useOrderbook(r.orderBookUrl,r.store),B=t.useMemo(()=>new P.BitcoinProvider(r.bitcoinNetwork,r.bitcoinRPCUrl),[r.bitcoinNetwork,r.bitcoinRPCUrl]),m=async n=>{if(!c||!s||!o||!i)return a.Err("Garden not initialized");const b=await c.swap(n);if(b.error)return a.Err(b.error);const u=b.val,v=20,l=1e3;let e=await s.getOrder(u,!0);for(let x=0;x<v;x++){if(e=await s.getOrder(u,!0),e.error){if(!e.error.includes("result is undefined"))return a.Err(e.error)}else if(e.val&&e.val.create_order.create_id===u)break;await a.sleep(l)}if(p.isBitcoin(e.val.source_swap.chain))return a.Ok(e.val);const d=await new G.OrderExecutor(e.val,r.orderBookUrl,o,{store:r.store}).init(i,0);return d.error?a.Err(d.error):a.Ok(e.val)};return t.useEffect(()=>{if(!o)return;const n=P.BitcoinWallet.fromPrivateKey(o.getMasterPrivKey(),B);g(n)},[o,B]),t.useEffect(()=>{if(!o||!i||!s)return;const n=new G.Garden(s,r.orderBookUrl,o,{store:r.store});E(n)},[o,i,s]),t.useEffect(()=>{if(!c)return;let n;return(async()=>{const u=async v=>{const l=v.getOrder(),e=p.isBitcoin(l.source_swap.chain)?f:i,k=p.isBitcoin(l.destination_swap.chain)?f:i;if(!e||!k)return;console.log("executing order:",l.create_order.create_id);const d=await v.execute({wallets:{source:e,destination:k}});console.log("execute result :",d.val),console.log("execute error: ",d.error)};n=await c.subscribeOrders(u)})(),()=>{n()}},[c]),t.createElement(O.Provider,{value:{orderBookUrl:r.orderBookUrl,initializeSecretManager:h,orderBook:s,swap:m}},w)},U=()=>{const w=t.useContext(O);if(!w)throw new Error("useGarden must be used within a GardenProvider");return w};exports.GardenContext=O;exports.GardenProvider=y;exports.useGarden=U;
|
package/dist/index2.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import h, { createContext as
|
|
2
|
-
import { useWalletClient as
|
|
1
|
+
import h, { createContext as S, useState as b, useMemo as W, useEffect as v } from "react";
|
|
2
|
+
import { useWalletClient as g } from "wagmi";
|
|
3
3
|
import { useSecretManager as y } from "./index4.js";
|
|
4
4
|
import { useOrderbook as E } from "./index3.js";
|
|
5
5
|
import { Garden as R, OrderExecutor as z } from "@gardenfi/core";
|
|
6
6
|
import { Err as m, sleep as K, Ok as O } from "@catalogfi/utils";
|
|
7
|
-
import { isBitcoin as
|
|
7
|
+
import { isBitcoin as f } from "@gardenfi/orderbook";
|
|
8
8
|
import { BitcoinProvider as N, BitcoinWallet as D } from "@catalogfi/wallets";
|
|
9
|
-
const P =
|
|
9
|
+
const P = S({}), L = ({
|
|
10
10
|
children: u,
|
|
11
11
|
config: r
|
|
12
12
|
}) => {
|
|
13
|
-
const [t, G] =
|
|
13
|
+
const [t, G] = b(), [a, C] = b(), [k, U] = b(), { data: s } = g(), { initializeSecretManager: _ } = y(G), { orderbook: n } = E(r.orderBookUrl, r.store), x = W(
|
|
14
14
|
() => new N(r.bitcoinNetwork, r.bitcoinRPCUrl),
|
|
15
15
|
[r.bitcoinNetwork, r.bitcoinRPCUrl]
|
|
16
|
-
),
|
|
17
|
-
if (!
|
|
16
|
+
), M = async (o) => {
|
|
17
|
+
if (!a || !n || !t || !s)
|
|
18
18
|
return m("Garden not initialized");
|
|
19
|
-
const d = await
|
|
19
|
+
const d = await a.swap(o);
|
|
20
20
|
if (d.error) return m(d.error);
|
|
21
21
|
const i = d.val, w = 20, c = 1e3;
|
|
22
22
|
let e = await n.getOrder(i, !0);
|
|
@@ -28,32 +28,34 @@ const P = M({}), L = ({
|
|
|
28
28
|
break;
|
|
29
29
|
await K(c);
|
|
30
30
|
}
|
|
31
|
-
if (
|
|
31
|
+
if (f(e.val.source_swap.chain)) return O(e.val);
|
|
32
32
|
const l = await new z(
|
|
33
33
|
e.val,
|
|
34
34
|
r.orderBookUrl,
|
|
35
35
|
t,
|
|
36
36
|
{ store: r.store }
|
|
37
|
-
).init(
|
|
37
|
+
).init(s, 0);
|
|
38
38
|
return l.error ? m(l.error) : O(e.val);
|
|
39
39
|
};
|
|
40
|
-
return
|
|
40
|
+
return v(() => {
|
|
41
41
|
if (!t) return;
|
|
42
42
|
const o = D.fromPrivateKey(
|
|
43
43
|
t.getMasterPrivKey(),
|
|
44
44
|
x
|
|
45
45
|
);
|
|
46
|
+
U(o);
|
|
47
|
+
}, [t, x]), v(() => {
|
|
48
|
+
if (!t || !s || !n) return;
|
|
49
|
+
const o = new R(n, r.orderBookUrl, t, {
|
|
50
|
+
store: r.store
|
|
51
|
+
});
|
|
46
52
|
C(o);
|
|
47
|
-
}, [t,
|
|
48
|
-
if (!
|
|
49
|
-
const o = new R(n, r.orderBookUrl, t);
|
|
50
|
-
g(o);
|
|
51
|
-
}, [t, a, n]), b(() => {
|
|
52
|
-
if (!s) return;
|
|
53
|
+
}, [t, s, n]), v(() => {
|
|
54
|
+
if (!a) return;
|
|
53
55
|
let o;
|
|
54
56
|
return (async () => {
|
|
55
57
|
const i = async (w) => {
|
|
56
|
-
const c = w.getOrder(), e =
|
|
58
|
+
const c = w.getOrder(), e = f(c.source_swap.chain) ? k : s, p = f(c.destination_swap.chain) ? k : s;
|
|
57
59
|
if (!e || !p) return;
|
|
58
60
|
console.log("executing order:", c.create_order.create_id);
|
|
59
61
|
const l = await w.execute({
|
|
@@ -64,18 +66,18 @@ const P = M({}), L = ({
|
|
|
64
66
|
});
|
|
65
67
|
console.log("execute result :", l.val), console.log("execute error: ", l.error);
|
|
66
68
|
};
|
|
67
|
-
o = await
|
|
69
|
+
o = await a.subscribeOrders(i);
|
|
68
70
|
})(), () => {
|
|
69
71
|
o();
|
|
70
72
|
};
|
|
71
|
-
}, [
|
|
73
|
+
}, [a]), /* @__PURE__ */ h.createElement(
|
|
72
74
|
P.Provider,
|
|
73
75
|
{
|
|
74
76
|
value: {
|
|
75
77
|
orderBookUrl: r.orderBookUrl,
|
|
76
|
-
initializeSecretManager:
|
|
78
|
+
initializeSecretManager: _,
|
|
77
79
|
orderBook: n,
|
|
78
|
-
swap:
|
|
80
|
+
swap: M
|
|
79
81
|
}
|
|
80
82
|
},
|
|
81
83
|
u
|
package/dist/index3.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@gardenfi/orderbook"),t=require("react"),b=require("wagmi"),i=(e,r)=>{const{data:o}=b.useWalletClient(),[s,n]=t.useState();return t.useEffect(()=>{if(!o||!e)return;const u=new c.Orderbook({url:e,walletClient:o,opts:{store:r}});n(u)},[o,e]),{orderbook:s}};exports.useOrderbook=i;
|
package/dist/index3.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import { Orderbook as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { useWalletClient as
|
|
4
|
-
const
|
|
5
|
-
const { data: e } =
|
|
6
|
-
return
|
|
1
|
+
import { Orderbook as u } from "@gardenfi/orderbook";
|
|
2
|
+
import { useState as f, useEffect as i } from "react";
|
|
3
|
+
import { useWalletClient as m } from "wagmi";
|
|
4
|
+
const l = (t, o) => {
|
|
5
|
+
const { data: e } = m(), [r, s] = f();
|
|
6
|
+
return i(() => {
|
|
7
7
|
if (!e || !t) return;
|
|
8
|
-
const n = new
|
|
8
|
+
const n = new u({
|
|
9
9
|
url: t,
|
|
10
|
-
walletClient: e
|
|
10
|
+
walletClient: e,
|
|
11
|
+
opts: {
|
|
12
|
+
store: o
|
|
13
|
+
}
|
|
11
14
|
});
|
|
12
|
-
|
|
13
|
-
}, [e, t]), { orderbook:
|
|
15
|
+
s(n);
|
|
16
|
+
}, [e, t]), { orderbook: r };
|
|
14
17
|
};
|
|
15
18
|
export {
|
|
16
|
-
|
|
19
|
+
l as useOrderbook
|
|
17
20
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IOrderbook } from '@gardenfi/orderbook';
|
|
2
|
+
import { IStore } from '@gardenfi/utils';
|
|
2
3
|
|
|
3
|
-
export declare const useOrderbook: (orderBookUrl: string) => {
|
|
4
|
+
export declare const useOrderbook: (orderBookUrl: string, store: IStore) => {
|
|
4
5
|
orderbook: IOrderbook | undefined;
|
|
5
6
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/react-hooks",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@catalogfi/utils": "^0.1.6",
|
|
30
30
|
"@catalogfi/wallets": "^0.2.49",
|
|
31
|
-
"@gardenfi/core": "^0.2.0-beta.
|
|
32
|
-
"@gardenfi/orderbook": "^0.2.0-beta.
|
|
33
|
-
"@gardenfi/utils": "^0.0.1-beta.
|
|
31
|
+
"@gardenfi/core": "^0.2.0-beta.3",
|
|
32
|
+
"@gardenfi/orderbook": "^0.2.0-beta.3",
|
|
33
|
+
"@gardenfi/utils": "^0.0.1-beta.3",
|
|
34
34
|
"react": "^18.3.1",
|
|
35
35
|
"viem": "^2.21.15",
|
|
36
36
|
"wagmi": "^2.12.16"
|