@calimero-network/mero-react 10.1.1 → 10.2.0
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/index.cjs +33 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -8
- package/dist/index.d.ts +16 -8
- package/dist/index.js +34 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -133,6 +133,15 @@ function resolveTokenAdoption(params) {
|
|
|
133
133
|
return { adopt: false, reason: "stale" };
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
// src/utils/desktop.ts
|
|
137
|
+
function isDesktopWindow() {
|
|
138
|
+
if (typeof window === "undefined") return false;
|
|
139
|
+
const w = window;
|
|
140
|
+
const internals = w.__TAURI_INTERNALS__;
|
|
141
|
+
const tauri = typeof internals === "object" && internals !== null && !(typeof Node !== "undefined" && internals instanceof Node) && typeof internals.invoke === "function";
|
|
142
|
+
return tauri || w.__TAURI_FETCH_PROXY_INJECTED__ === true;
|
|
143
|
+
}
|
|
144
|
+
|
|
136
145
|
// src/storage/index.ts
|
|
137
146
|
var STORAGE_KEYS = {
|
|
138
147
|
ACCESS_TOKEN: "mero:access_token",
|
|
@@ -283,6 +292,21 @@ function clearAllStorage() {
|
|
|
283
292
|
var MeroContext = react.createContext(null);
|
|
284
293
|
var DEFAULT_REGISTRY_URL = "https://apps.calimero.network";
|
|
285
294
|
var isBrowser = typeof window !== "undefined";
|
|
295
|
+
var DESKTOP_HOST = isDesktopWindow();
|
|
296
|
+
var parsedCallback = null;
|
|
297
|
+
function readAuthCallback() {
|
|
298
|
+
const href = window.location.href;
|
|
299
|
+
if (parsedCallback?.href !== href) {
|
|
300
|
+
parsedCallback = { href, result: meroJs.parseAuthCallback(href, { allowUnsolicited: DESKTOP_HOST }) };
|
|
301
|
+
}
|
|
302
|
+
return parsedCallback.result;
|
|
303
|
+
}
|
|
304
|
+
function clearAuthCallbackFromUrl() {
|
|
305
|
+
if (!new URLSearchParams(window.location.hash.slice(1)).has("access_token")) return;
|
|
306
|
+
const url = new URL(window.location.href);
|
|
307
|
+
url.searchParams.delete("auth_state");
|
|
308
|
+
window.history.replaceState({}, "", url.pathname + url.search);
|
|
309
|
+
}
|
|
286
310
|
function getPermissionsForMode(mode) {
|
|
287
311
|
switch (mode) {
|
|
288
312
|
case "single-context" /* SingleContext */:
|
|
@@ -345,7 +369,7 @@ function MeroProvider({
|
|
|
345
369
|
const recoveringRef = react.useRef(false);
|
|
346
370
|
const callbackRef = react.useRef(void 0);
|
|
347
371
|
if (callbackRef.current === void 0 && isBrowser) {
|
|
348
|
-
callbackRef.current =
|
|
372
|
+
callbackRef.current = readAuthCallback();
|
|
349
373
|
}
|
|
350
374
|
const createMeroInstance = react.useCallback(
|
|
351
375
|
(url) => {
|
|
@@ -478,6 +502,7 @@ function MeroProvider({
|
|
|
478
502
|
};
|
|
479
503
|
}, [delegated, contextId, packageName, registryUrl]);
|
|
480
504
|
react.useEffect(() => {
|
|
505
|
+
if (isBrowser) clearAuthCallbackFromUrl();
|
|
481
506
|
if (delegated) return;
|
|
482
507
|
let active = true;
|
|
483
508
|
const init = async () => {
|
|
@@ -492,9 +517,6 @@ function MeroProvider({
|
|
|
492
517
|
initiated: initiatedNodeUrl,
|
|
493
518
|
allowedNodeUrls
|
|
494
519
|
});
|
|
495
|
-
if (isBrowser) {
|
|
496
|
-
window.history.replaceState({}, "", window.location.pathname + window.location.search);
|
|
497
|
-
}
|
|
498
520
|
callbackRef.current = null;
|
|
499
521
|
if (rejected) {
|
|
500
522
|
console.error(
|
|
@@ -927,7 +949,7 @@ function isReturningFromWallet(location = typeof window === "undefined" ? void 0
|
|
|
927
949
|
}
|
|
928
950
|
function useAccountEnrolment({
|
|
929
951
|
walletUrl: walletOverride,
|
|
930
|
-
enabled =
|
|
952
|
+
enabled = !isDesktopWindow()
|
|
931
953
|
} = {}) {
|
|
932
954
|
const { connectWithAccount, cloudBaseUrl } = useMero();
|
|
933
955
|
const [note, setNote] = react.useState(null);
|
|
@@ -1019,13 +1041,6 @@ function useAccountEnrolment({
|
|
|
1019
1041
|
customWallet: walletOverride !== void 0
|
|
1020
1042
|
};
|
|
1021
1043
|
}
|
|
1022
|
-
|
|
1023
|
-
// src/utils/desktop.ts
|
|
1024
|
-
function isDesktopWindow() {
|
|
1025
|
-
if (typeof window === "undefined") return false;
|
|
1026
|
-
const w = window;
|
|
1027
|
-
return "__TAURI_INTERNALS__" in w || w.__TAURI_FETCH_PROXY_INJECTED__ === true;
|
|
1028
|
-
}
|
|
1029
1044
|
var CUSTOM_SELECTION = "__custom__";
|
|
1030
1045
|
var TABS = [
|
|
1031
1046
|
{ id: "node", label: "Node" },
|
|
@@ -1312,9 +1327,11 @@ function LoginModal({
|
|
|
1312
1327
|
theme,
|
|
1313
1328
|
localNodePorts = meroJs.DEFAULT_LOCAL_NODE_PORTS,
|
|
1314
1329
|
cloud,
|
|
1330
|
+
cloudOnDesktop = false,
|
|
1315
1331
|
initialTab: initialTabProp
|
|
1316
1332
|
}) {
|
|
1317
|
-
const
|
|
1333
|
+
const cloudAllowed = cloudOnDesktop || !isDesktopWindow();
|
|
1334
|
+
const ownCloud = cloud === void 0 && cloudAllowed;
|
|
1318
1335
|
const own = useAccountEnrolment({ enabled: ownCloud });
|
|
1319
1336
|
const cloudTab = react.useMemo(
|
|
1320
1337
|
() => ownCloud ? {
|
|
@@ -1324,8 +1341,8 @@ function LoginModal({
|
|
|
1324
1341
|
note: own.note,
|
|
1325
1342
|
walletUrl: own.walletUrl,
|
|
1326
1343
|
customWallet: own.customWallet
|
|
1327
|
-
} : cloud || null,
|
|
1328
|
-
[cloud, ownCloud, own.goToWallet, own.note, own.walletUrl, own.customWallet]
|
|
1344
|
+
} : cloudAllowed && cloud || null,
|
|
1345
|
+
[cloud, cloudAllowed, ownCloud, own.goToWallet, own.note, own.walletUrl, own.customWallet]
|
|
1329
1346
|
);
|
|
1330
1347
|
const initialTab = initialTabProp ?? (ownCloud && own.returning ? "cloud" : "node");
|
|
1331
1348
|
const [tab, setTab] = react.useState(initialTab);
|
|
@@ -1859,6 +1876,7 @@ function ConnectButton({
|
|
|
1859
1876
|
walletUrl: enrolment.walletUrl,
|
|
1860
1877
|
customWallet: enrolment.customWallet
|
|
1861
1878
|
} : false,
|
|
1879
|
+
cloudOnDesktop: cloud,
|
|
1862
1880
|
initialTab: cloud && enrolment.returning ? "cloud" : "node"
|
|
1863
1881
|
}
|
|
1864
1882
|
)
|