wallet-connect-button-react 1.1.7 → 1.1.8
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/WalletConnectButton.d.ts +3 -2
- package/dist/index.esm.js +32 -16
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +32 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -112,22 +112,39 @@ function useSearchParams() {
|
|
|
112
112
|
|
|
113
113
|
// Global cache to prevent duplicate requests
|
|
114
114
|
var credentialsCache = new Map();
|
|
115
|
-
function
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
function getDefaultHost(useLocalWcServer, business, issuance) {
|
|
116
|
+
// If useLocalWcServer is set, use local server
|
|
117
|
+
if (useLocalWcServer) {
|
|
118
|
+
if (business) {
|
|
119
|
+
return issuance ? 'http://localhost:4007' : 'http://bw.localhost:3021';
|
|
120
|
+
}
|
|
121
|
+
return issuance ? 'http://localhost:3007' : 'http://localhost:3021';
|
|
122
|
+
}
|
|
123
|
+
// Otherwise use remote servers
|
|
124
|
+
if (business) {
|
|
125
|
+
return issuance ? 'https://bw.issuance.wallet-connect.eu' : 'https://bw.wallet-connect.eu';
|
|
126
|
+
}
|
|
127
|
+
return issuance ? 'https://issuance.wallet-connect.eu' : 'https://wallet-connect.eu';
|
|
128
|
+
}
|
|
129
|
+
function constructURI(clientId, session_type, walletConnectHost, business) {
|
|
130
|
+
var request_uri = "".concat(walletConnectHost, "/disclosure/").concat(clientId, "/request_uri?session_type=").concat(session_type);
|
|
118
131
|
var request_uri_method = "post";
|
|
119
132
|
var client_id_uri = "".concat(clientId, ".example.com");
|
|
120
|
-
|
|
133
|
+
var deepLinkScheme = business
|
|
134
|
+
? 'businesswalletdebuginteraction://wallet.kvk.rijksoverheid.nl'
|
|
135
|
+
: 'walletdebuginteraction://wallet.edi.rijksoverheid.nl';
|
|
136
|
+
return "".concat(deepLinkScheme, "/disclosure_based_issuance?request_uri=").concat(encodeURIComponent(request_uri), "&request_uri_method=").concat(request_uri_method, "&client_id=").concat(client_id_uri);
|
|
121
137
|
}
|
|
122
138
|
function WalletConnectButton(_a) {
|
|
123
139
|
var _this = this;
|
|
124
|
-
var label = _a.label, clientId = _a.clientId, onSuccess = _a.onSuccess, apiKey = _a.apiKey,
|
|
125
|
-
var
|
|
126
|
-
var
|
|
127
|
-
var
|
|
140
|
+
var label = _a.label, clientId = _a.clientId, onSuccess = _a.onSuccess, apiKey = _a.apiKey, _b = _a.useLocalWcServer, useLocalWcServer = _b === void 0 ? false : _b, _c = _a.business, business = _c === void 0 ? false : _c, lang = _a.lang, helpBaseUrl = _a.helpBaseUrl, _d = _a.issuance, issuance = _d === void 0 ? false : _d;
|
|
141
|
+
var _e = useSearchParams(), searchParams = _e[0], setSearchParams = _e[1], removeSearchParam = _e[2];
|
|
142
|
+
var _f = react.useState(false), loading = _f[0], setLoading = _f[1];
|
|
143
|
+
var _g = react.useState(null), error = _g[0], setError = _g[1];
|
|
128
144
|
var buttonRef = react.useRef(null);
|
|
129
|
-
var
|
|
130
|
-
var
|
|
145
|
+
var walletConnectHost = getDefaultHost(useLocalWcServer, business, issuance);
|
|
146
|
+
var sameDeviceUl = constructURI(clientId, "same_device", walletConnectHost, business);
|
|
147
|
+
var crossDeviceUl = constructURI(clientId, "cross_device", walletConnectHost, business);
|
|
131
148
|
react.useEffect(function () {
|
|
132
149
|
// Dynamically import the web component
|
|
133
150
|
var loadWebComponent = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -175,7 +192,7 @@ function WalletConnectButton(_a) {
|
|
|
175
192
|
case 0:
|
|
176
193
|
if (!apiKey || !clientId)
|
|
177
194
|
return [2 /*return*/, []];
|
|
178
|
-
cacheKey = "".concat(clientId, "-").concat(walletConnectHost
|
|
195
|
+
cacheKey = "".concat(clientId, "-").concat(walletConnectHost);
|
|
179
196
|
cached = credentialsCache.get(cacheKey);
|
|
180
197
|
if (cached === null || cached === void 0 ? void 0 : cached.data) {
|
|
181
198
|
return [2 /*return*/, cached.data];
|
|
@@ -185,14 +202,13 @@ function WalletConnectButton(_a) {
|
|
|
185
202
|
case 1: return [2 /*return*/, _a.sent()];
|
|
186
203
|
case 2:
|
|
187
204
|
fetchPromise = (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
188
|
-
var
|
|
205
|
+
var url, headers, response, credentials, error_2;
|
|
189
206
|
var _a, _b;
|
|
190
207
|
return __generator(this, function (_c) {
|
|
191
208
|
switch (_c.label) {
|
|
192
209
|
case 0:
|
|
193
210
|
_c.trys.push([0, 2, , 3]);
|
|
194
|
-
|
|
195
|
-
url = "".concat(baseUrl, "/api/client/").concat(clientId, "/requested-credentials");
|
|
211
|
+
url = "".concat(walletConnectHost, "/api/client/").concat(clientId, "/requested-credentials");
|
|
196
212
|
headers = { 'Authorization': "Bearer ".concat(apiKey) };
|
|
197
213
|
return [4 /*yield*/, axios.get(url, { headers: headers })];
|
|
198
214
|
case 1:
|
|
@@ -311,7 +327,7 @@ function WalletConnectButton(_a) {
|
|
|
311
327
|
if (!session_token)
|
|
312
328
|
return;
|
|
313
329
|
setLoading(true);
|
|
314
|
-
var baseUrl = apiKey ?
|
|
330
|
+
var baseUrl = apiKey ? walletConnectHost : "";
|
|
315
331
|
var url = baseUrl + "/api/disclosed-attributes?session_token=".concat(session_token, "&client_id=").concat(clientId);
|
|
316
332
|
if (nonce)
|
|
317
333
|
url = "".concat(url, "&nonce=").concat(nonce);
|
|
@@ -345,7 +361,7 @@ function WalletConnectButton(_a) {
|
|
|
345
361
|
if (error) {
|
|
346
362
|
return (jsxRuntime.jsx("div", { className: "attributes", children: jsxRuntime.jsxs("div", { className: "verification-card", children: [jsxRuntime.jsx("h2", { children: "Error" }), jsxRuntime.jsxs("p", { children: ["An error occurred while verifying your attributes: ", error] })] }) }));
|
|
347
363
|
}
|
|
348
|
-
return (jsxRuntime.jsx("nl-wallet-button", { ref: buttonRef, text: label, usecase: issuance ? "" : clientId, "start-url": "".concat(walletConnectHost
|
|
364
|
+
return (jsxRuntime.jsx("nl-wallet-button", { ref: buttonRef, text: label, usecase: issuance ? "" : clientId, "start-url": "".concat(walletConnectHost, "/api/create-session?lang=en&return_url=").concat(encodeURIComponent(window.location.href)), lang: lang || "nl", "same-device-ul": sameDeviceUl, "cross-device-ul": crossDeviceUl, "help-base-url": helpBaseUrl, onClick: handleButtonClick }));
|
|
349
365
|
}
|
|
350
366
|
|
|
351
367
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|