wallet-connect-button-react 1.1.6 → 1.1.7
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 +1 -0
- package/dist/index.esm.js +132 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +132 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -106,8 +106,11 @@ function useSearchParams() {
|
|
|
106
106
|
return [searchParams, setSearchParams, removeSearchParam];
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
// Global cache to prevent duplicate requests
|
|
110
|
+
var credentialsCache = new Map();
|
|
111
|
+
function constructURI(clientId, session_type, walletConnectHost) {
|
|
112
|
+
var baseHost = walletConnectHost || "https://issuance.wallet-connect.eu";
|
|
113
|
+
var request_uri = "".concat(baseHost, "/disclosure/").concat(clientId, "/request_uri?session_type=").concat(session_type);
|
|
111
114
|
var request_uri_method = "post";
|
|
112
115
|
var client_id_uri = "".concat(clientId, ".example.com");
|
|
113
116
|
return "walletdebuginteraction://wallet.edi.rijksoverheid.nl/disclosure_based_issuance?request_uri=".concat(encodeURIComponent(request_uri), "&request_uri_method=").concat(request_uri_method, "&client_id=").concat(client_id_uri);
|
|
@@ -119,8 +122,8 @@ function WalletConnectButton(_a) {
|
|
|
119
122
|
var _c = useState(false), loading = _c[0], setLoading = _c[1];
|
|
120
123
|
var _d = useState(null), error = _d[0], setError = _d[1];
|
|
121
124
|
var buttonRef = useRef(null);
|
|
122
|
-
var sameDeviceUl = constructURI(clientId, "same_device");
|
|
123
|
-
var crossDeviceUl = constructURI(clientId, "cross_device");
|
|
125
|
+
var sameDeviceUl = constructURI(clientId, "same_device", walletConnectHost);
|
|
126
|
+
var crossDeviceUl = constructURI(clientId, "cross_device", walletConnectHost);
|
|
124
127
|
useEffect(function () {
|
|
125
128
|
// Dynamically import the web component
|
|
126
129
|
var loadWebComponent = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -137,6 +140,8 @@ function WalletConnectButton(_a) {
|
|
|
137
140
|
if (button) {
|
|
138
141
|
button.addEventListener("success", handleSuccess);
|
|
139
142
|
button.addEventListener("failed", handleFailed);
|
|
143
|
+
// Add click listener directly to the element
|
|
144
|
+
button.addEventListener("click", handleButtonClick);
|
|
140
145
|
}
|
|
141
146
|
return [3 /*break*/, 3];
|
|
142
147
|
case 2:
|
|
@@ -154,9 +159,131 @@ function WalletConnectButton(_a) {
|
|
|
154
159
|
if (button) {
|
|
155
160
|
button.removeEventListener("success", handleSuccess);
|
|
156
161
|
button.removeEventListener("failed", handleFailed);
|
|
162
|
+
button.removeEventListener("click", handleButtonClick);
|
|
157
163
|
}
|
|
158
164
|
};
|
|
159
165
|
}, []);
|
|
166
|
+
var fetchRequestedCredentials = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
167
|
+
var cacheKey, cached, fetchPromise;
|
|
168
|
+
var _this = this;
|
|
169
|
+
return __generator(this, function (_a) {
|
|
170
|
+
switch (_a.label) {
|
|
171
|
+
case 0:
|
|
172
|
+
if (!apiKey || !clientId)
|
|
173
|
+
return [2 /*return*/, []];
|
|
174
|
+
cacheKey = "".concat(clientId, "-").concat(walletConnectHost || "default");
|
|
175
|
+
cached = credentialsCache.get(cacheKey);
|
|
176
|
+
if (cached === null || cached === void 0 ? void 0 : cached.data) {
|
|
177
|
+
return [2 /*return*/, cached.data];
|
|
178
|
+
}
|
|
179
|
+
if (!(cached === null || cached === void 0 ? void 0 : cached.promise)) return [3 /*break*/, 2];
|
|
180
|
+
return [4 /*yield*/, cached.promise];
|
|
181
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
182
|
+
case 2:
|
|
183
|
+
fetchPromise = (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
184
|
+
var baseUrl, url, headers, response, credentials, error_2;
|
|
185
|
+
var _a, _b;
|
|
186
|
+
return __generator(this, function (_c) {
|
|
187
|
+
switch (_c.label) {
|
|
188
|
+
case 0:
|
|
189
|
+
_c.trys.push([0, 2, , 3]);
|
|
190
|
+
baseUrl = walletConnectHost || "https://wallet-connect.eu";
|
|
191
|
+
url = "".concat(baseUrl, "/api/client/").concat(clientId, "/requested-credentials");
|
|
192
|
+
headers = { 'Authorization': "Bearer ".concat(apiKey) };
|
|
193
|
+
return [4 /*yield*/, axios.get(url, { headers: headers })];
|
|
194
|
+
case 1:
|
|
195
|
+
response = _c.sent();
|
|
196
|
+
credentials = ((_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.requestedCredentials) || [];
|
|
197
|
+
// Cache the result
|
|
198
|
+
credentialsCache.set(cacheKey, { data: credentials });
|
|
199
|
+
return [2 /*return*/, credentials];
|
|
200
|
+
case 2:
|
|
201
|
+
error_2 = _c.sent();
|
|
202
|
+
// Remove failed request from cache
|
|
203
|
+
credentialsCache.delete(cacheKey);
|
|
204
|
+
throw error_2;
|
|
205
|
+
case 3: return [2 /*return*/];
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}); })();
|
|
209
|
+
// Cache the promise to prevent duplicate requests
|
|
210
|
+
credentialsCache.set(cacheKey, { promise: fetchPromise });
|
|
211
|
+
return [4 /*yield*/, fetchPromise];
|
|
212
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}); };
|
|
216
|
+
var injectCredentialsIntoShadowDOM = function (credentials, retryCount) {
|
|
217
|
+
if (retryCount === void 0) { retryCount = 0; }
|
|
218
|
+
var maxRetries = 10;
|
|
219
|
+
var walletButton = buttonRef.current;
|
|
220
|
+
if (!walletButton || !walletButton.shadowRoot) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
// Remove any existing credential info
|
|
224
|
+
var existingCredentials = walletButton.shadowRoot.querySelector('.required-credentials');
|
|
225
|
+
if (existingCredentials) {
|
|
226
|
+
existingCredentials.remove();
|
|
227
|
+
}
|
|
228
|
+
if (credentials.length === 0)
|
|
229
|
+
return;
|
|
230
|
+
// Look for the modal and website section
|
|
231
|
+
var modal = walletButton.shadowRoot.querySelector('.modal');
|
|
232
|
+
if (!modal) {
|
|
233
|
+
// Retry if modal not found yet
|
|
234
|
+
if (retryCount < maxRetries) {
|
|
235
|
+
setTimeout(function () {
|
|
236
|
+
injectCredentialsIntoShadowDOM(credentials, retryCount + 1);
|
|
237
|
+
}, 200);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
var websiteSection = modal.querySelector('.website');
|
|
243
|
+
// Determine language and translations
|
|
244
|
+
var isNL = lang === 'nl';
|
|
245
|
+
var headerText = isNL ? 'Benodigde Attestaties:' : 'Required Credentials:';
|
|
246
|
+
var getLinkText = isNL ? '→ Verkrijg attestatie' : '→ Get credential';
|
|
247
|
+
// Create credential info element
|
|
248
|
+
var credentialsDiv = document.createElement('div');
|
|
249
|
+
credentialsDiv.className = 'required-credentials';
|
|
250
|
+
credentialsDiv.innerHTML = "\n <div style=\"\n background: #f8f9fa;\n border: 1px solid #e9ecef;\n border-radius: 6px;\n padding: 12px;\n font-family: inherit;\n font-size: 13px;\n line-height: 1.4;\n \">\n <div style=\"margin: 0 0 8px 0; color: #212529; font-size: 14px; font-weight: 600;\">".concat(headerText, "</div>\n ").concat(credentials.map(function (credential) {
|
|
251
|
+
var credentialName = isNL ? credential.credentialName.nl : credential.credentialName.en;
|
|
252
|
+
return "\n <div style=\"margin-bottom: 6px; display: flex; align-items: center; flex-wrap: wrap; gap: 8px;\">\n <span style=\"color: #495057; font-weight: 500;\">".concat(credentialName, "</span>\n ").concat(credential.websiteUrl ? "\n <a href=\"".concat(credential.websiteUrl, "\" target=\"_blank\" rel=\"noopener noreferrer\" style=\"\n color: #0066cc;\n text-decoration: none;\n font-size: 12px;\n white-space: nowrap;\n \">").concat(getLinkText, "</a>\n ") : '', "\n </div>\n ");
|
|
253
|
+
}).join(''), "\n </div>\n ");
|
|
254
|
+
// Insert the credentials div after the website section
|
|
255
|
+
if (websiteSection) {
|
|
256
|
+
websiteSection.insertAdjacentElement('afterend', credentialsDiv);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
// Fallback: insert at the beginning of modal
|
|
260
|
+
modal.insertBefore(credentialsDiv, modal.firstChild);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
var handleButtonClick = function (_event) { return __awaiter(_this, void 0, void 0, function () {
|
|
264
|
+
var credentials_1, error_3;
|
|
265
|
+
return __generator(this, function (_a) {
|
|
266
|
+
switch (_a.label) {
|
|
267
|
+
case 0:
|
|
268
|
+
_a.trys.push([0, 2, , 3]);
|
|
269
|
+
return [4 /*yield*/, fetchRequestedCredentials()];
|
|
270
|
+
case 1:
|
|
271
|
+
credentials_1 = _a.sent();
|
|
272
|
+
if (credentials_1 && credentials_1.length > 0) {
|
|
273
|
+
// Inject credentials into the shadow DOM with multiple attempts
|
|
274
|
+
setTimeout(function () {
|
|
275
|
+
injectCredentialsIntoShadowDOM(credentials_1);
|
|
276
|
+
}, 100);
|
|
277
|
+
}
|
|
278
|
+
return [3 /*break*/, 3];
|
|
279
|
+
case 2:
|
|
280
|
+
error_3 = _a.sent();
|
|
281
|
+
console.error('Failed to fetch credentials:', error_3);
|
|
282
|
+
return [3 /*break*/, 3];
|
|
283
|
+
case 3: return [2 /*return*/];
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}); };
|
|
160
287
|
// Function to handle the 'success' event
|
|
161
288
|
var handleSuccess = function (e) {
|
|
162
289
|
var customEvent = e;
|
|
@@ -214,7 +341,7 @@ function WalletConnectButton(_a) {
|
|
|
214
341
|
if (error) {
|
|
215
342
|
return (jsx("div", { className: "attributes", children: jsxs("div", { className: "verification-card", children: [jsx("h2", { children: "Error" }), jsxs("p", { children: ["An error occurred while verifying your attributes: ", error] })] }) }));
|
|
216
343
|
}
|
|
217
|
-
return (jsx("nl-wallet-button", { ref: buttonRef, text: label, usecase: issuance ? "" : clientId, "start-url": "".concat(walletConnectHost || "https://wallet-connect.eu", "/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 }));
|
|
344
|
+
return (jsx("nl-wallet-button", { ref: buttonRef, text: label, usecase: issuance ? "" : clientId, "start-url": "".concat(walletConnectHost || "https://wallet-connect.eu", "/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 }));
|
|
218
345
|
}
|
|
219
346
|
|
|
220
347
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|