@unifold/connect-solid 0.1.59
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.d.ts +20 -0
- package/dist/index.js +87 -0
- package/dist/index.jsx +88 -0
- package/dist/styles-base.css +1 -0
- package/dist/styles.css +1 -0
- package/package.json +53 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as solid_js from 'solid-js';
|
|
2
|
+
import { JSX } from 'solid-js';
|
|
3
|
+
import { UnifoldConfig, DepositConfig, DepositResult } from '@unifold/ui-web';
|
|
4
|
+
export { DepositConfig, DepositError, DepositInitialScreen, DepositResult, UnifoldConfig, UnifoldConnectProviderConfig } from '@unifold/ui-web';
|
|
5
|
+
|
|
6
|
+
interface UnifoldProviderProps {
|
|
7
|
+
publishableKey: string;
|
|
8
|
+
config?: UnifoldConfig;
|
|
9
|
+
children?: JSX.Element;
|
|
10
|
+
}
|
|
11
|
+
declare function UnifoldProvider(props: UnifoldProviderProps): JSX.Element;
|
|
12
|
+
|
|
13
|
+
interface UnifoldContextValue {
|
|
14
|
+
beginDeposit: (config: DepositConfig) => Promise<DepositResult>;
|
|
15
|
+
closeDeposit: () => void;
|
|
16
|
+
}
|
|
17
|
+
declare const UnifoldContext: solid_js.Context<UnifoldContextValue | undefined>;
|
|
18
|
+
declare function useUnifold(): UnifoldContextValue;
|
|
19
|
+
|
|
20
|
+
export { UnifoldContext, type UnifoldContextValue, UnifoldProvider, type UnifoldProviderProps, useUnifold };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createComponent } from 'solid-js/web';
|
|
2
|
+
import { createContext, useContext, onMount, onCleanup } from 'solid-js';
|
|
3
|
+
|
|
4
|
+
// src/UnifoldProvider.tsx
|
|
5
|
+
var UnifoldContext = createContext();
|
|
6
|
+
function useUnifold() {
|
|
7
|
+
const ctx = useContext(UnifoldContext);
|
|
8
|
+
if (!ctx) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
"useUnifold() must be called inside a component wrapped by <UnifoldProvider>"
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
return ctx;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/UnifoldProvider.tsx
|
|
17
|
+
function UnifoldProvider(props) {
|
|
18
|
+
let unifold = null;
|
|
19
|
+
let destroyed = false;
|
|
20
|
+
let initStarted = false;
|
|
21
|
+
let resolveReady;
|
|
22
|
+
let rejectReady;
|
|
23
|
+
const readyPromise = new Promise((resolve, reject) => {
|
|
24
|
+
resolveReady = resolve;
|
|
25
|
+
rejectReady = reject;
|
|
26
|
+
});
|
|
27
|
+
readyPromise.catch(() => {
|
|
28
|
+
});
|
|
29
|
+
const destroyedBeforeInitError = new Error("UnifoldProvider was destroyed before initialization completed");
|
|
30
|
+
const abortIfDestroyed = () => {
|
|
31
|
+
if (!destroyed) return false;
|
|
32
|
+
rejectReady(destroyedBeforeInitError);
|
|
33
|
+
return true;
|
|
34
|
+
};
|
|
35
|
+
const ctx = {
|
|
36
|
+
beginDeposit: async (depositConfig) => {
|
|
37
|
+
await readyPromise;
|
|
38
|
+
if (destroyed || !unifold) {
|
|
39
|
+
throw new Error("UnifoldProvider has been destroyed");
|
|
40
|
+
}
|
|
41
|
+
return unifold.beginDeposit(depositConfig);
|
|
42
|
+
},
|
|
43
|
+
closeDeposit: () => {
|
|
44
|
+
unifold?.closeDeposit();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
onMount(async () => {
|
|
48
|
+
initStarted = true;
|
|
49
|
+
if (abortIfDestroyed()) return;
|
|
50
|
+
try {
|
|
51
|
+
const {
|
|
52
|
+
createUnifold
|
|
53
|
+
} = await import('@unifold/ui-web');
|
|
54
|
+
if (abortIfDestroyed()) return;
|
|
55
|
+
const instance = await createUnifold(props.publishableKey, props.config);
|
|
56
|
+
if (destroyed) {
|
|
57
|
+
instance.closeDeposit();
|
|
58
|
+
instance.destroy();
|
|
59
|
+
rejectReady(destroyedBeforeInitError);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
unifold = instance;
|
|
63
|
+
resolveReady();
|
|
64
|
+
} catch (err) {
|
|
65
|
+
if (destroyed) return;
|
|
66
|
+
console.error("[UnifoldProvider] Failed to initialize:", err);
|
|
67
|
+
rejectReady(err);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
onCleanup(() => {
|
|
71
|
+
destroyed = true;
|
|
72
|
+
unifold?.closeDeposit();
|
|
73
|
+
unifold?.destroy();
|
|
74
|
+
unifold = null;
|
|
75
|
+
if (initStarted) {
|
|
76
|
+
rejectReady(destroyedBeforeInitError);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return createComponent(UnifoldContext.Provider, {
|
|
80
|
+
value: ctx,
|
|
81
|
+
get children() {
|
|
82
|
+
return props.children;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { UnifoldContext, UnifoldProvider, useUnifold };
|
package/dist/index.jsx
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// src/UnifoldProvider.tsx
|
|
2
|
+
import { onMount, onCleanup } from "solid-js";
|
|
3
|
+
|
|
4
|
+
// src/context.ts
|
|
5
|
+
import { createContext, useContext } from "solid-js";
|
|
6
|
+
var UnifoldContext = createContext();
|
|
7
|
+
function useUnifold() {
|
|
8
|
+
const ctx = useContext(UnifoldContext);
|
|
9
|
+
if (!ctx) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
"useUnifold() must be called inside a component wrapped by <UnifoldProvider>"
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
return ctx;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// src/UnifoldProvider.tsx
|
|
18
|
+
function UnifoldProvider(props) {
|
|
19
|
+
let unifold = null;
|
|
20
|
+
let destroyed = false;
|
|
21
|
+
let initStarted = false;
|
|
22
|
+
let resolveReady;
|
|
23
|
+
let rejectReady;
|
|
24
|
+
const readyPromise = new Promise((resolve, reject) => {
|
|
25
|
+
resolveReady = resolve;
|
|
26
|
+
rejectReady = reject;
|
|
27
|
+
});
|
|
28
|
+
readyPromise.catch(() => {
|
|
29
|
+
});
|
|
30
|
+
const destroyedBeforeInitError = new Error(
|
|
31
|
+
"UnifoldProvider was destroyed before initialization completed"
|
|
32
|
+
);
|
|
33
|
+
const abortIfDestroyed = () => {
|
|
34
|
+
if (!destroyed) return false;
|
|
35
|
+
rejectReady(destroyedBeforeInitError);
|
|
36
|
+
return true;
|
|
37
|
+
};
|
|
38
|
+
const ctx = {
|
|
39
|
+
beginDeposit: async (depositConfig) => {
|
|
40
|
+
await readyPromise;
|
|
41
|
+
if (destroyed || !unifold) {
|
|
42
|
+
throw new Error("UnifoldProvider has been destroyed");
|
|
43
|
+
}
|
|
44
|
+
return unifold.beginDeposit(depositConfig);
|
|
45
|
+
},
|
|
46
|
+
closeDeposit: () => {
|
|
47
|
+
unifold?.closeDeposit();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
onMount(async () => {
|
|
51
|
+
initStarted = true;
|
|
52
|
+
if (abortIfDestroyed()) return;
|
|
53
|
+
try {
|
|
54
|
+
const { createUnifold } = await import("@unifold/ui-web");
|
|
55
|
+
if (abortIfDestroyed()) return;
|
|
56
|
+
const instance = await createUnifold(props.publishableKey, props.config);
|
|
57
|
+
if (destroyed) {
|
|
58
|
+
instance.closeDeposit();
|
|
59
|
+
instance.destroy();
|
|
60
|
+
rejectReady(destroyedBeforeInitError);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
unifold = instance;
|
|
64
|
+
resolveReady();
|
|
65
|
+
} catch (err) {
|
|
66
|
+
if (destroyed) return;
|
|
67
|
+
console.error("[UnifoldProvider] Failed to initialize:", err);
|
|
68
|
+
rejectReady(err);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
onCleanup(() => {
|
|
72
|
+
destroyed = true;
|
|
73
|
+
unifold?.closeDeposit();
|
|
74
|
+
unifold?.destroy();
|
|
75
|
+
unifold = null;
|
|
76
|
+
if (initStarted) {
|
|
77
|
+
rejectReady(destroyedBeforeInitError);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return <UnifoldContext.Provider value={ctx}>
|
|
81
|
+
{props.children}
|
|
82
|
+
</UnifoldContext.Provider>;
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
UnifoldContext,
|
|
86
|
+
UnifoldProvider,
|
|
87
|
+
useUnifold
|
|
88
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "@unifold/ui-web/styles-base.css";
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "@unifold/ui-web/styles.css";
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@unifold/connect-solid",
|
|
3
|
+
"version": "0.1.59",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Unifold Connect for Solid - Native Solid JS SDK for the Unifold deposit widget",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"solid": "./dist/index.jsx",
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"./styles.css": "./dist/styles.css",
|
|
15
|
+
"./styles-base.css": "./dist/styles-base.css"
|
|
16
|
+
},
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"browser": {},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@unifold/ui-web": "0.1.59"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"solid-js": "^1.6.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"esbuild-plugin-solid": "^0.6.0",
|
|
32
|
+
"solid-js": "^1.8.0",
|
|
33
|
+
"tsup": "^8.0.0",
|
|
34
|
+
"tsup-preset-solid": "^2.2.0",
|
|
35
|
+
"typescript": "^5.0.0"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"unifold",
|
|
39
|
+
"sdk",
|
|
40
|
+
"crypto",
|
|
41
|
+
"deposit",
|
|
42
|
+
"solid",
|
|
43
|
+
"solidjs"
|
|
44
|
+
],
|
|
45
|
+
"author": "Unifold",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsup",
|
|
49
|
+
"dev": "tsup --watch",
|
|
50
|
+
"type-check": "tsc --noEmit",
|
|
51
|
+
"clean": "rm -rf dist"
|
|
52
|
+
}
|
|
53
|
+
}
|