@gardenfi/wallet-connectors 2.4.4 → 3.0.0-beta.2
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 o=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),x=require("./index5.cjs"),y=require("./index6.cjs"),T=require("./index7.cjs"),B=require("./index8.cjs"),S=require("./index9.cjs"),i=require("@gardenfi/utils"),C=o.createContext(void 0),q=({children:u,network:c,store:f,wallets:s})=>{const[t,w]=o.useState(),[p,d]=o.useState(),[b,v]=o.useState(!1),[l,E]=o.useState({}),N=o.useMemo(()=>!!t&&!!p,[t,p]),g=async e=>{v(!0);const r=await e.connect(c);return r.ok?r.val.network!==c?(v(!1),i.Err("Network mismatch")):(w(r.val.provider),d(r.val.address),f.setItem("bitcoinWallet",JSON.stringify(r.val)),v(!1),i.Ok(i.Void)):(v(!1),i.Err(r.error))},h=()=>t?(t.disconnect(),w(void 0),d(void 0),f.removeItem("bitcoinWallet"),i.Ok(i.Void)):i.Err("No provider to disconnect"),m=o.useCallback(async()=>{if(!t)return;const e=await t.getAccounts();if(!e.ok){console.error("Error getting accounts:",e.error);return}d(e.val[0]);const r=await t.getNetwork();if(r.error){console.error("Error getting network:",r.error);return}},[t]),a=e=>{E(r=>({...r,[e.id]:e}))},W=async()=>{if(window.okxwallet&&window.okxwallet.bitcoin&&window.okxwallet.bitcoinTestnet){const e=new x.OKXProvider(c===i.Network.MAINNET?window.okxwallet.bitcoin:window.okxwallet.bitcoinTestnet,c);a(e)}if(c===i.Network.MAINNET&&window.phantom&&window.phantom.bitcoin){const e=new T.PhantomProvider(window.phantom.bitcoin);a(e)}if(window.unisat){const e=new y.UnisatProvider(window.unisat,c);a(e)}if(window.XverseProviders&&window.XverseProviders.BitcoinProvider){const e=new B.XverseProvider(window.XverseProviders.BitcoinProvider);a(e)}if(c===i.Network.MAINNET&&window.keplr&&window.keplr.bitcoin){const e=new S.KeplrProvider(window.keplr.bitcoin);a(e)}s==null||s.forEach(e=>{a(e.provider)})},A=async()=>{const e=f.getItem("bitcoinWallet");if(e){const r=JSON.parse(e),n=l[r.id];if(n){const P=await n.getAccounts();if(!P.ok||!P.val[0])return;const k=await n.getNetwork();if(k.error||k.val!==c)return;w(n),d(P.val[0])}}};return o.useEffect(()=>{const e=[];return s==null||s.forEach(r=>{if(r.registerConnect){const n=r.registerConnect(()=>{g(r.provider)});typeof n=="function"&&e.push(n)}if(r.registerDisconnect){const n=r.registerDisconnect(()=>{h()});typeof n=="function"&&e.push(n)}}),()=>{e.forEach(r=>r())}},[s]),o.useEffect(()=>{W()},[]),o.useEffect(()=>{l&&A()},[l]),o.useEffect(()=>{if(!t)return;const e=async r=>{r.length!==0&&d(r[0])};return t.on("accountsChanged",e),()=>{t.off("accountsChanged",e)}},[t]),o.createElement(C.Provider,{value:{availableWallets:l,connect:g,provider:t,account:p,network:c,isConnecting:b,updateAccount:m,disconnect:h,isConnected:N}},u)},I=()=>{const u=o.useContext(C);if(!u)throw new Error("useBitcoinWallet must be used within BTCWalletProvider");return u};exports.BTCWalletProvider=q;exports.useBitcoinWallet=I;
|
package/dist/index2.js
CHANGED
|
@@ -1,114 +1,139 @@
|
|
|
1
|
-
import
|
|
1
|
+
import I, { useState as v, useMemo as X, useCallback as M, useEffect as l, createContext as O, useContext as D } from "react";
|
|
2
2
|
import { OKXProvider as S } from "./index5.js";
|
|
3
3
|
import { UnisatProvider as J } from "./index6.js";
|
|
4
4
|
import { PhantomProvider as K } from "./index7.js";
|
|
5
5
|
import { XverseProvider as L } from "./index8.js";
|
|
6
6
|
import { KeplrProvider as z } from "./index9.js";
|
|
7
|
-
import {
|
|
8
|
-
const
|
|
9
|
-
children:
|
|
10
|
-
network:
|
|
11
|
-
store:
|
|
7
|
+
import { Err as P, Ok as k, Void as N, Network as h } from "@gardenfi/utils";
|
|
8
|
+
const x = O(void 0), G = ({
|
|
9
|
+
children: a,
|
|
10
|
+
network: n,
|
|
11
|
+
store: f,
|
|
12
|
+
wallets: i
|
|
12
13
|
}) => {
|
|
13
|
-
const [
|
|
14
|
+
const [t, w] = v(), [p, s] = v(), [A, d] = v(!1), [u, E] = v(
|
|
14
15
|
{}
|
|
15
|
-
),
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
return
|
|
22
|
-
},
|
|
23
|
-
if (!
|
|
24
|
-
const e = await
|
|
16
|
+
), W = X(
|
|
17
|
+
() => !!t && !!p,
|
|
18
|
+
[t, p]
|
|
19
|
+
), C = async (e) => {
|
|
20
|
+
d(!0);
|
|
21
|
+
const o = await e.connect(n);
|
|
22
|
+
return o.ok ? o.val.network !== n ? (d(!1), P("Network mismatch")) : (w(o.val.provider), s(o.val.address), f.setItem("bitcoinWallet", JSON.stringify(o.val)), d(!1), k(N)) : (d(!1), P(o.error));
|
|
23
|
+
}, g = () => t ? (t.disconnect(), w(void 0), s(void 0), f.removeItem("bitcoinWallet"), k(N)) : P("No provider to disconnect"), y = M(async () => {
|
|
24
|
+
if (!t) return;
|
|
25
|
+
const e = await t.getAccounts();
|
|
25
26
|
if (!e.ok) {
|
|
26
27
|
console.error("Error getting accounts:", e.error);
|
|
27
28
|
return;
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
console.error("Error getting network:",
|
|
30
|
+
s(e.val[0]);
|
|
31
|
+
const o = await t.getNetwork();
|
|
32
|
+
if (o.error) {
|
|
33
|
+
console.error("Error getting network:", o.error);
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
35
|
-
}, [
|
|
36
|
-
|
|
37
|
-
...
|
|
36
|
+
}, [t]), c = (e) => {
|
|
37
|
+
E((o) => ({
|
|
38
|
+
...o,
|
|
38
39
|
[e.id]: e
|
|
39
40
|
}));
|
|
40
41
|
}, T = async () => {
|
|
41
42
|
if (window.okxwallet && window.okxwallet.bitcoin && window.okxwallet.bitcoinTestnet) {
|
|
42
|
-
const e = new S(
|
|
43
|
-
|
|
43
|
+
const e = new S(
|
|
44
|
+
n === h.MAINNET ? window.okxwallet.bitcoin : window.okxwallet.bitcoinTestnet,
|
|
45
|
+
n
|
|
46
|
+
);
|
|
47
|
+
c(e);
|
|
44
48
|
}
|
|
45
|
-
if (
|
|
49
|
+
if (n === h.MAINNET && window.phantom && window.phantom.bitcoin) {
|
|
46
50
|
const e = new K(window.phantom.bitcoin);
|
|
47
|
-
|
|
51
|
+
c(e);
|
|
48
52
|
}
|
|
49
53
|
if (window.unisat) {
|
|
50
|
-
const e = new J(window.unisat,
|
|
51
|
-
|
|
54
|
+
const e = new J(window.unisat, n);
|
|
55
|
+
c(e);
|
|
52
56
|
}
|
|
53
57
|
if (window.XverseProviders && window.XverseProviders.BitcoinProvider) {
|
|
54
58
|
const e = new L(
|
|
55
59
|
window.XverseProviders.BitcoinProvider
|
|
56
60
|
);
|
|
57
|
-
|
|
61
|
+
c(e);
|
|
58
62
|
}
|
|
59
|
-
if (
|
|
63
|
+
if (n === h.MAINNET && window.keplr && window.keplr.bitcoin) {
|
|
60
64
|
const e = new z(window.keplr.bitcoin);
|
|
61
|
-
|
|
65
|
+
c(e);
|
|
62
66
|
}
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
i == null || i.forEach((e) => {
|
|
68
|
+
c(e.provider);
|
|
69
|
+
});
|
|
70
|
+
}, B = async () => {
|
|
71
|
+
const e = f.getItem("bitcoinWallet");
|
|
65
72
|
if (e) {
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
68
|
-
const
|
|
69
|
-
if (!
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
+
const o = JSON.parse(e), r = u[o.id];
|
|
74
|
+
if (r) {
|
|
75
|
+
const m = await r.getAccounts();
|
|
76
|
+
if (!m.ok || !m.val[0]) return;
|
|
77
|
+
const b = await r.getNetwork();
|
|
78
|
+
if (b.error || b.val !== n) return;
|
|
79
|
+
w(r), s(m.val[0]);
|
|
73
80
|
}
|
|
74
81
|
}
|
|
75
82
|
};
|
|
76
|
-
return
|
|
83
|
+
return l(() => {
|
|
84
|
+
const e = [];
|
|
85
|
+
return i == null || i.forEach((o) => {
|
|
86
|
+
if (o.registerConnect) {
|
|
87
|
+
const r = o.registerConnect(() => {
|
|
88
|
+
C(o.provider);
|
|
89
|
+
});
|
|
90
|
+
typeof r == "function" && e.push(r);
|
|
91
|
+
}
|
|
92
|
+
if (o.registerDisconnect) {
|
|
93
|
+
const r = o.registerDisconnect(() => {
|
|
94
|
+
g();
|
|
95
|
+
});
|
|
96
|
+
typeof r == "function" && e.push(r);
|
|
97
|
+
}
|
|
98
|
+
}), () => {
|
|
99
|
+
e.forEach((o) => o());
|
|
100
|
+
};
|
|
101
|
+
}, [i]), l(() => {
|
|
77
102
|
T();
|
|
78
|
-
}, []),
|
|
79
|
-
|
|
80
|
-
}, [
|
|
81
|
-
if (!
|
|
82
|
-
const e = async (
|
|
83
|
-
|
|
103
|
+
}, []), l(() => {
|
|
104
|
+
u && B();
|
|
105
|
+
}, [u]), l(() => {
|
|
106
|
+
if (!t) return;
|
|
107
|
+
const e = async (o) => {
|
|
108
|
+
o.length !== 0 && s(o[0]);
|
|
84
109
|
};
|
|
85
|
-
return
|
|
86
|
-
|
|
110
|
+
return t.on("accountsChanged", e), () => {
|
|
111
|
+
t.off("accountsChanged", e);
|
|
87
112
|
};
|
|
88
|
-
}, [
|
|
89
|
-
|
|
113
|
+
}, [t]), /* @__PURE__ */ I.createElement(
|
|
114
|
+
x.Provider,
|
|
90
115
|
{
|
|
91
116
|
value: {
|
|
92
|
-
availableWallets:
|
|
93
|
-
connect:
|
|
94
|
-
provider:
|
|
95
|
-
account:
|
|
96
|
-
network:
|
|
97
|
-
isConnecting:
|
|
98
|
-
updateAccount:
|
|
99
|
-
disconnect:
|
|
100
|
-
isConnected:
|
|
117
|
+
availableWallets: u,
|
|
118
|
+
connect: C,
|
|
119
|
+
provider: t,
|
|
120
|
+
account: p,
|
|
121
|
+
network: n,
|
|
122
|
+
isConnecting: A,
|
|
123
|
+
updateAccount: y,
|
|
124
|
+
disconnect: g,
|
|
125
|
+
isConnected: W
|
|
101
126
|
}
|
|
102
127
|
},
|
|
103
|
-
|
|
128
|
+
a
|
|
104
129
|
);
|
|
105
|
-
},
|
|
106
|
-
const
|
|
107
|
-
if (!
|
|
130
|
+
}, H = () => {
|
|
131
|
+
const a = D(x);
|
|
132
|
+
if (!a)
|
|
108
133
|
throw new Error("useBitcoinWallet must be used within BTCWalletProvider");
|
|
109
|
-
return
|
|
134
|
+
return a;
|
|
110
135
|
};
|
|
111
136
|
export {
|
|
112
|
-
|
|
113
|
-
|
|
137
|
+
G as BTCWalletProvider,
|
|
138
|
+
H as useBitcoinWallet
|
|
114
139
|
};
|
|
@@ -12,7 +12,7 @@ export type Connect = {
|
|
|
12
12
|
network: Network;
|
|
13
13
|
id: WalletId;
|
|
14
14
|
};
|
|
15
|
-
export type WalletId = (typeof WALLET_CONFIG)[keyof typeof WALLET_CONFIG]['id'];
|
|
15
|
+
export type WalletId = (typeof WALLET_CONFIG)[keyof typeof WALLET_CONFIG]['id'] | string;
|
|
16
16
|
export type ProviderEvents = {
|
|
17
17
|
accountsChanged: (accounts: string[]) => void;
|
|
18
18
|
};
|
|
@@ -28,5 +28,5 @@ declare global {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
export declare const BTCWalletProvider: ({ children, network, store, }: BTCWalletProviderProps) => React.JSX.Element;
|
|
31
|
+
export declare const BTCWalletProvider: ({ children, network, store, wallets, }: BTCWalletProviderProps) => React.JSX.Element;
|
|
32
32
|
export declare const useBitcoinWallet: () => BTCWalletProviderContextType;
|
|
@@ -15,8 +15,15 @@ export type BTCWalletProviderContextType = {
|
|
|
15
15
|
isConnecting: boolean;
|
|
16
16
|
isConnected: boolean;
|
|
17
17
|
};
|
|
18
|
+
export type CustomWalletConfig = {
|
|
19
|
+
id: string;
|
|
20
|
+
provider: IInjectedBitcoinProvider;
|
|
21
|
+
registerConnect?: (connect: () => void) => void | (() => void);
|
|
22
|
+
registerDisconnect?: (disconnect: () => void) => void | (() => void);
|
|
23
|
+
};
|
|
18
24
|
export type BTCWalletProviderProps = {
|
|
19
25
|
network: Network;
|
|
20
26
|
children: React.ReactNode;
|
|
21
27
|
store: IStore;
|
|
28
|
+
wallets?: CustomWalletConfig[];
|
|
22
29
|
};
|
|
@@ -1,5 +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, Balance } from './bitcoin.types';
|
|
5
|
-
export type { AvailableWallets, BTCWalletProviderProps, } from './btcWalletsProvider.types';
|
|
4
|
+
export type { IInjectedBitcoinProvider, Balance, Connect, } from './bitcoin.types';
|
|
5
|
+
export type { AvailableWallets, BTCWalletProviderProps, CustomWalletConfig, } from './btcWalletsProvider.types';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/wallet-connectors",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-beta.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "vite build",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
},
|
|
38
38
|
"sideEffects": false,
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@gardenfi/core": "3.0.1",
|
|
41
|
-
"@gardenfi/utils": "3.0.0",
|
|
40
|
+
"@gardenfi/core": "3.0.1-beta.1",
|
|
41
|
+
"@gardenfi/utils": "3.0.0-beta.1",
|
|
42
42
|
"axios": "^1.7.9",
|
|
43
43
|
"bitcoinjs-lib": "^6.1.7",
|
|
44
44
|
"react": "^18.3.1",
|