@btc-vision/walletconnect 1.5.4 → 1.5.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/browser/index.js +1 -1
- package/browser/wallets/unisat/controller.d.ts +1 -1
- package/build/provider/WalletConnectProvider.js +17 -4
- package/build/wallets/unisat/controller.d.ts +1 -1
- package/build/wallets/unisat/controller.js +3 -3
- package/package.json +4 -4
- package/src/provider/WalletConnectProvider.tsx +25 -4
- package/src/utils/style.css +4 -0
- package/src/wallets/unisat/controller.ts +8 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Unisat, UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
|
|
2
|
-
import { type WalletBase } from '../types';
|
|
3
2
|
import { AbstractRpcProvider } from 'opnet';
|
|
3
|
+
import { type WalletBase } from '../types';
|
|
4
4
|
declare class UnisatWallet implements WalletBase {
|
|
5
5
|
private walletBase;
|
|
6
6
|
private accountsChangedHookWrapper?;
|
|
@@ -9,6 +9,7 @@ import '../utils/theme.css';
|
|
|
9
9
|
import { WalletController } from '../wallets';
|
|
10
10
|
const AUTO_RECONNECT_RETRIES = 5;
|
|
11
11
|
const WalletConnectProvider = ({ theme, children }) => {
|
|
12
|
+
const [pageLoaded, setPageLoaded] = useState(false);
|
|
12
13
|
const [connectError, setConnectError] = useState(undefined);
|
|
13
14
|
const timeoutRef = useRef(null);
|
|
14
15
|
const [network, setNetwork] = useState(DefaultWalletConnectNetwork);
|
|
@@ -27,6 +28,18 @@ const WalletConnectProvider = ({ theme, children }) => {
|
|
|
27
28
|
clearTimeout(timeoutRef.current);
|
|
28
29
|
timeoutRef.current = setTimeout(() => setConnectError(undefined), 5000);
|
|
29
30
|
}, []);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const onPageLoad = () => {
|
|
33
|
+
setPageLoaded(true);
|
|
34
|
+
};
|
|
35
|
+
if (document.readyState === 'complete') {
|
|
36
|
+
onPageLoad();
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
window.addEventListener('load', onPageLoad, false);
|
|
40
|
+
return () => window.removeEventListener('load', onPageLoad);
|
|
41
|
+
}
|
|
42
|
+
}, []);
|
|
30
43
|
useEffect(() => {
|
|
31
44
|
if (connectError) {
|
|
32
45
|
clearConnectError();
|
|
@@ -109,7 +122,7 @@ const WalletConnectProvider = ({ theme, children }) => {
|
|
|
109
122
|
}
|
|
110
123
|
};
|
|
111
124
|
await reconnect();
|
|
112
|
-
}, [selectedWallet, connectToWallet]);
|
|
125
|
+
}, [selectedWallet, connectToWallet, pageLoaded]);
|
|
113
126
|
useEffect(() => {
|
|
114
127
|
void attemptReconnect();
|
|
115
128
|
}, [attemptReconnect]);
|
|
@@ -136,10 +149,10 @@ const WalletConnectProvider = ({ theme, children }) => {
|
|
|
136
149
|
isConnected: wallet.controller.isConnected(),
|
|
137
150
|
};
|
|
138
151
|
});
|
|
139
|
-
}, [supportedWallets, network]);
|
|
152
|
+
}, [supportedWallets, network, pageLoaded]);
|
|
140
153
|
const availableWallets = useMemo(() => {
|
|
141
154
|
return supportedWallets.filter((wallet) => wallet.controller.isInstalled());
|
|
142
|
-
}, [supportedWallets, network]);
|
|
155
|
+
}, [supportedWallets, network, pageLoaded]);
|
|
143
156
|
useEffect(() => {
|
|
144
157
|
const walletType = walletAddress ? WalletController.getWalletType() : null;
|
|
145
158
|
setWalletType(walletType);
|
|
@@ -183,6 +196,6 @@ const WalletConnectProvider = ({ theme, children }) => {
|
|
|
183
196
|
walletType,
|
|
184
197
|
}, children: [children, modalOpen && (_jsx("div", { className: `wallet-connect-modal-backdrop ${currentTheme}`, children: _jsxs("div", { className: "wallet-connect-modal", role: "dialog", "aria-modal": "true", "aria-labelledby": "wallet-connect-modal-title", children: [_jsxs("div", { className: "wallet-connect-header", children: [_jsx("span", { children: "Connect Wallet" }), _jsx("button", { className: "close", onClick: () => closeConnectModal(), children: _jsx("span", { className: "close-icon", children: _jsx("svg", { width: "30px", height: "30px", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { className: "close-x-path", d: "M16 8L8 16M8.00001 8L16 16", stroke: "#fff", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) }) }) })] }), connectError && (_jsx("div", { className: "wallet-connect-error", children: _jsx("p", { className: "error-message", children: connectError }) })), availableWallets.length > 0 ? (_jsx("div", { className: "wallet-list", children: availableWallets.map((wallet) => (_jsxs("button", { onClick: () => connectToWallet(wallet.name), disabled: connecting || !wallet.controller.isInstalled(), className: `wallet-button ${wallet.controller.isInstalled()
|
|
185
198
|
? 'wallet-installed'
|
|
186
|
-
: 'wallet-not-installed'}`, children: [wallet.icon ? (_jsx("div", { className: "wallet-icon", title: wallet.name, children: _jsx("img", { src: wallet.icon, alt: wallet.name }) })) : (_jsx("div", { className: "wallet-name", children: wallet.name })), wallet.controller.isConnected() ? (_jsx("div", { className: "wallet-connected", children: "(Connected)" })) : (_jsx(_Fragment, {})), wallet.controller.isInstalled() ? (_jsx(_Fragment, {})) : (_jsx("div", { className: "wallet-not-installed", children: "(Not Installed)" }))] }, wallet.name))) })) : (_jsxs("div", { children: [_jsx("p", { children: "No wallets available" }), _jsx("p", { children: "Supporting the following wallets" }), _jsx("div", { className: "wallet-list", children: supportedWallets.map((wallet) => (_jsx("a", { href: `https://chromewebstore.google.com/search/${wallet.name}`, children: wallet.icon ? (_jsx("div", { className: "wallet-icon", title: wallet.name, children: _jsx("img", { src: wallet.icon, alt: wallet.name }) })) : (_jsx("div", { className: "wallet-name", children: wallet.name })) }))) })] }))] }) }))] }));
|
|
199
|
+
: 'wallet-not-installed'}`, children: [wallet.icon ? (_jsx("div", { className: "wallet-icon", title: wallet.name, children: _jsx("img", { src: wallet.icon, alt: wallet.name }) })) : (_jsx("div", { className: "wallet-name", children: wallet.name })), wallet.controller.isConnected() ? (_jsx("div", { className: "wallet-connected", children: "(Connected)" })) : (_jsx(_Fragment, {})), wallet.controller.isInstalled() ? (_jsx(_Fragment, {})) : (_jsx("div", { className: "wallet-not-installed", children: "(Not Installed)" }))] }, wallet.name))) })) : pageLoaded ? (_jsxs("div", { children: [_jsx("p", { children: "No wallets available" }), _jsx("p", { children: "Supporting the following wallets" }), _jsx("div", { className: "wallet-list", children: supportedWallets.map((wallet) => (_jsx("a", { href: `https://chromewebstore.google.com/search/${wallet.name}`, children: wallet.icon ? (_jsx("div", { className: "wallet-icon", title: wallet.name, children: _jsx("img", { src: wallet.icon, alt: wallet.name }) })) : (_jsx("div", { className: "wallet-name", children: wallet.name })) }))) })] })) : (_jsxs("div", { className: "wallet-waiting-plugin", children: [_jsx("p", { children: "Loading plugins..." }), _jsx("p", { children: "Please wait" })] }))] }) }))] }));
|
|
187
200
|
};
|
|
188
201
|
export default WalletConnectProvider;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Unisat, UnisatChainType, UnisatSigner } from '@btc-vision/transaction';
|
|
2
|
-
import { type WalletBase } from '../types';
|
|
3
2
|
import { AbstractRpcProvider } from 'opnet';
|
|
3
|
+
import { type WalletBase } from '../types';
|
|
4
4
|
declare class UnisatWallet implements WalletBase {
|
|
5
5
|
private walletBase;
|
|
6
6
|
private accountsChangedHookWrapper?;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { networks } from '@btc-vision/bitcoin';
|
|
2
|
+
import { UnisatChainType, UnisatSigner, } from '@btc-vision/transaction';
|
|
3
|
+
import { AbstractRpcProvider, JSONRpcProvider } from 'opnet';
|
|
2
4
|
import {} from '../types';
|
|
3
5
|
import {} from './interface';
|
|
4
|
-
import { AbstractRpcProvider, JSONRpcProvider } from 'opnet';
|
|
5
|
-
import { networks } from '@btc-vision/bitcoin';
|
|
6
6
|
const notInstalledError = 'UNISAT is not installed';
|
|
7
7
|
class UnisatWallet {
|
|
8
8
|
constructor() {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@btc-vision/walletconnect",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.5.
|
|
4
|
+
"version": "1.5.6",
|
|
5
5
|
"author": "impredmet",
|
|
6
6
|
"description": "The OP_NET Wallet Connect library helps your dApp connect to any compatible wallet.",
|
|
7
7
|
"engines": {
|
|
@@ -82,19 +82,19 @@
|
|
|
82
82
|
"react-dom": "^19.1.1",
|
|
83
83
|
"stream-browserify": "^3.0.0",
|
|
84
84
|
"stream-http": "^3.2.0",
|
|
85
|
-
"typescript-eslint": "^8.
|
|
85
|
+
"typescript-eslint": "^8.42.0",
|
|
86
86
|
"webpack-cli": "^6.0.1"
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
89
|
"@btc-vision/bitcoin": "^6.4.8",
|
|
90
|
-
"@btc-vision/transaction": "^1.6.
|
|
90
|
+
"@btc-vision/transaction": "^1.6.15",
|
|
91
91
|
"@eslint/js": "^9.34.0",
|
|
92
92
|
"css-loader": "^7.1.2",
|
|
93
93
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
94
94
|
"gulp-clean": "^0.4.0",
|
|
95
95
|
"gulp-eslint-new": "^2.4.0",
|
|
96
96
|
"gulp-logger-new": "^1.0.1",
|
|
97
|
-
"opnet": "^1.6.
|
|
97
|
+
"opnet": "^1.6.27",
|
|
98
98
|
"style-loader": "^4.0.0",
|
|
99
99
|
"webpack": "^5.101.3"
|
|
100
100
|
}
|
|
@@ -22,6 +22,7 @@ interface WalletConnectProviderProps {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const WalletConnectProvider: React.FC<WalletConnectProviderProps> = ({ theme, children }) => {
|
|
25
|
+
const [pageLoaded, setPageLoaded] = useState<boolean>(false);
|
|
25
26
|
const [connectError, setConnectError] = useState<string | undefined>(undefined);
|
|
26
27
|
const timeoutRef = useRef<NodeJS.Timeout | null>(null);
|
|
27
28
|
|
|
@@ -46,6 +47,21 @@ const WalletConnectProvider: React.FC<WalletConnectProviderProps> = ({ theme, ch
|
|
|
46
47
|
timeoutRef.current = setTimeout(() => setConnectError(undefined), 5000);
|
|
47
48
|
}, []);
|
|
48
49
|
|
|
50
|
+
// This will run one time after the component mounts
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
// callback function to call when event triggers
|
|
53
|
+
const onPageLoad = () => {
|
|
54
|
+
setPageLoaded(true);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
if (document.readyState === 'complete') {
|
|
58
|
+
onPageLoad();
|
|
59
|
+
} else {
|
|
60
|
+
window.addEventListener('load', onPageLoad, false);
|
|
61
|
+
return () => window.removeEventListener('load', onPageLoad);
|
|
62
|
+
}
|
|
63
|
+
}, []);
|
|
64
|
+
|
|
49
65
|
useEffect(() => {
|
|
50
66
|
if (connectError) {
|
|
51
67
|
clearConnectError();
|
|
@@ -144,7 +160,7 @@ const WalletConnectProvider: React.FC<WalletConnectProviderProps> = ({ theme, ch
|
|
|
144
160
|
|
|
145
161
|
await reconnect();
|
|
146
162
|
// eslint-disable-next-line
|
|
147
|
-
}, [selectedWallet, connectToWallet]);
|
|
163
|
+
}, [selectedWallet, connectToWallet, pageLoaded]);
|
|
148
164
|
|
|
149
165
|
useEffect(() => {
|
|
150
166
|
void attemptReconnect();
|
|
@@ -184,13 +200,13 @@ const WalletConnectProvider: React.FC<WalletConnectProviderProps> = ({ theme, ch
|
|
|
184
200
|
};
|
|
185
201
|
});
|
|
186
202
|
// eslint-disable-next-line
|
|
187
|
-
}, [supportedWallets, network]);
|
|
203
|
+
}, [supportedWallets, network, pageLoaded]);
|
|
188
204
|
|
|
189
205
|
const availableWallets = useMemo(() => {
|
|
190
206
|
return supportedWallets.filter((wallet) => wallet.controller.isInstalled());
|
|
191
207
|
//return supportedWallets
|
|
192
208
|
// eslint-disable-next-line
|
|
193
|
-
}, [supportedWallets, network]);
|
|
209
|
+
}, [supportedWallets, network, pageLoaded]);
|
|
194
210
|
|
|
195
211
|
useEffect(() => {
|
|
196
212
|
const walletType = walletAddress ? WalletController.getWalletType() : null;
|
|
@@ -317,7 +333,7 @@ const WalletConnectProvider: React.FC<WalletConnectProviderProps> = ({ theme, ch
|
|
|
317
333
|
</button>
|
|
318
334
|
))}
|
|
319
335
|
</div>
|
|
320
|
-
) : (
|
|
336
|
+
) : pageLoaded ? (
|
|
321
337
|
<div>
|
|
322
338
|
<p>No wallets available</p>
|
|
323
339
|
<p>Supporting the following wallets</p>
|
|
@@ -341,6 +357,11 @@ const WalletConnectProvider: React.FC<WalletConnectProviderProps> = ({ theme, ch
|
|
|
341
357
|
))}
|
|
342
358
|
</div>
|
|
343
359
|
</div>
|
|
360
|
+
) : (
|
|
361
|
+
<div className="wallet-waiting-plugin">
|
|
362
|
+
<p>Loading plugins...</p>
|
|
363
|
+
<p>Please wait</p>
|
|
364
|
+
</div>
|
|
344
365
|
)}
|
|
345
366
|
</div>
|
|
346
367
|
</div>
|
package/src/utils/style.css
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { networks } from '@btc-vision/bitcoin';
|
|
2
|
+
import {
|
|
3
|
+
type Unisat,
|
|
4
|
+
type UnisatChainInfo,
|
|
5
|
+
UnisatChainType,
|
|
6
|
+
UnisatSigner,
|
|
7
|
+
} from '@btc-vision/transaction';
|
|
8
|
+
import { AbstractRpcProvider, JSONRpcProvider } from 'opnet';
|
|
2
9
|
import { type WalletBase } from '../types';
|
|
3
10
|
import { type UnisatWalletInterface } from './interface';
|
|
4
|
-
import { AbstractRpcProvider, JSONRpcProvider } from 'opnet';
|
|
5
|
-
import { networks } from '@btc-vision/bitcoin';
|
|
6
11
|
|
|
7
12
|
interface UnisatWalletWindow extends Window {
|
|
8
13
|
unisat?: UnisatWalletInterface;
|