@gardenfi/react-hooks 0.0.1-beta.3 → 0.0.1-beta.6
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 +72 -77
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +14 -16
- package/dist/src/lib/context/gardenProvider.types.d.ts +5 -1
- package/dist/src/lib/hooks/useOrderbook.d.ts +2 -2
- 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 e=require("react"),M=require("wagmi"),R=require("./index4.cjs"),g=require("./index3.cjs"),d=require("@gardenfi/core"),s=require("@catalogfi/utils"),W=require("@gardenfi/orderbook"),E=require("@catalogfi/wallets"),S=require("@gardenfi/utils"),w=e.createContext({}),x=({children:c,config:r})=>{const[n,q]=e.useState(),[a,B]=e.useState(),[u,C]=e.useState(),[G,U]=e.useState(),[m,O]=e.useState(0),{data:o}=M.useWalletClient(),{initializeSecretManager:k}=R.useSecretManager(q),{orderbook:l}=g.useOrderbook(r.orderBookUrl,u),v=new d.Quote(r.quoteUrl),b=e.useMemo(()=>new E.BitcoinProvider(r.bitcoinNetwork,r.bitcoinRPCUrl),[r.bitcoinNetwork,r.bitcoinRPCUrl]),y=async t=>{if(!a||!l||!o||!u)return s.Err("Garden not initialized");if(!n){const h=await k();if(h.error)return s.Err(h.error)}const i=await a.swap(t);if(i.error)return s.Err(i.error);if(W.isBitcoin(i.val.source_swap.chain))return s.Ok(i.val);const f=await d.switchOrAddNetwork(t.fromAsset.chain,o);if(f.error)return s.Err("Failed to switch network: "+f.error);const P=await new d.EvmRelay(i.val,r.orderBookUrl,u).init(o);return P.error?s.Err(P.error):s.Ok(i.val)};return e.useEffect(()=>{if(!o)return;const t=new S.Siwe(new S.Url(r.orderBookUrl),o,{store:r.store});C(t)},[o]),e.useEffect(()=>{if(!n)return;const t=E.BitcoinWallet.fromPrivateKey(n.getMasterPrivKey(),b);U(t)},[n,b]),e.useEffect(()=>{if(!n||!o||!l||!u)return;const t=new d.Garden({orderbookURl:r.orderBookUrl,secretManager:n,quote:v,auth:u,wallets:{evmWallet:o,btcWallet:G}});B(t)},[n,o,l]),e.useEffect(()=>{a&&(a.execute(),a.on("onPendingOrdersChanged",t=>{O(t.length)}))},[a]),e.createElement(w.Provider,{value:{orderBookUrl:r.orderBookUrl,initializeSecretManager:k,orderBook:l,swap:y,pendingOrdersCount:m,quote:v}},c)},p=()=>{const c=e.useContext(w);if(!c)throw new Error("useGarden must be used within a GardenProvider");return c};exports.GardenContext=w;exports.GardenProvider=x;exports.useGarden=p;
|
package/dist/index2.js
CHANGED
|
@@ -1,95 +1,90 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useWalletClient as
|
|
3
|
-
import { useSecretManager as
|
|
4
|
-
import { useOrderbook as
|
|
5
|
-
import { Garden as
|
|
6
|
-
import { Err as
|
|
7
|
-
import { isBitcoin as
|
|
8
|
-
import { BitcoinProvider as
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import b, { createContext as W, useState as s, useMemo as x, useEffect as u } from "react";
|
|
2
|
+
import { useWalletClient as E } from "wagmi";
|
|
3
|
+
import { useSecretManager as S } from "./index4.js";
|
|
4
|
+
import { useOrderbook as g } from "./index3.js";
|
|
5
|
+
import { Quote as A, Garden as N, switchOrAddNetwork as q, EvmRelay as z } from "@gardenfi/core";
|
|
6
|
+
import { Err as l, Ok as h } from "@catalogfi/utils";
|
|
7
|
+
import { isBitcoin as K } from "@gardenfi/orderbook";
|
|
8
|
+
import { BitcoinProvider as F, BitcoinWallet as Q } from "@catalogfi/wallets";
|
|
9
|
+
import { Siwe as _, Url as j } from "@gardenfi/utils";
|
|
10
|
+
const B = W({}), $ = ({
|
|
11
|
+
children: c,
|
|
11
12
|
config: r
|
|
12
13
|
}) => {
|
|
13
|
-
const [
|
|
14
|
-
() => new
|
|
14
|
+
const [o, P] = s(), [n, U] = s(), [a, C] = s(), [G, R] = s(), [y, M] = s(0), { data: t } = E(), { initializeSecretManager: w } = S(P), { orderbook: d } = g(r.orderBookUrl, a), m = new A(r.quoteUrl), v = x(
|
|
15
|
+
() => new F(r.bitcoinNetwork, r.bitcoinRPCUrl),
|
|
15
16
|
[r.bitcoinNetwork, r.bitcoinRPCUrl]
|
|
16
|
-
),
|
|
17
|
-
if (!
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let e = await n.getOrder(i, !0);
|
|
23
|
-
for (let B = 0; B < w; B++) {
|
|
24
|
-
if (e = await n.getOrder(i, !0), e.error) {
|
|
25
|
-
if (!e.error.includes("result is undefined"))
|
|
26
|
-
return m(e.error);
|
|
27
|
-
} else if (e.val && e.val.create_order.create_id === i)
|
|
28
|
-
break;
|
|
29
|
-
await K(c);
|
|
17
|
+
), O = async (e) => {
|
|
18
|
+
if (!n || !d || !t || !a)
|
|
19
|
+
return l("Garden not initialized");
|
|
20
|
+
if (!o) {
|
|
21
|
+
const p = await w();
|
|
22
|
+
if (p.error) return l(p.error);
|
|
30
23
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
)
|
|
38
|
-
|
|
24
|
+
const i = await n.swap(e);
|
|
25
|
+
if (i.error) return l(i.error);
|
|
26
|
+
if (K(i.val.source_swap.chain)) return h(i.val);
|
|
27
|
+
const f = await q(
|
|
28
|
+
e.fromAsset.chain,
|
|
29
|
+
t
|
|
30
|
+
);
|
|
31
|
+
if (f.error)
|
|
32
|
+
return l("Failed to switch network: " + f.error);
|
|
33
|
+
const k = await new z(i.val, r.orderBookUrl, a).init(t);
|
|
34
|
+
return k.error ? l(k.error) : h(i.val);
|
|
39
35
|
};
|
|
40
|
-
return
|
|
36
|
+
return u(() => {
|
|
41
37
|
if (!t) return;
|
|
42
|
-
const
|
|
43
|
-
t.getMasterPrivKey(),
|
|
44
|
-
x
|
|
45
|
-
);
|
|
46
|
-
U(o);
|
|
47
|
-
}, [t, x]), v(() => {
|
|
48
|
-
if (!t || !s || !n) return;
|
|
49
|
-
const o = new R(n, r.orderBookUrl, t, {
|
|
38
|
+
const e = new _(new j(r.orderBookUrl), t, {
|
|
50
39
|
store: r.store
|
|
51
40
|
});
|
|
52
|
-
C(
|
|
53
|
-
}, [t
|
|
54
|
-
if (!
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}, [
|
|
74
|
-
|
|
41
|
+
C(e);
|
|
42
|
+
}, [t]), u(() => {
|
|
43
|
+
if (!o) return;
|
|
44
|
+
const e = Q.fromPrivateKey(
|
|
45
|
+
o.getMasterPrivKey(),
|
|
46
|
+
v
|
|
47
|
+
);
|
|
48
|
+
R(e);
|
|
49
|
+
}, [o, v]), u(() => {
|
|
50
|
+
if (!o || !t || !d || !a) return;
|
|
51
|
+
const e = new N({
|
|
52
|
+
orderbookURl: r.orderBookUrl,
|
|
53
|
+
secretManager: o,
|
|
54
|
+
quote: m,
|
|
55
|
+
auth: a,
|
|
56
|
+
wallets: {
|
|
57
|
+
evmWallet: t,
|
|
58
|
+
btcWallet: G
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
U(e);
|
|
62
|
+
}, [o, t, d]), u(() => {
|
|
63
|
+
n && (n.execute(), n.on("onPendingOrdersChanged", (e) => {
|
|
64
|
+
M(e.length);
|
|
65
|
+
}));
|
|
66
|
+
}, [n]), /* @__PURE__ */ b.createElement(
|
|
67
|
+
B.Provider,
|
|
75
68
|
{
|
|
76
69
|
value: {
|
|
77
70
|
orderBookUrl: r.orderBookUrl,
|
|
78
|
-
initializeSecretManager:
|
|
79
|
-
orderBook:
|
|
80
|
-
swap:
|
|
71
|
+
initializeSecretManager: w,
|
|
72
|
+
orderBook: d,
|
|
73
|
+
swap: O,
|
|
74
|
+
pendingOrdersCount: y,
|
|
75
|
+
quote: m
|
|
81
76
|
}
|
|
82
77
|
},
|
|
83
|
-
|
|
78
|
+
c
|
|
84
79
|
);
|
|
85
|
-
},
|
|
86
|
-
const
|
|
87
|
-
if (!
|
|
80
|
+
}, rr = () => {
|
|
81
|
+
const c = b.useContext(B);
|
|
82
|
+
if (!c)
|
|
88
83
|
throw new Error("useGarden must be used within a GardenProvider");
|
|
89
|
-
return
|
|
84
|
+
return c;
|
|
90
85
|
};
|
|
91
86
|
export {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
B as GardenContext,
|
|
88
|
+
$ as GardenProvider,
|
|
89
|
+
rr as useGarden
|
|
95
90
|
};
|
package/dist/index3.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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||!r)return;const u=new c.Orderbook({url:e,walletClient:o,auth:r});n(u)},[o,e]),{orderbook:s}};exports.useOrderbook=i;
|
package/dist/index3.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import { Orderbook as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { useWalletClient as
|
|
4
|
-
const
|
|
5
|
-
const { data:
|
|
6
|
-
return
|
|
7
|
-
if (!e || !
|
|
8
|
-
const
|
|
9
|
-
url:
|
|
10
|
-
walletClient:
|
|
11
|
-
|
|
12
|
-
store: o
|
|
13
|
-
}
|
|
1
|
+
import { Orderbook as f } from "@gardenfi/orderbook";
|
|
2
|
+
import { useState as i, useEffect as m } from "react";
|
|
3
|
+
import { useWalletClient as u } from "wagmi";
|
|
4
|
+
const a = (e, o) => {
|
|
5
|
+
const { data: t } = u(), [r, n] = i();
|
|
6
|
+
return m(() => {
|
|
7
|
+
if (!t || !e || !o) return;
|
|
8
|
+
const s = new f({
|
|
9
|
+
url: e,
|
|
10
|
+
walletClient: t,
|
|
11
|
+
auth: o
|
|
14
12
|
});
|
|
15
|
-
s
|
|
16
|
-
}, [
|
|
13
|
+
n(s);
|
|
14
|
+
}, [t, e]), { orderbook: r };
|
|
17
15
|
};
|
|
18
16
|
export {
|
|
19
|
-
|
|
17
|
+
a as useOrderbook
|
|
20
18
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsyncResult } from '@catalogfi/utils';
|
|
2
2
|
import { BitcoinNetwork } from '@catalogfi/wallets';
|
|
3
|
-
import { SecretManager, SwapParams } from '@gardenfi/core';
|
|
3
|
+
import { IQuote, SecretManager, SwapParams } from '@gardenfi/core';
|
|
4
4
|
import { IOrderbook, MatchedOrder } from '@gardenfi/orderbook';
|
|
5
5
|
import { IStore } from '@gardenfi/utils';
|
|
6
6
|
|
|
@@ -14,11 +14,15 @@ export type GardenContextType = {
|
|
|
14
14
|
* @returns {AsyncResult<string, string>} - create order ID.
|
|
15
15
|
*/
|
|
16
16
|
swap?: (params: SwapParams) => AsyncResult<MatchedOrder, string>;
|
|
17
|
+
pendingOrders?: number;
|
|
18
|
+
quote?: IQuote;
|
|
19
|
+
pendingOrdersCount?: number;
|
|
17
20
|
};
|
|
18
21
|
export type GardenProviderProps = {
|
|
19
22
|
children: React.ReactNode;
|
|
20
23
|
config: {
|
|
21
24
|
orderBookUrl: string;
|
|
25
|
+
quoteUrl: string;
|
|
22
26
|
store: IStore;
|
|
23
27
|
bitcoinNetwork: BitcoinNetwork;
|
|
24
28
|
bitcoinRPCUrl?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IOrderbook } from '@gardenfi/orderbook';
|
|
2
|
-
import {
|
|
2
|
+
import { IAuth } from '@gardenfi/utils';
|
|
3
3
|
|
|
4
|
-
export declare const useOrderbook: (orderBookUrl: string,
|
|
4
|
+
export declare const useOrderbook: (orderBookUrl: string, auth: IAuth | undefined) => {
|
|
5
5
|
orderbook: IOrderbook | undefined;
|
|
6
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.6",
|
|
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.5",
|
|
32
|
+
"@gardenfi/orderbook": "^0.2.0-beta.6",
|
|
33
|
+
"@gardenfi/utils": "^0.0.1-beta.13",
|
|
34
34
|
"react": "^18.3.1",
|
|
35
35
|
"viem": "^2.21.15",
|
|
36
36
|
"wagmi": "^2.12.16"
|