@gardenfi/wallet-connectors 0.1.0-beta.9 → 2.0.1

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 n=require("react"),h=require("./index5.cjs"),o=require("@catalogfi/utils"),x=require("./index6.cjs"),S=require("@gardenfi/utils"),W=require("./index3.cjs"),p=n.createContext(void 0),B=({children:a,network:i,store:d})=>{const[r,v]=n.useState(),[f,c]=n.useState(),[P,l]=n.useState(!1),[u,b]=n.useState({}),E=n.useMemo(()=>!!r&&!!f,[r,f]),k=async e=>{l(!0);const t=await e.connect(i);return t.error?(l(!1),o.Err(t.error)):t.val.network!==i?(l(!1),o.Err("Network mismatch")):(v(t.val.provider),c(t.val.address),d.setItem("bitcoinWallet",JSON.stringify(t.val)),l(!1),o.Ok(o.Void))},m=()=>r?(r.disconnect(),v(void 0),c(void 0),d.removeItem("bitcoinWallet"),o.Ok(o.Void)):o.Err("No provider to disconnect"),A=n.useCallback(async()=>{if(!r)return;const e=await r.getAccounts();if(e.error){console.error("Error getting accounts:",e.error);return}c(e.val[0]);const t=await r.getNetwork();if(t.error){console.error("Error getting network:",t.error);return}},[r]),g=(e,t)=>{b(s=>({...s,[e]:t}))},N=async()=>{if(window.okxwallet&&i===S.Network.MAINNET&&window.okxwallet.bitcoin){const e=new h.OKXProvider(window.okxwallet.bitcoin,i);g(W.walletIDs.OKX,e)}if(window.unisat){const e=new x.UnisatProvider(window.unisat);g(W.walletIDs.Unisat,e)}},y=async()=>{const e=d.getItem("bitcoinWallet");if(e){const t=JSON.parse(e),s=u[t.id];if(s){const w=await s.getAccounts();if(w.error||!w.val[0])return;const C=await s.getNetwork();if(C.error||C.val!==i)return;v(s),c(w.val[0])}}};return n.useEffect(()=>{N()},[]),n.useEffect(()=>{u&&y()},[u]),n.useEffect(()=>{if(!r)return;const e=async t=>{t.length!==0&&c(t[0])};return r.on("accountsChanged",e),()=>{r.off("accountsChanged",e)}},[r]),n.createElement(p.Provider,{value:{availableWallets:u,connect:k,provider:r,account:f,network:i,isConnecting:P,updateAccount:A,disconnect:m,isConnected:E}},a)},I=()=>{const a=n.useContext(p);if(!a)throw new Error("useBitcoinWallet must be used within BTCWalletProvider");return a};exports.BTCWalletProvider=B;exports.useBitcoinWallet=I;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),y=require("./index5.cjs"),n=require("@catalogfi/utils"),h=require("./index6.cjs"),x=require("@gardenfi/utils"),W=o.createContext(void 0),S=({children:c,network:i,store:d})=>{const[r,v]=o.useState(),[f,s]=o.useState(),[p,a]=o.useState(!1),[l,P]=o.useState({}),b=o.useMemo(()=>!!r&&!!f,[r,f]),E=async e=>{a(!0);const t=await e.connect(i);return t.error?(a(!1),n.Err(t.error)):t.val.network!==i?(a(!1),n.Err("Network mismatch")):(v(t.val.provider),s(t.val.address),d.setItem("bitcoinWallet",JSON.stringify(t.val)),a(!1),n.Ok(n.Void))},k=()=>r?(r.disconnect(),v(void 0),s(void 0),d.removeItem("bitcoinWallet"),n.Ok(n.Void)):n.Err("No provider to disconnect"),m=o.useCallback(async()=>{if(!r)return;const e=await r.getAccounts();if(e.error){console.error("Error getting accounts:",e.error);return}s(e.val[0]);const t=await r.getNetwork();if(t.error){console.error("Error getting network:",t.error);return}},[r]),g=e=>{P(t=>({...t,[e.id]:e}))},A=async()=>{if(window.okxwallet&&i===x.Network.MAINNET&&window.okxwallet.bitcoin){const e=new y.OKXProvider(window.okxwallet.bitcoin,i);g(e)}if(window.unisat){const e=new h.UnisatProvider(window.unisat);g(e)}},N=async()=>{const e=d.getItem("bitcoinWallet");if(e){const t=JSON.parse(e),u=l[t.id];if(u){const w=await u.getAccounts();if(w.error||!w.val[0])return;const C=await u.getNetwork();if(C.error||C.val!==i)return;v(u),s(w.val[0])}}};return o.useEffect(()=>{A()},[]),o.useEffect(()=>{l&&N()},[l]),o.useEffect(()=>{if(!r)return;const e=async t=>{t.length!==0&&s(t[0])};return r.on("accountsChanged",e),()=>{r.off("accountsChanged",e)}},[r]),o.createElement(W.Provider,{value:{availableWallets:l,connect:E,provider:r,account:f,network:i,isConnecting:p,updateAccount:m,disconnect:k,isConnected:b}},c)},B=()=>{const c=o.useContext(W);if(!c)throw new Error("useBitcoinWallet must be used within BTCWalletProvider");return c};exports.BTCWalletProvider=S;exports.useBitcoinWallet=B;
package/dist/index2.js CHANGED
@@ -1,99 +1,98 @@
1
- import B, { createContext as O, useState as l, useMemo as T, useCallback as S, useEffect as w, useContext as D } from "react";
1
+ import B, { createContext as I, useState as l, useMemo as T, useCallback as O, useEffect as w, useContext as S } from "react";
2
2
  import { OKXProvider as J } from "./index5.js";
