@getpara/graz-integration 2.0.0-alpha.50 → 2.0.0-alpha.51

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/package.json CHANGED
@@ -1,19 +1,22 @@
1
1
  {
2
2
  "name": "@getpara/graz-integration",
3
- "version": "2.0.0-alpha.50",
3
+ "version": "2.0.0-alpha.51",
4
4
  "sideEffects": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
8
11
  "scripts": {
9
12
  "typegen": "tsc --emitDeclarationOnly",
10
13
  "build": "rm -rf dist && yarn typegen && node ./scripts/build.mjs"
11
14
  },
12
15
  "dependencies": {
13
- "@getpara/graz-connector": "2.0.0-alpha.50"
16
+ "@getpara/graz-connector": "2.0.0-alpha.51"
14
17
  },
15
18
  "devDependencies": {
16
- "@getpara/react-sdk-lite": "2.0.0-alpha.50",
19
+ "@getpara/react-sdk-lite": "2.0.0-alpha.51",
17
20
  "@tanstack/react-query": "^5.74.0",
18
21
  "graz": "^0.3.3",
19
22
  "react": "^18.2.0",
@@ -21,7 +24,7 @@
21
24
  "typescript": "5.1.6"
22
25
  },
23
26
  "peerDependencies": {
24
- "@getpara/react-sdk-lite": "2.0.0-alpha.50",
27
+ "@getpara/react-sdk-lite": "2.0.0-alpha.51",
25
28
  "@tanstack/react-query": "^5.74.0",
26
29
  "graz": "^0.3.3",
27
30
  "react": ">=18.0.0",
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
- }
@@ -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
@@ -1,2 +0,0 @@
1
- export { ParaGrazConnector } from './connector';
2
- export type { ParaModalProps, ParaGrazConfig } from './connector';
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
- }