@frak-labs/components 0.0.23 → 0.0.24-beta.2c88e0f4
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/README.md +22 -0
- package/cdn/ButtonShare.CxDA1Jbf.js +1 -0
- package/cdn/ButtonWallet.B7W8FpC_.js +1 -0
- package/cdn/OpenInAppButton.Cnnm1eVm.js +1 -0
- package/cdn/Spinner.BdByV2g7.js +1 -0
- package/cdn/components.js +1 -1
- package/cdn/initFrakSdk.r5jBer2O.js +14 -0
- package/cdn/loader.css +14 -0
- package/cdn/loader.js +1 -32
- package/cdn/useClientReady.CZoeKW9z.js +1 -0
- package/dist/Spinner-ByXrz_8L.js +36 -0
- package/dist/Spinner-CHZD3tMn.css +1 -0
- package/dist/buttonShare.css +1 -1
- package/dist/buttonShare.d.ts +103 -85
- package/dist/buttonShare.js +311 -1
- package/dist/buttonWallet.css +1 -1
- package/dist/buttonWallet.d.ts +79 -64
- package/dist/buttonWallet.js +109 -1
- package/dist/openInApp.css +1 -0
- package/dist/openInApp.d.ts +64 -0
- package/dist/openInApp.js +110 -0
- package/dist/useClientReady-iCtUeDsc.js +197 -0
- package/dist/useReward-DAkT-7wT.js +48 -0
- package/package.json +51 -17
- package/cdn/564.74bbd23d.js +0 -1
- package/cdn/button-share.4d8a18a0.js +0 -1
- package/cdn/button-share.823884d0.css +0 -1
- package/cdn/button-wallet.0a2b7d12.js +0 -1
- package/cdn/button-wallet.390d543a.css +0 -1
- package/cdn/loader.js.LICENSE.txt +0 -1
package/dist/buttonWallet.d.ts
CHANGED
|
@@ -1,64 +1,79 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* @
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* @
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*
|
|
46
|
-
* @
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
import { InteractionTypeKey } from "@frak-labs/core-sdk";
|
|
2
|
+
import * as preact from "preact";
|
|
3
|
+
|
|
4
|
+
//#region src/components/ButtonWallet/types.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The props type for {@link ButtonWallet}.
|
|
7
|
+
* @inline
|
|
8
|
+
*/
|
|
9
|
+
type ButtonWalletProps = {
|
|
10
|
+
/**
|
|
11
|
+
* Classname to apply to the button
|
|
12
|
+
*/
|
|
13
|
+
classname?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Do we display the reward on the button?
|
|
16
|
+
* @defaultValue `false`
|
|
17
|
+
*/
|
|
18
|
+
useReward?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Target interaction behind this sharing action (will be used to get the right reward to display)
|
|
21
|
+
*/
|
|
22
|
+
targetInteraction?: InteractionTypeKey;
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/components/ButtonWallet/ButtonWallet.d.ts
|
|
26
|
+
/**
|
|
27
|
+
* Button to open wallet modal
|
|
28
|
+
*
|
|
29
|
+
* @param args
|
|
30
|
+
* @returns The wallet button with `<button>` tag
|
|
31
|
+
*
|
|
32
|
+
* @group components
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* Basic usage:
|
|
36
|
+
* ```html
|
|
37
|
+
* <frak-button-wallet></frak-button-wallet>
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* Using a custom class:
|
|
42
|
+
* ```html
|
|
43
|
+
* <frak-button-wallet classname="button button-primary"></frak-button-wallet>
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* Using reward information:
|
|
48
|
+
* ```html
|
|
49
|
+
* <frak-button-wallet use-reward></frak-button-wallet>
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* Using reward information for specific reward:
|
|
54
|
+
* ```html
|
|
55
|
+
* <frak-button-wallet use-reward target-interaction="custom.customerMeeting"></frak-button-wallet>
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the modal display
|
|
59
|
+
* @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
|
|
60
|
+
*/
|
|
61
|
+
declare function ButtonWallet({
|
|
62
|
+
classname,
|
|
63
|
+
useReward: rawUseReward,
|
|
64
|
+
targetInteraction
|
|
65
|
+
}: ButtonWalletProps): preact.JSX.Element;
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/components/ButtonWallet/index.d.ts
|
|
68
|
+
/**
|
|
69
|
+
* Custom element interface for `<frak-button-wallet>`.
|
|
70
|
+
* Combines standard {@link HTMLElement} with {@link ButtonWalletProps}.
|
|
71
|
+
*/
|
|
72
|
+
interface ButtonWalletElement extends HTMLElement, ButtonWalletProps {}
|
|
73
|
+
declare global {
|
|
74
|
+
interface HTMLElementTagNameMap {
|
|
75
|
+
"frak-button-wallet": ButtonWalletElement;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
export { ButtonWallet, ButtonWalletElement };
|
package/dist/buttonWallet.js
CHANGED
|
@@ -1 +1,109 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { i as openWalletModal, n as registerWebComponent, t as useClientReady } from "./useClientReady-iCtUeDsc.js";
|
|
2
|
+
import { t as useReward } from "./useReward-DAkT-7wT.js";
|
|
3
|
+
import { trackEvent } from "@frak-labs/core-sdk";
|
|
4
|
+
import { cx } from "class-variance-authority";
|
|
5
|
+
import { useEffect, useMemo, useState } from "preact/hooks";
|
|
6
|
+
import { jsx, jsxs } from "preact/jsx-runtime";
|
|
7
|
+
|
|
8
|
+
//#region src/components/ButtonWallet/assets/GiftIcon.tsx
|
|
9
|
+
function GiftIcon(props) {
|
|
10
|
+
return /* @__PURE__ */ jsxs("svg", {
|
|
11
|
+
fill: "none",
|
|
12
|
+
height: "1em",
|
|
13
|
+
viewBox: "0 0 28 28",
|
|
14
|
+
width: "1em",
|
|
15
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
16
|
+
...props,
|
|
17
|
+
children: [/* @__PURE__ */ jsx("title", { children: "Gift icon" }), /* @__PURE__ */ jsx("path", {
|
|
18
|
+
d: "m23.1427 13.9999v11.4285h-18.2857v-11.4285m9.1429 11.4285v-17.14282m0 0h-5.1429c-.75776 0-1.48448-.30102-2.0203-.83684s-.83684-1.26255-.83684-2.02031.30102-1.48448.83684-2.0203 1.26254-.83684 2.0203-.83684c4 0 5.1429 5.71429 5.1429 5.71429zm0 0h5.1428c.7578 0 1.4845-.30102 2.0203-.83684s.8369-1.26255.8369-2.02031-.3011-1.48448-.8369-2.0203-1.2625-.83684-2.0203-.83684c-4 0-5.1428 5.71429-5.1428 5.71429zm-11.42861 0h22.85711v5.71432h-22.85711z",
|
|
19
|
+
stroke: "#fff",
|
|
20
|
+
"stroke-linecap": "round",
|
|
21
|
+
"stroke-linejoin": "round"
|
|
22
|
+
})]
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/components/ButtonWallet/ButtonWallet.module.css?css_module
|
|
28
|
+
const classes = {
|
|
29
|
+
"button__right": "Kl62ia_button__right",
|
|
30
|
+
"button__left": "Kl62ia_button__left",
|
|
31
|
+
"button": "Kl62ia_button",
|
|
32
|
+
"reward": "Kl62ia_reward"
|
|
33
|
+
};
|
|
34
|
+
const _button__right0 = classes["button__right"];
|
|
35
|
+
const _button__left0 = classes["button__left"];
|
|
36
|
+
const _button0 = classes["button"];
|
|
37
|
+
const _reward0 = classes["reward"];
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/components/ButtonWallet/ButtonWallet.tsx
|
|
41
|
+
/**
|
|
42
|
+
* Button to open wallet modal
|
|
43
|
+
*
|
|
44
|
+
* @param args
|
|
45
|
+
* @returns The wallet button with `<button>` tag
|
|
46
|
+
*
|
|
47
|
+
* @group components
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* Basic usage:
|
|
51
|
+
* ```html
|
|
52
|
+
* <frak-button-wallet></frak-button-wallet>
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* Using a custom class:
|
|
57
|
+
* ```html
|
|
58
|
+
* <frak-button-wallet classname="button button-primary"></frak-button-wallet>
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* Using reward information:
|
|
63
|
+
* ```html
|
|
64
|
+
* <frak-button-wallet use-reward></frak-button-wallet>
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* Using reward information for specific reward:
|
|
69
|
+
* ```html
|
|
70
|
+
* <frak-button-wallet use-reward target-interaction="custom.customerMeeting"></frak-button-wallet>
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the modal display
|
|
74
|
+
* @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
|
|
75
|
+
*/
|
|
76
|
+
function ButtonWallet({ classname = "", useReward: rawUseReward, targetInteraction }) {
|
|
77
|
+
const shouldUseReward = useMemo(() => rawUseReward !== void 0, [rawUseReward]);
|
|
78
|
+
const { isClientReady } = useClientReady();
|
|
79
|
+
const { reward } = useReward(shouldUseReward && isClientReady, targetInteraction);
|
|
80
|
+
const [position, setPosition] = useState("right");
|
|
81
|
+
/**
|
|
82
|
+
* Setup the position of the button
|
|
83
|
+
*/
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
const position = window.FrakSetup?.modalWalletConfig?.metadata?.position;
|
|
86
|
+
setPosition(position ?? "right");
|
|
87
|
+
}, []);
|
|
88
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
89
|
+
type: "button",
|
|
90
|
+
"aria-label": "Open wallet",
|
|
91
|
+
class: cx(classes.button, position === "left" ? classes.button__left : classes.button__right, classname, "override"),
|
|
92
|
+
disabled: !isClientReady,
|
|
93
|
+
onClick: () => {
|
|
94
|
+
trackEvent(window.FrakSetup.client, "wallet_button_clicked");
|
|
95
|
+
openWalletModal();
|
|
96
|
+
},
|
|
97
|
+
children: [/* @__PURE__ */ jsx(GiftIcon, {}), reward && /* @__PURE__ */ jsx("span", {
|
|
98
|
+
className: classes.reward,
|
|
99
|
+
children: reward
|
|
100
|
+
})]
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/components/ButtonWallet/index.ts
|
|
106
|
+
registerWebComponent(ButtonWallet, "frak-button-wallet", [], { shadow: false });
|
|
107
|
+
|
|
108
|
+
//#endregion
|
|
109
|
+
export { ButtonWallet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.XYfqGq_button{justify-content:center;align-items:center;gap:10px;display:flex}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as preact from "preact";
|
|
2
|
+
|
|
3
|
+
//#region src/components/OpenInAppButton/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* The props type for {@link OpenInAppButton}.
|
|
6
|
+
* @inline
|
|
7
|
+
*/
|
|
8
|
+
type OpenInAppButtonProps = {
|
|
9
|
+
/**
|
|
10
|
+
* Text to display on the button
|
|
11
|
+
* @defaultValue `"Open in App"`
|
|
12
|
+
*/
|
|
13
|
+
text?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Classname to apply to the button
|
|
16
|
+
*/
|
|
17
|
+
classname?: string;
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/components/OpenInAppButton/OpenInAppButton.d.ts
|
|
21
|
+
/**
|
|
22
|
+
* Button to open the Frak Wallet mobile app via deep link
|
|
23
|
+
*
|
|
24
|
+
* @param args
|
|
25
|
+
* @returns The open in app button with `<button>` tag (only renders on mobile devices)
|
|
26
|
+
*
|
|
27
|
+
* @group components
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* Basic usage:
|
|
31
|
+
* ```html
|
|
32
|
+
* <frak-open-in-app></frak-open-in-app>
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* Using a custom text:
|
|
37
|
+
* ```html
|
|
38
|
+
* <frak-open-in-app text="Get the App"></frak-open-in-app>
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* With login action:
|
|
43
|
+
* ```html
|
|
44
|
+
* <frak-open-in-app classname="button button-primary"></frak-open-in-app>
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
declare function OpenInAppButton({
|
|
48
|
+
text,
|
|
49
|
+
classname
|
|
50
|
+
}: OpenInAppButtonProps): preact.JSX.Element | null;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/components/OpenInAppButton/index.d.ts
|
|
53
|
+
/**
|
|
54
|
+
* Custom element interface for `<frak-open-in-app>`.
|
|
55
|
+
* Combines standard {@link HTMLElement} with {@link OpenInAppButtonProps}.
|
|
56
|
+
*/
|
|
57
|
+
interface OpenInAppButtonElement extends HTMLElement, OpenInAppButtonProps {}
|
|
58
|
+
declare global {
|
|
59
|
+
interface HTMLElementTagNameMap {
|
|
60
|
+
"frak-open-in-app": OpenInAppButtonElement;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { OpenInAppButton, OpenInAppButtonElement };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { n as registerWebComponent, t as useClientReady } from "./useClientReady-iCtUeDsc.js";
|
|
2
|
+
import { t as Spinner } from "./Spinner-ByXrz_8L.js";
|
|
3
|
+
import { DEEP_LINK_SCHEME, trackEvent, triggerDeepLinkWithFallback } from "@frak-labs/core-sdk";
|
|
4
|
+
import { cx } from "class-variance-authority";
|
|
5
|
+
import { useMemo } from "preact/hooks";
|
|
6
|
+
import { jsx, jsxs } from "preact/jsx-runtime";
|
|
7
|
+
|
|
8
|
+
//#region src/utils/isMobile.ts
|
|
9
|
+
/**
|
|
10
|
+
* Check if the current device is a mobile device
|
|
11
|
+
* Uses UA regex + iPad desktop mode heuristic (maxTouchPoints)
|
|
12
|
+
*
|
|
13
|
+
* iPadOS 13+ sends a Macintosh UA in desktop mode, so the regex alone
|
|
14
|
+
* misses it. The maxTouchPoints check catches iPads reporting as Mac.
|
|
15
|
+
*
|
|
16
|
+
* @returns True if the device is mobile (iOS, Android, iPadOS, etc.)
|
|
17
|
+
*/
|
|
18
|
+
function isMobile() {
|
|
19
|
+
if (typeof navigator === "undefined") return false;
|
|
20
|
+
if (/iPhone|iPad|iPod|Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) return true;
|
|
21
|
+
if (/Macintosh/i.test(navigator.userAgent) && navigator.maxTouchPoints > 1) return true;
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/hooks/useIsMobile.ts
|
|
27
|
+
function useIsMobile() {
|
|
28
|
+
return { isMobile: useMemo(() => isMobile(), []) };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/utils/openInApp.ts
|
|
33
|
+
const DEFAULT_PATH = "wallet";
|
|
34
|
+
/**
|
|
35
|
+
* Open the Frak Wallet mobile app via deep link with fallback detection.
|
|
36
|
+
*
|
|
37
|
+
* Uses visibility-based detection to determine if the app opened.
|
|
38
|
+
* If the app is not installed (page stays visible after 2.5s),
|
|
39
|
+
* tracks an "app_not_installed" event.
|
|
40
|
+
*
|
|
41
|
+
* @param path - Path to open in the app (default: "wallet")
|
|
42
|
+
*/
|
|
43
|
+
function openFrakWalletApp(path = DEFAULT_PATH) {
|
|
44
|
+
const client = window.FrakSetup?.client;
|
|
45
|
+
if (client) trackEvent(client, "open_in_app_clicked");
|
|
46
|
+
triggerDeepLinkWithFallback(`${DEEP_LINK_SCHEME}${path}`, { onFallback: () => {
|
|
47
|
+
if (client) trackEvent(client, "app_not_installed");
|
|
48
|
+
} });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/components/OpenInAppButton/OpenInAppButton.module.css?css_module
|
|
53
|
+
const classes = { "button": "XYfqGq_button" };
|
|
54
|
+
const _button0 = classes["button"];
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/components/OpenInAppButton/OpenInAppButton.tsx
|
|
58
|
+
/**
|
|
59
|
+
* Button to open the Frak Wallet mobile app via deep link
|
|
60
|
+
*
|
|
61
|
+
* @param args
|
|
62
|
+
* @returns The open in app button with `<button>` tag (only renders on mobile devices)
|
|
63
|
+
*
|
|
64
|
+
* @group components
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* Basic usage:
|
|
68
|
+
* ```html
|
|
69
|
+
* <frak-open-in-app></frak-open-in-app>
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* Using a custom text:
|
|
74
|
+
* ```html
|
|
75
|
+
* <frak-open-in-app text="Get the App"></frak-open-in-app>
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* With login action:
|
|
80
|
+
* ```html
|
|
81
|
+
* <frak-open-in-app classname="button button-primary"></frak-open-in-app>
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
function OpenInAppButton({ text = "Open in App", classname = "" }) {
|
|
85
|
+
const { isClientReady } = useClientReady();
|
|
86
|
+
const { isMobile } = useIsMobile();
|
|
87
|
+
if (!isMobile) return null;
|
|
88
|
+
const handleClick = () => {
|
|
89
|
+
openFrakWalletApp();
|
|
90
|
+
};
|
|
91
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
92
|
+
type: "button",
|
|
93
|
+
"aria-label": "Open in Frak Wallet app",
|
|
94
|
+
className: cx(classes.button, classname, "override"),
|
|
95
|
+
disabled: !isClientReady,
|
|
96
|
+
onClick: handleClick,
|
|
97
|
+
children: [
|
|
98
|
+
!isClientReady && /* @__PURE__ */ jsx(Spinner, {}),
|
|
99
|
+
" ",
|
|
100
|
+
text
|
|
101
|
+
]
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/components/OpenInAppButton/index.ts
|
|
107
|
+
registerWebComponent(OpenInAppButton, "frak-open-in-app", ["text"], { shadow: false });
|
|
108
|
+
|
|
109
|
+
//#endregion
|
|
110
|
+
export { OpenInAppButton };
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import register from "preact-custom-element";
|
|
2
|
+
import { setupClient } from "@frak-labs/core-sdk";
|
|
3
|
+
import * as coreSdk from "@frak-labs/core-sdk/bundle";
|
|
4
|
+
import { displayEmbeddedWallet, modalBuilder, referralInteraction } from "@frak-labs/core-sdk/actions";
|
|
5
|
+
import { useCallback, useEffect, useState } from "preact/hooks";
|
|
6
|
+
|
|
7
|
+
//#region ../../packages/ui/utils/onDocumentReady.ts
|
|
8
|
+
/**
|
|
9
|
+
* When the document is ready, run the callback
|
|
10
|
+
* @param callback
|
|
11
|
+
*/
|
|
12
|
+
function onDocumentReady(callback) {
|
|
13
|
+
if (document.readyState === "complete" || document.readyState === "interactive") setTimeout(callback, 1);
|
|
14
|
+
else if (document.addEventListener) document.addEventListener("DOMContentLoaded", callback);
|
|
15
|
+
else document.attachEvent("onreadystatechange", () => {
|
|
16
|
+
if (document.readyState === "complete") callback();
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/utils/safeVibrate.ts
|
|
22
|
+
/**
|
|
23
|
+
* Attempt to vibrate the device
|
|
24
|
+
*/
|
|
25
|
+
function safeVibrate() {
|
|
26
|
+
if ("vibrate" in navigator) navigator.vibrate(10);
|
|
27
|
+
else console.log("Vibration not supported");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/components/ButtonWallet/utils.ts
|
|
32
|
+
/**
|
|
33
|
+
* Open the wallet modal
|
|
34
|
+
*
|
|
35
|
+
* @description
|
|
36
|
+
* This function will open the wallet modal with the configuration provided in the `window.FrakSetup.modalWalletConfig` object.
|
|
37
|
+
*/
|
|
38
|
+
function openWalletModal() {
|
|
39
|
+
if (!window.FrakSetup?.client) {
|
|
40
|
+
console.error("Frak client not found");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
safeVibrate();
|
|
44
|
+
displayEmbeddedWallet(window.FrakSetup.client, window.FrakSetup?.modalWalletConfig ?? {});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/utils/clientReady.ts
|
|
49
|
+
const CUSTOM_EVENT_NAME = "frakClientReady";
|
|
50
|
+
/**
|
|
51
|
+
* Dispatch a custom event when the Frak client is ready
|
|
52
|
+
*/
|
|
53
|
+
function dispatchClientReadyEvent() {
|
|
54
|
+
const event = new CustomEvent(CUSTOM_EVENT_NAME);
|
|
55
|
+
window.dispatchEvent(event);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Add or remove an event listener for when the Frak client is ready
|
|
59
|
+
* @param action
|
|
60
|
+
* @param callback
|
|
61
|
+
*/
|
|
62
|
+
function onClientReady(action, callback) {
|
|
63
|
+
if (window.FrakSetup?.client && action === "add") {
|
|
64
|
+
callback();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
(action === "add" ? window.addEventListener : window.removeEventListener)(CUSTOM_EVENT_NAME, callback, false);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/utils/setup.ts
|
|
72
|
+
/**
|
|
73
|
+
* Setup the modal config
|
|
74
|
+
* @param client
|
|
75
|
+
*/
|
|
76
|
+
function setupModalConfig(client) {
|
|
77
|
+
window.modalBuilderSteps = modalBuilder(client, window.FrakSetup?.modalConfig ?? {});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Setup the referral
|
|
81
|
+
* @param client
|
|
82
|
+
*/
|
|
83
|
+
async function setupReferral(client) {
|
|
84
|
+
const referral = await referralInteraction(client, { modalConfig: window.FrakSetup?.modalWalletConfig });
|
|
85
|
+
console.log("referral", referral);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Return the modal builder steps
|
|
89
|
+
*/
|
|
90
|
+
function getModalBuilderSteps() {
|
|
91
|
+
if (!window.modalBuilderSteps) throw new Error("modalBuilderSteps not found");
|
|
92
|
+
return window.modalBuilderSteps;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/utils/initFrakSdk.ts
|
|
97
|
+
/**
|
|
98
|
+
* Initializes the Frak SDK client and sets up necessary configurations.
|
|
99
|
+
* This function handles the one-time setup of the Frak client and related features.
|
|
100
|
+
*
|
|
101
|
+
* @returns {Promise<void>}
|
|
102
|
+
*/
|
|
103
|
+
async function initFrakSdk() {
|
|
104
|
+
window.FrakSetup.core = coreSdk;
|
|
105
|
+
if (!preChecks()) return;
|
|
106
|
+
console.log("[Frak SDK] Starting initialization");
|
|
107
|
+
if (!window.FrakSetup.config) {
|
|
108
|
+
console.error("[Frak SDK] Configuration not found");
|
|
109
|
+
window.frakSetupInProgress = false;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const client = await setupClient({ config: window.FrakSetup.config });
|
|
113
|
+
if (!client) {
|
|
114
|
+
console.error("[Frak SDK] Failed to create client");
|
|
115
|
+
window.frakSetupInProgress = false;
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
window.FrakSetup.client = client;
|
|
119
|
+
console.log("[Frak SDK] Client initialized successfully");
|
|
120
|
+
dispatchClientReadyEvent();
|
|
121
|
+
setupModalConfig(client);
|
|
122
|
+
setupReferral(client);
|
|
123
|
+
window.frakSetupInProgress = false;
|
|
124
|
+
handleActionQueryParam();
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Pre-checks for the Frak SDK initialization
|
|
128
|
+
* Sets frakSetupInProgress flag atomically to prevent race conditions
|
|
129
|
+
*/
|
|
130
|
+
function preChecks() {
|
|
131
|
+
if (window.frakSetupInProgress) {
|
|
132
|
+
console.log("[Frak SDK] Initialization already in progress");
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
window.frakSetupInProgress = true;
|
|
136
|
+
if (window.FrakSetup?.client) {
|
|
137
|
+
console.log("[Frak SDK] Client already initialized");
|
|
138
|
+
window.frakSetupInProgress = false;
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
if (!window.FrakSetup?.config) {
|
|
142
|
+
console.error("[Frak SDK] Configuration not found. Please ensure window.FrakSetup.config is set.");
|
|
143
|
+
window.frakSetupInProgress = false;
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Check the query param contain params for an auto opening of the frak modal
|
|
150
|
+
*/
|
|
151
|
+
function handleActionQueryParam() {
|
|
152
|
+
const frakAction = new URLSearchParams(window.location.search).get("frakAction");
|
|
153
|
+
if (!frakAction) return;
|
|
154
|
+
if (frakAction === "share") {
|
|
155
|
+
console.log("[Frak SDK] Auto open query param found");
|
|
156
|
+
openWalletModal();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/utils/registerWebComponent.ts
|
|
162
|
+
/**
|
|
163
|
+
* Registers a Preact component as a custom web component
|
|
164
|
+
*
|
|
165
|
+
* @param component - The Preact component to register
|
|
166
|
+
* @param tagName - The custom element tag name (e.g., "frak-button-wallet")
|
|
167
|
+
* @param observedAttributes - Array of attribute names to observe for changes
|
|
168
|
+
* @param options - Registration options (e.g., { shadow: false })
|
|
169
|
+
*/
|
|
170
|
+
function registerWebComponent(component, tagName, observedAttributes = [], options = { shadow: false }) {
|
|
171
|
+
if (typeof window !== "undefined") {
|
|
172
|
+
onDocumentReady(initFrakSdk);
|
|
173
|
+
if (!customElements.get(tagName)) register(component, tagName, observedAttributes, options);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/hooks/useClientReady.ts
|
|
179
|
+
/**
|
|
180
|
+
* Hook to manage client readiness state for the wallet button
|
|
181
|
+
* Handles subscription to client ready events and manages readiness state
|
|
182
|
+
* @returns Object containing the readiness state of the client
|
|
183
|
+
*/
|
|
184
|
+
function useClientReady() {
|
|
185
|
+
const [disabled, setDisabled] = useState(true);
|
|
186
|
+
const handleClientReady = useCallback(() => {
|
|
187
|
+
setDisabled(false);
|
|
188
|
+
}, []);
|
|
189
|
+
useEffect(() => {
|
|
190
|
+
onClientReady("add", handleClientReady);
|
|
191
|
+
return () => onClientReady("remove", handleClientReady);
|
|
192
|
+
}, [handleClientReady]);
|
|
193
|
+
return { isClientReady: !disabled };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
//#endregion
|
|
197
|
+
export { openWalletModal as i, registerWebComponent as n, getModalBuilderSteps as r, useClientReady as t };
|