@frak-labs/components 0.0.24 → 0.0.25
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.Ql9TdTHB.js +1 -0
- package/cdn/ButtonWallet.CZRopLW5.js +1 -0
- package/cdn/OpenInAppButton.D0ffT0OI.js +1 -0
- package/cdn/Spinner.CpK9_1R-.js +1 -0
- package/cdn/components.js +1 -1
- package/cdn/initFrakSdk.CW4lZNoL.js +14 -0
- package/cdn/loader.css +10 -3
- package/cdn/loader.js +1 -18
- package/cdn/useClientReady.CGRQ81It.js +1 -0
- package/dist/Spinner-ByXrz_8L.js +36 -0
- package/dist/Spinner-CHZD3tMn.css +1 -0
- package/dist/buttonShare.css +0 -1
- package/dist/buttonShare.d.ts +10 -7
- package/dist/buttonShare.js +9 -41
- package/dist/buttonWallet.d.ts +10 -7
- package/dist/buttonWallet.js +10 -10
- package/dist/openInApp.css +1 -0
- package/dist/openInApp.d.ts +64 -0
- package/dist/openInApp.js +110 -0
- package/dist/{useReward-1io3tiHR.js → useClientReady-iCtUeDsc.js} +7 -49
- package/dist/useReward-DAkT-7wT.js +48 -0
- package/package.json +20 -15
- package/cdn/ButtonShare.D40CBIiu.js +0 -1
- package/cdn/ButtonWallet.CwEBNV5I.js +0 -1
package/dist/buttonShare.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as registerWebComponent, r as getModalBuilderSteps, t as useClientReady } from "./useClientReady-iCtUeDsc.js";
|
|
2
|
+
import { t as Spinner } from "./Spinner-ByXrz_8L.js";
|
|
3
|
+
import { t as useReward } from "./useReward-DAkT-7wT.js";
|
|
2
4
|
import { DebugInfoGatherer, trackEvent } from "@frak-labs/core-sdk";
|
|
3
5
|
import { displayEmbeddedWallet } from "@frak-labs/core-sdk/actions";
|
|
4
6
|
import { cx } from "class-variance-authority";
|
|
@@ -6,42 +8,8 @@ import { useCallback, useMemo, useState } from "preact/hooks";
|
|
|
6
8
|
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
|
|
7
9
|
import { FrakRpcError, RpcErrorCodes } from "@frak-labs/frame-connector";
|
|
8
10
|
|
|
9
|
-
//#region src/components/Spinner/index.module.css?css_module
|
|
10
|
-
const classes$1 = {
|
|
11
|
-
"spinner__leaf": "M4fSKa_spinner__leaf",
|
|
12
|
-
"rt-spinner-leaf-fade": "M4fSKa_rt-spinner-leaf-fade",
|
|
13
|
-
"spinner": "M4fSKa_spinner"
|
|
14
|
-
};
|
|
15
|
-
var index_module_default = classes$1;
|
|
16
|
-
const _spinner__leaf0 = classes$1["spinner__leaf"];
|
|
17
|
-
const _rt_spinner_leaf_fade0 = classes$1["rt-spinner-leaf-fade"];
|
|
18
|
-
const _spinner0 = classes$1["spinner"];
|
|
19
|
-
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region src/components/Spinner/index.tsx
|
|
22
|
-
const Spinner = ({ ref, className, ...props }) => {
|
|
23
|
-
return /* @__PURE__ */ jsxs("span", {
|
|
24
|
-
...props,
|
|
25
|
-
ref,
|
|
26
|
-
className: cx(index_module_default.spinner),
|
|
27
|
-
children: [
|
|
28
|
-
/* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
|
|
29
|
-
/* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
|
|
30
|
-
/* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
|
|
31
|
-
/* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
|
|
32
|
-
/* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
|
|
33
|
-
/* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
|
|
34
|
-
/* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
|
|
35
|
-
/* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf })
|
|
36
|
-
]
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
Spinner.displayName = "Spinner";
|
|
40
|
-
|
|
41
|
-
//#endregion
|
|
42
11
|
//#region src/components/ButtonShare/ButtonShare.module.css?css_module
|
|
43
12
|
const classes = { "buttonShare": "nOB7Uq_buttonShare" };
|
|
44
|
-
var ButtonShare_module_default = classes;
|
|
45
13
|
const _buttonShare0 = classes["buttonShare"];
|
|
46
14
|
|
|
47
15
|
//#endregion
|
|
@@ -228,12 +196,12 @@ function useShareModal(targetInteraction) {
|
|
|
228
196
|
console.debug("User aborted the modal");
|
|
229
197
|
return;
|
|
230
198
|
}
|
|
231
|
-
const debugInfo
|
|
199
|
+
const debugInfo = window.FrakSetup.client.debugInfo.formatDebugInfo(e);
|
|
232
200
|
trackEvent(window.FrakSetup.client, "share_modal_error", {
|
|
233
201
|
error: e instanceof Object && "message" in e ? e.message : "Unknown error",
|
|
234
|
-
debugInfo
|
|
202
|
+
debugInfo
|
|
235
203
|
});
|
|
236
|
-
setDebugInfo(debugInfo
|
|
204
|
+
setDebugInfo(debugInfo);
|
|
237
205
|
setIsError(true);
|
|
238
206
|
console.error("Error while opening the modal", e);
|
|
239
207
|
}
|
|
@@ -290,11 +258,11 @@ async function modalEmbeddedWallet() {
|
|
|
290
258
|
* @example
|
|
291
259
|
* Using reward information for specific reward and fallback text:
|
|
292
260
|
* ```html
|
|
293
|
-
* <frak-button-share use-reward text="Share and earn up to {REWARD}!" no-reward-text="Share and earn!" target-interaction="
|
|
261
|
+
* <frak-button-share use-reward text="Share and earn up to {REWARD}!" no-reward-text="Share and earn!" target-interaction="custom.customerMeeting"></frak-button-share>
|
|
294
262
|
* ```
|
|
295
263
|
*
|
|
296
264
|
* @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the modal display
|
|
297
|
-
* @see {@link @frak-labs/core-sdk!actions.
|
|
265
|
+
* @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
|
|
298
266
|
*/
|
|
299
267
|
function ButtonShare({ text = "Share and earn!", classname = "", useReward: rawUseReward, noRewardText, targetInteraction, showWallet: rawShowWallet }) {
|
|
300
268
|
const shouldUseReward = useMemo(() => rawUseReward !== void 0, [rawUseReward]);
|
|
@@ -325,7 +293,7 @@ function ButtonShare({ text = "Share and earn!", classname = "", useReward: rawU
|
|
|
325
293
|
}, [showWallet, handleShare]);
|
|
326
294
|
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("button", {
|
|
327
295
|
type: "button",
|
|
328
|
-
className: cx(
|
|
296
|
+
className: cx(classes.buttonShare, classname, "override"),
|
|
329
297
|
onClick,
|
|
330
298
|
children: [
|
|
331
299
|
!isClientReady && /* @__PURE__ */ jsx(Spinner, {}),
|
package/dist/buttonWallet.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as
|
|
1
|
+
import { InteractionTypeKey } from "@frak-labs/core-sdk";
|
|
2
|
+
import * as preact from "preact";
|
|
3
3
|
|
|
4
4
|
//#region src/components/ButtonWallet/types.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* The props type for {@link ButtonWallet}.
|
|
8
7
|
* @inline
|
|
@@ -20,7 +19,7 @@ type ButtonWalletProps = {
|
|
|
20
19
|
/**
|
|
21
20
|
* Target interaction behind this sharing action (will be used to get the right reward to display)
|
|
22
21
|
*/
|
|
23
|
-
targetInteraction?:
|
|
22
|
+
targetInteraction?: InteractionTypeKey;
|
|
24
23
|
};
|
|
25
24
|
//#endregion
|
|
26
25
|
//#region src/components/ButtonWallet/ButtonWallet.d.ts
|
|
@@ -53,19 +52,23 @@ type ButtonWalletProps = {
|
|
|
53
52
|
* @example
|
|
54
53
|
* Using reward information for specific reward:
|
|
55
54
|
* ```html
|
|
56
|
-
* <frak-button-wallet use-reward target-interaction="
|
|
55
|
+
* <frak-button-wallet use-reward target-interaction="custom.customerMeeting"></frak-button-wallet>
|
|
57
56
|
* ```
|
|
58
57
|
*
|
|
59
58
|
* @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the modal display
|
|
60
|
-
* @see {@link @frak-labs/core-sdk!actions.
|
|
59
|
+
* @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
|
|
61
60
|
*/
|
|
62
61
|
declare function ButtonWallet({
|
|
63
62
|
classname,
|
|
64
63
|
useReward: rawUseReward,
|
|
65
64
|
targetInteraction
|
|
66
|
-
}: ButtonWalletProps):
|
|
65
|
+
}: ButtonWalletProps): preact.JSX.Element;
|
|
67
66
|
//#endregion
|
|
68
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
|
+
*/
|
|
69
72
|
interface ButtonWalletElement extends HTMLElement, ButtonWalletProps {}
|
|
70
73
|
declare global {
|
|
71
74
|
interface HTMLElementTagNameMap {
|
package/dist/buttonWallet.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
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";
|
|
2
3
|
import { trackEvent } from "@frak-labs/core-sdk";
|
|
3
4
|
import { cx } from "class-variance-authority";
|
|
4
5
|
import { useEffect, useMemo, useState } from "preact/hooks";
|
|
@@ -25,15 +26,14 @@ function GiftIcon(props) {
|
|
|
25
26
|
//#endregion
|
|
26
27
|
//#region src/components/ButtonWallet/ButtonWallet.module.css?css_module
|
|
27
28
|
const classes = {
|
|
28
|
-
"button__right": "Kl62ia_button__right",
|
|
29
29
|
"button__left": "Kl62ia_button__left",
|
|
30
30
|
"button": "Kl62ia_button",
|
|
31
|
+
"button__right": "Kl62ia_button__right",
|
|
31
32
|
"reward": "Kl62ia_reward"
|
|
32
33
|
};
|
|
33
|
-
var ButtonWallet_module_default = classes;
|
|
34
|
-
const _button__right0 = classes["button__right"];
|
|
35
34
|
const _button__left0 = classes["button__left"];
|
|
36
35
|
const _button0 = classes["button"];
|
|
36
|
+
const _button__right0 = classes["button__right"];
|
|
37
37
|
const _reward0 = classes["reward"];
|
|
38
38
|
|
|
39
39
|
//#endregion
|
|
@@ -67,11 +67,11 @@ const _reward0 = classes["reward"];
|
|
|
67
67
|
* @example
|
|
68
68
|
* Using reward information for specific reward:
|
|
69
69
|
* ```html
|
|
70
|
-
* <frak-button-wallet use-reward target-interaction="
|
|
70
|
+
* <frak-button-wallet use-reward target-interaction="custom.customerMeeting"></frak-button-wallet>
|
|
71
71
|
* ```
|
|
72
72
|
*
|
|
73
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.
|
|
74
|
+
* @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
|
|
75
75
|
*/
|
|
76
76
|
function ButtonWallet({ classname = "", useReward: rawUseReward, targetInteraction }) {
|
|
77
77
|
const shouldUseReward = useMemo(() => rawUseReward !== void 0, [rawUseReward]);
|
|
@@ -82,20 +82,20 @@ function ButtonWallet({ classname = "", useReward: rawUseReward, targetInteracti
|
|
|
82
82
|
* Setup the position of the button
|
|
83
83
|
*/
|
|
84
84
|
useEffect(() => {
|
|
85
|
-
const position
|
|
86
|
-
setPosition(position
|
|
85
|
+
const position = window.FrakSetup?.modalWalletConfig?.metadata?.position;
|
|
86
|
+
setPosition(position ?? "right");
|
|
87
87
|
}, []);
|
|
88
88
|
return /* @__PURE__ */ jsxs("button", {
|
|
89
89
|
type: "button",
|
|
90
90
|
"aria-label": "Open wallet",
|
|
91
|
-
class: cx(
|
|
91
|
+
class: cx(classes.button, position === "left" ? classes.button__left : classes.button__right, classname, "override"),
|
|
92
92
|
disabled: !isClientReady,
|
|
93
93
|
onClick: () => {
|
|
94
94
|
trackEvent(window.FrakSetup.client, "wallet_button_clicked");
|
|
95
95
|
openWalletModal();
|
|
96
96
|
},
|
|
97
97
|
children: [/* @__PURE__ */ jsx(GiftIcon, {}), reward && /* @__PURE__ */ jsx("span", {
|
|
98
|
-
className:
|
|
98
|
+
className: classes.reward,
|
|
99
99
|
children: reward
|
|
100
100
|
})]
|
|
101
101
|
});
|
|
@@ -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 };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import register from "preact-custom-element";
|
|
2
|
-
import {
|
|
2
|
+
import { setupClient } from "@frak-labs/core-sdk";
|
|
3
3
|
import * as coreSdk from "@frak-labs/core-sdk/bundle";
|
|
4
|
-
import { displayEmbeddedWallet,
|
|
4
|
+
import { displayEmbeddedWallet, modalBuilder, referralInteraction } from "@frak-labs/core-sdk/actions";
|
|
5
5
|
import { useCallback, useEffect, useState } from "preact/hooks";
|
|
6
6
|
|
|
7
7
|
//#region ../../packages/ui/utils/onDocumentReady.ts
|
|
@@ -104,7 +104,6 @@ async function initFrakSdk() {
|
|
|
104
104
|
window.FrakSetup.core = coreSdk;
|
|
105
105
|
if (!preChecks()) return;
|
|
106
106
|
console.log("[Frak SDK] Starting initialization");
|
|
107
|
-
window.frakSetupInProgress = true;
|
|
108
107
|
if (!window.FrakSetup.config) {
|
|
109
108
|
console.error("[Frak SDK] Configuration not found");
|
|
110
109
|
window.frakSetupInProgress = false;
|
|
@@ -126,18 +125,22 @@ async function initFrakSdk() {
|
|
|
126
125
|
}
|
|
127
126
|
/**
|
|
128
127
|
* Pre-checks for the Frak SDK initialization
|
|
128
|
+
* Sets frakSetupInProgress flag atomically to prevent race conditions
|
|
129
129
|
*/
|
|
130
130
|
function preChecks() {
|
|
131
131
|
if (window.frakSetupInProgress) {
|
|
132
132
|
console.log("[Frak SDK] Initialization already in progress");
|
|
133
133
|
return false;
|
|
134
134
|
}
|
|
135
|
+
window.frakSetupInProgress = true;
|
|
135
136
|
if (window.FrakSetup?.client) {
|
|
136
137
|
console.log("[Frak SDK] Client already initialized");
|
|
138
|
+
window.frakSetupInProgress = false;
|
|
137
139
|
return false;
|
|
138
140
|
}
|
|
139
141
|
if (!window.FrakSetup?.config) {
|
|
140
142
|
console.error("[Frak SDK] Configuration not found. Please ensure window.FrakSetup.config is set.");
|
|
143
|
+
window.frakSetupInProgress = false;
|
|
141
144
|
return false;
|
|
142
145
|
}
|
|
143
146
|
return true;
|
|
@@ -191,49 +194,4 @@ function useClientReady() {
|
|
|
191
194
|
}
|
|
192
195
|
|
|
193
196
|
//#endregion
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Find the estimated reward
|
|
197
|
-
* @param targetInteraction
|
|
198
|
-
* @returns
|
|
199
|
-
*/
|
|
200
|
-
async function getCurrentReward({ targetInteraction }) {
|
|
201
|
-
const client = window.FrakSetup?.client;
|
|
202
|
-
if (!client) {
|
|
203
|
-
console.warn("Frak client not ready yet");
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
const { maxReferrer, rewards } = await getProductInformation(client);
|
|
207
|
-
if (!maxReferrer) return;
|
|
208
|
-
const currencyAmountKey = getCurrencyAmountKey(client.config.metadata?.currency);
|
|
209
|
-
let currentReward = Math.round(maxReferrer[currencyAmountKey]);
|
|
210
|
-
if (targetInteraction) {
|
|
211
|
-
const targetReward = rewards.filter((reward) => reward.interactionTypeKey === targetInteraction).map((reward) => reward.referrer[currencyAmountKey]).reduce((acc, reward) => reward > acc ? reward : acc, 0);
|
|
212
|
-
if (targetReward > 0) currentReward = Math.round(targetReward);
|
|
213
|
-
}
|
|
214
|
-
return formatAmount(currentReward, client.config.metadata?.currency);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
//#endregion
|
|
218
|
-
//#region src/hooks/useReward.ts
|
|
219
|
-
/**
|
|
220
|
-
* Hook to fetch and format the current reward value for a given interaction
|
|
221
|
-
* @param shouldUseReward - Flag to determine if reward should be fetched
|
|
222
|
-
* @param targetInteraction - Optional interaction type to get specific reward for
|
|
223
|
-
* @param currency - The currency to use for the reward (default is "eur")
|
|
224
|
-
* @returns Object containing the formatted reward value in euros
|
|
225
|
-
*/
|
|
226
|
-
function useReward(shouldUseReward, targetInteraction) {
|
|
227
|
-
const [reward, setReward] = useState(void 0);
|
|
228
|
-
useEffect(() => {
|
|
229
|
-
if (!shouldUseReward) return;
|
|
230
|
-
getCurrentReward({ targetInteraction }).then((reward$1) => {
|
|
231
|
-
if (!reward$1) return;
|
|
232
|
-
setReward(reward$1);
|
|
233
|
-
});
|
|
234
|
-
}, [shouldUseReward, targetInteraction]);
|
|
235
|
-
return { reward };
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
//#endregion
|
|
239
|
-
export { openWalletModal as a, getModalBuilderSteps as i, useClientReady as n, registerWebComponent as r, useReward as t };
|
|
197
|
+
export { openWalletModal as i, registerWebComponent as n, getModalBuilderSteps as r, useClientReady as t };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { formatAmount, getCurrencyAmountKey } from "@frak-labs/core-sdk";
|
|
2
|
+
import { getMerchantInformation } from "@frak-labs/core-sdk/actions";
|
|
3
|
+
import { useEffect, useState } from "preact/hooks";
|
|
4
|
+
|
|
5
|
+
//#region src/utils/getCurrentReward.ts
|
|
6
|
+
function getFixedFiatAmount(estimated, key) {
|
|
7
|
+
if (!estimated || estimated.payoutType !== "fixed") return 0;
|
|
8
|
+
return estimated.amount[key];
|
|
9
|
+
}
|
|
10
|
+
function getMaxFixedReferrerReward(rewards, key) {
|
|
11
|
+
return rewards.reduce((max, reward) => Math.max(max, getFixedFiatAmount(reward.referrer, key)), 0);
|
|
12
|
+
}
|
|
13
|
+
async function getCurrentReward({ targetInteraction }) {
|
|
14
|
+
const client = window.FrakSetup?.client;
|
|
15
|
+
if (!client) {
|
|
16
|
+
console.warn("Frak client not ready yet");
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const { rewards } = await getMerchantInformation(client);
|
|
20
|
+
const currencyAmountKey = getCurrencyAmountKey(client.config.metadata?.currency);
|
|
21
|
+
const maxReward = getMaxFixedReferrerReward(targetInteraction ? rewards.filter((r) => r.interactionTypeKey === targetInteraction) : rewards, currencyAmountKey);
|
|
22
|
+
if (maxReward <= 0) return;
|
|
23
|
+
return formatAmount(Math.round(maxReward), client.config.metadata?.currency);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/hooks/useReward.ts
|
|
28
|
+
/**
|
|
29
|
+
* Hook to fetch and format the current reward value for a given interaction
|
|
30
|
+
* @param shouldUseReward - Flag to determine if reward should be fetched
|
|
31
|
+
* @param targetInteraction - Optional interaction type to get specific reward for
|
|
32
|
+
* @param currency - The currency to use for the reward (default is "eur")
|
|
33
|
+
* @returns Object containing the formatted reward value in euros
|
|
34
|
+
*/
|
|
35
|
+
function useReward(shouldUseReward, targetInteraction) {
|
|
36
|
+
const [reward, setReward] = useState(void 0);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (!shouldUseReward) return;
|
|
39
|
+
getCurrentReward({ targetInteraction }).then((reward) => {
|
|
40
|
+
if (!reward) return;
|
|
41
|
+
setReward(reward);
|
|
42
|
+
});
|
|
43
|
+
}, [shouldUseReward, targetInteraction]);
|
|
44
|
+
return { reward };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
export { useReward as t };
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "https://twitter.com/QNivelais"
|
|
12
12
|
}
|
|
13
13
|
],
|
|
14
|
-
"version": "0.0.
|
|
14
|
+
"version": "0.0.25",
|
|
15
15
|
"description": "Frak Wallet components, helping any person to interact with the Frak wallet.",
|
|
16
16
|
"repository": {
|
|
17
17
|
"url": "https://github.com/frak-id/wallet",
|
|
@@ -51,6 +51,11 @@
|
|
|
51
51
|
"import": "./dist/buttonShare.js",
|
|
52
52
|
"types": "./dist/buttonShare.d.ts"
|
|
53
53
|
},
|
|
54
|
+
"./openInApp": {
|
|
55
|
+
"development": "./src/components/OpenInAppButton/index.ts",
|
|
56
|
+
"import": "./dist/openInApp.js",
|
|
57
|
+
"types": "./dist/openInApp.d.ts"
|
|
58
|
+
},
|
|
54
59
|
"./cdn": {
|
|
55
60
|
"import": "./cdn/components.js"
|
|
56
61
|
},
|
|
@@ -63,7 +68,7 @@
|
|
|
63
68
|
"clean": "rimraf cdn dist",
|
|
64
69
|
"build": "tsdown",
|
|
65
70
|
"build:watch": "tsdown --watch",
|
|
66
|
-
"typecheck": "
|
|
71
|
+
"typecheck": "tsgo --noEmit",
|
|
67
72
|
"test": "vitest",
|
|
68
73
|
"test:ui": "vitest --ui",
|
|
69
74
|
"test:coverage": "vitest --coverage",
|
|
@@ -71,10 +76,10 @@
|
|
|
71
76
|
"publish": "echo 'Publishing components...'"
|
|
72
77
|
},
|
|
73
78
|
"dependencies": {
|
|
74
|
-
"@frak-labs/frame-connector": "0.
|
|
75
|
-
"@frak-labs/core-sdk": "0.
|
|
79
|
+
"@frak-labs/frame-connector": "0.2.0",
|
|
80
|
+
"@frak-labs/core-sdk": "0.2.0",
|
|
76
81
|
"class-variance-authority": "^0.7.1",
|
|
77
|
-
"preact": "^10.28.
|
|
82
|
+
"preact": "^10.28.3",
|
|
78
83
|
"preact-custom-element": "^4.6.0"
|
|
79
84
|
},
|
|
80
85
|
"devDependencies": {
|
|
@@ -82,21 +87,21 @@
|
|
|
82
87
|
"@frak-labs/dev-tooling": "0.0.0",
|
|
83
88
|
"@frak-labs/test-foundation": "0.1.0",
|
|
84
89
|
"@frak-labs/ui": "0.0.0",
|
|
85
|
-
"@preact/preset-vite": "^2.10.
|
|
86
|
-
"@rolldown/plugin-node-polyfills": "^1.0.
|
|
90
|
+
"@preact/preset-vite": "^2.10.3",
|
|
91
|
+
"@rolldown/plugin-node-polyfills": "^1.0.3",
|
|
87
92
|
"@testing-library/jest-dom": "^6.9.1",
|
|
88
93
|
"@testing-library/preact": "^3.2.4",
|
|
89
94
|
"@testing-library/user-event": "^14.6.1",
|
|
90
95
|
"@types/jsdom": "^27.0.0",
|
|
91
|
-
"@types/node": "^24.10.
|
|
96
|
+
"@types/node": "^24.10.13",
|
|
92
97
|
"@types/preact-custom-element": "^4.0.4",
|
|
93
|
-
"@vitest/coverage-v8": "^4.0.
|
|
94
|
-
"@vitest/ui": "^4.0.
|
|
95
|
-
"jsdom": "^
|
|
96
|
-
"tsdown": "^0.
|
|
98
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
99
|
+
"@vitest/ui": "^4.0.18",
|
|
100
|
+
"jsdom": "^28.0.0",
|
|
101
|
+
"tsdown": "^0.20.3",
|
|
97
102
|
"typescript": "^5",
|
|
98
|
-
"unplugin-lightningcss": "^0.4.
|
|
99
|
-
"vite-tsconfig-paths": "^6.0
|
|
100
|
-
"vitest": "^4.0.
|
|
103
|
+
"unplugin-lightningcss": "^0.4.5",
|
|
104
|
+
"vite-tsconfig-paths": "^6.1.0",
|
|
105
|
+
"vitest": "^4.0.18"
|
|
101
106
|
}
|
|
102
107
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as e,c as t,d as n,f as r,l as i,n as a,o,p as s,r as c,s as l,t as u,u as d}from"./loader.js";var f,p,m,h,g,_,v,y,b,x,S,C={},w=[],T=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,E=Array.isArray;function D(e,t){for(var n in t)e[n]=t[n];return e}function O(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function k(e,t,n){var r,i,a,o={};for(a in t)a==`key`?r=t[a]:a==`ref`?i=t[a]:o[a]=t[a];if(arguments.length>2&&(o.children=arguments.length>3?f.call(arguments,2):n),typeof e==`function`&&e.defaultProps!=null)for(a in e.defaultProps)o[a]===void 0&&(o[a]=e.defaultProps[a]);return A(e,o,r,i,null)}function A(e,t,n,r,i){var a={type:e,props:t,key:n,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++m,__i:-1,__u:0};return i==null&&p.vnode!=null&&p.vnode(a),a}function j(e){return e.children}function M(e,t){this.props=e,this.context=t}function N(e,t){if(t==null)return e.__?N(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type==`function`?N(e):null}function ee(e){var t,n;if((e=e.__)!=null&&e.__c!=null){for(e.__e=e.__c.base=null,t=0;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null){e.__e=e.__c.base=n.__e;break}return ee(e)}}function te(e){(!e.__d&&(e.__d=!0)&&h.push(e)&&!P.__r++||g!=p.debounceRendering)&&((g=p.debounceRendering)||_)(P)}function P(){for(var e,t,n,r,i,a,o,s=1;h.length;)h.length>s&&h.sort(v),e=h.shift(),s=h.length,e.__d&&(n=void 0,r=void 0,i=(r=(t=e).__v).__e,a=[],o=[],t.__P&&((n=D({},r)).__v=r.__v+1,p.vnode&&p.vnode(n),ce(t.__P,n,r,t.__n,t.__P.namespaceURI,32&r.__u?[i]:null,a,i??N(r),!!(32&r.__u),o),n.__v=r.__v,n.__.__k[n.__i]=n,ue(a,n,o),r.__e=r.__=null,n.__e!=i&&ee(n)));P.__r=0}function ne(e,t,n,r,i,a,o,s,c,l,u){var d,f,p,m,h,g,_,v=r&&r.__k||w,y=t.length;for(c=re(n,t,v,c,y),d=0;d<y;d++)(p=n.__k[d])!=null&&(f=p.__i==-1?C:v[p.__i]||C,p.__i=d,g=ce(e,p,f,i,a,o,s,c,l,u),m=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&pe(f.ref,null,p),u.push(p.ref,p.__c||m,p)),h==null&&m!=null&&(h=m),(_=!!(4&p.__u))||f.__k===p.__k?c=ie(p,c,e,_):typeof p.type==`function`&&g!==void 0?c=g:m&&(c=m.nextSibling),p.__u&=-7);return n.__e=h,c}function re(e,t,n,r,i){var a,o,s,c,l,u=n.length,d=u,f=0;for(e.__k=Array(i),a=0;a<i;a++)(o=t[a])!=null&&typeof o!=`boolean`&&typeof o!=`function`?(typeof o==`string`||typeof o==`number`||typeof o==`bigint`||o.constructor==String?o=e.__k[a]=A(null,o,null,null,null):E(o)?o=e.__k[a]=A(j,{children:o},null,null,null):o.constructor==null&&o.__b>0?o=e.__k[a]=A(o.type,o.props,o.key,o.ref?o.ref:null,o.__v):e.__k[a]=o,c=a+f,o.__=e,o.__b=e.__b+1,(l=o.__i=ae(o,n,c,d))!=-1&&(d--,(s=n[l])&&(s.__u|=2)),s==null||s.__v==null?(l==-1&&(i>u?f--:i<u&&f++),typeof o.type!=`function`&&(o.__u|=4)):l!=c&&(l==c-1?f--:l==c+1?f++:(l>c?f--:f++,o.__u|=4))):e.__k[a]=null;if(d)for(a=0;a<u;a++)(s=n[a])!=null&&!(2&s.__u)&&(s.__e==r&&(r=N(s)),me(s,s));return r}function ie(e,t,n,r){var i,a;if(typeof e.type==`function`){for(i=e.__k,a=0;i&&a<i.length;a++)i[a]&&(i[a].__=e,t=ie(i[a],t,n,r));return t}e.__e!=t&&(r&&(t&&e.type&&!t.parentNode&&(t=N(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do t&&=t.nextSibling;while(t!=null&&t.nodeType==8);return t}function ae(e,t,n,r){var i,a,o,s=e.key,c=e.type,l=t[n],u=l!=null&&(2&l.__u)==0;if(l===null&&s==null||u&&s==l.key&&c==l.type)return n;if(r>(u?1:0)){for(i=n-1,a=n+1;i>=0||a<t.length;)if((l=t[o=i>=0?i--:a++])!=null&&!(2&l.__u)&&s==l.key&&c==l.type)return o}return-1}function oe(e,t,n){t[0]==`-`?e.setProperty(t,n??``):e[t]=n==null?``:typeof n!=`number`||T.test(t)?n:n+`px`}function F(e,t,n,r,i){var a,o;n:if(t==`style`)if(typeof n==`string`)e.style.cssText=n;else{if(typeof r==`string`&&(e.style.cssText=r=``),r)for(t in r)n&&t in n||oe(e.style,t,``);if(n)for(t in n)r&&n[t]==r[t]||oe(e.style,t,n[t])}else if(t[0]==`o`&&t[1]==`n`)a=t!=(t=t.replace(y,`$1`)),o=t.toLowerCase(),t=o in e||t==`onFocusOut`||t==`onFocusIn`?o.slice(2):t.slice(2),e.l||={},e.l[t+a]=n,n?r?n.u=r.u:(n.u=b,e.addEventListener(t,a?S:x,a)):e.removeEventListener(t,a?S:x,a);else{if(i==`http://www.w3.org/2000/svg`)t=t.replace(/xlink(H|:h)/,`h`).replace(/sName$/,`s`);else if(t!=`width`&&t!=`height`&&t!=`href`&&t!=`list`&&t!=`form`&&t!=`tabIndex`&&t!=`download`&&t!=`rowSpan`&&t!=`colSpan`&&t!=`role`&&t!=`popover`&&t in e)try{e[t]=n??``;break n}catch{}typeof n==`function`||(n==null||!1===n&&t[4]!=`-`?e.removeAttribute(t):e.setAttribute(t,t==`popover`&&n==1?``:n))}}function se(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t.t==null)t.t=b++;else if(t.t<n.u)return;return n(p.event?p.event(t):t)}}}function ce(e,t,n,r,i,a,o,s,c,l){var u,d,f,m,h,g,_,v,y,b,x,S,C,w,T,k,A,N=t.type;if(t.constructor!=null)return null;128&n.__u&&(c=!!(32&n.__u),a=[s=t.__e=n.__e]),(u=p.__b)&&u(t);n:if(typeof N==`function`)try{if(v=t.props,y=`prototype`in N&&N.prototype.render,b=(u=N.contextType)&&r[u.__c],x=u?b?b.props.value:u.__:r,n.__c?_=(d=t.__c=n.__c).__=d.__E:(y?t.__c=d=new N(v,x):(t.__c=d=new M(v,x),d.constructor=N,d.render=he),b&&b.sub(d),d.state||={},d.__n=r,f=d.__d=!0,d.__h=[],d._sb=[]),y&&d.__s==null&&(d.__s=d.state),y&&N.getDerivedStateFromProps!=null&&(d.__s==d.state&&(d.__s=D({},d.__s)),D(d.__s,N.getDerivedStateFromProps(v,d.__s))),m=d.props,h=d.state,d.__v=t,f)y&&N.getDerivedStateFromProps==null&&d.componentWillMount!=null&&d.componentWillMount(),y&&d.componentDidMount!=null&&d.__h.push(d.componentDidMount);else{if(y&&N.getDerivedStateFromProps==null&&v!==m&&d.componentWillReceiveProps!=null&&d.componentWillReceiveProps(v,x),t.__v==n.__v||!d.__e&&d.shouldComponentUpdate!=null&&!1===d.shouldComponentUpdate(v,d.__s,x)){for(t.__v!=n.__v&&(d.props=v,d.state=d.__s,d.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(e){e&&(e.__=t)}),S=0;S<d._sb.length;S++)d.__h.push(d._sb[S]);d._sb=[],d.__h.length&&o.push(d);break n}d.componentWillUpdate!=null&&d.componentWillUpdate(v,d.__s,x),y&&d.componentDidUpdate!=null&&d.__h.push(function(){d.componentDidUpdate(m,h,g)})}if(d.context=x,d.props=v,d.__P=e,d.__e=!1,C=p.__r,w=0,y){for(d.state=d.__s,d.__d=!1,C&&C(t),u=d.render(d.props,d.state,d.context),T=0;T<d._sb.length;T++)d.__h.push(d._sb[T]);d._sb=[]}else do d.__d=!1,C&&C(t),u=d.render(d.props,d.state,d.context),d.state=d.__s;while(d.__d&&++w<25);d.state=d.__s,d.getChildContext!=null&&(r=D(D({},r),d.getChildContext())),y&&!f&&d.getSnapshotBeforeUpdate!=null&&(g=d.getSnapshotBeforeUpdate(m,h)),k=u,u!=null&&u.type===j&&u.key==null&&(k=de(u.props.children)),s=ne(e,E(k)?k:[k],t,n,r,i,a,o,s,c,l),d.base=t.__e,t.__u&=-161,d.__h.length&&o.push(d),_&&(d.__E=d.__=null)}catch(e){if(t.__v=null,c||a!=null)if(e.then){for(t.__u|=c?160:128;s&&s.nodeType==8&&s.nextSibling;)s=s.nextSibling;a[a.indexOf(s)]=null,t.__e=s}else{for(A=a.length;A--;)O(a[A]);le(t)}else t.__e=n.__e,t.__k=n.__k,e.then||le(t);p.__e(e,t,n)}else a==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):s=t.__e=fe(n.__e,t,n,r,i,a,o,c,l);return(u=p.diffed)&&u(t),128&t.__u?void 0:s}function le(e){e&&e.__c&&(e.__c.__e=!0),e&&e.__k&&e.__k.forEach(le)}function ue(e,t,n){for(var r=0;r<n.length;r++)pe(n[r],n[++r],n[++r]);p.__c&&p.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){p.__e(e,t.__v)}})}function de(e){return typeof e!=`object`||!e||e.__b&&e.__b>0?e:E(e)?e.map(de):D({},e)}function fe(e,t,n,r,i,a,o,s,c){var l,u,d,m,h,g,_,v=n.props||C,y=t.props,b=t.type;if(b==`svg`?i=`http://www.w3.org/2000/svg`:b==`math`?i=`http://www.w3.org/1998/Math/MathML`:i||=`http://www.w3.org/1999/xhtml`,a!=null){for(l=0;l<a.length;l++)if((h=a[l])&&`setAttribute`in h==!!b&&(b?h.localName==b:h.nodeType==3)){e=h,a[l]=null;break}}if(e==null){if(b==null)return document.createTextNode(y);e=document.createElementNS(i,b,y.is&&y),s&&=(p.__m&&p.__m(t,a),!1),a=null}if(b==null)v===y||s&&e.data==y||(e.data=y);else{if(a&&=f.call(e.childNodes),!s&&a!=null)for(v={},l=0;l<e.attributes.length;l++)v[(h=e.attributes[l]).name]=h.value;for(l in v)if(h=v[l],l!=`children`){if(l==`dangerouslySetInnerHTML`)d=h;else if(!(l in y)){if(l==`value`&&`defaultValue`in y||l==`checked`&&`defaultChecked`in y)continue;F(e,l,null,h,i)}}for(l in y)h=y[l],l==`children`?m=h:l==`dangerouslySetInnerHTML`?u=h:l==`value`?g=h:l==`checked`?_=h:s&&typeof h!=`function`||v[l]===h||F(e,l,h,v[l],i);if(u)s||d&&(u.__html==d.__html||u.__html==e.innerHTML)||(e.innerHTML=u.__html),t.__k=[];else if(d&&(e.innerHTML=``),ne(t.type==`template`?e.content:e,E(m)?m:[m],t,n,r,b==`foreignObject`?`http://www.w3.org/1999/xhtml`:i,a,o,a?a[0]:n.__k&&N(n,0),s,c),a!=null)for(l=a.length;l--;)O(a[l]);s||(l=`value`,b==`progress`&&g==null?e.removeAttribute(`value`):g!=null&&(g!==e[l]||b==`progress`&&!g||b==`option`&&g!=v[l])&&F(e,l,g,v[l],i),l=`checked`,_!=null&&_!=e[l]&&F(e,l,_,v[l],i))}return e}function pe(e,t,n){try{if(typeof e==`function`){var r=typeof e.__u==`function`;r&&e.__u(),r&&t==null||(e.__u=e(t))}else e.current=t}catch(e){p.__e(e,n)}}function me(e,t,n){var r,i;if(p.unmount&&p.unmount(e),(r=e.ref)&&(r.current&&r.current!=e.__e||pe(r,null,t)),(r=e.__c)!=null){if(r.componentWillUnmount)try{r.componentWillUnmount()}catch(e){p.__e(e,t)}r.base=r.__P=null}if(r=e.__k)for(i=0;i<r.length;i++)r[i]&&me(r[i],t,n||typeof e.type!=`function`);n||O(e.__e),e.__c=e.__=e.__e=void 0}function he(e,t,n){return this.constructor(e,n)}function I(e,t,n){var r,i,a,o;t==document&&(t=document.documentElement),p.__&&p.__(e,t),i=(r=typeof n==`function`)?null:n&&n.__k||t.__k,a=[],o=[],ce(t,e=(!r&&n||t).__k=k(j,null,[e]),i||C,C,t.namespaceURI,!r&&n?[n]:i?null:t.firstChild?f.call(t.childNodes):null,a,!r&&n?n:i?i.__e:t.firstChild,r,o),ue(a,e,o)}function ge(e,t){I(e,t,ge)}function _e(e,t,n){var r,i,a,o,s=D({},e.props);for(a in e.type&&e.type.defaultProps&&(o=e.type.defaultProps),t)a==`key`?r=t[a]:a==`ref`?i=t[a]:s[a]=t[a]===void 0&&o!=null?o[a]:t[a];return arguments.length>2&&(s.children=arguments.length>3?f.call(arguments,2):n),A(e.type,s,r||e.key,i||e.ref,null)}f=w.slice,p={__e:function(e,t,n,r){for(var i,a,o;t=t.__;)if((i=t.__c)&&!i.__)try{if((a=i.constructor)&&a.getDerivedStateFromError!=null&&(i.setState(a.getDerivedStateFromError(e)),o=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,r||{}),o=i.__d),o)return i.__E=i}catch(t){e=t}throw e}},m=0,M.prototype.setState=function(e,t){var n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=D({},this.state);typeof e==`function`&&(e=e(D({},n),this.props)),e&&D(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),te(this))},M.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),te(this))},M.prototype.render=j,h=[],_=typeof Promise==`function`?Promise.prototype.then.bind(Promise.resolve()):setTimeout,v=function(e,t){return e.__v.__b-t.__v.__b},P.__r=0,y=/(PointerCapture)$|Capture$/i,b=0,x=se(!1),S=se(!0);function L(){return L=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},L.apply(this,arguments)}function ve(e,t){if(e==null)return{};var n,r,i={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])>=0||(i[n]=e[n]);return i}var ye=[`context`,`children`],be=[`useFragment`];function xe(e,t,n,r){function i(){var t,n=Reflect.construct(HTMLElement,[],i);return n._vdomComponent=e,r&&r.shadow?(n._root=n.attachShadow({mode:r.mode||`open`,serializable:(t=r.serializable)!=null&&t}),r.adoptedStyleSheets&&(n._root.adoptedStyleSheets=r.adoptedStyleSheets)):n._root=n,n}return(i.prototype=Object.create(HTMLElement.prototype)).constructor=i,i.prototype.connectedCallback=function(){Ce.call(this,r)},i.prototype.attributeChangedCallback=Te,i.prototype.disconnectedCallback=Ee,n=n||e.observedAttributes||Object.keys(e.propTypes||{}),i.observedAttributes=n,e.formAssociated&&(i.formAssociated=!0),n.forEach(function(e){Object.defineProperty(i.prototype,e,{get:function(){return this._vdom?this._vdom.props[e]:this._props[e]},set:function(t){this._vdom?this.attributeChangedCallback(e,null,t):(this._props||={},this._props[e]=t);var n=typeof t;t!=null&&n!==`string`&&n!==`boolean`&&n!==`number`||this.setAttribute(e,t)}})}),customElements.define(t||e.tagName||e.displayName||e.name,i),i}function Se(e){this.getChildContext=function(){return e.context};var t=e.children;return _e(t,ve(e,ye))}function Ce(e){var t=new CustomEvent(`_preact`,{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(t),this._vdom=k(Se,L({},this._props,{context:t.detail.context}),Oe(this,this._vdomComponent,e)),(this.hasAttribute(`hydrate`)?ge:I)(this._vdom,this._root)}function we(e){return e.replace(/-(\w)/g,function(e,t){return t?t.toUpperCase():``})}function Te(e,t,n){if(this._vdom){var r={};r[e]=n??=void 0,r[we(e)]=n,this._vdom=_e(this._vdom,r),I(this._vdom,this._root)}}function Ee(){I(this._vdom=null,this._root)}function De(e,t){var n=this,r=e.useFragment,i=ve(e,be);return k(r?j:`slot`,L({},i,{ref:function(e){e?(n.ref=e,n._listener||(n._listener=function(e){e.stopPropagation(),e.detail.context=t},e.addEventListener(`_preact`,n._listener))):n.ref.removeEventListener(`_preact`,n._listener)}}))}function Oe(e,t,n){if(e.nodeType===3)return e.data;if(e.nodeType!==1)return null;var r=[],i={},a=0,o=e.attributes,s=e.childNodes;for(a=o.length;a--;)o[a].name!==`slot`&&(i[o[a].name]=o[a].value,i[we(o[a].name)]=o[a].value);for(a=s.length;a--;){var c=Oe(s[a],null,n),l=s[a].slot;l?i[l]=k(De,{name:l},c):r[a]=c}var u=!(!n||!n.shadow),d=t?k(De,{useFragment:!u},r):r;return!u&&t&&(e.innerHTML=``),k(t||e.nodeName.toLowerCase(),i,d)}function ke(e,t,n=[],r={shadow:!1}){typeof window<`u`&&(s(u),customElements.get(t)||xe(e,t,n,r))}function Ae(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`)if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=Ae(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n);return r}function je(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=Ae(e))&&(r&&(r+=` `),r+=t);return r}const R=je;var z,B,V,Me,H=0,Ne=[],U=p,Pe=U.__b,Fe=U.__r,Ie=U.diffed,Le=U.__c,Re=U.unmount,ze=U.__;function W(e,t){U.__h&&U.__h(B,e,H||t),H=0;var n=B.__H||={__:[],__h:[]};return e>=n.__.length&&n.__.push({}),n.__[e]}function G(e){return H=1,Be(Ke,e)}function Be(e,t,n){var r=W(z++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):Ke(void 0,t),function(e){var t=r.__N?r.__N[0]:r.__[0],n=r.t(t,e);t!==n&&(r.__N=[n,r.__[1]],r.__c.setState({}))}],r.__c=B,!B.__f)){var i=function(e,t,n){if(!r.__c.__H)return!0;var i=r.__c.__H.__.filter(function(e){return!!e.__c});if(i.every(function(e){return!e.__N}))return!a||a.call(this,e,t,n);var o=r.__c.props!==e;return i.forEach(function(e){if(e.__N){var t=e.__[0];e.__=e.__N,e.__N=void 0,t!==e.__[0]&&(o=!0)}}),a&&a.call(this,e,t,n)||o};B.__f=!0;var a=B.shouldComponentUpdate,o=B.componentWillUpdate;B.componentWillUpdate=function(e,t,n){if(this.__e){var r=a;a=void 0,i(e,t,n),a=r}o&&o.call(this,e,t,n)},B.shouldComponentUpdate=i}return r.__N||r.__}function K(e,t){var n=W(z++,3);!U.__s&&Ge(n.__H,t)&&(n.__=e,n.u=t,B.__H.__h.push(n))}function q(e,t){var n=W(z++,7);return Ge(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function J(e,t){return H=8,q(function(){return e},t)}function Ve(){for(var e;e=Ne.shift();)if(e.__P&&e.__H)try{e.__H.__h.forEach(Y),e.__H.__h.forEach(We),e.__H.__h=[]}catch(t){e.__H.__h=[],U.__e(t,e.__v)}}U.__b=function(e){B=null,Pe&&Pe(e)},U.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),ze&&ze(e,t)},U.__r=function(e){Fe&&Fe(e),z=0;var t=(B=e.__c).__H;t&&(V===B?(t.__h=[],B.__h=[],t.__.forEach(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.forEach(Y),t.__h.forEach(We),t.__h=[],z=0)),V=B},U.diffed=function(e){Ie&&Ie(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Ne.push(t)!==1&&Me===U.requestAnimationFrame||((Me=U.requestAnimationFrame)||Ue)(Ve)),t.__H.__.forEach(function(e){e.u&&(e.__H=e.u),e.u=void 0})),V=B=null},U.__c=function(e,t){t.some(function(e){try{e.__h.forEach(Y),e.__h=e.__h.filter(function(e){return!e.__||We(e)})}catch(n){t.some(function(e){e.__h&&=[]}),t=[],U.__e(n,e.__v)}}),Le&&Le(e,t)},U.unmount=function(e){Re&&Re(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.forEach(function(e){try{Y(e)}catch(e){t=e}}),n.__H=void 0,t&&U.__e(t,n.__v))};var He=typeof requestAnimationFrame==`function`;function Ue(e){var t,n=function(){clearTimeout(r),He&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);He&&(t=requestAnimationFrame(n))}function Y(e){var t=B,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),B=t}function We(e){var t=B;e.__c=e.__(),B=t}function Ge(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function Ke(e,t){return typeof t==`function`?t(e):t}const X={spinner__leaf:`M4fSKa_spinner__leaf`,spinner:`M4fSKa_spinner`,"rt-spinner-leaf-fade":`M4fSKa_rt-spinner-leaf-fade`};var Z=X;X.spinner__leaf,X.spinner,X[`rt-spinner-leaf-fade`];var qe=0;Array.isArray;function Q(e,t,n,r,i,a){t||={};var o,s,c=t;if(`ref`in c)for(s in c={},t)s==`ref`?o=t[s]:c[s]=t[s];var l={type:e,props:c,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--qe,__i:-1,__u:0,__source:i,__self:a};if(typeof e==`function`&&(o=e.defaultProps))for(s in o)c[s]===void 0&&(c[s]=o[s]);return p.vnode&&p.vnode(l),l}const Je=({ref:e,className:t,...n})=>Q(`span`,{...n,ref:e,className:R(Z.spinner),children:[Q(`span`,{className:Z.spinner__leaf}),Q(`span`,{className:Z.spinner__leaf}),Q(`span`,{className:Z.spinner__leaf}),Q(`span`,{className:Z.spinner__leaf}),Q(`span`,{className:Z.spinner__leaf}),Q(`span`,{className:Z.spinner__leaf}),Q(`span`,{className:Z.spinner__leaf}),Q(`span`,{className:Z.spinner__leaf})]});Je.displayName=`Spinner`;function Ye(){let[e,t]=G(!0),n=J(()=>{t(!1)},[]);return K(()=>(c(`add`,n),()=>c(`remove`,n)),[n]),{isClientReady:!e}}async function Xe({targetInteraction:t}){let n=window.FrakSetup?.client;if(!n){console.warn(`Frak client not ready yet`);return}let{maxReferrer:r,rewards:a}=await e(n);if(!r)return;let o=i(n.config.metadata?.currency),s=Math.round(r[o]);if(t){let e=a.filter(e=>e.interactionTypeKey===t).map(e=>e.referrer[o]).reduce((e,t)=>t>e?t:e,0);e>0&&(s=Math.round(e))}return l(s,n.config.metadata?.currency)}function Ze(e,t){let[n,r]=G(void 0);return K(()=>{e&&Xe({targetInteraction:t}).then(e=>{e&&r(e)})},[e,t]),{reward:n}}const Qe={buttonShare:`nOB7Uq_buttonShare`};var $e=Qe;Qe.buttonShare;function et(e={}){let{successDuration:t=2e3}=e,[n,r]=G(!1);return{copy:J(async e=>{try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(e),r(!0);else{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.focus(),t.select();try{document.execCommand(`copy`),r(!0)}catch(e){return console.error(`Failed to copy text:`,e),!1}finally{t.remove()}}return setTimeout(()=>{r(!1)},t),!0}catch(e){return console.error(`Failed to copy text:`,e),!1}},[t]),copied:n}}const $={errorContainer:{marginTop:`16px`,padding:`16px`,backgroundColor:`#FEE2E2`,border:`1px solid #FCA5A5`,borderRadius:`4px`,color:`#991B1B`},header:{display:`flex`,alignItems:`center`,gap:`8px`,marginBottom:`12px`},title:{margin:0,fontSize:`16px`,fontWeight:500},message:{fontSize:`14px`,lineHeight:`1.5`,margin:`0 0 12px 0`},link:{color:`#991B1B`,textDecoration:`underline`,textUnderlineOffset:`2px`},copyButton:{display:`inline-flex`,alignItems:`center`,gap:`8px`,marginBottom:`10px`,padding:`8px 12px`,backgroundColor:`white`,border:`1px solid #D1D5DB`,borderRadius:`4px`,color:`black`,fontSize:`14px`,fontWeight:500}};function tt({debugInfo:e}){let[t,n]=G(!1);return Q(`div`,{children:[Q(`button`,{type:`button`,style:$.copyButton,onClick:()=>n(!t),children:`Ouvrir les informations`}),t&&Q(`textarea`,{style:{display:`block`,width:`100%`,height:`200px`,fontSize:`12px`},children:e})]})}function nt({debugInfo:e}){let{copied:t,copy:n}=et();return Q(`div`,{style:$.errorContainer,children:[Q(`div`,{style:$.header,children:Q(`h3`,{style:$.title,children:`Oups ! Nous avons rencontré un petit problème`})}),Q(`p`,{style:$.message,children:[`Impossible d'ouvrir le menu de partage pour le moment. Si le problème persiste, copiez les informations ci-dessous et collez-les dans votre mail à`,` `,Q(`a`,{href:`mailto:help@frak-labs.com?subject=Debug`,style:$.link,children:`help@frak-labs.com`}),` `,Q(`br`,{}),`Merci pour votre retour, nous traitons votre demande dans les plus brefs délais.`]}),Q(`button`,{type:`button`,onClick:()=>n(e??``),style:$.copyButton,children:t?`Informations copiées !`:`Copier les informations de débogage`}),Q(tt,{debugInfo:e})]})}function rt(e){let[i,o]=G(void 0),[s,c]=G(!1);return{handleShare:J(async()=>{if(!window.FrakSetup?.client){console.error(`Frak client not found`),o(t.empty().formatDebugInfo(`Frak client not found`)),c(!0);return}let i=a();if(!i)throw Error(`modalBuilderSteps not found`);try{await i.sharing(window.FrakSetup?.modalShareConfig??{}).display(t=>({...t,targetInteraction:e}))}catch(e){if(e instanceof n&&e.code===r.clientAborted){console.debug(`User aborted the modal`);return}let t=window.FrakSetup.client.debugInfo.formatDebugInfo(e);d(window.FrakSetup.client,`share_modal_error`,{error:e instanceof Object&&`message`in e?e.message:`Unknown error`,debugInfo:t}),o(t),c(!0),console.error(`Error while opening the modal`,e)}},[e]),isError:s,debugInfo:i}}async function it(){if(!window.FrakSetup?.client)throw Error(`Frak client not found`);await o(window.FrakSetup.client,window.FrakSetup?.modalWalletConfig??{})}function at({text:e=`Share and earn!`,classname:t=``,useReward:n,noRewardText:r,targetInteraction:i,showWallet:a}){let o=q(()=>n!==void 0,[n]),s=q(()=>a!==void 0,[a]),{isClientReady:c}=Ye(),{reward:l}=Ze(o&&c,i),{handleShare:u,isError:f,debugInfo:p}=rt(i),m=q(()=>o?l?e.includes(`{REWARD}`)?e.replace(`{REWARD}`,l):`${e} ${l}`:r??e.replace(`{REWARD}`,``):e,[o,e,r,l]),h=J(async()=>{d(window.FrakSetup.client,`share_button_clicked`),s?await it():await u()},[s,u]);return Q(j,{children:[Q(`button`,{type:`button`,className:R($e.buttonShare,t,`override`),onClick:h,children:[!c&&Q(Je,{}),` `,m]}),f&&Q(nt,{debugInfo:p})]})}ke(at,`frak-button-share`,[`text`],{shadow:!1});export{at as ButtonShare,G as a,ke as c,q as i,Ye as n,K as o,Q as r,R as s,Ze as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e,u as t}from"./loader.js";import{a as n,c as r,i,n as a,o,r as s,s as c,t as l}from"./ButtonShare.D40CBIiu.js";function u(e){return s(`svg`,{fill:`none`,height:`1em`,viewBox:`0 0 28 28`,width:`1em`,xmlns:`http://www.w3.org/2000/svg`,...e,children:[s(`title`,{children:`Gift icon`}),s(`path`,{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`,stroke:`#fff`,"stroke-linecap":`round`,"stroke-linejoin":`round`})]})}const d={button__left:`Kl62ia_button__left`,button:`Kl62ia_button`,button__right:`Kl62ia_button__right`,reward:`Kl62ia_reward`};var f=d;d.button__left,d.button,d.button__right,d.reward;function p({classname:r=``,useReward:d,targetInteraction:p}){let m=i(()=>d!==void 0,[d]),{isClientReady:h}=a(),{reward:g}=l(m&&h,p),[_,v]=n(`right`);return o(()=>{let e=window.FrakSetup?.modalWalletConfig?.metadata?.position;v(e??`right`)},[]),s(`button`,{type:`button`,"aria-label":`Open wallet`,class:c(f.button,_===`left`?f.button__left:f.button__right,r,`override`),disabled:!h,onClick:()=>{t(window.FrakSetup.client,`wallet_button_clicked`),e()},children:[s(u,{}),g&&s(`span`,{className:f.reward,children:g})]})}r(p,`frak-button-wallet`,[],{shadow:!1});export{p as ButtonWallet};
|