@gardenfi/react-hooks 0.0.1-beta.67 → 0.0.1-beta.69
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
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),z=require("wagmi"),A=require("./index4.cjs"),K=require("./index3.cjs"),d=require("@gardenfi/core"),n=require("@catalogfi/utils"),M=require("@gardenfi/orderbook"),v=require("@catalogfi/wallets"),S=require("@gardenfi/utils"),Q=require("./index5.cjs"),y=i.createContext({isExecuting:!1}),$=({children:b,config:r})=>{const[l,q]=i.useState(),[c,B]=i.useState(),[s,_]=i.useState(),[O,C]=i.useState(),N=!!(l&&c&&s&&O),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),z=require("wagmi"),A=require("./index4.cjs"),K=require("./index3.cjs"),d=require("@gardenfi/core"),n=require("@catalogfi/utils"),M=require("@gardenfi/orderbook"),v=require("@catalogfi/wallets"),S=require("@gardenfi/utils"),Q=require("./index5.cjs"),y=i.createContext({isExecuting:!1}),$=({children:b,config:r})=>{const[l,q]=i.useState(),[c,B]=i.useState(),[s,_]=i.useState(),[O,C]=i.useState(),N=!!(l&&c&&s&&O),h=new d.Quote(r.quoteUrl),{data:a}=z.useWalletClient(),{initializeSecretManager:U}=A.useSecretManager(q),{orderbook:m}=K.useOrderbook(r.orderBookUrl,s,C),f=r.network===v.BitcoinNetwork.Mainnet?"mainnet":r.network===v.BitcoinNetwork.Testnet?"testnet":void 0,W=r.blockNumberFetcherUrl&&f?{url:r.blockNumberFetcherUrl,network:f}:void 0,P=i.useMemo(()=>new v.BitcoinProvider(r.network,r.bitcoinRPCUrl),[r.network,r.bitcoinRPCUrl]),p=async()=>{if(!a||!s)return n.Err("WalletClient or auth not initialized");const e=await U();if(e.error)return n.Err(e.error);const o=v.BitcoinWallet.fromPrivateKey(e.val.getMasterPrivKey(),P),t=new d.Garden({orderbookURl:r.orderBookUrl,secretManager:e.val,quote:h,auth:s,wallets:{evmWallet:a,btcWallet:o},blockNumberFetcher:W});return B(t),n.Ok(t)},g=async e=>{if(!m||!a||!s)return n.Err("Orderbook or walletClient or auth not initialized");let o=c;if(!l||!o){const R=await p();if(R.error)return n.Err(R.error);o=R.val}const t=await o.swap(e);if(t.error)return n.Err(t.error);if(M.isBitcoin(t.val.source_swap.chain))return n.Ok(t.val);const u=await d.switchOrAddNetwork(e.fromAsset.chain,a);if(u.error)return n.Err("Failed to switch network: "+u.error);const G=u.val.walletClient,w=await new d.EvmRelay(t.val,r.orderBookUrl,s).init(G);if(w.error)return n.Err(w.error);const k={...t.val,source_swap:{...t.val.source_swap,initiate_tx_hash:w.val}};return n.Ok(k)},x=async e=>{if(!a||!s)return n.Err("Orderbook or walletClient or auth not initialized");let o=c;if(!l||!o){const k=await p();if(k.error)return n.Err(k.error);o=k.val}if(M.isBitcoin(e.source_swap.chain))return n.Err("Not an EVM order: sourceSwap.chain is Bitcoin");const t=await d.switchOrAddNetwork(e.source_swap.chain,a);if(t.error)return n.Err("Failed to switch network: "+t.error);const u=t.val.walletClient,E=await new d.EvmRelay(e,r.orderBookUrl,s).init(u);if(E.error)return n.Err(E.error);const w={...e,source_swap:{...e.source_swap,initiate_tx_hash:E.val}};return n.Ok(w)},F=async({fromAsset:e,toAsset:o,amount:t,isExactOut:u=!1})=>await h.getQuote(Q.constructOrderpair(e,o),t,u);return i.useEffect(()=>{if(!a)return;const e=new S.Siwe(new S.Url(r.orderBookUrl),a,{store:r.store});_(e)},[a]),i.useEffect(()=>{if(!l||!a||!m||!s)return;const e=v.BitcoinWallet.fromPrivateKey(l.getMasterPrivKey(),P),o=new d.Garden({orderbookURl:r.orderBookUrl,secretManager:l,quote:h,auth:s,wallets:{evmWallet:a,btcWallet:e}});B(o)},[l,a,m,s]),i.useEffect(()=>{if(!c)return;const e=c.execute();return c.on("onPendingOrdersChanged",o=>{C(o)}),()=>{(async()=>(await e)())()}},[c]),i.createElement(y.Provider,{value:{orderBookUrl:r.orderBookUrl,initializeSecretManager:U,orderBook:m,swap:g,pendingOrders:O,getQuote:F,secretManager:l,garden:c,isExecuting:N,evmInitiate:x,quote:h}},b)},T=()=>{const b=i.useContext(y);if(!b)throw new Error("useGarden must be used within a GardenProvider");return b};exports.GardenContext=y;exports.GardenProvider=$;exports.useGarden=T;
|
package/dist/index2.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import N, { createContext as T, useState as
|
|
1
|
+
import N, { createContext as T, useState as h, useMemo as V, useEffect as f } from "react";
|
|
2
2
|
import { useWalletClient as j } from "wagmi";
|
|
3
3
|
import { useSecretManager as D } from "./index4.js";
|
|
4
4
|
import { useOrderbook as H } from "./index3.js";
|
|
5
5
|
import { Quote as J, Garden as _, switchOrAddNetwork as G, EvmRelay as x } from "@gardenfi/core";
|
|
6
|
-
import { Err as a, Ok as
|
|
6
|
+
import { Err as a, Ok as b } from "@catalogfi/utils";
|
|
7
7
|
import { isBitcoin as W } from "@gardenfi/orderbook";
|
|
8
8
|
import { BitcoinNetwork as E, BitcoinProvider as L, BitcoinWallet as F } from "@catalogfi/wallets";
|
|
9
9
|
import { Siwe as X, Url as Y } from "@gardenfi/utils";
|
|
@@ -14,7 +14,7 @@ const S = T({
|
|
|
14
14
|
children: w,
|
|
15
15
|
config: r
|
|
16
16
|
}) => {
|
|
17
|
-
const [s, g] =
|
|
17
|
+
const [s, g] = h(), [l, R] = h(), [i, z] = h(), [U, C] = h(), K = !!(s && l && i && U), m = new J(r.quoteUrl), { data: n } = j(), { initializeSecretManager: y } = D(g), { orderbook: v } = H(
|
|
18
18
|
r.orderBookUrl,
|
|
19
19
|
i,
|
|
20
20
|
C
|
|
@@ -35,7 +35,7 @@ const S = T({
|
|
|
35
35
|
), t = new _({
|
|
36
36
|
orderbookURl: r.orderBookUrl,
|
|
37
37
|
secretManager: e.val,
|
|
38
|
-
quote:
|
|
38
|
+
quote: m,
|
|
39
39
|
auth: i,
|
|
40
40
|
wallets: {
|
|
41
41
|
evmWallet: n,
|
|
@@ -43,9 +43,9 @@ const S = T({
|
|
|
43
43
|
},
|
|
44
44
|
blockNumberFetcher: A
|
|
45
45
|
});
|
|
46
|
-
return R(t),
|
|
46
|
+
return R(t), b(t);
|
|
47
47
|
}, Q = async (e) => {
|
|
48
|
-
if (!
|
|
48
|
+
if (!v || !n || !i)
|
|
49
49
|
return a("Orderbook or walletClient or auth not initialized");
|
|
50
50
|
let o = l;
|
|
51
51
|
if (!s || !o) {
|
|
@@ -55,7 +55,7 @@ const S = T({
|
|
|
55
55
|
}
|
|
56
56
|
const t = await o.swap(e);
|
|
57
57
|
if (t.error) return a(t.error);
|
|
58
|
-
if (W(t.val.source_swap.chain)) return
|
|
58
|
+
if (W(t.val.source_swap.chain)) return b(t.val);
|
|
59
59
|
const c = await G(
|
|
60
60
|
e.fromAsset.chain,
|
|
61
61
|
n
|
|
@@ -71,7 +71,7 @@ const S = T({
|
|
|
71
71
|
initiate_tx_hash: u.val
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
|
-
return
|
|
74
|
+
return b(d);
|
|
75
75
|
}, q = async (e) => {
|
|
76
76
|
if (!n || !i)
|
|
77
77
|
return a("Orderbook or walletClient or auth not initialized");
|
|
@@ -89,22 +89,22 @@ const S = T({
|
|
|
89
89
|
);
|
|
90
90
|
if (t.error)
|
|
91
91
|
return a("Failed to switch network: " + t.error);
|
|
92
|
-
const c = t.val.walletClient,
|
|
93
|
-
if (
|
|
92
|
+
const c = t.val.walletClient, k = await new x(e, r.orderBookUrl, i).init(c);
|
|
93
|
+
if (k.error) return a(k.error);
|
|
94
94
|
const u = {
|
|
95
95
|
...e,
|
|
96
96
|
source_swap: {
|
|
97
97
|
...e.source_swap,
|
|
98
|
-
initiate_tx_hash:
|
|
98
|
+
initiate_tx_hash: k.val
|
|
99
99
|
}
|
|
100
100
|
};
|
|
101
|
-
return
|
|
101
|
+
return b(u);
|
|
102
102
|
}, I = async ({
|
|
103
103
|
fromAsset: e,
|
|
104
104
|
toAsset: o,
|
|
105
105
|
amount: t,
|
|
106
106
|
isExactOut: c = !1
|
|
107
|
-
}) => await
|
|
107
|
+
}) => await m.getQuote(
|
|
108
108
|
Z(e, o),
|
|
109
109
|
t,
|
|
110
110
|
c
|
|
@@ -116,14 +116,14 @@ const S = T({
|
|
|
116
116
|
});
|
|
117
117
|
z(e);
|
|
118
118
|
}, [n]), f(() => {
|
|
119
|
-
if (!s || !n || !
|
|
119
|
+
if (!s || !n || !v || !i) return;
|
|
120
120
|
const e = F.fromPrivateKey(
|
|
121
121
|
s.getMasterPrivKey(),
|
|
122
122
|
P
|
|
123
123
|
), o = new _({
|
|
124
124
|
orderbookURl: r.orderBookUrl,
|
|
125
125
|
secretManager: s,
|
|
126
|
-
quote:
|
|
126
|
+
quote: m,
|
|
127
127
|
auth: i,
|
|
128
128
|
wallets: {
|
|
129
129
|
evmWallet: n,
|
|
@@ -131,7 +131,7 @@ const S = T({
|
|
|
131
131
|
}
|
|
132
132
|
});
|
|
133
133
|
R(o);
|
|
134
|
-
}, [s, n,
|
|
134
|
+
}, [s, n, v, i]), f(() => {
|
|
135
135
|
if (!l) return;
|
|
136
136
|
const e = l.execute();
|
|
137
137
|
return l.on("onPendingOrdersChanged", (o) => {
|
|
@@ -145,14 +145,15 @@ const S = T({
|
|
|
145
145
|
value: {
|
|
146
146
|
orderBookUrl: r.orderBookUrl,
|
|
147
147
|
initializeSecretManager: y,
|
|
148
|
-
orderBook:
|
|
148
|
+
orderBook: v,
|
|
149
149
|
swap: Q,
|
|
150
150
|
pendingOrders: U,
|
|
151
151
|
getQuote: I,
|
|
152
152
|
secretManager: s,
|
|
153
153
|
garden: l,
|
|
154
154
|
isExecuting: K,
|
|
155
|
-
evmInitiate: q
|
|
155
|
+
evmInitiate: q,
|
|
156
|
+
quote: m
|
|
156
157
|
}
|
|
157
158
|
},
|
|
158
159
|
w
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsyncResult } from '@catalogfi/utils';
|
|
2
2
|
import { BitcoinNetwork } from '@catalogfi/wallets';
|
|
3
|
-
import { IGardenJS, ISecretManager, QuoteResponse, SecretManager, SwapParams } from '@gardenfi/core';
|
|
3
|
+
import { IGardenJS, IQuote, ISecretManager, QuoteResponse, SecretManager, SwapParams } from '@gardenfi/core';
|
|
4
4
|
import { Asset, IOrderbook, MatchedOrder } from '@gardenfi/orderbook';
|
|
5
5
|
import { IStore } from '@gardenfi/utils';
|
|
6
6
|
|
|
@@ -20,6 +20,7 @@ export type GardenContextType = {
|
|
|
20
20
|
garden?: IGardenJS;
|
|
21
21
|
evmInitiate?: (order: MatchedOrder) => AsyncResult<MatchedOrder, string>;
|
|
22
22
|
isExecuting: boolean;
|
|
23
|
+
quote?: IQuote;
|
|
23
24
|
};
|
|
24
25
|
export type GardenProviderProps = {
|
|
25
26
|
children: React.ReactNode;
|
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.69",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@catalogfi/utils": "^0.1.6",
|
|
30
30
|
"@catalogfi/wallets": "^0.2.50",
|
|
31
|
-
"@gardenfi/core": "^0.2.0-beta.
|
|
31
|
+
"@gardenfi/core": "^0.2.0-beta.48",
|
|
32
32
|
"@gardenfi/orderbook": "^0.2.0-beta.14",
|
|
33
33
|
"@gardenfi/utils": "^0.0.1-beta.18",
|
|
34
34
|
"react": "^18.3.1",
|