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
|
@@ -8,7 +8,8 @@ export interface WalletConnectButtonProps {
|
|
|
8
8
|
clientId: string;
|
|
9
9
|
onSuccess: (attributes: AttributeData | undefined) => void;
|
|
10
10
|
apiKey?: string;
|
|
11
|
-
|
|
11
|
+
useLocalWcServer?: boolean;
|
|
12
|
+
business?: boolean;
|
|
12
13
|
lang?: string;
|
|
13
14
|
helpBaseUrl?: string;
|
|
14
15
|
issuance?: boolean;
|
|
@@ -30,5 +31,5 @@ declare global {
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
declare function WalletConnectButton({ label, clientId, onSuccess, apiKey,
|
|
34
|
+
declare function WalletConnectButton({ label, clientId, onSuccess, apiKey, useLocalWcServer, business, lang, helpBaseUrl, issuance }: WalletConnectButtonProps): import("react/jsx-runtime").JSX.Element;
|
|
34
35
|
export default WalletConnectButton;
|
package/dist/index.esm.js
CHANGED
|
@@ -108,22 +108,39 @@ function useSearchParams() {
|
|
|
108
108
|
|
|
109
109
|
// Global cache to prevent duplicate requests
|
|
110
110
|
var credentialsCache = new Map();
|
|
111
|
-
function
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
function getDefaultHost(useLocalWcServer, business, issuance) {
|
|
112
|
+
// If useLocalWcServer is set, use local server
|
|
113
|
+
if (useLocalWcServer) {
|
|
114
|
+
if (business) {
|
|
115
|
+
return issuance ? 'http://localhost:4007' : 'http://bw.localhost:3021';
|
|
116
|
+
}
|
|
117
|
+
return issuance ? 'http://localhost:3007' : 'http://localhost:3021';
|
|
118
|
+
}
|
|
119
|
+
// Otherwise use remote servers
|
|
120
|
+
if (business) {
|
|
121
|
+
return issuance ? 'https://bw.issuance.wallet-connect.eu' : 'https://bw.wallet-connect.eu';
|
|
122
|
+
}
|
|
123
|
+
return issuance ? 'https://issuance.wallet-connect.eu' : 'https://wallet-connect.eu';
|
|
124
|
+
}
|
|
125
|
+
function constructURI(clientId, session_type, walletConnectHost, business) {
|
|
126
|
+
var request_uri = "".concat(walletConnectHost, "/disclosure/").concat(clientId, "/request_uri?session_type=").concat(session_type);
|
|
114
127
|
var request_uri_method = "post";
|
|
115
128
|
var client_id_uri = "".concat(clientId, ".example.com");
|
|
116
|
-
|
|
129
|
+
var deepLinkScheme = business
|
|
130
|
+
? 'businesswalletdebuginteraction://wallet.kvk.rijksoverheid.nl'
|
|
131
|
+
: 'walletdebuginteraction://wallet.edi.rijksoverheid.nl';
|
|
132
|
+
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);
|
|
117
133
|
}
|
|
118
134
|
function WalletConnectButton(_a) {
|
|
119
135
|
var _this = this;
|
|
120
|
-
var label = _a.label, clientId = _a.clientId, onSuccess = _a.onSuccess, apiKey = _a.apiKey,
|
|
121
|
-
var
|
|
122
|
-
var
|
|
123
|
-
var
|
|
136
|
+
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;
|
|
137
|
+
var _e = useSearchParams(), searchParams = _e[0], setSearchParams = _e[1], removeSearchParam = _e[2];
|
|
138
|
+
var _f = useState(false), loading = _f[0], setLoading = _f[1];
|
|
139
|
+
var _g = useState(null), error = _g[0], setError = _g[1];
|
|
124
140
|
var buttonRef = useRef(null);
|
|
125
|
-
var
|
|
126
|
-
var
|
|
141
|
+
var walletConnectHost = getDefaultHost(useLocalWcServer, business, issuance);
|
|
142
|
+
var sameDeviceUl = constructURI(clientId, "same_device", walletConnectHost, business);
|
|
143
|
+
var crossDeviceUl = constructURI(clientId, "cross_device", walletConnectHost, business);
|
|
127
144
|
useEffect(function () {
|
|
128
145
|
// Dynamically import the web component
|
|
129
146
|
var loadWebComponent = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -171,7 +188,7 @@ function WalletConnectButton(_a) {
|
|
|
171
188
|
case 0:
|
|
172
189
|
if (!apiKey || !clientId)
|
|
173
190
|
return [2 /*return*/, []];
|
|
174
|
-
cacheKey = "".concat(clientId, "-").concat(walletConnectHost
|
|
191
|
+
cacheKey = "".concat(clientId, "-").concat(walletConnectHost);
|
|
175
192
|
cached = credentialsCache.get(cacheKey);
|
|
176
193
|
if (cached === null || cached === void 0 ? void 0 : cached.data) {
|
|
177
194
|
return [2 /*return*/, cached.data];
|
|
@@ -181,14 +198,13 @@ function WalletConnectButton(_a) {
|
|
|
181
198
|
case 1: return [2 /*return*/, _a.sent()];
|
|
182
199
|
case 2:
|
|
183
200
|
fetchPromise = (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
184
|
-
var
|
|
201
|
+
var url, headers, response, credentials, error_2;
|
|
185
202
|
var _a, _b;
|
|
186
203
|
return __generator(this, function (_c) {
|
|
187
204
|
switch (_c.label) {
|
|
188
205
|
case 0:
|
|
189
206
|
_c.trys.push([0, 2, , 3]);
|
|
190
|
-
|
|
191
|
-
url = "".concat(baseUrl, "/api/client/").concat(clientId, "/requested-credentials");
|
|
207
|
+
url = "".concat(walletConnectHost, "/api/client/").concat(clientId, "/requested-credentials");
|
|
192
208
|
headers = { 'Authorization': "Bearer ".concat(apiKey) };
|
|
193
209
|
return [4 /*yield*/, axios.get(url, { headers: headers })];
|
|
194
210
|
case 1:
|
|
@@ -307,7 +323,7 @@ function WalletConnectButton(_a) {
|
|
|
307
323
|
if (!session_token)
|
|
308
324
|
return;
|
|
309
325
|
setLoading(true);
|
|
310
|
-
var baseUrl = apiKey ?
|
|
326
|
+
var baseUrl = apiKey ? walletConnectHost : "";
|
|
311
327
|
var url = baseUrl + "/api/disclosed-attributes?session_token=".concat(session_token, "&client_id=").concat(clientId);
|
|
312
328
|
if (nonce)
|
|
313
329
|
url = "".concat(url, "&nonce=").concat(nonce);
|
|
@@ -341,7 +357,7 @@ function WalletConnectButton(_a) {
|
|
|
341
357
|
if (error) {
|
|
342
358
|
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] })] }) }));
|
|
343
359
|
}
|
|
344
|
-
return (jsx("nl-wallet-button", { ref: buttonRef, text: label, usecase: issuance ? "" : clientId, "start-url": "".concat(walletConnectHost
|
|
360
|
+
return (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 }));
|
|
345
361
|
}
|
|
346
362
|
|
|
347
363
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|