3
- import { Err as m, Ok as C, Void as W } from "@catalogfi/utils";
4
- import { UnisatProvider as K } from "./index6.js";
5
- import { Network as L } from "@gardenfi/utils";
6
- import { walletIDs as A } from "./index3.js";
7
- const N = O(void 0), _ = ({
8
- children: c,
3
+ import { Err as m, Ok as p, Void as W } from "@catalogfi/utils";
4
+ import { UnisatProvider as L } from "./index6.js";
5
+ import { Network as M } from "@gardenfi/utils";
6
+ const A = I(void 0), V = ({
7
+ children: i,
9
8
  network: o,
10
9
  store: d
11
10
  }) => {
12
- const [r, u] = l(), [f, i] = l(), [P, s] = l(!1), [a, b] = l(
11
+ const [r, u] = l(), [f, n] = l(), [N, c] = l(!1), [s, P] = l(
13
12
  {}
14
- ), k = T(
13
+ ), b = T(
15
14
  () => !!r && !!f,
16
15
  [r, f]
17
- ), x = async (t) => {
18
- s(!0);
16
+ ), k = async (t) => {
17
+ c(!0);
19
18
  const e = await t.connect(o);
20
- return e.error ? (s(!1), m(e.error)) : e.val.network !== o ? (s(!1), m("Network mismatch")) : (u(e.val.provider), i(e.val.address), d.setItem("bitcoinWallet", JSON.stringify(e.val)), s(!1), C(W));
21
- }, h = () => r ? (r.disconnect(), u(void 0), i(void 0), d.removeItem("bitcoinWallet"), C(W)) : m("No provider to disconnect"), y = S(async () => {
19
+ return e.error ? (c(!1), m(e.error)) : e.val.network !== o ? (c(!1), m("Network mismatch")) : (u(e.val.provider), n(e.val.address), d.setItem("bitcoinWallet", JSON.stringify(e.val)), c(!1), p(W));
20
+ }, x = () => r ? (r.disconnect(), u(void 0), n(void 0), d.removeItem("bitcoinWallet"), p(W)) : m("No provider to disconnect"), h = O(async () => {
22
21
  if (!r) return;
23
22
  const t = await r.getAccounts();
24
23
  if (t.error) {
25
24
  console.error("Error getting accounts:", t.error);
26
25
  return;
27
26
  }
28
- i(t.val[0]);
27
+ n(t.val[0]);
29
28
  const e = await r.getNetwork();
30
29
  if (e.error) {
31
30
  console.error("Error getting network:", e.error);
32
31
  return;
33
32
  }
34
- }, [r]), g = (t, e) => {
35
- b((n) => ({
36
- ...n,
37
- [t]: e
33
+ }, [r]), g = (t) => {
34
+ P((e) => ({
35
+ ...e,
36
+ [t.id]: t
38
37
  }));
39
- }, E = async () => {
40
- if (window.okxwallet && o === L.MAINNET && window.okxwallet.bitcoin) {
38
+ }, y = async () => {
39
+ if (window.okxwallet && o === M.MAINNET && window.okxwallet.bitcoin) {
41
40
  const t = new J(window.okxwallet.bitcoin, o);
42
- g(A.OKX, t);
41
+ g(t);
43
42
  }
44
43
  if (window.unisat) {
45
- const t = new K(window.unisat);
46
- g(A.Unisat, t);
44
+ const t = new L(window.unisat);
45
+ g(t);
47
46
  }
48
- }, I = async () => {
47
+ }, E = async () => {
49
48
  const t = d.getItem("bitcoinWallet");
50
49
  if (t) {
51
- const e = JSON.parse(t), n = a[e.id];
52
- if (n) {
53
- const v = await n.getAccounts();
50
+ const e = JSON.parse(t), a = s[e.id];
51
+ if (a) {
52
+ const v = await a.getAccounts();
54
53
  if (v.error || !v.val[0]) return;
55
- const p = await n.getNetwork();
56
- if (p.error || p.val !== o) return;
57
- u(n), i(v.val[0]);
54
+ const C = await a.getNetwork();
55
+ if (C.error || C.val !== o) return;
56
+ u(a), n(v.val[0]);
58
57
  }
59
58
  }
60
59
  };
61
60
  return w(() => {
62
- E();
61
+ y();
63
62
  }, []), w(() => {
64
- a && I();
65
- }, [a]), w(() => {
63
+ s && E();
64
+ }, [s]), w(() => {
66
65
  if (!r) return;
67
66
  const t = async (e) => {
68
- e.length !== 0 && i(e[0]);
67
+ e.length !== 0 && n(e[0]);
69
68
  };
70
69
  return r.on("accountsChanged", t), () => {
71
70
  r.off("accountsChanged", t);
72
71
  };
73
72
  }, [r]), /* @__PURE__ */ B.createElement(
74
- N.Provider,
73
+ A.Provider,
75
74
  {
76
75
  value: {
77
- availableWallets: a,
78
- connect: x,
76
+ availableWallets: s,
77
+ connect: k,
79
78
  provider: r,
80
79
  account: f,
81
80
  network: o,
82
- isConnecting: P,
83
- updateAccount: y,
84
- disconnect: h,
85
- isConnected: k
81
+ isConnecting: N,
82
+ updateAccount: h,
83
+ disconnect: x,
84
+ isConnected: b
86
85
  }
87
86
  },
88
- c
87
+ i
89
88
  );
90
- }, j = () => {
91
- const c = D(N);
92
- if (!c)
89
+ }, X = () => {
90
+ const i = S(A);
91
+ if (!i)
93
92
  throw new Error("useBitcoinWallet must be used within BTCWalletProvider");
94
- return c;
93
+ return i;
95
94
  };
96
95
  export {
97
- _ as BTCWalletProvider,
98
- j as useBitcoinWallet
96
+ V as BTCWalletProvider,
97
+ X as useBitcoinWallet
99
98
  };
package/dist/index3.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={OKX:{name:"OKX",icon:"https://garden-finance.s3.ap-south-2.amazonaws.com/wallets/okx.svg",description:"OKX wallet"},Unisat:{name:"Unisat",icon:"https://next-cdn.unisat.io/_/285/logo/color.svg",description:"Unisat wallet"},Xverse:{name:"Xverse",icon:"https://cdn.prod.website-files.com/624b08d53d7ac60ccfc11d8d/64637a04ad4e523a3e07675c_32x32.png",description:"Xverse wallet"},Xdefi:{name:"Xdefi",icon:"https://garden-finance.s3.ap-south-2.amazonaws.com/wallets/xdefi.svg",description:"Xdefi wallet"},Phantom:{name:"Phantom",icon:"",description:"Phantom wallet"}},t={OKX:"okx",Unisat:"unisat",Xverse:"xverse",Xdefi:"xdefi",Phantom:"phantom"};exports.SupportedWallets=e;exports.walletIDs=t;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={OKX:{name:"OKX",icon:"https://garden-finance.s3.ap-south-2.amazonaws.com/wallets/okx.svg",description:"OKX wallet"},Unisat:{name:"Unisat",icon:"https://next-cdn.unisat.io/_/285/logo/color.svg",description:"Unisat wallet"},Xverse:{name:"Xverse",icon:"https://cdn.prod.website-files.com/624b08d53d7ac60ccfc11d8d/64637a04ad4e523a3e07675c_32x32.png",description:"Xverse wallet"},Xdefi:{name:"Xdefi",icon:"https://garden-finance.s3.ap-south-2.amazonaws.com/wallets/xdefi.svg",description:"Xdefi wallet"},Phantom:{name:"Phantom",icon:"",description:"Phantom wallet"}},a={OKX:{id:"okx",name:"OKX wallet",icon:"https://garden-finance.imgix.net/wallets/okx.svg"},Unisat:{id:"unisat",name:"Unisat wallet",icon:"https://garden-finance.imgix.net/wallets/unisat.svg"},Xverse:{id:"xverse",name:"Xverse wallet",icon:"https://cdn.prod.website-files.com/624b08d53d7ac60ccfc11d8d/64637a04ad4e523a3e07675c_32x32.png"},Xdefi:{id:"xdefi",name:"Xdefi wallet",icon:"https://garden-finance.s3.ap-south-2.amazonaws.com/wallets/xdefi.svg"},Phantom:{id:"phantom",name:"Phantom wallet",icon:"https://garden-finance.imgix.net/wallets/phantom.svg"}};exports.SupportedWallets=e;exports.WALLET_CONFIG=a;
package/dist/index3.js CHANGED
@@ -25,13 +25,33 @@ const e = {
25
25
  description: "Phantom wallet"
26
26
  }
27
27
  }, a = {
28
- OKX: "okx",
29
- Unisat: "unisat",
30
- Xverse: "xverse",
31
- Xdefi: "xdefi",
32
- Phantom: "phantom"
28
+ OKX: {
29
+ id: "okx",
30
+ name: "OKX wallet",
31
+ icon: "https://garden-finance.imgix.net/wallets/okx.svg"
32
+ },
33
+ Unisat: {
34
+ id: "unisat",
35
+ name: "Unisat wallet",
36
+ icon: "https://garden-finance.imgix.net/wallets/unisat.svg"
37
+ },
38
+ Xverse: {
39
+ id: "xverse",
40
+ name: "Xverse wallet",
41
+ icon: "https://cdn.prod.website-files.com/624b08d53d7ac60ccfc11d8d/64637a04ad4e523a3e07675c_32x32.png"
42
+ },
43
+ Xdefi: {
44
+ id: "xdefi",
45
+ name: "Xdefi wallet",
46
+ icon: "https://garden-finance.s3.ap-south-2.amazonaws.com/wallets/xdefi.svg"
47
+ },
48
+ Phantom: {
49
+ id: "phantom",
50
+ name: "Phantom wallet",
51
+ icon: "https://garden-finance.imgix.net/wallets/phantom.svg"
52
+ }
33
53
  };
34
54
  export {
35
55
  e as SupportedWallets,
36
- a as walletIDs
56
+ a as WALLET_CONFIG
37
57
  };
package/dist/index5.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var l=r=>{throw TypeError(r)};var w=(r,t,e)=>t.has(r)||l("Cannot "+e);var s=(r,t,e)=>(w(r,t,"read from private field"),e?e.call(r):t.get(r)),u=(r,t,e)=>t.has(r)?l("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,e),a=(r,t,e,h)=>(w(r,t,"write to private field"),h?h.call(r,e):t.set(r,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@catalogfi/utils"),o=require("@gardenfi/utils"),d=require("./index3.cjs");var i,c;class y{constructor(t,e){u(this,i);u(this,c);this.address="",this.id=d.walletIDs.OKX,this.disconnect=()=>(this.address="",s(this,i).disconnect(),Promise.resolve(n.Ok("Disconnected OKX wallet"))),a(this,i,t),a(this,c,e)}async connect(){try{const t=await s(this,i).connect();return!t||!t.address?n.Err("Failed to connect to OKX wallet"):(this.address=t.address,n.Ok({address:this.address,provider:this,network:s(this,c),id:d.walletIDs.OKX}))}catch(t){return n.Err("Error while connecting to the OKX wallet",t)}}async getPublicKey(){return await n.executeWithTryCatch(async()=>await s(this,i).getPublicKey(),"Error while getting public key from OKX wallet")}async requestAccounts(){const t=await this.connect();return t.error?n.Err(t.error):n.Ok([t.val.address])}async getAccounts(){return s(this,c)===o.Network.TESTNET?await this.requestAccounts():await n.executeWithTryCatch(async()=>await s(this,i).getAccounts(),"Error while getting accounts from OKX wallet")}async getNetwork(){return n.Ok(s(this,c))}async switchNetwork(){a(this,c,s(this,c)===o.Network.MAINNET?o.Network.TESTNET:o.Network.MAINNET);const t=await this.connect();return t.error?n.Err(`Failed to connect to ${s(this,c)}: ${t.error}`):n.Ok(s(this,c))}async getBalance(){return await n.executeWithTryCatch(async()=>await s(this,i).getBalance(),"Error while getting balance from OKX wallet")}async sendBitcoin(t,e){return await n.executeWithTryCatch(async()=>await s(this,i).sendBitcoin(t,e),"Error while sending bitcoin from OKX wallet")}on(t,e){s(this,i).on(t,e)}off(t,e){s(this,i).off(t,e)}}i=new WeakMap,c=new WeakMap;exports.OKXProvider=y;
1
+ "use strict";var d=r=>{throw TypeError(r)};var w=(r,t,e)=>t.has(r)||d("Cannot "+e);var i=(r,t,e)=>(w(r,t,"read from private field"),e?e.call(r):t.get(r)),u=(r,t,e)=>t.has(r)?d("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,e),a=(r,t,e,l)=>(w(r,t,"write to private field"),l?l.call(r,e):t.set(r,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@catalogfi/utils"),o=require("@gardenfi/utils"),h=require("./index3.cjs");var s,c;class O{constructor(t,e){u(this,s);u(this,c);this.address="",this.id=h.WALLET_CONFIG.OKX.id,this.name=h.WALLET_CONFIG.OKX.name,this.icon=h.WALLET_CONFIG.OKX.icon,this.disconnect=()=>(this.address="",i(this,s).disconnect(),Promise.resolve(n.Ok("Disconnected OKX wallet"))),a(this,s,t),a(this,c,e)}async connect(){try{const t=await i(this,s).connect();return!t||!t.address?n.Err("Failed to connect to OKX wallet"):(this.address=t.address,n.Ok({address:this.address,provider:this,network:i(this,c),id:h.WALLET_CONFIG.OKX.id}))}catch(t){return n.Err("Error while connecting to the OKX wallet",t)}}async getPublicKey(){return await n.executeWithTryCatch(async()=>await i(this,s).getPublicKey(),"Error while getting public key from OKX wallet")}async requestAccounts(){const t=await this.connect();return t.error?n.Err(t.error):n.Ok([t.val.address])}async getAccounts(){return i(this,c)===o.Network.TESTNET?await this.requestAccounts():await n.executeWithTryCatch(async()=>await i(this,s).getAccounts(),"Error while getting accounts from OKX wallet")}async getNetwork(){return n.Ok(i(this,c))}async switchNetwork(){a(this,c,i(this,c)===o.Network.MAINNET?o.Network.TESTNET:o.Network.MAINNET);const t=await this.connect();return t.error?n.Err(`Failed to connect to ${i(this,c)}: ${t.error}`):n.Ok(i(this,c))}async getBalance(){return await n.executeWithTryCatch(async()=>await i(this,s).getBalance(),"Error while getting balance from OKX wallet")}async sendBitcoin(t,e){return await n.executeWithTryCatch(async()=>await i(this,s).sendBitcoin(t,e),"Error while sending bitcoin from OKX wallet")}on(t,e){i(this,s).on(t,e)}off(t,e){i(this,s).off(t,e)}}s=new WeakMap,c=new WeakMap;exports.OKXProvider=O;
package/dist/index5.js CHANGED
@@ -1,65 +1,65 @@
1
- var d = (e) => {
1
+ var y = (e) => {
2
2
  throw TypeError(e);
3
3
  };
4
- var y = (e, t, r) => t.has(e) || d("Cannot " + r);
5
- var n = (e, t, r) => (y(e, t, "read from private field"), r ? r.call(e) : t.get(e)), u = (e, t, r) => t.has(e) ? d("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), a = (e, t, r, w) => (y(e, t, "write to private field"), w ? w.call(e, r) : t.set(e, r), r);
6
- import { Ok as c, Err as o, executeWithTryCatch as h } from "@catalogfi/utils";
4
+ var f = (e, t, r) => t.has(e) || y("Cannot " + r);
5
+ var n = (e, t, r) => (f(e, t, "read from private field"), r ? r.call(e) : t.get(e)), d = (e, t, r) => t.has(e) ? y("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), o = (e, t, r, w) => (f(e, t, "write to private field"), w ? w.call(e, r) : t.set(e, r), r);
6
+ import { Ok as c, Err as a, executeWithTryCatch as h } from "@catalogfi/utils";
7
7
  import { Network as l } from "@gardenfi/utils";
8
- import { walletIDs as f } from "./index3.js";
9
- var s, i;
10
- class O {
8
+ import { WALLET_CONFIG as u } from "./index3.js";
9
+ var i, s;
10
+ class E {
11
11
  constructor(t, r) {
12
- u(this, s);
13
- u(this, i);
14
- this.address = "", this.id = f.OKX, this.disconnect = () => (this.address = "", n(this, s).disconnect(), Promise.resolve(c("Disconnected OKX wallet"))), a(this, s, t), a(this, i, r);
12
+ d(this, i);
13
+ d(this, s);
14
+ this.address = "", this.id = u.OKX.id, this.name = u.OKX.name, this.icon = u.OKX.icon, this.disconnect = () => (this.address = "", n(this, i).disconnect(), Promise.resolve(c("Disconnected OKX wallet"))), o(this, i, t), o(this, s, r);
15
15
  }
16
16
  async connect() {
17
17
  try {
18
- const t = await n(this, s).connect();
19
- return !t || !t.address ? o("Failed to connect to OKX wallet") : (this.address = t.address, c({
18
+ const t = await n(this, i).connect();
19
+ return !t || !t.address ? a("Failed to connect to OKX wallet") : (this.address = t.address, c({
20
20
  address: this.address,
21
21
  provider: this,
22
- network: n(this, i),
23
- id: f.OKX
22
+ network: n(this, s),
23
+ id: u.OKX.id
24
24
  }));
25
25
  } catch (t) {
26
- return o("Error while connecting to the OKX wallet", t);
26
+ return a("Error while connecting to the OKX wallet", t);
27
27
  }
28
28
  }
29
29
  async getPublicKey() {
30
- return await h(async () => await n(this, s).getPublicKey(), "Error while getting public key from OKX wallet");
30
+ return await h(async () => await n(this, i).getPublicKey(), "Error while getting public key from OKX wallet");
31
31
  }
32
32
  async requestAccounts() {
33
33
  const t = await this.connect();
34
- return t.error ? o(t.error) : c([t.val.address]);
34
+ return t.error ? a(t.error) : c([t.val.address]);
35
35
  }
36
36
  async getAccounts() {
37
- return n(this, i) === l.TESTNET ? await this.requestAccounts() : await h(async () => await n(this, s).getAccounts(), "Error while getting accounts from OKX wallet");
37
+ return n(this, s) === l.TESTNET ? await this.requestAccounts() : await h(async () => await n(this, i).getAccounts(), "Error while getting accounts from OKX wallet");
38
38
  }
39
39
  async getNetwork() {
40
- return c(n(this, i));
40
+ return c(n(this, s));
41
41
  }
42
42
  async switchNetwork() {
43
- a(this, i, n(this, i) === l.MAINNET ? l.TESTNET : l.MAINNET);
43
+ o(this, s, n(this, s) === l.MAINNET ? l.TESTNET : l.MAINNET);
44
44
  const t = await this.connect();
45
- return t.error ? o(
46
- `Failed to connect to ${n(this, i)}: ${t.error}`
47
- ) : c(n(this, i));
45
+ return t.error ? a(
46
+ `Failed to connect to ${n(this, s)}: ${t.error}`
47
+ ) : c(n(this, s));
48
48
  }
49
49
  async getBalance() {
50
- return await h(async () => await n(this, s).getBalance(), "Error while getting balance from OKX wallet");
50
+ return await h(async () => await n(this, i).getBalance(), "Error while getting balance from OKX wallet");
51
51
  }
52
52
  async sendBitcoin(t, r) {
53
- return await h(async () => await n(this, s).sendBitcoin(t, r), "Error while sending bitcoin from OKX wallet");
53
+ return await h(async () => await n(this, i).sendBitcoin(t, r), "Error while sending bitcoin from OKX wallet");
54
54
  }
55
55
  on(t, r) {
56
- n(this, s).on(t, r);
56
+ n(this, i).on(t, r);
57
57
  }
58
58
  off(t, r) {
59
- n(this, s).off(t, r);
59
+ n(this, i).off(t, r);
60
60
  }
61
61
  }
62
- s = new WeakMap(), i = new WeakMap();
62
+ i = new WeakMap(), s = new WeakMap();
63
63
  export {
64
- O as OKXProvider
64
+ E as OKXProvider
65
65
  };
package/dist/index6.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var w=e=>{throw TypeError(e)};var u=(e,t,r)=>t.has(e)||w("Cannot "+r);var s=(e,t,r)=>(u(e,t,"read from private field"),r?r.call(e):t.get(e)),h=(e,t,r)=>t.has(e)?w("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),l=(e,t,r,a)=>(u(e,t,"write to private field"),a?a.call(e,r):t.set(e,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@catalogfi/utils"),o=require("@gardenfi/utils"),N=require("./index3.cjs");var n;class d{constructor(t){h(this,n);this.address="",this.id=N.walletIDs.Unisat,this.disconnect=()=>(this.address="",Promise.resolve(i.Ok("Disconnected unisat wallet"))),l(this,n,t)}async connect(t){try{t||(t=o.Network.MAINNET);const r=await s(this,n).requestAccounts();r.length>0&&(this.address=r[0]);const a=await this.getNetwork();if(a.error)return i.Err("Could not get network",a.error);if(a.val!==t){const c=await this.switchNetwork();if(c.error)return i.Err("Failed to switch network",c.error)}return i.Ok({address:this.address,provider:this,network:t,id:N.walletIDs.Unisat})}catch(r){return i.Err("Error while connecting to the Unisat wallet",r)}}async requestAccounts(){return await i.executeWithTryCatch(async()=>await s(this,n).requestAccounts(),"Error while requesting accounts from the Unisat wallet")}async getAccounts(){return await i.executeWithTryCatch(async()=>await s(this,n).getAccounts(),"Error while getting accounts from the Unisat wallet")}async getNetwork(){return await i.executeWithTryCatch(async()=>await s(this,n).getNetwork()==="livenet"?o.Network.MAINNET:o.Network.TESTNET,"Error while getting network from Unisat wallet")}async switchNetwork(){try{const t=await this.getNetwork();if(t.error)return i.Err("Failed to get current network");const r=t.val===o.Network.MAINNET?o.Network.TESTNET:o.Network.MAINNET;await s(this,n).switchNetwork(r);const a=await this.getNetwork();return a.error?i.Err("Failed to verify network switch"):a.val!==r?i.Err("Network switch failed"):i.Ok(r)}catch(t){return i.Err("Error while switching network in Unisat:",t)}}async getBalance(){return await i.executeWithTryCatch(async()=>await s(this,n).getBalance(),"Error while getting balance from Unisat wallet")}async sendBitcoin(t,r){return await i.executeWithTryCatch(async()=>await s(this,n).sendBitcoin(t,r),"Error while sending bitcoin from Unisat wallet")}on(t,r){s(this,n).on(t,r)}off(t,r){s(this,n).removeListener(t,r)}}n=new WeakMap;exports.UnisatProvider=d;
1
+ "use strict";var w=e=>{throw TypeError(e)};var l=(e,t,r)=>t.has(e)||w("Cannot "+r);var s=(e,t,r)=>(l(e,t,"read from private field"),r?r.call(e):t.get(e)),N=(e,t,r)=>t.has(e)?w("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),E=(e,t,r,a)=>(l(e,t,"write to private field"),a?a.call(e,r):t.set(e,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./index7.cjs"),n=require("@catalogfi/utils"),c=require("@gardenfi/utils"),u=require("./index3.cjs");var i;class d{constructor(t){N(this,i);this.address="",this.id=u.WALLET_CONFIG.Unisat.id,this.name=u.WALLET_CONFIG.Unisat.name,this.icon=u.WALLET_CONFIG.Unisat.icon,this.disconnect=()=>(this.address="",Promise.resolve(n.Ok("Disconnected unisat wallet"))),E(this,i,t)}async connect(t){try{t||(t=c.Network.MAINNET);const r=await this.getNetwork();if(r.error)return n.Err("Could not get network",r.error);if(r.val!==t){const h=await this.switchNetwork();if(h.error)return n.Err("Failed to switch network",h.error)}const a=await s(this,i).requestAccounts();return a.length>0&&(this.address=a[0]),n.Ok({address:this.address,provider:this,network:t,id:u.WALLET_CONFIG.Unisat.id})}catch(r){return n.Err("Error while connecting to the Unisat wallet",r)}}async requestAccounts(){return await n.executeWithTryCatch(async()=>await s(this,i).requestAccounts(),"Error while requesting accounts from the Unisat wallet")}async getAccounts(){return await n.executeWithTryCatch(async()=>await s(this,i).getAccounts(),"Error while getting accounts from the Unisat wallet")}async getNetwork(){return await n.executeWithTryCatch(async()=>{const t=await s(this,i).getChain();if(t.enum===o.UnisatChainEnum.BITCOIN_MAINNET)return c.Network.MAINNET;if(t.enum===o.UnisatChainEnum.BITCOIN_TESTNET4)return c.Network.TESTNET;throw new Error("Invalid or unsupported network"+t.enum)},"Error while getting network from Unisat wallet")}async switchNetwork(){try{const t=await this.getNetwork();if(t.error)return n.Err("Failed to get current network");const r=t.val===c.Network.MAINNET?o.UnisatChainEnum.BITCOIN_TESTNET4:o.UnisatChainEnum.BITCOIN_MAINNET;await s(this,i).switchChain(r);const a=await this.getNetwork();return a.error?n.Err("Failed to verify network switch"):n.Ok(a.val)}catch(t){return n.Err("Error while switching network in Unisat:",t)}}async getBalance(){return await n.executeWithTryCatch(async()=>await s(this,i).getBalance(),"Error while getting balance from Unisat wallet")}async sendBitcoin(t,r){return await n.executeWithTryCatch(async()=>await s(this,i).sendBitcoin(t,r),"Error while sending bitcoin from Unisat wallet")}on(t,r){s(this,i).on(t,r)}off(t,r){s(this,i).removeListener(t,r)}}i=new WeakMap;exports.UnisatProvider=d;
package/dist/index6.js CHANGED
@@ -1,35 +1,35 @@
1
- var u = (e) => {
1
+ var N = (e) => {
2
2
  throw TypeError(e);
3
3
  };
4
- var l = (e, t, r) => t.has(e) || u("Cannot " + r);
5
- var n = (e, t, r) => (l(e, t, "read from private field"), r ? r.call(e) : t.get(e)), d = (e, t, r) => t.has(e) ? u("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), N = (e, t, r, s) => (l(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
6
- import { Ok as w, Err as a, executeWithTryCatch as c } from "@catalogfi/utils";
7
- import { Network as o } from "@gardenfi/utils";
8
- import { walletIDs as g } from "./index3.js";
9
- var i;
10
- class m {
4
+ var d = (e, t, r) => t.has(e) || N("Cannot " + r);
5
+ var i = (e, t, r) => (d(e, t, "read from private field"), r ? r.call(e) : t.get(e)), g = (e, t, r) => t.has(e) ? N("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), E = (e, t, r, s) => (d(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
6
+ import { UnisatChainEnum as c } from "./index7.js";
7
+ import { Ok as u, Err as a, executeWithTryCatch as o } from "@catalogfi/utils";
8
+ import { Network as w } from "@gardenfi/utils";
9
+ import { WALLET_CONFIG as h } from "./index3.js";
10
+ var n;
11
+ class I {
11
12
  constructor(t) {
12
- d(this, i);
13
- this.address = "", this.id = g.Unisat, this.disconnect = () => (this.address = "", Promise.resolve(w("Disconnected unisat wallet"))), N(this, i, t);
13
+ g(this, n);
14
+ this.address = "", this.id = h.Unisat.id, this.name = h.Unisat.name, this.icon = h.Unisat.icon, this.disconnect = () => (this.address = "", Promise.resolve(u("Disconnected unisat wallet"))), E(this, n, t);
14
15
  }
15
16
  async connect(t) {
16
17
  try {
17
- t || (t = o.MAINNET);
18
- const r = await n(this, i).requestAccounts();
19
- r.length > 0 && (this.address = r[0]);
20
- const s = await this.getNetwork();
21
- if (s.error)
22
- return a("Could not get network", s.error);
23
- if (s.val !== t) {
24
- const h = await this.switchNetwork();
25
- if (h.error)
26
- return a("Failed to switch network", h.error);
18
+ t || (t = w.MAINNET);
19
+ const r = await this.getNetwork();
20
+ if (r.error)
21
+ return a("Could not get network", r.error);
22
+ if (r.val !== t) {
23
+ const l = await this.switchNetwork();
24
+ if (l.error)
25
+ return a("Failed to switch network", l.error);
27
26
  }
28
- return w({
27
+ const s = await i(this, n).requestAccounts();
28
+ return s.length > 0 && (this.address = s[0]), u({
29
29
  address: this.address,
30
30
  provider: this,
31
31
  network: t,
32
- id: g.Unisat
32
+ id: h.Unisat.id
33
33
  });
34
34
  } catch (r) {
35
35
  return a("Error while connecting to the Unisat wallet", r);
@@ -37,42 +37,49 @@ class m {
37
37
  }
38
38
  // requests accounts from the wallet, if not connected, it will connect first
39
39
  async requestAccounts() {
40
- return await c(async () => await n(this, i).requestAccounts(), "Error while requesting accounts from the Unisat wallet");
40
+ return await o(async () => await i(this, n).requestAccounts(), "Error while requesting accounts from the Unisat wallet");
41
41
  }
42
42
  //silently gets accounts if already connected
43
43
  async getAccounts() {
44
- return await c(async () => await n(this, i).getAccounts(), "Error while getting accounts from the Unisat wallet");
44
+ return await o(async () => await i(this, n).getAccounts(), "Error while getting accounts from the Unisat wallet");
45
45
  }
46
46
  async getNetwork() {
47
- return await c(async () => await n(this, i).getNetwork() === "livenet" ? o.MAINNET : o.TESTNET, "Error while getting network from Unisat wallet");
47
+ return await o(async () => {
48
+ const t = await i(this, n).getChain();
49
+ if (t.enum === c.BITCOIN_MAINNET)
50
+ return w.MAINNET;
51
+ if (t.enum === c.BITCOIN_TESTNET4)
52
+ return w.TESTNET;
53
+ throw new Error("Invalid or unsupported network" + t.enum);
54
+ }, "Error while getting network from Unisat wallet");
48
55
  }
49
56
  async switchNetwork() {
50
57
  try {
51
58
  const t = await this.getNetwork();
52
59
  if (t.error)
53
60
  return a("Failed to get current network");
54
- const r = t.val === o.MAINNET ? o.TESTNET : o.MAINNET;
55
- await n(this, i).switchNetwork(r);
61
+ const r = t.val === w.MAINNET ? c.BITCOIN_TESTNET4 : c.BITCOIN_MAINNET;
62
+ await i(this, n).switchChain(r);
56
63
  const s = await this.getNetwork();
57
- return s.error ? a("Failed to verify network switch") : s.val !== r ? a("Network switch failed") : w(r);
64
+ return s.error ? a("Failed to verify network switch") : u(s.val);
58
65
  } catch (t) {
59
66
  return a("Error while switching network in Unisat:", t);
60
67
  }
61
68
  }
62
69
  async getBalance() {
63
- return await c(async () => await n(this, i).getBalance(), "Error while getting balance from Unisat wallet");
70
+ return await o(async () => await i(this, n).getBalance(), "Error while getting balance from Unisat wallet");
64
71
  }
65
72
  async sendBitcoin(t, r) {
66
- return await c(async () => await n(this, i).sendBitcoin(t, r), "Error while sending bitcoin from Unisat wallet");
73
+ return await o(async () => await i(this, n).sendBitcoin(t, r), "Error while sending bitcoin from Unisat wallet");
67
74
  }
68
75
  on(t, r) {
69
- n(this, i).on(t, r);
76
+ i(this, n).on(t, r);
70
77
  }
71
78
  off(t, r) {
72
- n(this, i).removeListener(t, r);
79
+ i(this, n).removeListener(t, r);
73
80
  }
74
81
  }
75
- i = new WeakMap();
82
+ n = new WeakMap();
76
83
  export {
77
- m as UnisatProvider
84
+ I as UnisatProvider
78
85
  };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var I=(T=>(T.BITCOIN_MAINNET="BITCOIN_MAINNET",T.BITCOIN_TESTNET4="BITCOIN_TESTNET4",T))(I||{});exports.UnisatChainEnum=I;
package/dist/index7.js ADDED
@@ -0,0 +1,4 @@
1
+ var I = /* @__PURE__ */ ((T) => (T.BITCOIN_MAINNET = "BITCOIN_MAINNET", T.BITCOIN_TESTNET4 = "BITCOIN_TESTNET4", T))(I || {});
2
+ export {
3
+ I as UnisatChainEnum
4
+ };
@@ -1,6 +1,6 @@
1
- import { walletIDs } from './constants';
2
1
  import { AsyncResult } from '@catalogfi/utils';
3
2
  import { Network } from '@gardenfi/utils';
3
+ import { WALLET_CONFIG } from './constants';
4
4
 
5
5
  export type Balance = {
6
6
  confirmed: number;
@@ -13,14 +13,15 @@ export type Connect = {
13
13
  network: Network;
14
14
  id: WalletId;
15
15
  };
16
- export type WalletId = (typeof walletIDs)[keyof typeof walletIDs];
16
+ export type WalletId = (typeof WALLET_CONFIG)[keyof typeof WALLET_CONFIG]['id'];
17
17
  export type ProviderEvents = {
18
18
  accountsChanged: (accounts: string[]) => void;
19
19
  };
20
- type walletId = (typeof walletIDs)[keyof typeof walletIDs];
21
20
  export interface IInjectedBitcoinProvider {
22
- id: walletId;
21
+ id: WalletId;
23
22
  address: string;
23
+ name: string;
24
+ icon: string;
24
25
  getBalance: () => AsyncResult<Balance, string>;
25
26
  /**
26
27
  * requests accounts from the wallet, if not connected, it will connect first
@@ -49,4 +50,3 @@ export interface BitcoinWallet {
49
50
  symbol: string;
50
51
  connect: () => AsyncResult<IInjectedBitcoinProvider, string>;
51
52
  }
52
- export {};
@@ -25,10 +25,30 @@ export declare const SupportedWallets: {
25
25
  description: string;
26
26
  };
27
27
  };
28
- export declare const walletIDs: {
29
- readonly OKX: "okx";
30
- readonly Unisat: "unisat";
31
- readonly Xverse: "xverse";
32
- readonly Xdefi: "xdefi";
33
- readonly Phantom: "phantom";
28
+ export declare const WALLET_CONFIG: {
29
+ readonly OKX: {
30
+ readonly id: "okx";
31
+ readonly name: "OKX wallet";
32
+ readonly icon: "https://garden-finance.imgix.net/wallets/okx.svg";
33
+ };
34
+ readonly Unisat: {
35
+ readonly id: "unisat";
36
+ readonly name: "Unisat wallet";
37
+ readonly icon: "https://garden-finance.imgix.net/wallets/unisat.svg";
38
+ };
39
+ readonly Xverse: {
40
+ readonly id: "xverse";
41
+ readonly name: "Xverse wallet";
42
+ readonly icon: "https://cdn.prod.website-files.com/624b08d53d7ac60ccfc11d8d/64637a04ad4e523a3e07675c_32x32.png";
43
+ };
44
+ readonly Xdefi: {
45
+ readonly id: "xdefi";
46
+ readonly name: "Xdefi wallet";
47
+ readonly icon: "https://garden-finance.s3.ap-south-2.amazonaws.com/wallets/xdefi.svg";
48
+ };
49
+ readonly Phantom: {
50
+ readonly id: "phantom";
51
+ readonly name: "Phantom wallet";
52
+ readonly icon: "https://garden-finance.imgix.net/wallets/phantom.svg";
53
+ };
34
54
  };
@@ -1,4 +1,5 @@
1
1
  export { BTCWalletProvider, useBitcoinWallet } from './btcWalletsProvider';
2
2
  export { SupportedWallets } from './constants';
3
3
  export { getBalance } from './utils';
4
- export type { IInjectedBitcoinProvider } from './bitcoin.types';
4
+ export type { IInjectedBitcoinProvider, Balance } from './bitcoin.types';
5
+ export type { AvailableWallets, BTCWalletProviderProps, } from './btcWalletsProvider.types';
@@ -7,6 +7,8 @@ export declare class OKXProvider implements IInjectedBitcoinProvider {
7
7
  #private;
8
8
  address: string;
9
9
  id: "okx";
10
+ name: "OKX wallet";
11
+ icon: "https://garden-finance.imgix.net/wallets/okx.svg";
10
12
  constructor(provider: OKXBitcoinProvider, network: Network);
11
13
  connect(): AsyncResult<Connect, string>;
12
14
  getPublicKey(): AsyncResult<string, string>;
@@ -8,6 +8,8 @@ export declare class PhantomProvider implements IInjectedBitcoinProvider {
8
8
  address: string;
9
9
  id: "phantom";
10
10
  private mempoolApiBaseUrl;
11
+ name: "Phantom wallet";
12
+ icon: "https://garden-finance.imgix.net/wallets/phantom.svg";
11
13
  constructor(phantomProvider: PhantomBitcoinProvider);
12
14
  connect(network?: Network): AsyncResult<Connect, string>;
13
15
  requestAccounts(): Promise<import('@catalogfi/utils').Result<string[], string>>;
@@ -7,6 +7,8 @@ export declare class UnisatProvider implements IInjectedBitcoinProvider {
7
7
  #private;
8
8
  address: string;
9
9
  id: "unisat";
10
+ name: "Unisat wallet";
11
+ icon: "https://garden-finance.imgix.net/wallets/unisat.svg";
10
12
  constructor(unisatProvider: UnisatBitcoinProvider);
11
13
  connect(network?: Network): AsyncResult<Connect, string>;
12
14
  requestAccounts(): Promise<import('@catalogfi/utils').Result<string[], string>>;
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @reference https://docs.unisat.io/dev/unisat-developer-center/unisat-wallet
3
+ */
1
4
  export interface UnisatBitcoinProvider {
2
5
  _selectedAddress: string;
3
6
  getAccounts: () => Promise<string[]>;
@@ -8,10 +11,20 @@ export interface UnisatBitcoinProvider {
8
11
  unconfirmed: number;
9
12
  total: number;
10
13
  }>;
11
- getNetwork: () => Promise<string>;
12
- switchNetwork: (network: string) => Promise<string>;
14
+ getChain: () => Promise<UnisatChain>;
15
+ switchChain: (chain: UnisatChainEnum) => Promise<UnisatChain>;
13
16
  getPublicKey(): Promise<string>;
14
17
  on: (event: string, callback: (data: any) => void) => void;
15
18
  removeListener: (event: string, callback: (data: any) => void) => void;
16
19
  disconnect: () => void;
17
20
  }
21
+ export type UnisatChain = {
22
+ enum: UnisatChainEnum;
23
+ name: string;
24
+ network: UnisatNetwork;
25
+ };
26
+ export declare enum UnisatChainEnum {
27
+ BITCOIN_MAINNET = "BITCOIN_MAINNET",
28
+ BITCOIN_TESTNET4 = "BITCOIN_TESTNET4"
29
+ }
30
+ export type UnisatNetwork = 'livenet' | 'testnet';
@@ -7,6 +7,8 @@ export declare class XdefiProvider implements IInjectedBitcoinProvider {
7
7
  #private;
8
8
  address: string;
9
9
  id: "xdefi";
10
+ name: "Xdefi wallet";
11
+ icon: "https://garden-finance.s3.ap-south-2.amazonaws.com/wallets/xdefi.svg";
10
12
  constructor(xdefiProvider: XdefiBitcoinProvider);
11
13
  connect(network?: Network): AsyncResult<Connect, string>;
12
14
  requestAccounts(): Promise<import('@catalogfi/utils').Result<string[], string>>;
@@ -8,6 +8,8 @@ export declare class XverseProvider implements IInjectedBitcoinProvider {
8
8
  private provider;
9
9
  address: string;
10
10
  id: "xverse";
11
+ name: "Xverse wallet";
12
+ icon: "https://cdn.prod.website-files.com/624b08d53d7ac60ccfc11d8d/64637a04ad4e523a3e07675c_32x32.png";
11
13
  constructor(provider: XVerseBitcoinProvider);
12
14
  connect: () => Promise<import('@catalogfi/utils').Result<never, string> | import('@catalogfi/utils').Result<{
13
15
  address: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/wallet-connectors",
3
- "version": "0.1.0-beta.9",
3
+ "version": "2.0.1",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": "vite build",
@@ -38,7 +38,7 @@
38
38
  "dependencies": {
39
39
  "@catalogfi/utils": "^0.1.11",
40
40
  "@catalogfi/wallets": "^0.2.54",
41
- "@gardenfi/utils": "^0.0.1-beta.19",
41
+ "@gardenfi/utils": "^2.0.0",
42
42
  "bitcoinjs-lib": "^7.0.0-rc.0",
43
43
  "react": "^18.3.1",
44
44
  "tiny-secp256k1": "^2.2.3"