@getpara/graz-integration 2.0.0-dev.12 → 2.1.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/cjs/connector.js +109 -0
- package/dist/cjs/connectorModal.js +154 -0
- package/dist/cjs/index.js +28 -0
- package/dist/cjs/package.json +3 -0
- package/dist/{connector.js → esm/connector.js} +1 -1
- package/dist/{connectorModal.js → esm/connectorModal.js} +1 -27
- package/dist/{index.js → esm/index.js} +1 -1
- package/dist/{connectorModal.d.ts → types/connectorModal.d.ts} +1 -1
- package/dist/{index.d.ts → types/index.d.ts} +2 -2
- package/package.json +26 -15
- package/scripts/build.mjs +0 -36
- package/src/connector.ts +0 -88
- package/src/connectorModal.tsx +0 -120
- package/src/index.ts +0 -2
- package/tsconfig.json +0 -13
- package/vitest.config.js +0 -22
- /package/dist/{chunk-IV3L3JVM.js → esm/chunk-IV3L3JVM.js} +0 -0
- /package/dist/{package.json → esm/package.json} +0 -0
- /package/dist/{connector.d.ts → types/connector.d.ts} +0 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __async = (__this, __arguments, generator) => {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
var fulfilled = (value) => {
|
|
22
|
+
try {
|
|
23
|
+
step(generator.next(value));
|
|
24
|
+
} catch (e) {
|
|
25
|
+
reject(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var rejected = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
step(generator.throw(value));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var connector_exports = {};
|
|
40
|
+
__export(connector_exports, {
|
|
41
|
+
ParaGrazConnector: () => ParaGrazConnector
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(connector_exports);
|
|
44
|
+
var import_graz_connector = require("@getpara/graz-connector");
|
|
45
|
+
var import_connectorModal = require("./connectorModal.js");
|
|
46
|
+
class ParaGrazConnector extends import_graz_connector.ParaGrazConnector {
|
|
47
|
+
constructor(config, chains) {
|
|
48
|
+
super(config, chains);
|
|
49
|
+
this.isModalClosed = true;
|
|
50
|
+
}
|
|
51
|
+
waitForLogin(timeoutMs = 6e4) {
|
|
52
|
+
return __async(this, null, function* () {
|
|
53
|
+
const deadline = Date.now() + timeoutMs;
|
|
54
|
+
let delay = 500;
|
|
55
|
+
const MAX_DELAY = 5e3;
|
|
56
|
+
while (true) {
|
|
57
|
+
if (yield this.paraWebClient.isFullyLoggedIn()) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (this.isModalClosed) {
|
|
61
|
+
throw new Error("Login modal closed by user");
|
|
62
|
+
}
|
|
63
|
+
if (Date.now() >= deadline) {
|
|
64
|
+
throw new Error(`Login timeout after ${timeoutMs / 1e3}s`);
|
|
65
|
+
}
|
|
66
|
+
yield new Promise((r) => setTimeout(r, delay));
|
|
67
|
+
delay = Math.min(delay * 1.5, MAX_DELAY);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
enable(chainIdsInput) {
|
|
72
|
+
return __async(this, null, function* () {
|
|
73
|
+
var _a, _b, _c, _d, _e;
|
|
74
|
+
const chainIds = (0, import_graz_connector.toArray)(chainIdsInput);
|
|
75
|
+
const previousEnabled = new Set(this.enabledChainIds);
|
|
76
|
+
try {
|
|
77
|
+
chainIds.forEach((id) => this.enabledChainIds.add(id));
|
|
78
|
+
if (yield this.hasCosmosWallet()) {
|
|
79
|
+
(_b = (_a = this.events) == null ? void 0 : _a.onEnabled) == null ? void 0 : _b.call(_a, chainIds, this);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
this.isModalClosed = false;
|
|
83
|
+
yield (0, import_connectorModal.renderModal)(
|
|
84
|
+
this.paraWebClient,
|
|
85
|
+
(_c = this.config.modalProps) != null ? _c : {},
|
|
86
|
+
() => {
|
|
87
|
+
this.isModalClosed = true;
|
|
88
|
+
},
|
|
89
|
+
this.config.queryClient
|
|
90
|
+
);
|
|
91
|
+
yield this.waitForLogin();
|
|
92
|
+
yield this.waitForAccounts();
|
|
93
|
+
(_e = (_d = this.events) == null ? void 0 : _d.onEnabled) == null ? void 0 : _e.call(_d, chainIds, this);
|
|
94
|
+
} catch (err) {
|
|
95
|
+
this.enabledChainIds = previousEnabled;
|
|
96
|
+
if (err instanceof Error) {
|
|
97
|
+
throw err;
|
|
98
|
+
}
|
|
99
|
+
throw new Error("Failed to enable Para wallet with modal");
|
|
100
|
+
} finally {
|
|
101
|
+
this.isModalClosed = true;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
107
|
+
0 && (module.exports = {
|
|
108
|
+
ParaGrazConnector
|
|
109
|
+
});
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __export = (target, all) => {
|
|
26
|
+
for (var name in all)
|
|
27
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
|
+
};
|
|
29
|
+
var __copyProps = (to, from, except, desc) => {
|
|
30
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
+
for (let key of __getOwnPropNames(from))
|
|
32
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
33
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
34
|
+
}
|
|
35
|
+
return to;
|
|
36
|
+
};
|
|
37
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
38
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
39
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
40
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
41
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
42
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
43
|
+
mod
|
|
44
|
+
));
|
|
45
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
+
var __async = (__this, __arguments, generator) => {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
var fulfilled = (value) => {
|
|
49
|
+
try {
|
|
50
|
+
step(generator.next(value));
|
|
51
|
+
} catch (e) {
|
|
52
|
+
reject(e);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
var rejected = (value) => {
|
|
56
|
+
try {
|
|
57
|
+
step(generator.throw(value));
|
|
58
|
+
} catch (e) {
|
|
59
|
+
reject(e);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
63
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
var connectorModal_exports = {};
|
|
67
|
+
__export(connectorModal_exports, {
|
|
68
|
+
renderModal: () => renderModal
|
|
69
|
+
});
|
|
70
|
+
module.exports = __toCommonJS(connectorModal_exports);
|
|
71
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
72
|
+
var import_react_sdk_lite = require("@getpara/react-sdk-lite");
|
|
73
|
+
let rendererPromise = null;
|
|
74
|
+
function getRenderer() {
|
|
75
|
+
if (!rendererPromise) {
|
|
76
|
+
rendererPromise = (() => __async(this, null, function* () {
|
|
77
|
+
try {
|
|
78
|
+
const { createRoot } = yield import("react-dom/client");
|
|
79
|
+
return { createRoot: (el) => createRoot(el) };
|
|
80
|
+
} catch (e) {
|
|
81
|
+
const ReactDOM = yield import("react-dom");
|
|
82
|
+
return {
|
|
83
|
+
legacyRender: ReactDOM.render,
|
|
84
|
+
legacyUnmount: ReactDOM.unmountComponentAtNode
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}))();
|
|
88
|
+
}
|
|
89
|
+
return rendererPromise;
|
|
90
|
+
}
|
|
91
|
+
const wrap = (ctx, err, extraInfo) => {
|
|
92
|
+
const baseMsg = `connectorModal error in ${ctx}: ${err.message}`;
|
|
93
|
+
const fullMsg = extraInfo ? `${baseMsg}. Additional details: ${extraInfo}` : baseMsg;
|
|
94
|
+
throw new Error(fullMsg);
|
|
95
|
+
};
|
|
96
|
+
function renderModal(para, modalProps, onCloseArg, queryClient) {
|
|
97
|
+
return __async(this, null, function* () {
|
|
98
|
+
var _a, _b, _c;
|
|
99
|
+
if (typeof window === "undefined") {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const props = modalProps != null ? modalProps : {};
|
|
103
|
+
const containerId = "para-modal";
|
|
104
|
+
let container = document.getElementById(containerId);
|
|
105
|
+
if (!container) {
|
|
106
|
+
container = document.createElement("div");
|
|
107
|
+
container.id = containerId;
|
|
108
|
+
document.body.appendChild(container);
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const renderer = yield getRenderer();
|
|
112
|
+
let root = (_a = container.__paraRoot) != null ? _a : null;
|
|
113
|
+
if (!root && renderer.createRoot) {
|
|
114
|
+
root = renderer.createRoot(container);
|
|
115
|
+
container.__paraRoot = root;
|
|
116
|
+
}
|
|
117
|
+
const { ParaProvider } = yield import("@getpara/react-sdk-lite");
|
|
118
|
+
const { QueryClientProvider } = yield import("@tanstack/react-query");
|
|
119
|
+
const handleClose = () => {
|
|
120
|
+
var _a2, _b2;
|
|
121
|
+
onCloseArg();
|
|
122
|
+
(_a2 = props.onClose) == null ? void 0 : _a2.call(props);
|
|
123
|
+
(0, import_react_sdk_lite.setIsOpen)(false);
|
|
124
|
+
if (root) {
|
|
125
|
+
root.unmount();
|
|
126
|
+
} else {
|
|
127
|
+
(_b2 = renderer.legacyUnmount) == null ? void 0 : _b2.call(renderer, container);
|
|
128
|
+
}
|
|
129
|
+
container == null ? void 0 : container.remove();
|
|
130
|
+
};
|
|
131
|
+
const element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
132
|
+
ParaProvider,
|
|
133
|
+
{
|
|
134
|
+
paraClientConfig: para,
|
|
135
|
+
config: { appName: (_b = props.appName) != null ? _b : "" },
|
|
136
|
+
paraModalConfig: __spreadProps(__spreadValues({}, props), { onClose: handleClose })
|
|
137
|
+
}
|
|
138
|
+
) });
|
|
139
|
+
if (root) {
|
|
140
|
+
root.render(element);
|
|
141
|
+
} else {
|
|
142
|
+
(_c = renderer.legacyRender) == null ? void 0 : _c.call(renderer, element, container);
|
|
143
|
+
}
|
|
144
|
+
(0, import_react_sdk_lite.setIsOpen)(true);
|
|
145
|
+
} catch (err) {
|
|
146
|
+
container == null ? void 0 : container.remove();
|
|
147
|
+
throw wrap("renderModal", err, `containerId: ${containerId}, modalProps: ${JSON.stringify(props)}`);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
152
|
+
0 && (module.exports = {
|
|
153
|
+
renderModal
|
|
154
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var src_exports = {};
|
|
20
|
+
__export(src_exports, {
|
|
21
|
+
ParaGrazConnector: () => import_connector.ParaGrazConnector
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(src_exports);
|
|
24
|
+
var import_connector = require("./connector.js");
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
ParaGrazConnector
|
|
28
|
+
});
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
ParaGrazConnector as CoreParaGrazConnector,
|
|
7
7
|
toArray
|
|
8
8
|
} from "@getpara/graz-connector";
|
|
9
|
-
import { renderModal } from "./connectorModal";
|
|
9
|
+
import { renderModal } from "./connectorModal.js";
|
|
10
10
|
class ParaGrazConnector extends CoreParaGrazConnector {
|
|
11
11
|
constructor(config, chains) {
|
|
12
12
|
super(config, chains);
|
|
@@ -8,20 +8,13 @@ import { jsx } from "react/jsx-runtime";
|
|
|
8
8
|
import { setIsOpen } from "@getpara/react-sdk-lite";
|
|
9
9
|
let rendererPromise = null;
|
|
10
10
|
function getRenderer() {
|
|
11
|
-
console.log("[DEBUG] getRenderer called.");
|
|
12
11
|
if (!rendererPromise) {
|
|
13
12
|
rendererPromise = (() => __async(this, null, function* () {
|
|
14
13
|
try {
|
|
15
14
|
const { createRoot } = yield import("react-dom/client");
|
|
16
|
-
console.log("[DEBUG] Imported createRoot from react-dom/client.");
|
|
17
15
|
return { createRoot: (el) => createRoot(el) };
|
|
18
|
-
} catch (
|
|
19
|
-
console.log(
|
|
20
|
-
"[DEBUG] Failed to import react-dom/client; falling back to legacy ReactDOM. Error:",
|
|
21
|
-
err.message
|
|
22
|
-
);
|
|
16
|
+
} catch (e) {
|
|
23
17
|
const ReactDOM = yield import("react-dom");
|
|
24
|
-
console.log("[DEBUG] Imported legacy ReactDOM.");
|
|
25
18
|
return {
|
|
26
19
|
legacyRender: ReactDOM.render,
|
|
27
20
|
legacyUnmount: ReactDOM.unmountComponentAtNode
|
|
@@ -39,51 +32,37 @@ const wrap = (ctx, err, extraInfo) => {
|
|
|
39
32
|
function renderModal(para, modalProps, onCloseArg, queryClient) {
|
|
40
33
|
return __async(this, null, function* () {
|
|
41
34
|
var _a, _b, _c;
|
|
42
|
-
console.log("[DEBUG] renderModal called with para:", para, "modalProps:", modalProps, "queryClient:", queryClient);
|
|
43
35
|
if (typeof window === "undefined") {
|
|
44
|
-
console.log("[DEBUG] renderModal: window undefined, returning early.");
|
|
45
36
|
return;
|
|
46
37
|
}
|
|
47
38
|
const props = modalProps != null ? modalProps : {};
|
|
48
|
-
console.log("[DEBUG] Using modal props:", props);
|
|
49
39
|
const containerId = "para-modal";
|
|
50
40
|
let container = document.getElementById(containerId);
|
|
51
|
-
console.log("[DEBUG] Existing container:", container);
|
|
52
41
|
if (!container) {
|
|
53
42
|
container = document.createElement("div");
|
|
54
43
|
container.id = containerId;
|
|
55
44
|
document.body.appendChild(container);
|
|
56
|
-
console.log("[DEBUG] Created new container:", container);
|
|
57
45
|
}
|
|
58
46
|
try {
|
|
59
47
|
const renderer = yield getRenderer();
|
|
60
|
-
console.log("[DEBUG] Retrieved renderer:", renderer);
|
|
61
48
|
let root = (_a = container.__paraRoot) != null ? _a : null;
|
|
62
|
-
console.log("[DEBUG] Existing root:", root);
|
|
63
49
|
if (!root && renderer.createRoot) {
|
|
64
50
|
root = renderer.createRoot(container);
|
|
65
51
|
container.__paraRoot = root;
|
|
66
|
-
console.log("[DEBUG] Created new root with createRoot.");
|
|
67
52
|
}
|
|
68
53
|
const { ParaProvider } = yield import("@getpara/react-sdk-lite");
|
|
69
|
-
console.log("[DEBUG] Imported ParaProvider from @getpara/react-sdk-lite.");
|
|
70
54
|
const { QueryClientProvider } = yield import("@tanstack/react-query");
|
|
71
|
-
console.log("[DEBUG] Imported QueryClientProvider from @tanstack/react-query.");
|
|
72
55
|
const handleClose = () => {
|
|
73
56
|
var _a2, _b2;
|
|
74
|
-
console.log("[DEBUG] handleClose triggered.");
|
|
75
57
|
onCloseArg();
|
|
76
58
|
(_a2 = props.onClose) == null ? void 0 : _a2.call(props);
|
|
77
59
|
setIsOpen(false);
|
|
78
60
|
if (root) {
|
|
79
61
|
root.unmount();
|
|
80
|
-
console.log("[DEBUG] Unmounted using root.unmount.");
|
|
81
62
|
} else {
|
|
82
63
|
(_b2 = renderer.legacyUnmount) == null ? void 0 : _b2.call(renderer, container);
|
|
83
|
-
console.log("[DEBUG] Unmounted using legacyUnmount.");
|
|
84
64
|
}
|
|
85
65
|
container == null ? void 0 : container.remove();
|
|
86
|
-
console.log("[DEBUG] Removed container.");
|
|
87
66
|
};
|
|
88
67
|
const element = /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ jsx(
|
|
89
68
|
ParaProvider,
|
|
@@ -93,18 +72,13 @@ function renderModal(para, modalProps, onCloseArg, queryClient) {
|
|
|
93
72
|
paraModalConfig: __spreadProps(__spreadValues({}, props), { onClose: handleClose })
|
|
94
73
|
}
|
|
95
74
|
) });
|
|
96
|
-
console.log("[DEBUG] Created render element.");
|
|
97
75
|
if (root) {
|
|
98
76
|
root.render(element);
|
|
99
|
-
console.log("[DEBUG] Rendered using root.render.");
|
|
100
77
|
} else {
|
|
101
78
|
(_c = renderer.legacyRender) == null ? void 0 : _c.call(renderer, element, container);
|
|
102
|
-
console.log("[DEBUG] Rendered using legacyRender.");
|
|
103
79
|
}
|
|
104
80
|
setIsOpen(true);
|
|
105
|
-
console.log("[DEBUG] Set modal isOpen to true.");
|
|
106
81
|
} catch (err) {
|
|
107
|
-
console.log("[DEBUG] Error in renderModal; cleaning up container.");
|
|
108
82
|
container == null ? void 0 : container.remove();
|
|
109
83
|
throw wrap("renderModal", err, `containerId: ${containerId}, modalProps: ${JSON.stringify(props)}`);
|
|
110
84
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import ParaWeb from '@getpara/react-sdk-lite';
|
|
2
2
|
import { type QueryClient } from '@tanstack/react-query';
|
|
3
|
-
import { ParaModalProps } from './connector';
|
|
3
|
+
import { ParaModalProps } from './connector.js';
|
|
4
4
|
export declare function renderModal(para: ParaWeb, modalProps: Partial<ParaModalProps> | undefined, onCloseArg: () => void, queryClient: QueryClient): Promise<void>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { ParaGrazConnector } from './connector';
|
|
2
|
-
export type { ParaModalProps, ParaGrazConfig } from './connector';
|
|
1
|
+
export { ParaGrazConnector } from './connector.js';
|
|
2
|
+
export type { ParaModalProps, ParaGrazConfig } from './connector.js';
|
package/package.json
CHANGED
|
@@ -1,29 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/graz-integration",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
5
|
+
"main": "dist/esm/index.js",
|
|
6
|
+
"types": "dist/types/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/types/index.d.ts",
|
|
10
|
+
"import": "./dist/esm/index.js",
|
|
11
|
+
"default": "./dist/esm/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
8
17
|
"scripts": {
|
|
9
|
-
"build": "rm -rf dist &&
|
|
10
|
-
"
|
|
11
|
-
"typegen": "tsc --emitDeclarationOnly"
|
|
18
|
+
"build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
|
|
19
|
+
"build:types": "rm -rf dist/types && tsc --module esnext --declarationDir dist/types --emitDeclarationOnly --declaration"
|
|
12
20
|
},
|
|
13
21
|
"dependencies": {
|
|
14
|
-
"@getpara/graz-connector": "
|
|
22
|
+
"@getpara/graz-connector": "2.1.0"
|
|
15
23
|
},
|
|
16
24
|
"devDependencies": {
|
|
17
|
-
"@getpara/react-sdk-lite": "
|
|
25
|
+
"@getpara/react-sdk-lite": "2.1.0",
|
|
18
26
|
"@tanstack/react-query": "^5.74.0",
|
|
19
|
-
"graz": "^0.
|
|
27
|
+
"graz": "^0.4.1",
|
|
28
|
+
"react": "^18.2.0",
|
|
29
|
+
"react-dom": "^18.2.0",
|
|
20
30
|
"typescript": "5.1.6"
|
|
21
31
|
},
|
|
22
32
|
"peerDependencies": {
|
|
23
|
-
"@getpara/react-sdk-lite": "
|
|
33
|
+
"@getpara/react-sdk-lite": "2.0.0-alpha.65",
|
|
24
34
|
"@tanstack/react-query": "^5.74.0",
|
|
25
|
-
"graz": "
|
|
26
|
-
"react": ">=18",
|
|
27
|
-
"react-dom": ">=18"
|
|
28
|
-
}
|
|
35
|
+
"graz": ">=0.4.1",
|
|
36
|
+
"react": ">=18.0.0",
|
|
37
|
+
"react-dom": ">=18.0.0"
|
|
38
|
+
},
|
|
39
|
+
"gitHead": "3ae7f836324a3a2a8a57156e16304aeaf0d37b42"
|
|
29
40
|
}
|
package/scripts/build.mjs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import * as esbuild from 'esbuild';
|
|
2
|
-
import * as fs from 'fs/promises';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
import { dirname, resolve } from 'path';
|
|
5
|
-
import { glob } from 'glob';
|
|
6
|
-
|
|
7
|
-
const entryPoints = await glob('src/**/*.{ts,tsx,js,jsx}');
|
|
8
|
-
|
|
9
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
|
-
const distDir = resolve(__dirname, '../dist');
|
|
11
|
-
|
|
12
|
-
await fs.mkdir(distDir, { recursive: true });
|
|
13
|
-
await fs.writeFile(`${distDir}/package.json`, JSON.stringify({ type: 'module', sideEffects: false }, null, 2));
|
|
14
|
-
|
|
15
|
-
/** @type {import('esbuild').BuildOptions} */
|
|
16
|
-
await esbuild.build({
|
|
17
|
-
banner: {
|
|
18
|
-
js: '"use client";', // Required for Next 13 App Router
|
|
19
|
-
},
|
|
20
|
-
bundle: false,
|
|
21
|
-
write: true,
|
|
22
|
-
format: 'esm',
|
|
23
|
-
loader: {
|
|
24
|
-
'.png': 'dataurl',
|
|
25
|
-
'.svg': 'dataurl',
|
|
26
|
-
'.json': 'text',
|
|
27
|
-
},
|
|
28
|
-
platform: 'browser',
|
|
29
|
-
entryPoints,
|
|
30
|
-
outdir: distDir,
|
|
31
|
-
allowOverwrite: true,
|
|
32
|
-
splitting: true, // Required for tree shaking
|
|
33
|
-
minify: false,
|
|
34
|
-
target: ['es2015'],
|
|
35
|
-
packages: 'external',
|
|
36
|
-
});
|
package/src/connector.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { ChainInfo } from '@keplr-wallet/types';
|
|
2
|
-
import {
|
|
3
|
-
ParaGrazConnector as CoreParaGrazConnector,
|
|
4
|
-
ParaGrazConfig as CoreParaGrazConfig,
|
|
5
|
-
toArray,
|
|
6
|
-
} from '@getpara/graz-connector';
|
|
7
|
-
import { ParaModalProps as CoreParaModalProps } from '@getpara/react-sdk-lite';
|
|
8
|
-
import { renderModal } from './connectorModal';
|
|
9
|
-
import { QueryClient } from '@tanstack/react-query';
|
|
10
|
-
|
|
11
|
-
export type ParaModalProps = Omit<CoreParaModalProps, 'isOpen' | 'para'> & { appName: string };
|
|
12
|
-
|
|
13
|
-
export interface ParaGrazConfig extends CoreParaGrazConfig {
|
|
14
|
-
modalProps?: ParaModalProps;
|
|
15
|
-
queryClient?: QueryClient;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class ParaGrazConnector extends CoreParaGrazConnector {
|
|
19
|
-
protected isModalClosed = true;
|
|
20
|
-
declare protected config: ParaGrazConfig;
|
|
21
|
-
|
|
22
|
-
constructor(config: ParaGrazConfig, chains?: ChainInfo[] | null) {
|
|
23
|
-
super(config, chains);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
protected async waitForLogin(timeoutMs = 60_000): Promise<void> {
|
|
27
|
-
const deadline = Date.now() + timeoutMs;
|
|
28
|
-
let delay = 500;
|
|
29
|
-
const MAX_DELAY = 5_000;
|
|
30
|
-
|
|
31
|
-
while (true) {
|
|
32
|
-
if (await this.paraWebClient.isFullyLoggedIn()) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (this.isModalClosed) {
|
|
37
|
-
throw new Error('Login modal closed by user');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (Date.now() >= deadline) {
|
|
41
|
-
throw new Error(`Login timeout after ${timeoutMs / 1000}s`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
await new Promise(r => setTimeout(r, delay));
|
|
45
|
-
delay = Math.min(delay * 1.5, MAX_DELAY);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async enable(chainIdsInput: string | string[]): Promise<void> {
|
|
50
|
-
const chainIds = toArray(chainIdsInput);
|
|
51
|
-
const previousEnabled = new Set(this.enabledChainIds);
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
chainIds.forEach(id => this.enabledChainIds.add(id));
|
|
55
|
-
|
|
56
|
-
if (await this.hasCosmosWallet()) {
|
|
57
|
-
this.events?.onEnabled?.(chainIds, this);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
this.isModalClosed = false;
|
|
62
|
-
|
|
63
|
-
await renderModal(
|
|
64
|
-
this.paraWebClient,
|
|
65
|
-
this.config.modalProps ?? {},
|
|
66
|
-
() => {
|
|
67
|
-
this.isModalClosed = true;
|
|
68
|
-
},
|
|
69
|
-
this.config.queryClient!,
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
await this.waitForLogin();
|
|
73
|
-
await this.waitForAccounts();
|
|
74
|
-
|
|
75
|
-
this.events?.onEnabled?.(chainIds, this);
|
|
76
|
-
} catch (err) {
|
|
77
|
-
this.enabledChainIds = previousEnabled;
|
|
78
|
-
|
|
79
|
-
if (err instanceof Error) {
|
|
80
|
-
throw err;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
throw new Error('Failed to enable Para wallet with modal');
|
|
84
|
-
} finally {
|
|
85
|
-
this.isModalClosed = true;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
package/src/connectorModal.tsx
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import ParaWeb, { setIsOpen } from '@getpara/react-sdk-lite';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { type QueryClient } from '@tanstack/react-query';
|
|
4
|
-
import { ParaModalProps } from './connector';
|
|
5
|
-
|
|
6
|
-
type Root = { render(node: React.ReactNode): void; unmount(): void };
|
|
7
|
-
|
|
8
|
-
let rendererPromise: Promise<{
|
|
9
|
-
createRoot?: (el: HTMLElement) => Root;
|
|
10
|
-
legacyRender?: (node: React.ReactNode, el: HTMLElement) => void;
|
|
11
|
-
legacyUnmount?: (el: HTMLElement) => void;
|
|
12
|
-
}> | null = null;
|
|
13
|
-
|
|
14
|
-
function getRenderer() {
|
|
15
|
-
console.log('[DEBUG] getRenderer called.');
|
|
16
|
-
if (!rendererPromise) {
|
|
17
|
-
rendererPromise = (async () => {
|
|
18
|
-
try {
|
|
19
|
-
const { createRoot } = await import('react-dom/client');
|
|
20
|
-
console.log('[DEBUG] Imported createRoot from react-dom/client.');
|
|
21
|
-
return { createRoot: (el: HTMLElement) => createRoot(el) };
|
|
22
|
-
} catch (err) {
|
|
23
|
-
console.log(
|
|
24
|
-
'[DEBUG] Failed to import react-dom/client; falling back to legacy ReactDOM. Error:',
|
|
25
|
-
(err as Error).message,
|
|
26
|
-
);
|
|
27
|
-
const ReactDOM = await import('react-dom');
|
|
28
|
-
console.log('[DEBUG] Imported legacy ReactDOM.');
|
|
29
|
-
return {
|
|
30
|
-
legacyRender: ReactDOM.render,
|
|
31
|
-
legacyUnmount: ReactDOM.unmountComponentAtNode,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
})();
|
|
35
|
-
}
|
|
36
|
-
return rendererPromise;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const wrap = (ctx: string, err: unknown, extraInfo?: string): never => {
|
|
40
|
-
const baseMsg = `connectorModal error in ${ctx}: ${(err as Error).message}`;
|
|
41
|
-
const fullMsg = extraInfo ? `${baseMsg}. Additional details: ${extraInfo}` : baseMsg;
|
|
42
|
-
throw new Error(fullMsg);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export async function renderModal(
|
|
46
|
-
para: ParaWeb,
|
|
47
|
-
modalProps: Partial<ParaModalProps> | undefined,
|
|
48
|
-
onCloseArg: () => void,
|
|
49
|
-
queryClient: QueryClient,
|
|
50
|
-
): Promise<void> {
|
|
51
|
-
console.log('[DEBUG] renderModal called with para:', para, 'modalProps:', modalProps, 'queryClient:', queryClient);
|
|
52
|
-
if (typeof window === 'undefined') {
|
|
53
|
-
console.log('[DEBUG] renderModal: window undefined, returning early.');
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const props = modalProps ?? {};
|
|
57
|
-
console.log('[DEBUG] Using modal props:', props);
|
|
58
|
-
const containerId = 'para-modal';
|
|
59
|
-
let container = document.getElementById(containerId) as HTMLElement | null;
|
|
60
|
-
console.log('[DEBUG] Existing container:', container);
|
|
61
|
-
if (!container) {
|
|
62
|
-
container = document.createElement('div');
|
|
63
|
-
container.id = containerId;
|
|
64
|
-
document.body.appendChild(container);
|
|
65
|
-
console.log('[DEBUG] Created new container:', container);
|
|
66
|
-
}
|
|
67
|
-
try {
|
|
68
|
-
const renderer = await getRenderer();
|
|
69
|
-
console.log('[DEBUG] Retrieved renderer:', renderer);
|
|
70
|
-
let root: Root | null = (container as any).__paraRoot ?? null;
|
|
71
|
-
console.log('[DEBUG] Existing root:', root);
|
|
72
|
-
if (!root && renderer.createRoot) {
|
|
73
|
-
root = renderer.createRoot(container);
|
|
74
|
-
(container as any).__paraRoot = root;
|
|
75
|
-
console.log('[DEBUG] Created new root with createRoot.');
|
|
76
|
-
}
|
|
77
|
-
const { ParaProvider } = await import('@getpara/react-sdk-lite');
|
|
78
|
-
console.log('[DEBUG] Imported ParaProvider from @getpara/react-sdk-lite.');
|
|
79
|
-
const { QueryClientProvider } = await import('@tanstack/react-query');
|
|
80
|
-
console.log('[DEBUG] Imported QueryClientProvider from @tanstack/react-query.');
|
|
81
|
-
const handleClose = () => {
|
|
82
|
-
console.log('[DEBUG] handleClose triggered.');
|
|
83
|
-
onCloseArg();
|
|
84
|
-
props.onClose?.();
|
|
85
|
-
setIsOpen(false);
|
|
86
|
-
if (root) {
|
|
87
|
-
root.unmount();
|
|
88
|
-
console.log('[DEBUG] Unmounted using root.unmount.');
|
|
89
|
-
} else {
|
|
90
|
-
renderer.legacyUnmount?.(container!);
|
|
91
|
-
console.log('[DEBUG] Unmounted using legacyUnmount.');
|
|
92
|
-
}
|
|
93
|
-
container?.remove();
|
|
94
|
-
console.log('[DEBUG] Removed container.');
|
|
95
|
-
};
|
|
96
|
-
const element = (
|
|
97
|
-
<QueryClientProvider client={queryClient}>
|
|
98
|
-
<ParaProvider
|
|
99
|
-
paraClientConfig={para}
|
|
100
|
-
config={{ appName: props.appName ?? '' }}
|
|
101
|
-
paraModalConfig={{ ...props, onClose: handleClose }}
|
|
102
|
-
/>
|
|
103
|
-
</QueryClientProvider>
|
|
104
|
-
);
|
|
105
|
-
console.log('[DEBUG] Created render element.');
|
|
106
|
-
if (root) {
|
|
107
|
-
root.render(element);
|
|
108
|
-
console.log('[DEBUG] Rendered using root.render.');
|
|
109
|
-
} else {
|
|
110
|
-
renderer.legacyRender?.(element, container!);
|
|
111
|
-
console.log('[DEBUG] Rendered using legacyRender.');
|
|
112
|
-
}
|
|
113
|
-
setIsOpen(true);
|
|
114
|
-
console.log('[DEBUG] Set modal isOpen to true.');
|
|
115
|
-
} catch (err) {
|
|
116
|
-
console.log('[DEBUG] Error in renderModal; cleaning up container.');
|
|
117
|
-
container?.remove();
|
|
118
|
-
throw wrap('renderModal', err, `containerId: ${containerId}, modalProps: ${JSON.stringify(props)}`);
|
|
119
|
-
}
|
|
120
|
-
}
|
package/src/index.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "./dist",
|
|
5
|
-
"lib": ["dom", "dom.iterable", "esnext"],
|
|
6
|
-
"jsx": "react-jsx",
|
|
7
|
-
"module": "ESNext",
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"declarationDir": "./dist"
|
|
10
|
-
},
|
|
11
|
-
"include": ["src/**/*.ts", "src/**/*.tsx"],
|
|
12
|
-
"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.test.tsx", "__tests__"]
|
|
13
|
-
}
|
package/vitest.config.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { mergeConfig } from 'vite';
|
|
2
|
-
import baseConfig from '../../vitest.config.js';
|
|
3
|
-
|
|
4
|
-
export default mergeConfig(baseConfig, {
|
|
5
|
-
test: {
|
|
6
|
-
environment: 'jsdom',
|
|
7
|
-
coverage: {
|
|
8
|
-
provider: 'v8',
|
|
9
|
-
reporter: ['html', 'text'],
|
|
10
|
-
all: true,
|
|
11
|
-
include: ['src/**/*.{ts,tsx,js,jsx}'],
|
|
12
|
-
thresholds: {
|
|
13
|
-
lines: 98,
|
|
14
|
-
functions: 90,
|
|
15
|
-
branches: 98,
|
|
16
|
-
statements: 98,
|
|
17
|
-
},
|
|
18
|
-
reportOnFailure: true,
|
|
19
|
-
exclude: ['src/index.ts'],
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|