@frak-labs/components 0.0.26-beta.06c52c98 → 0.0.26-beta.1c24fe7c
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/cdn/Banner.D-DB7VwI.js +1 -0
- package/cdn/ButtonShare.BM9Inhmf.js +1 -0
- package/cdn/ButtonWallet.B7UmJcbb.js +40 -0
- package/cdn/OpenInAppButton.B4mrsz6L.js +1 -0
- package/cdn/PostPurchase.CMa-59qR.js +1 -0
- package/cdn/components.js +1 -1
- package/cdn/formatReward.C8hlSKRj.js +1 -0
- package/cdn/jsxRuntime.module.5UNmmhNi.js +138 -0
- package/cdn/loader.js +26 -26
- package/cdn/useLightDomStyles.D895e4W1.js +1 -0
- package/cdn/useReward.DEU0AF3P.js +1 -0
- package/cdn/useShareModal.CN9_P7Sl.js +1 -0
- package/dist/banner.d.ts +73 -0
- package/dist/banner.js +171 -0
- package/dist/buttonShare.d.ts +1 -1
- package/dist/buttonShare.js +20 -54
- package/dist/buttonWallet.js +2 -2
- package/dist/formatReward-6JQldDEC.js +28 -0
- package/dist/openInApp.js +2 -2
- package/dist/postPurchase.d.ts +98 -0
- package/dist/postPurchase.js +140 -0
- package/dist/{useLightDomStyles-C029nIFk.js → useLightDomStyles-DukxuNnJ.js} +3 -3
- package/dist/{usePlacement-DD1NUBps.js → usePlacement-BbMuz8_A.js} +112 -65
- package/dist/useReward-CI2yRrCj.js +67 -0
- package/dist/useShareModal-DHlayNqk.js +55 -0
- package/package.json +13 -4
- package/cdn/ButtonShare.BG6DCGo6.js +0 -1
- package/cdn/ButtonWallet.BlV-eDcH.js +0 -40
- package/cdn/OpenInAppButton.Dq3J_3Ci.js +0 -1
- package/cdn/jsxRuntime.module.PHHpn0I_.js +0 -58
- package/dist/useReward-DAkT-7wT.js +0 -48
|
@@ -1,24 +1,10 @@
|
|
|
1
1
|
import register from "preact-custom-element";
|
|
2
2
|
import * as coreSdkIndex from "@frak-labs/core-sdk";
|
|
3
|
-
import { sdkConfigStore, setupClient } from "@frak-labs/core-sdk";
|
|
3
|
+
import { sdkConfigStore, setupClient, withCache } from "@frak-labs/core-sdk";
|
|
4
4
|
import * as coreSdkActions from "@frak-labs/core-sdk/actions";
|
|
5
|
-
import { displayEmbeddedWallet
|
|
5
|
+
import { displayEmbeddedWallet } from "@frak-labs/core-sdk/actions";
|
|
6
6
|
import { useEffect, useMemo, useState } from "preact/hooks";
|
|
7
7
|
|
|
8
|
-
//#region ../../packages/ui/utils/onDocumentReady.ts
|
|
9
|
-
/**
|
|
10
|
-
* When the document is ready, run the callback
|
|
11
|
-
* @param callback
|
|
12
|
-
*/
|
|
13
|
-
function onDocumentReady(callback) {
|
|
14
|
-
if (document.readyState === "complete" || document.readyState === "interactive") setTimeout(callback, 1);
|
|
15
|
-
else if (document.addEventListener) document.addEventListener("DOMContentLoaded", callback);
|
|
16
|
-
else document.attachEvent("onreadystatechange", () => {
|
|
17
|
-
if (document.readyState === "complete") callback();
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
8
|
//#region src/utils/embeddedWallet.ts
|
|
23
9
|
async function openEmbeddedWallet(targetInteraction, placement) {
|
|
24
10
|
if (!window.FrakSetup?.client) {
|
|
@@ -75,73 +61,42 @@ function onClientReady(action, callback) {
|
|
|
75
61
|
(action === "add" ? window.addEventListener : window.removeEventListener)(CUSTOM_EVENT_NAME, callback, false);
|
|
76
62
|
}
|
|
77
63
|
|
|
78
|
-
//#endregion
|
|
79
|
-
//#region src/utils/setup.ts
|
|
80
|
-
/**
|
|
81
|
-
* Setup the referral
|
|
82
|
-
* @param client
|
|
83
|
-
*/
|
|
84
|
-
async function setupReferral(client) {
|
|
85
|
-
const referral = await referralInteraction(client);
|
|
86
|
-
console.log("referral", referral);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
64
|
//#endregion
|
|
90
65
|
//#region src/utils/initFrakSdk.ts
|
|
91
66
|
/**
|
|
92
67
|
* Initializes the Frak SDK client and sets up necessary configurations.
|
|
93
|
-
*
|
|
68
|
+
* Uses withCache for inflight dedup — concurrent callers share the same promise.
|
|
69
|
+
* Failures are not cached, allowing retry on next call.
|
|
94
70
|
*
|
|
95
71
|
* @returns {Promise<void>}
|
|
96
72
|
*/
|
|
97
|
-
|
|
73
|
+
function initFrakSdk() {
|
|
98
74
|
window.FrakSetup.core = {
|
|
99
75
|
...coreSdkIndex,
|
|
100
76
|
...coreSdkActions
|
|
101
77
|
};
|
|
102
|
-
if (
|
|
78
|
+
if (window.FrakSetup?.client) return Promise.resolve();
|
|
79
|
+
return withCache(() => doInit(), {
|
|
80
|
+
cacheKey: "frak-sdk-init",
|
|
81
|
+
cacheTime: Number.POSITIVE_INFINITY
|
|
82
|
+
}).catch(() => {});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Performs the actual SDK initialization.
|
|
86
|
+
* Throws on failure so withCache doesn't cache failed attempts.
|
|
87
|
+
*/
|
|
88
|
+
async function doInit() {
|
|
89
|
+
if (!window.FrakSetup?.config) throw new Error("[Frak SDK] Configuration not found. Please ensure window.FrakSetup.config is set.");
|
|
103
90
|
console.log("[Frak SDK] Starting initialization");
|
|
104
|
-
if (!window.FrakSetup.config) {
|
|
105
|
-
console.error("[Frak SDK] Configuration not found");
|
|
106
|
-
window.frakSetupInProgress = false;
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
91
|
const client = await setupClient({ config: window.FrakSetup.config });
|
|
110
|
-
if (!client)
|
|
111
|
-
console.error("[Frak SDK] Failed to create client");
|
|
112
|
-
window.frakSetupInProgress = false;
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
92
|
+
if (!client) throw new Error("[Frak SDK] Failed to create client");
|
|
115
93
|
window.FrakSetup.client = client;
|
|
116
94
|
console.log("[Frak SDK] Client initialized successfully");
|
|
117
95
|
dispatchClientReadyEvent();
|
|
118
|
-
setupReferral(client);
|
|
119
|
-
window.frakSetupInProgress = false;
|
|
96
|
+
coreSdkActions.setupReferral(client);
|
|
120
97
|
handleActionQueryParam();
|
|
121
98
|
}
|
|
122
99
|
/**
|
|
123
|
-
* Pre-checks for the Frak SDK initialization
|
|
124
|
-
* Sets frakSetupInProgress flag atomically to prevent race conditions
|
|
125
|
-
*/
|
|
126
|
-
function preChecks() {
|
|
127
|
-
if (window.frakSetupInProgress) {
|
|
128
|
-
console.log("[Frak SDK] Initialization already in progress");
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
window.frakSetupInProgress = true;
|
|
132
|
-
if (window.FrakSetup?.client) {
|
|
133
|
-
console.log("[Frak SDK] Client already initialized");
|
|
134
|
-
window.frakSetupInProgress = false;
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
if (!window.FrakSetup?.config) {
|
|
138
|
-
console.error("[Frak SDK] Configuration not found. Please ensure window.FrakSetup.config is set.");
|
|
139
|
-
window.frakSetupInProgress = false;
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
100
|
* Check the query param contain params for an auto opening of the frak modal
|
|
146
101
|
*/
|
|
147
102
|
function handleActionQueryParam() {
|
|
@@ -153,6 +108,17 @@ function handleActionQueryParam() {
|
|
|
153
108
|
}
|
|
154
109
|
}
|
|
155
110
|
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/utils/onDocumentReady.ts
|
|
113
|
+
/**
|
|
114
|
+
* When the document is ready, run the callback
|
|
115
|
+
* @param callback
|
|
116
|
+
*/
|
|
117
|
+
function onDocumentReady(callback) {
|
|
118
|
+
if (document.readyState === "complete" || document.readyState === "interactive") setTimeout(callback, 1);
|
|
119
|
+
else document.addEventListener("DOMContentLoaded", callback);
|
|
120
|
+
}
|
|
121
|
+
|
|
156
122
|
//#endregion
|
|
157
123
|
//#region src/utils/registerWebComponent.ts
|
|
158
124
|
/**
|
|
@@ -270,6 +236,87 @@ const lightDomBaseCss = `
|
|
|
270
236
|
}
|
|
271
237
|
}
|
|
272
238
|
`;
|
|
239
|
+
const bannerBaseCss = `
|
|
240
|
+
:where(frak-banner) {
|
|
241
|
+
display: block;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
:where(frak-banner .banner) {
|
|
245
|
+
display: flex;
|
|
246
|
+
align-items: center;
|
|
247
|
+
gap: 12px;
|
|
248
|
+
padding: 12px 16px;
|
|
249
|
+
border-top: 2px solid #3b82f6;
|
|
250
|
+
border-bottom: 2px solid #3b82f6;
|
|
251
|
+
font-family: inherit;
|
|
252
|
+
line-height: 1.4;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
:where(frak-banner .banner__fadeIn) {
|
|
256
|
+
animation: frak-fadeIn 300ms ease-in;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
@keyframes frak-fadeIn {
|
|
260
|
+
from {
|
|
261
|
+
opacity: 0;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
to {
|
|
265
|
+
opacity: 1;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
:where(frak-banner .banner__icon) {
|
|
270
|
+
flex-shrink: 0;
|
|
271
|
+
display: flex;
|
|
272
|
+
align-items: center;
|
|
273
|
+
justify-content: center;
|
|
274
|
+
width: 32px;
|
|
275
|
+
height: 32px;
|
|
276
|
+
color: #3b82f6;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
:where(frak-banner .banner__icon svg) {
|
|
280
|
+
width: 100%;
|
|
281
|
+
height: 100%;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
:where(frak-banner .banner__content) {
|
|
285
|
+
flex: 1;
|
|
286
|
+
min-width: 0;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
:where(frak-banner .banner__title) {
|
|
290
|
+
font-weight: 700;
|
|
291
|
+
font-size: 0.875rem;
|
|
292
|
+
margin: 0 0 2px;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
:where(frak-banner .banner__description) {
|
|
296
|
+
font-size: 0.75rem;
|
|
297
|
+
margin: 0;
|
|
298
|
+
opacity: 0.7;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
:where(frak-banner .banner__cta) {
|
|
302
|
+
flex-shrink: 0;
|
|
303
|
+
padding: 8px 16px;
|
|
304
|
+
font-weight: 700;
|
|
305
|
+
font-size: 0.75rem;
|
|
306
|
+
text-transform: uppercase;
|
|
307
|
+
letter-spacing: 0.05em;
|
|
308
|
+
border: 2px solid #eab308;
|
|
309
|
+
border-radius: 0;
|
|
310
|
+
background: #eab308;
|
|
311
|
+
color: #1e293b;
|
|
312
|
+
cursor: pointer;
|
|
313
|
+
white-space: nowrap;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
:where(frak-banner .banner__cta:hover) {
|
|
317
|
+
opacity: 0.9;
|
|
318
|
+
}
|
|
319
|
+
`;
|
|
273
320
|
|
|
274
321
|
//#endregion
|
|
275
322
|
//#region src/hooks/usePlacement.ts
|
|
@@ -290,4 +337,4 @@ function usePlacement(placementId) {
|
|
|
290
337
|
}
|
|
291
338
|
|
|
292
339
|
//#endregion
|
|
293
|
-
export {
|
|
340
|
+
export { useClientReady as a, openEmbeddedWallet as c, lightDomBaseCss as i, bannerBaseCss as n, registerWebComponent as o, buildStyleContent as r, openWalletModal as s, usePlacement as t };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { t as formatEstimatedReward } from "./formatReward-6JQldDEC.js";
|
|
2
|
+
import { getCurrencyAmountKey, getSupportedCurrency } from "@frak-labs/core-sdk";
|
|
3
|
+
import { getMerchantInformation } from "@frak-labs/core-sdk/actions";
|
|
4
|
+
import { useEffect, useState } from "preact/hooks";
|
|
5
|
+
|
|
6
|
+
//#region src/hooks/useReward.ts
|
|
7
|
+
/**
|
|
8
|
+
* Get the comparable fiat value of a reward for ranking purposes.
|
|
9
|
+
*/
|
|
10
|
+
function getRewardValue(reward, key) {
|
|
11
|
+
switch (reward.payoutType) {
|
|
12
|
+
case "fixed": return reward.amount[key];
|
|
13
|
+
case "tiered": return reward.tiers.reduce((acc, tier) => Math.max(acc, tier.amount[key]), 0);
|
|
14
|
+
case "percentage": return 0;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Pick the best referrer reward from merchant info and format it.
|
|
19
|
+
* Returns `undefined` when no displayable reward is found.
|
|
20
|
+
*/
|
|
21
|
+
function resolveBestReward({ rewards }, currency, targetInteraction) {
|
|
22
|
+
const referrerRewards = (targetInteraction ? rewards.filter((r) => r.interactionTypeKey === targetInteraction) : rewards).map((r) => r.referrer).filter((r) => r !== void 0);
|
|
23
|
+
if (referrerRewards.length === 0) return void 0;
|
|
24
|
+
const key = getCurrencyAmountKey(getSupportedCurrency(currency));
|
|
25
|
+
let bestReward = referrerRewards[0];
|
|
26
|
+
let bestValue = getRewardValue(bestReward, key);
|
|
27
|
+
for (let i = 1; i < referrerRewards.length; i++) {
|
|
28
|
+
const value = getRewardValue(referrerRewards[i], key);
|
|
29
|
+
if (value > bestValue) {
|
|
30
|
+
bestReward = referrerRewards[i];
|
|
31
|
+
bestValue = value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (bestValue <= 0) {
|
|
35
|
+
const percentageReward = referrerRewards.find((r) => r.payoutType === "percentage");
|
|
36
|
+
if (!percentageReward) return void 0;
|
|
37
|
+
bestReward = percentageReward;
|
|
38
|
+
}
|
|
39
|
+
return formatEstimatedReward(bestReward, currency);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Hook to fetch and format the best referrer reward for a given interaction type.
|
|
43
|
+
*
|
|
44
|
+
* Calls `getMerchantInformation`, picks the highest-value referrer reward
|
|
45
|
+
* across all matching campaigns, and returns it as a formatted string.
|
|
46
|
+
*
|
|
47
|
+
* @param shouldUseReward - Whether to fetch the reward at all
|
|
48
|
+
* @param targetInteraction - Optional filter by interaction type (e.g. "purchase")
|
|
49
|
+
* @returns Object containing the formatted reward string, or undefined if unavailable
|
|
50
|
+
*/
|
|
51
|
+
function useReward(shouldUseReward, targetInteraction) {
|
|
52
|
+
const [reward, setReward] = useState(void 0);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (!shouldUseReward) return;
|
|
55
|
+
const client = window.FrakSetup?.client;
|
|
56
|
+
if (!client) return;
|
|
57
|
+
getMerchantInformation(client).then((merchantInfo) => {
|
|
58
|
+
const currency = client.config.metadata?.currency;
|
|
59
|
+
const formatted = resolveBestReward(merchantInfo, currency, targetInteraction);
|
|
60
|
+
if (formatted) setReward(formatted);
|
|
61
|
+
}).catch(() => {});
|
|
62
|
+
}, [shouldUseReward, targetInteraction]);
|
|
63
|
+
return { reward };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { useReward as t };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { DebugInfoGatherer, trackEvent } from "@frak-labs/core-sdk";
|
|
2
|
+
import { modalBuilder } from "@frak-labs/core-sdk/actions";
|
|
3
|
+
import { useCallback, useState } from "preact/hooks";
|
|
4
|
+
import { FrakRpcError, RpcErrorCodes } from "@frak-labs/frame-connector";
|
|
5
|
+
|
|
6
|
+
//#region src/components/ButtonShare/hooks/useShareModal.ts
|
|
7
|
+
/**
|
|
8
|
+
* Open the share modal
|
|
9
|
+
*
|
|
10
|
+
* @description
|
|
11
|
+
* This function will open the share modal, lazily creating a modal builder on demand.
|
|
12
|
+
*/
|
|
13
|
+
function useShareModal(targetInteraction, placement, sharingLink) {
|
|
14
|
+
const [debugInfo, setDebugInfo] = useState(void 0);
|
|
15
|
+
const [isError, setIsError] = useState(false);
|
|
16
|
+
return {
|
|
17
|
+
handleShare: useCallback(async () => {
|
|
18
|
+
if (!window.FrakSetup?.client) {
|
|
19
|
+
console.error("Frak client not found");
|
|
20
|
+
setDebugInfo(DebugInfoGatherer.empty().formatDebugInfo("Frak client not found"));
|
|
21
|
+
setIsError(true);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const builder = modalBuilder(window.FrakSetup.client, {});
|
|
25
|
+
try {
|
|
26
|
+
await builder.sharing(sharingLink ? { link: sharingLink } : {}).display((metadata) => ({
|
|
27
|
+
...metadata,
|
|
28
|
+
targetInteraction
|
|
29
|
+
}), placement);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
if (e instanceof FrakRpcError && e.code === RpcErrorCodes.clientAborted) {
|
|
32
|
+
console.debug("User aborted the modal");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const debugInfo = window.FrakSetup.client.debugInfo.formatDebugInfo(e);
|
|
36
|
+
trackEvent(window.FrakSetup.client, "share_modal_error", {
|
|
37
|
+
error: e instanceof Object && "message" in e ? e.message : "Unknown error",
|
|
38
|
+
debugInfo
|
|
39
|
+
});
|
|
40
|
+
setDebugInfo(debugInfo);
|
|
41
|
+
setIsError(true);
|
|
42
|
+
console.error("Error while opening the modal", e);
|
|
43
|
+
}
|
|
44
|
+
}, [
|
|
45
|
+
targetInteraction,
|
|
46
|
+
placement,
|
|
47
|
+
sharingLink
|
|
48
|
+
]),
|
|
49
|
+
isError,
|
|
50
|
+
debugInfo
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
export { useShareModal 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.26-beta.
|
|
14
|
+
"version": "0.0.26-beta.1c24fe7c",
|
|
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",
|
|
@@ -56,6 +56,16 @@
|
|
|
56
56
|
"import": "./dist/openInApp.js",
|
|
57
57
|
"types": "./dist/openInApp.d.ts"
|
|
58
58
|
},
|
|
59
|
+
"./postPurchase": {
|
|
60
|
+
"development": "./src/components/PostPurchase/index.ts",
|
|
61
|
+
"import": "./dist/postPurchase.js",
|
|
62
|
+
"types": "./dist/postPurchase.d.ts"
|
|
63
|
+
},
|
|
64
|
+
"./banner": {
|
|
65
|
+
"development": "./src/components/Banner/index.ts",
|
|
66
|
+
"import": "./dist/banner.js",
|
|
67
|
+
"types": "./dist/banner.d.ts"
|
|
68
|
+
},
|
|
59
69
|
"./cdn": {
|
|
60
70
|
"import": "./cdn/components.js"
|
|
61
71
|
},
|
|
@@ -76,15 +86,14 @@
|
|
|
76
86
|
"publish": "echo 'Publishing components...'"
|
|
77
87
|
},
|
|
78
88
|
"dependencies": {
|
|
79
|
-
"@frak-labs/core-sdk": "0.2.1-beta.
|
|
80
|
-
"@frak-labs/frame-connector": "0.2.0-beta.
|
|
89
|
+
"@frak-labs/core-sdk": "0.2.1-beta.1c24fe7c",
|
|
90
|
+
"@frak-labs/frame-connector": "0.2.0-beta.1c24fe7c",
|
|
81
91
|
"preact": "^10.29.0",
|
|
82
92
|
"preact-custom-element": "^4.6.0"
|
|
83
93
|
},
|
|
84
94
|
"devDependencies": {
|
|
85
95
|
"@frak-labs/dev-tooling": "0.0.0",
|
|
86
96
|
"@frak-labs/test-foundation": "0.1.0",
|
|
87
|
-
"@frak-labs/ui": "0.0.0",
|
|
88
97
|
"@preact/preset-vite": "^2.10.4",
|
|
89
98
|
"@rolldown/plugin-node-polyfills": "^1.0.3",
|
|
90
99
|
"@testing-library/jest-dom": "^6.9.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as e,c as t,f as n,g as r,h as i,l as a,m as o,o as s,s as c}from"./loader.js";import{a as l,c as u,d,l as f,n as p,o as m,s as h,t as g,u as _}from"./jsxRuntime.module.PHHpn0I_.js";import{t as v}from"./ButtonWallet.BlV-eDcH.js";function y(e,t){return!e||e.payoutType!==`fixed`?0:e.amount[t]}function b(e,t){return e.reduce((e,n)=>Math.max(e,y(n.referrer,t)),0)}async function x({targetInteraction:e}){let t=window.FrakSetup?.client;if(!t){console.warn(`Frak client not ready yet`);return}let{rewards:r}=await s(t),i=a(t.config.metadata?.currency),o=b(e?r.filter(t=>t.interactionTypeKey===e):r,i);if(!(o<=0))return n(Math.round(o),t.config.metadata?.currency)}function S(e,t){let[n,r]=h(void 0);return f(()=>{e&&x({targetInteraction:t}).then(e=>{e&&r(e)})},[e,t]),{reward:n}}function C(e={}){let{successDuration:t=2e3}=e,[n,r]=h(!1);return{copy:u(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 w={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 T({debugInfo:e}){let[t,n]=h(!1);return g(`div`,{children:[g(`button`,{type:`button`,style:w.copyButton,onClick:()=>n(!t),children:`Ouvrir les informations`}),t&&g(`textarea`,{style:{display:`block`,width:`100%`,height:`200px`,fontSize:`12px`},children:e})]})}function E({debugInfo:e}){let{copied:t,copy:n}=C();return g(`div`,{style:w.errorContainer,children:[g(`div`,{style:w.header,children:g(`h3`,{style:w.title,children:`Oups ! Nous avons rencontré un petit problème`})}),g(`p`,{style:w.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 à`,` `,g(`a`,{href:`mailto:help@frak-labs.com?subject=Debug`,style:w.link,children:`help@frak-labs.com`}),` `,g(`br`,{}),`Merci pour votre retour, nous traitons votre demande dans les plus brefs délais.`]}),g(`button`,{type:`button`,onClick:()=>n(e??``),style:w.copyButton,children:t?`Informations copiées !`:`Copier les informations de débogage`}),g(T,{debugInfo:e})]})}function D(e,n){let[a,s]=h(void 0),[l,d]=h(!1);return{handleShare:u(async()=>{if(!window.FrakSetup?.client){console.error(`Frak client not found`),s(t.empty().formatDebugInfo(`Frak client not found`)),d(!0);return}let a=c(window.FrakSetup.client,{});try{await a.sharing({}).display(t=>({...t,targetInteraction:e}),n)}catch(e){if(e instanceof r&&e.code===i.clientAborted){console.debug(`User aborted the modal`);return}let t=window.FrakSetup.client.debugInfo.formatDebugInfo(e);o(window.FrakSetup.client,`share_modal_error`,{error:e instanceof Object&&`message`in e?e.message:`Unknown error`,debugInfo:t}),s(t),d(!0),console.error(`Error while opening the modal`,e)}},[e,n]),isError:l,debugInfo:a}}function O({placement:t,text:n=`Share and earn!`,classname:r=``,useReward:i,noRewardText:a,targetInteraction:s,clickAction:c}){let f=p(t),h=f?.components?.buttonShare;v(`frak-button-share`,t,h?.css);let _=m(()=>f?.targetInteraction===void 0?s:f.targetInteraction,[f?.targetInteraction,s]),y=h?.text??n,b=h?.noRewardText??a,x=m(()=>h?.useReward??i===!0,[h?.useReward,i]),C=m(()=>h?.clickAction??c??`embedded-wallet`,[h?.clickAction,c]),{shouldRender:w,isHidden:T,isClientReady:O}=l(),{reward:k}=S(x&&O,_),{handleShare:A,isError:j,debugInfo:M}=D(_,t),N=m(()=>x?k?y.includes(`{REWARD}`)?y.replace(`{REWARD}`,k):`${y} ${k}`:b??y.replace(`{REWARD}`,``):y,[x,y,b,k]),P=u(async()=>{o(window.FrakSetup.client,`share_button_clicked`),C===`share-modal`?await A():e(_,t)},[C,A,_,t]);if(!w||T)return null;let F=[`button`,`button__fadeIn`,r].filter(Boolean).join(` `);return g(d,{children:[g(`button`,{type:`button`,disabled:!O,class:F,onClick:P,children:N}),j&&g(E,{debugInfo:M})]})}_(O,`frak-button-share`,[`text`,`placement`,`classname`,`clickAction`,`useReward`,`noRewardText`,`targetInteraction`],{shadow:!1});export{O as ButtonShare,S as t};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import{i as e,m as t,t as n}from"./loader.js";import{a as r,d as i,i as a,l as o,n as s,o as c,r as l,s as u,t as d,u as f}from"./jsxRuntime.module.PHHpn0I_.js";import{t as p}from"./ButtonShare.BG6DCGo6.js";function m(e,t,r){o(()=>{n.injectBase(e,a)},[e]),o(()=>{!t||!r||n.injectPlacement(e,t,r)},[e,t,r])}function h(e){return d(`svg`,{fill:`none`,height:`1em`,viewBox:`0 0 28 28`,width:`1em`,xmlns:`http://www.w3.org/2000/svg`,...e,children:[d(`title`,{children:`Gift icon`}),d(`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`})]})}function g({placement:n,classname:a=``,useReward:f,targetInteraction:m}){let g=s(n),_=c(()=>g?.targetInteraction===void 0?m:g.targetInteraction,[g?.targetInteraction,m]),v=c(()=>f===!0,[f]),{shouldRender:y,isHidden:b,isClientReady:x}=r(),{reward:S}=p(v&&x,_),[C,w]=u(`right`);if(o(()=>{let e=g?.components?.buttonWallet?.position,t=window.FrakSetup?.modalWalletConfig?.metadata?.position;w(e??t??`right`)},[g?.components?.buttonWallet?.position]),!y||b)return null;let T=[`button`,`button__fadeIn`,C===`left`?`button__left`:`button__right`,a].filter(Boolean).join(` `);return d(i,{children:[d(`style`,{children:l(`
|
|
2
|
-
.button {
|
|
3
|
-
all: unset;
|
|
4
|
-
position: fixed;
|
|
5
|
-
bottom: 20px;
|
|
6
|
-
z-index: 2000000;
|
|
7
|
-
display: flex;
|
|
8
|
-
justify-content: center;
|
|
9
|
-
align-items: center;
|
|
10
|
-
background-color: #3e557e;
|
|
11
|
-
width: 45px;
|
|
12
|
-
height: 45px;
|
|
13
|
-
border-radius: 50%;
|
|
14
|
-
cursor: pointer;
|
|
15
|
-
text-align: center;
|
|
16
|
-
font-size: 24px;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
.button__left {
|
|
20
|
-
left: 20px;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.button__right {
|
|
24
|
-
right: 20px;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.reward {
|
|
28
|
-
position: absolute;
|
|
29
|
-
top: -4px;
|
|
30
|
-
right: 27px;
|
|
31
|
-
padding: 2px 3px;
|
|
32
|
-
border-radius: 5px;
|
|
33
|
-
background: #ff3f3f;
|
|
34
|
-
font-size: 9px;
|
|
35
|
-
color: #fff;
|
|
36
|
-
font-weight: 600;
|
|
37
|
-
white-space: nowrap;
|
|
38
|
-
line-height: 9px;
|
|
39
|
-
}
|
|
40
|
-
`,g?.components?.buttonWallet?.css)}),d(`button`,{type:`button`,"aria-label":`Open wallet`,part:`button`,disabled:!x,class:T,onClick:()=>{t(window.FrakSetup.client,`wallet_button_clicked`),e(_,n)},children:[d(h,{}),S&&d(`span`,{class:`reward`,children:S})]})]})}f(g,`frak-button-wallet`,[`placement`,`classname`,`useReward`,`targetInteraction`],{shadow:!0});export{g as ButtonWallet,m as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{d as e,m as t,u as n}from"./loader.js";import{a as r,n as i,o as a,t as o,u as s}from"./jsxRuntime.module.PHHpn0I_.js";import{t as c}from"./ButtonWallet.BlV-eDcH.js";function l(){return typeof navigator>`u`?!1:!!(/iPhone|iPad|iPod|Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)||/Macintosh/i.test(navigator.userAgent)&&navigator.maxTouchPoints>1)}function u(){return{isMobile:a(()=>l(),[])}}function d(r=`wallet`){let i=window.FrakSetup?.client;i&&t(i,`open_in_app_clicked`),e(`${n}${r}`,{onFallback:()=>{i&&t(i,`app_not_installed`)}})}function f({placement:e,text:t=`Open in App`,classname:n=``}){let a=i(e),{shouldRender:s,isHidden:l,isClientReady:f}=r(),{isMobile:p}=u();c(`frak-open-in-app`,e,a?.components?.openInApp?.css);let m=a?.components?.openInApp?.text??t;if(!p||!s||l)return null;let h=()=>{d()},g=[`button`,`button__fadeIn`,n].filter(Boolean).join(` `);return o(`button`,{type:`button`,"aria-label":`Open in Frak Wallet app`,disabled:!f,class:g,onClick:h,children:m})}s(f,`frak-open-in-app`,[`text`,`placement`,`classname`],{shadow:!1});export{f as OpenInAppButton};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import{_ as e,n as t,p as n,r}from"./loader.js";var i,a,o,s,c,l,u,d,f,p,m,h={},g=[],_=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,v=Array.isArray;function y(e,t){for(var n in t)e[n]=t[n];return e}function b(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function x(e,t,n){var r,a,o,s={};for(o in t)o==`key`?r=t[o]:o==`ref`?a=t[o]:s[o]=t[o];if(arguments.length>2&&(s.children=arguments.length>3?i.call(arguments,2):n),typeof e==`function`&&e.defaultProps!=null)for(o in e.defaultProps)s[o]===void 0&&(s[o]=e.defaultProps[o]);return S(e,s,r,a,null)}function S(e,t,n,r,i){var s={type:e,props:t,key:n,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++o,__i:-1,__u:0};return i==null&&a.vnode!=null&&a.vnode(s),s}function C(e){return e.children}function w(e,t){this.props=e,this.context=t}function T(e,t){if(t==null)return e.__?T(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`?T(e):null}function E(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,r=[],i=[],o=y({},t);o.__v=t.__v+1,a.vnode&&a.vnode(o),P(e.__P,o,t,e.__n,e.__P.namespaceURI,32&t.__u?[n]:null,r,n??T(t),!!(32&t.__u),i),o.__v=t.__v,o.__.__k[o.__i]=o,I(r,o,i),t.__e=t.__=null,o.__e!=n&&D(o)}}function D(e){if((e=e.__)!=null&&e.__c!=null)return e.__e=e.__c.base=null,e.__k.some(function(t){if(t!=null&&t.__e!=null)return e.__e=e.__c.base=t.__e}),D(e)}function O(e){(!e.__d&&(e.__d=!0)&&s.push(e)&&!k.__r++||c!=a.debounceRendering)&&((c=a.debounceRendering)||l)(k)}function k(){try{for(var e,t=1;s.length;)s.length>t&&s.sort(u),e=s.shift(),t=s.length,E(e)}finally{s.length=k.__r=0}}function ee(e,t,n,r,i,a,o,s,c,l,u){var d,f,p,m,_,v,y,b=r&&r.__k||g,x=t.length;for(c=A(n,t,b,c,x),d=0;d<x;d++)(p=n.__k[d])!=null&&(f=p.__i!=-1&&b[p.__i]||h,p.__i=d,v=P(e,p,f,i,a,o,s,c,l,u),m=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&L(f.ref,null,p),u.push(p.ref,p.__c||m,p)),_==null&&m!=null&&(_=m),(y=!!(4&p.__u))||f.__k===p.__k?c=j(p,c,e,y):typeof p.type==`function`&&v!==void 0?c=v:m&&(c=m.nextSibling),p.__u&=-7);return n.__e=_,c}function A(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]=S(null,o,null,null,null):v(o)?o=e.__k[a]=S(C,{children:o},null,null,null):o.constructor===void 0&&o.__b>0?o=e.__k[a]=S(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,s=null,(l=o.__i=M(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=T(s)),ae(s,s));return r}function j(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=j(i[a],t,n,r));return t}e.__e!=t&&(r&&(t&&e.type&&!t.parentNode&&(t=T(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do t&&=t.nextSibling;while(t!=null&&t.nodeType==8);return t}function M(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 te(e,t,n){t[0]==`-`?e.setProperty(t,n??``):e[t]=n==null?``:typeof n!=`number`||_.test(t)?n:n+`px`}function N(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||te(e.style,t,``);if(n)for(t in n)r&&n[t]==r[t]||te(e.style,t,n[t])}else if(t[0]==`o`&&t[1]==`n`)a=t!=(t=t.replace(d,`$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=f,e.addEventListener(t,a?m:p,a)):e.removeEventListener(t,a?m:p,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 ne(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t.t==null)t.t=f++;else if(t.t<n.u)return;return n(a.event?a.event(t):t)}}}function P(e,t,n,r,i,o,s,c,l,u){var d,f,p,m,h,_,x,S,T,E,D,O,k,A,j,M=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(l=!!(32&n.__u),o=[c=t.__e=n.__e]),(d=a.__b)&&d(t);n:if(typeof M==`function`)try{if(S=t.props,T=M.prototype&&M.prototype.render,E=(d=M.contextType)&&r[d.__c],D=d?E?E.props.value:d.__:r,n.__c?x=(f=t.__c=n.__c).__=f.__E:(T?t.__c=f=new M(S,D):(t.__c=f=new w(S,D),f.constructor=M,f.render=oe),E&&E.sub(f),f.state||={},f.__n=r,p=f.__d=!0,f.__h=[],f._sb=[]),T&&f.__s==null&&(f.__s=f.state),T&&M.getDerivedStateFromProps!=null&&(f.__s==f.state&&(f.__s=y({},f.__s)),y(f.__s,M.getDerivedStateFromProps(S,f.__s))),m=f.props,h=f.state,f.__v=t,p)T&&M.getDerivedStateFromProps==null&&f.componentWillMount!=null&&f.componentWillMount(),T&&f.componentDidMount!=null&&f.__h.push(f.componentDidMount);else{if(T&&M.getDerivedStateFromProps==null&&S!==m&&f.componentWillReceiveProps!=null&&f.componentWillReceiveProps(S,D),t.__v==n.__v||!f.__e&&f.shouldComponentUpdate!=null&&!1===f.shouldComponentUpdate(S,f.__s,D)){t.__v!=n.__v&&(f.props=S,f.state=f.__s,f.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(e){e&&(e.__=t)}),g.push.apply(f.__h,f._sb),f._sb=[],f.__h.length&&s.push(f);break n}f.componentWillUpdate!=null&&f.componentWillUpdate(S,f.__s,D),T&&f.componentDidUpdate!=null&&f.__h.push(function(){f.componentDidUpdate(m,h,_)})}if(f.context=D,f.props=S,f.__P=e,f.__e=!1,O=a.__r,k=0,T)f.state=f.__s,f.__d=!1,O&&O(t),d=f.render(f.props,f.state,f.context),g.push.apply(f.__h,f._sb),f._sb=[];else do f.__d=!1,O&&O(t),d=f.render(f.props,f.state,f.context),f.state=f.__s;while(f.__d&&++k<25);f.state=f.__s,f.getChildContext!=null&&(r=y(y({},r),f.getChildContext())),T&&!p&&f.getSnapshotBeforeUpdate!=null&&(_=f.getSnapshotBeforeUpdate(m,h)),A=d!=null&&d.type===C&&d.key==null?re(d.props.children):d,c=ee(e,v(A)?A:[A],t,n,r,i,o,s,c,l,u),f.base=t.__e,t.__u&=-161,f.__h.length&&s.push(f),x&&(f.__E=f.__=null)}catch(e){if(t.__v=null,l||o!=null)if(e.then){for(t.__u|=l?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;o[o.indexOf(c)]=null,t.__e=c}else{for(j=o.length;j--;)b(o[j]);F(t)}else t.__e=n.__e,t.__k=n.__k,e.then||F(t);a.__e(e,t,n)}else o==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):c=t.__e=ie(n.__e,t,n,r,i,o,s,l,u);return(d=a.diffed)&&d(t),128&t.__u?void 0:c}function F(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(F))}function I(e,t,n){for(var r=0;r<n.length;r++)L(n[r],n[++r],n[++r]);a.__c&&a.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){a.__e(e,t.__v)}})}function re(e){return typeof e!=`object`||!e||e.__b>0?e:v(e)?e.map(re):y({},e)}function ie(e,t,n,r,o,s,c,l,u){var d,f,p,m,g,_,y,x=n.props||h,S=t.props,C=t.type;if(C==`svg`?o=`http://www.w3.org/2000/svg`:C==`math`?o=`http://www.w3.org/1998/Math/MathML`:o||=`http://www.w3.org/1999/xhtml`,s!=null){for(d=0;d<s.length;d++)if((g=s[d])&&`setAttribute`in g==!!C&&(C?g.localName==C:g.nodeType==3)){e=g,s[d]=null;break}}if(e==null){if(C==null)return document.createTextNode(S);e=document.createElementNS(o,C,S.is&&S),l&&=(a.__m&&a.__m(t,s),!1),s=null}if(C==null)x===S||l&&e.data==S||(e.data=S);else{if(s&&=i.call(e.childNodes),!l&&s!=null)for(x={},d=0;d<e.attributes.length;d++)x[(g=e.attributes[d]).name]=g.value;for(d in x)g=x[d],d==`dangerouslySetInnerHTML`?p=g:d==`children`||d in S||d==`value`&&`defaultValue`in S||d==`checked`&&`defaultChecked`in S||N(e,d,null,g,o);for(d in S)g=S[d],d==`children`?m=g:d==`dangerouslySetInnerHTML`?f=g:d==`value`?_=g:d==`checked`?y=g:l&&typeof g!=`function`||x[d]===g||N(e,d,g,x[d],o);if(f)l||p&&(f.__html==p.__html||f.__html==e.innerHTML)||(e.innerHTML=f.__html),t.__k=[];else if(p&&(e.innerHTML=``),ee(t.type==`template`?e.content:e,v(m)?m:[m],t,n,r,C==`foreignObject`?`http://www.w3.org/1999/xhtml`:o,s,c,s?s[0]:n.__k&&T(n,0),l,u),s!=null)for(d=s.length;d--;)b(s[d]);l||(d=`value`,C==`progress`&&_==null?e.removeAttribute(`value`):_!=null&&(_!==e[d]||C==`progress`&&!_||C==`option`&&_!=x[d])&&N(e,d,_,x[d],o),d=`checked`,y!=null&&y!=e[d]&&N(e,d,y,x[d],o))}return e}function L(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){a.__e(e,n)}}function ae(e,t,n){var r,i;if(a.unmount&&a.unmount(e),(r=e.ref)&&(r.current&&r.current!=e.__e||L(r,null,t)),(r=e.__c)!=null){if(r.componentWillUnmount)try{r.componentWillUnmount()}catch(e){a.__e(e,t)}r.base=r.__P=null}if(r=e.__k)for(i=0;i<r.length;i++)r[i]&&ae(r[i],t,n||typeof e.type!=`function`);n||b(e.__e),e.__c=e.__=e.__e=void 0}function oe(e,t,n){return this.constructor(e,n)}function R(e,t,n){var r,o,s,c;t==document&&(t=document.documentElement),a.__&&a.__(e,t),o=(r=typeof n==`function`)?null:n&&n.__k||t.__k,s=[],c=[],P(t,e=(!r&&n||t).__k=x(C,null,[e]),o||h,h,t.namespaceURI,!r&&n?[n]:o?null:t.firstChild?i.call(t.childNodes):null,s,!r&&n?n:o?o.__e:t.firstChild,r,c),I(s,e,c)}function se(e,t){R(e,t,se)}function ce(e,t,n){var r,a,o,s,c=y({},e.props);for(o in e.type&&e.type.defaultProps&&(s=e.type.defaultProps),t)o==`key`?r=t[o]:o==`ref`?a=t[o]:c[o]=t[o]===void 0&&s!=null?s[o]:t[o];return arguments.length>2&&(c.children=arguments.length>3?i.call(arguments,2):n),S(e.type,c,r||e.key,a||e.ref,null)}i=g.slice,a={__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}},o=0,w.prototype.setState=function(e,t){var n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=y({},this.state);typeof e==`function`&&(e=e(y({},n),this.props)),e&&y(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),O(this))},w.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),O(this))},w.prototype.render=C,s=[],l=typeof Promise==`function`?Promise.prototype.then.bind(Promise.resolve()):setTimeout,u=function(e,t){return e.__v.__b-t.__v.__b},k.__r=0,d=/(PointerCapture)$|Capture$/i,f=0,p=ne(!1),m=ne(!0);function z(){return z=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},z.apply(this,arguments)}function le(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 ue=[`context`,`children`],de=[`useFragment`];function fe(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(){me.call(this,r)},i.prototype.attributeChangedCallback=he,i.prototype.disconnectedCallback=ge,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 pe(e){this.getChildContext=function(){return e.context};var t=e.children;return ce(t,le(e,ue))}function me(e){var t=new CustomEvent(`_preact`,{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(t),this._vdom=x(pe,z({},this._props,{context:t.detail.context}),_e(this,this._vdomComponent,e)),(this.hasAttribute(`hydrate`)?se:R)(this._vdom,this._root)}function B(e){return e.replace(/-(\w)/g,function(e,t){return t?t.toUpperCase():``})}function he(e,t,n){if(this._vdom){var r={};r[e]=n??=void 0,r[B(e)]=n,this._vdom=ce(this._vdom,r),R(this._vdom,this._root)}}function ge(){R(this._vdom=null,this._root)}function V(e,t){var n=this,r=e.useFragment,i=le(e,de);return x(r?C:`slot`,z({},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 _e(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[B(o[a].name)]=o[a].value);for(a=s.length;a--;){var c=_e(s[a],null,n),l=s[a].slot;l?i[l]=x(V,{name:l},c):r[a]=c}var u=!(!n||!n.shadow),d=t?x(V,{useFragment:!u},r):r;return!u&&t&&(e.innerHTML=``),x(t||e.nodeName.toLowerCase(),i,d)}function ve(n,r,i=[],a={shadow:!0}){typeof window<`u`&&(e(t),customElements.get(r)||fe(n,r,i,a))}var H,U,W,ye,G=0,be=[],K=a,xe=K.__b,Se=K.__r,Ce=K.diffed,we=K.__c,Te=K.unmount,Ee=K.__;function q(e,t){K.__h&&K.__h(U,e,G||t),G=0;var n=U.__H||={__:[],__h:[]};return e>=n.__.length&&n.__.push({}),n.__[e]}function J(e){return G=1,De(Ne,e)}function De(e,t,n){var r=q(H++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):Ne(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=U,!U.__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.some(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};U.__f=!0;var a=U.shouldComponentUpdate,o=U.componentWillUpdate;U.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)},U.shouldComponentUpdate=i}return r.__N||r.__}function Y(e,t){var n=q(H++,3);!K.__s&&Me(n.__H,t)&&(n.__=e,n.u=t,U.__H.__h.push(n))}function X(e,t){var n=q(H++,7);return Me(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function Oe(e,t){return G=8,X(function(){return e},t)}function ke(){for(var e;e=be.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Z),t.__h.some(Q),t.__h=[]}catch(n){t.__h=[],K.__e(n,e.__v)}}}K.__b=function(e){U=null,xe&&xe(e)},K.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Ee&&Ee(e,t)},K.__r=function(e){Se&&Se(e),H=0;var t=(U=e.__c).__H;t&&(W===U?(t.__h=[],U.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(Z),t.__h.some(Q),t.__h=[],H=0)),W=U},K.diffed=function(e){Ce&&Ce(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(be.push(t)!==1&&ye===K.requestAnimationFrame||((ye=K.requestAnimationFrame)||je)(ke)),t.__H.__.some(function(e){e.u&&(e.__H=e.u),e.u=void 0})),W=U=null},K.__c=function(e,t){t.some(function(e){try{e.__h.some(Z),e.__h=e.__h.filter(function(e){return!e.__||Q(e)})}catch(n){t.some(function(e){e.__h&&=[]}),t=[],K.__e(n,e.__v)}}),we&&we(e,t)},K.unmount=function(e){Te&&Te(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{Z(e)}catch(e){t=e}}),n.__H=void 0,t&&K.__e(t,n.__v))};var Ae=typeof requestAnimationFrame==`function`;function je(e){var t,n=function(){clearTimeout(r),Ae&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);Ae&&(t=requestAnimationFrame(n))}function Z(e){var t=U,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),U=t}function Q(e){var t=U;e.__c=e.__(),U=t}function Me(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function Ne(e,t){return typeof t==`function`?t(e):t}function Pe(){let[e,t]=J(()=>window.FrakSetup?.config?.waitForBackendConfig===!1?!0:n.isResolved),[i,a]=J(()=>n.getConfig().hidden??!1),[o,s]=J(()=>!!window.FrakSetup?.client);return Y(()=>{let e=n.getConfig();e.isResolved&&(t(!0),a(e.hidden??!1)),window.FrakSetup?.client&&s(!0);let i=e=>{let n=e.detail;n.isResolved&&t(!0),a(n.hidden??!1)};window.addEventListener(`frak:config`,i);let o=()=>s(!0);return r(`add`,o),()=>{window.removeEventListener(`frak:config`,i),r(`remove`,o)}},[]),{shouldRender:e,isHidden:i,isClientReady:o}}const $=`
|
|
2
|
-
:host {
|
|
3
|
-
display: contents;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
:host([hidden]) {
|
|
7
|
-
display: none;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
.button:disabled {
|
|
11
|
-
opacity: 0.7;
|
|
12
|
-
cursor: default;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.button__fadeIn {
|
|
16
|
-
animation: frak-fadeIn 300ms ease-in;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
@keyframes frak-fadeIn {
|
|
20
|
-
from {
|
|
21
|
-
opacity: 0;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
to {
|
|
25
|
-
opacity: 1;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
`;function Fe(e,t){return t?`${$}\n${e}\n${t}`:`${$}\n${e}`}const Ie=`
|
|
29
|
-
:where(frak-button-share, frak-open-in-app) {
|
|
30
|
-
display: contents;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
:where(frak-button-share .button, frak-open-in-app .button) {
|
|
34
|
-
display: flex;
|
|
35
|
-
align-items: center;
|
|
36
|
-
justify-content: center;
|
|
37
|
-
gap: 10px;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
:where(frak-button-share .button:disabled, frak-open-in-app .button:disabled) {
|
|
41
|
-
opacity: 0.7;
|
|
42
|
-
cursor: default;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
:where(frak-button-share .button__fadeIn, frak-open-in-app .button__fadeIn) {
|
|
46
|
-
animation: frak-fadeIn 300ms ease-in;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@keyframes frak-fadeIn {
|
|
50
|
-
from {
|
|
51
|
-
opacity: 0;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
to {
|
|
55
|
-
opacity: 1;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
`;function Le(e){return n.getConfig().placements?.[e]}function Re(e){let[t,n]=J(0);return Y(()=>{let e=e=>{n(e=>e+1)};return window.addEventListener(`frak:config`,e),n(e=>e+1),()=>window.removeEventListener(`frak:config`,e)},[]),X(()=>e?Le(e):void 0,[e,t])}var ze=0;Array.isArray;function Be(e,t,n,r,i,o){t||={};var s,c,l=t;if(`ref`in l)for(c in l={},t)c==`ref`?s=t[c]:l[c]=t[c];var u={type:e,props:l,key:n,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--ze,__i:-1,__u:0,__source:i,__self:o};if(typeof e==`function`&&(s=e.defaultProps))for(c in s)l[c]===void 0&&(l[c]=s[c]);return a.vnode&&a.vnode(u),u}export{Pe as a,Oe as c,C as d,Ie as i,Y as l,Re as n,X as o,Fe as r,J as s,Be as t,ve as u};
|
|
@@ -1,48 +0,0 @@
|
|
|
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 };
|