@gardenfi/react-hooks 0.0.1-beta.6 → 0.0.1-beta.60
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.cjs +1 -1
- package/dist/index.js +6 -4
- package/dist/index2.cjs +1 -1
- package/dist/index2.js +114 -73
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +17 -13
- package/dist/index5.cjs +1 -0
- package/dist/index5.js +4 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/lib/context/gardenProvider.types.d.ts +12 -5
- package/dist/src/lib/hooks/useOrderbook.d.ts +2 -2
- package/dist/src/lib/utils.d.ts +3 -0
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index2.cjs"),r=require("./index3.cjs"),o=require("./index4.cjs");exports.GardenProvider=e.GardenProvider;exports.useGarden=e.useGarden;exports.useOrderbook=r.useOrderbook;exports.useSecretManager=o.useSecretManager;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index2.cjs"),r=require("./index3.cjs"),o=require("./index4.cjs"),t=require("@catalogfi/wallets");exports.GardenProvider=e.GardenProvider;exports.useGarden=e.useGarden;exports.useOrderbook=r.useOrderbook;exports.useSecretManager=o.useSecretManager;Object.defineProperty(exports,"BitcoinNetwork",{enumerable:!0,get:()=>t.BitcoinNetwork});
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { GardenProvider as o, useGarden as
|
|
2
|
-
import { useOrderbook as
|
|
1
|
+
import { GardenProvider as o, useGarden as t } from "./index2.js";
|
|
2
|
+
import { useOrderbook as d } from "./index3.js";
|
|
3
3
|
import { useSecretManager as m } from "./index4.js";
|
|
4
|
+
import { BitcoinNetwork as p } from "@catalogfi/wallets";
|
|
4
5
|
export {
|
|
6
|
+
p as BitcoinNetwork,
|
|
5
7
|
o as GardenProvider,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
t as useGarden,
|
|
9
|
+
d as useOrderbook,
|
|
8
10
|
m as useSecretManager
|
|
9
11
|
};
|
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"),W=require("wagmi"),p=require("./index4.cjs"),x=require("./index3.cjs"),d=require("@gardenfi/core"),i=require("@catalogfi/utils"),_=require("@gardenfi/orderbook"),h=require("@catalogfi/wallets"),G=require("@gardenfi/utils"),K=require("./index5.cjs"),m=t.createContext({}),A=({children:w,config:e})=>{const[l,O]=t.useState(),[c,C]=t.useState(),[a,f]=t.useState(),[E,U]=t.useState(),k=new d.Quote(e.quoteUrl),{data:n}=W.useWalletClient(),{initializeSecretManager:q}=p.useSecretManager(O),{orderbook:v}=x.useOrderbook(e.orderBookUrl,a,U),y=t.useMemo(()=>new h.BitcoinProvider(e.bitcoinNetwork,e.bitcoinRPCUrl),[e.bitcoinNetwork,e.bitcoinRPCUrl]),R=async o=>{if(!v||!n||!a)return i.Err("Orderbook or walletClient or auth not initialized");let r=c;if(!l||!r){const b=await q();if(b.error)return i.Err(b.error);const M=h.BitcoinWallet.fromPrivateKey(b.val.getMasterPrivKey(),y);r=new d.Garden({orderbookURl:e.orderBookUrl,secretManager:b.val,quote:k,auth:a,wallets:{evmWallet:n,btcWallet:M}}),C(r)}const s=await r.swap(o);if(s.error)return i.Err(s.error);if(_.isBitcoin(s.val.source_swap.chain))return i.Ok(s.val);const u=await d.switchOrAddNetwork(o.fromAsset.chain,n);if(u.error)return i.Err("Failed to switch network: "+u.error);const B=u.val.walletClient;console.log("newWalletClient :",B);const P=await new d.EvmRelay(s.val,e.orderBookUrl,a).init(B);if(P.error)return i.Err(P.error);const g={...s.val,source_swap:{...s.val.source_swap,initiate_tx_hash:P.val}};return i.Ok(g)},S=async({fromAsset:o,toAsset:r,amount:s,isExactOut:u=!1})=>await k.getQuote(K.constructOrderpair(o,r),s,u);return t.useEffect(()=>{if(!n)return;const o=new G.Siwe(new G.Url(e.orderBookUrl),n,{store:e.store});f(o)},[n]),t.useEffect(()=>{if(!l||!n||!v||!a)return;const o=h.BitcoinWallet.fromPrivateKey(l.getMasterPrivKey(),y),r=new d.Garden({orderbookURl:e.orderBookUrl,secretManager:l,quote:k,auth:a,wallets:{evmWallet:n,btcWallet:o}});C(r)},[l,n,v,a]),t.useEffect(()=>{if(!c)return;const o=c.execute();return c.on("onPendingOrdersChanged",r=>{U(r)}),()=>{(async()=>(await o)())()}},[c]),t.createElement(m.Provider,{value:{orderBookUrl:e.orderBookUrl,initializeSecretManager:q,orderBook:v,swap:R,pendingOrders:E,getQuote:S,secretManager:l,garden:c}},w)},F=()=>{const w=t.useContext(m);if(!w)throw new Error("useGarden must be used within a GardenProvider");return w};exports.GardenContext=m;exports.GardenProvider=A;exports.useGarden=F;
|
package/dist/index2.js
CHANGED
|
@@ -1,90 +1,131 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useWalletClient as
|
|
3
|
-
import { useSecretManager as
|
|
4
|
-
import { useOrderbook as
|
|
5
|
-
import { Quote as
|
|
6
|
-
import { Err as
|
|
7
|
-
import { isBitcoin as
|
|
8
|
-
import { BitcoinProvider as
|
|
9
|
-
import { Siwe as
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import y, { createContext as _, useState as m, useMemo as K, useEffect as k } from "react";
|
|
2
|
+
import { useWalletClient as A } from "wagmi";
|
|
3
|
+
import { useSecretManager as F } from "./index4.js";
|
|
4
|
+
import { useOrderbook as N } from "./index3.js";
|
|
5
|
+
import { Quote as Q, Garden as C, switchOrAddNetwork as q, EvmRelay as z } from "@gardenfi/core";
|
|
6
|
+
import { Err as c, Ok as B } from "@catalogfi/utils";
|
|
7
|
+
import { isBitcoin as j } from "@gardenfi/orderbook";
|
|
8
|
+
import { BitcoinProvider as D, BitcoinWallet as R } from "@catalogfi/wallets";
|
|
9
|
+
import { Siwe as H, Url as I } from "@gardenfi/utils";
|
|
10
|
+
import { constructOrderpair as J } from "./index5.js";
|
|
11
|
+
const O = _({}), ne = ({
|
|
12
|
+
children: d,
|
|
13
|
+
config: e
|
|
13
14
|
}) => {
|
|
14
|
-
const [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
const [s, G] = m(), [i, p] = m(), [a, M] = m(), [W, f] = m(), v = new Q(e.quoteUrl), { data: o } = A(), { initializeSecretManager: h } = F(G), { orderbook: u } = N(
|
|
16
|
+
e.orderBookUrl,
|
|
17
|
+
a,
|
|
18
|
+
f
|
|
19
|
+
), P = K(
|
|
20
|
+
() => new D(e.bitcoinNetwork, e.bitcoinRPCUrl),
|
|
21
|
+
[e.bitcoinNetwork, e.bitcoinRPCUrl]
|
|
22
|
+
), g = async (t) => {
|
|
23
|
+
if (!u || !o || !a)
|
|
24
|
+
return c("Orderbook or walletClient or auth not initialized");
|
|
25
|
+
let r = i;
|
|
26
|
+
if (!s || !r) {
|
|
27
|
+
const w = await h();
|
|
28
|
+
if (w.error) return c(w.error);
|
|
29
|
+
const S = R.fromPrivateKey(
|
|
30
|
+
w.val.getMasterPrivKey(),
|
|
31
|
+
P
|
|
32
|
+
);
|
|
33
|
+
r = new C({
|
|
34
|
+
orderbookURl: e.orderBookUrl,
|
|
35
|
+
secretManager: w.val,
|
|
36
|
+
quote: v,
|
|
37
|
+
auth: a,
|
|
38
|
+
wallets: {
|
|
39
|
+
evmWallet: o,
|
|
40
|
+
btcWallet: S
|
|
41
|
+
}
|
|
42
|
+
}), p(r);
|
|
23
43
|
}
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
26
|
-
if (
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
44
|
+
const n = await r.swap(t);
|
|
45
|
+
if (n.error) return c(n.error);
|
|
46
|
+
if (j(n.val.source_swap.chain)) return B(n.val);
|
|
47
|
+
const l = await q(
|
|
48
|
+
t.fromAsset.chain,
|
|
49
|
+
o
|
|
30
50
|
);
|
|
31
|
-
if (
|
|
32
|
-
return
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
if (l.error)
|
|
52
|
+
return c("Failed to switch network: " + l.error);
|
|
53
|
+
const U = l.val.walletClient;
|
|
54
|
+
console.log("newWalletClient :", U);
|
|
55
|
+
const b = await new z(n.val, e.orderBookUrl, a).init(U);
|
|
56
|
+
if (b.error) return c(b.error);
|
|
57
|
+
const E = {
|
|
58
|
+
...n.val,
|
|
59
|
+
source_swap: {
|
|
60
|
+
...n.val.source_swap,
|
|
61
|
+
initiate_tx_hash: b.val
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return B(E);
|
|
65
|
+
}, x = async ({
|
|
66
|
+
fromAsset: t,
|
|
67
|
+
toAsset: r,
|
|
68
|
+
amount: n,
|
|
69
|
+
isExactOut: l = !1
|
|
70
|
+
}) => await v.getQuote(
|
|
71
|
+
J(t, r),
|
|
72
|
+
n,
|
|
73
|
+
l
|
|
74
|
+
);
|
|
75
|
+
return k(() => {
|
|
43
76
|
if (!o) return;
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
77
|
+
const t = new H(new I(e.orderBookUrl), o, {
|
|
78
|
+
store: e.store
|
|
79
|
+
});
|
|
80
|
+
M(t);
|
|
81
|
+
}, [o]), k(() => {
|
|
82
|
+
if (!s || !o || !u || !a) return;
|
|
83
|
+
const t = R.fromPrivateKey(
|
|
84
|
+
s.getMasterPrivKey(),
|
|
85
|
+
P
|
|
86
|
+
), r = new C({
|
|
87
|
+
orderbookURl: e.orderBookUrl,
|
|
88
|
+
secretManager: s,
|
|
89
|
+
quote: v,
|
|
55
90
|
auth: a,
|
|
56
91
|
wallets: {
|
|
57
|
-
evmWallet:
|
|
58
|
-
btcWallet:
|
|
92
|
+
evmWallet: o,
|
|
93
|
+
btcWallet: t
|
|
59
94
|
}
|
|
60
95
|
});
|
|
61
|
-
|
|
62
|
-
}, [o,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
96
|
+
p(r);
|
|
97
|
+
}, [s, o, u, a]), k(() => {
|
|
98
|
+
if (!i) return;
|
|
99
|
+
const t = i.execute();
|
|
100
|
+
return i.on("onPendingOrdersChanged", (r) => {
|
|
101
|
+
f(r);
|
|
102
|
+
}), () => {
|
|
103
|
+
(async () => (await t)())();
|
|
104
|
+
};
|
|
105
|
+
}, [i]), /* @__PURE__ */ y.createElement(
|
|
106
|
+
O.Provider,
|
|
68
107
|
{
|
|
69
108
|
value: {
|
|
70
|
-
orderBookUrl:
|
|
71
|
-
initializeSecretManager:
|
|
72
|
-
orderBook:
|
|
73
|
-
swap:
|
|
74
|
-
|
|
75
|
-
|
|
109
|
+
orderBookUrl: e.orderBookUrl,
|
|
110
|
+
initializeSecretManager: h,
|
|
111
|
+
orderBook: u,
|
|
112
|
+
swap: g,
|
|
113
|
+
pendingOrders: W,
|
|
114
|
+
getQuote: x,
|
|
115
|
+
secretManager: s,
|
|
116
|
+
garden: i
|
|
76
117
|
}
|
|
77
118
|
},
|
|
78
|
-
|
|
119
|
+
d
|
|
79
120
|
);
|
|
80
|
-
},
|
|
81
|
-
const
|
|
82
|
-
if (!
|
|
121
|
+
}, ae = () => {
|
|
122
|
+
const d = y.useContext(O);
|
|
123
|
+
if (!d)
|
|
83
124
|
throw new Error("useGarden must be used within a GardenProvider");
|
|
84
|
-
return
|
|
125
|
+
return d;
|
|
85
126
|
};
|
|
86
127
|
export {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
128
|
+
O as GardenContext,
|
|
129
|
+
ne as GardenProvider,
|
|
130
|
+
ae as useGarden
|
|
90
131
|
};
|
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 i=require("@gardenfi/orderbook"),s=require("react"),b=require("wagmi"),l=(e,r,u)=>{const{data:t}=b.useWalletClient(),[a,c]=s.useState();return s.useEffect(()=>{if(!t||!e||!r)return;const n=new i.Orderbook({url:e,walletClient:t,auth:r});c(n),n.fetchOrders(!0,!0,{per_page:500}).then(o=>{!o.error&&o.val&&u(o.val.data)})},[t,e,r]),{orderbook:a}};exports.useOrderbook=l;
|
package/dist/index3.js
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { Orderbook as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { useWalletClient as
|
|
4
|
-
const
|
|
5
|
-
const { data:
|
|
6
|
-
return
|
|
7
|
-
if (!
|
|
8
|
-
const
|
|
1
|
+
import { Orderbook as i } from "@gardenfi/orderbook";
|
|
2
|
+
import { useState as l, useEffect as u } from "react";
|
|
3
|
+
import { useWalletClient as c } from "wagmi";
|
|
4
|
+
const d = (e, t, a) => {
|
|
5
|
+
const { data: r } = c(), [f, s] = l();
|
|
6
|
+
return u(() => {
|
|
7
|
+
if (!r || !e || !t) return;
|
|
8
|
+
const n = new i({
|
|
9
9
|
url: e,
|
|
10
|
-
walletClient:
|
|
11
|
-
auth:
|
|
10
|
+
walletClient: r,
|
|
11
|
+
auth: t
|
|
12
12
|
});
|
|
13
|
-
n(
|
|
14
|
-
|
|
13
|
+
s(n), n.fetchOrders(!0, !0, {
|
|
14
|
+
per_page: 500
|
|
15
|
+
}).then((o) => {
|
|
16
|
+
!o.error && o.val && a(o.val.data);
|
|
17
|
+
});
|
|
18
|
+
}, [r, e, t]), { orderbook: f };
|
|
15
19
|
};
|
|
16
20
|
export {
|
|
17
|
-
|
|
21
|
+
d as useOrderbook
|
|
18
22
|
};
|
package/dist/index5.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=(r,c)=>`${r.chain}:${r.atomicSwapAddress}::${c.chain}:${c.atomicSwapAddress}`;exports.constructOrderpair=a;
|
package/dist/index5.js
ADDED
package/dist/src/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AsyncResult } from '@catalogfi/utils';
|
|
2
2
|
import { BitcoinNetwork } from '@catalogfi/wallets';
|
|
3
|
-
import {
|
|
4
|
-
import { IOrderbook, MatchedOrder } from '@gardenfi/orderbook';
|
|
3
|
+
import { IGardenJS, ISecretManager, QuoteResponse, SecretManager, SwapParams } from '@gardenfi/core';
|
|
4
|
+
import { Asset, IOrderbook, MatchedOrder } from '@gardenfi/orderbook';
|
|
5
5
|
import { IStore } from '@gardenfi/utils';
|
|
6
6
|
|
|
7
7
|
export type GardenContextType = {
|
|
@@ -14,9 +14,10 @@ export type GardenContextType = {
|
|
|
14
14
|
* @returns {AsyncResult<string, string>} - create order ID.
|
|
15
15
|
*/
|
|
16
16
|
swap?: (params: SwapParams) => AsyncResult<MatchedOrder, string>;
|
|
17
|
-
pendingOrders?:
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
pendingOrders?: MatchedOrder[];
|
|
18
|
+
getQuote?: (params: QuoteParams) => AsyncResult<QuoteResponse, string>;
|
|
19
|
+
secretManager?: ISecretManager;
|
|
20
|
+
garden?: IGardenJS;
|
|
20
21
|
};
|
|
21
22
|
export type GardenProviderProps = {
|
|
22
23
|
children: React.ReactNode;
|
|
@@ -28,3 +29,9 @@ export type GardenProviderProps = {
|
|
|
28
29
|
bitcoinRPCUrl?: string;
|
|
29
30
|
};
|
|
30
31
|
};
|
|
32
|
+
export type QuoteParams = {
|
|
33
|
+
fromAsset: Asset;
|
|
34
|
+
toAsset: Asset;
|
|
35
|
+
amount: number;
|
|
36
|
+
isExactOut?: boolean;
|
|
37
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IOrderbook } from '@gardenfi/orderbook';
|
|
1
|
+
import { IOrderbook, MatchedOrder } from '@gardenfi/orderbook';
|
|
2
2
|
import { IAuth } from '@gardenfi/utils';
|
|
3
3
|
|
|
4
|
-
export declare const useOrderbook: (orderBookUrl: string, auth: IAuth | undefined) => {
|
|
4
|
+
export declare const useOrderbook: (orderBookUrl: string, auth: IAuth | undefined, setPendingOrders: React.Dispatch<React.SetStateAction<MatchedOrder[] | 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.60",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@catalogfi/utils": "^0.1.6",
|
|
30
|
-
"@catalogfi/wallets": "^0.2.
|
|
31
|
-
"@gardenfi/core": "^0.2.0-beta.
|
|
32
|
-
"@gardenfi/orderbook": "^0.2.0-beta.
|
|
33
|
-
"@gardenfi/utils": "^0.0.1-beta.
|
|
30
|
+
"@catalogfi/wallets": "^0.2.50",
|
|
31
|
+
"@gardenfi/core": "^0.2.0-beta.41",
|
|
32
|
+
"@gardenfi/orderbook": "^0.2.0-beta.14",
|
|
33
|
+
"@gardenfi/utils": "^0.0.1-beta.18",
|
|
34
34
|
"react": "^18.3.1",
|
|
35
35
|
"viem": "^2.21.15",
|
|
36
36
|
"wagmi": "^2.12.16"
|