@frak-labs/components 1.0.9 → 1.0.10-beta.5b65e64f

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.
Files changed (41) hide show
  1. package/cdn/Banner.Ds4HXhVK.js +167 -0
  2. package/cdn/ButtonShare.DiC5e1BJ.js +1 -0
  3. package/cdn/{ButtonWallet.B0buPR_z.js → ButtonWallet.CoFDK0ky.js} +1 -1
  4. package/cdn/{GiftIcon.eRNTGQ_r.js → GiftIcon.DnSW4dJQ.js} +1 -1
  5. package/cdn/{OpenInAppButton.Dgb-qhM8.js → OpenInAppButton.B8O6YFx-.js} +1 -1
  6. package/cdn/PostPurchase.BqxojeOo.js +89 -0
  7. package/cdn/components.js +1 -1
  8. package/cdn/embeddedWallet.CDUxjdX2.js +1 -0
  9. package/cdn/loader.js +1 -1
  10. package/cdn/replay-V6FXES7X.CNozpSRg.js +1 -0
  11. package/cdn/rewards.ObaTYOMx.js +1 -0
  12. package/cdn/{useGlobalComponents.TG9kIYSc.js → useGlobalComponents.pjgSwLk9.js} +1 -1
  13. package/cdn/{useLightDomStyles.tjNBKcOr.js → useLightDomStyles.2RQE6Iby.js} +1 -1
  14. package/cdn/usePlacement.CRfzWKVY.js +58 -0
  15. package/cdn/useReward.BxGRytCE.js +1 -0
  16. package/dist/{GiftIcon-BIp9FTJs.js → GiftIcon-WEWSJ8kV.js} +1 -1
  17. package/dist/banner.d.ts +1 -2
  18. package/dist/banner.js +64 -70
  19. package/dist/buttonShare.d.ts +1 -2
  20. package/dist/buttonShare.js +6 -6
  21. package/dist/buttonWallet.d.ts +1 -2
  22. package/dist/buttonWallet.js +2 -2
  23. package/dist/openInApp.d.ts +1 -3
  24. package/dist/openInApp.js +2 -2
  25. package/dist/postPurchase.d.ts +1 -2
  26. package/dist/postPurchase.js +21 -14
  27. package/dist/rewards-4ZjvQInq.js +126 -0
  28. package/dist/{useLightDomStyles-CgAkUlb_.js → useLightDomStyles-DPKMhggr.js} +1 -1
  29. package/dist/{usePlacement-rmDVnK7X.js → usePlacement-DTN6H6vW.js} +55 -1
  30. package/dist/useReward-CJIKPMmq.js +39 -0
  31. package/package.json +3 -3
  32. package/cdn/Banner.CcOWT4lZ.js +0 -178
  33. package/cdn/ButtonShare.D9-F0jJJ.js +0 -1
  34. package/cdn/PostPurchase.BYxnAEyn.js +0 -89
  35. package/cdn/embeddedWallet.BS-9u4Be.js +0 -1
  36. package/cdn/formatReward.B1ZyoceC.js +0 -1
  37. package/cdn/replay-V6FXES7X.BoL9fAjx.js +0 -1
  38. package/cdn/usePlacement.BgMXY5CX.js +0 -58
  39. package/cdn/useReward.BtBpuMwt.js +0 -1
  40. package/dist/formatReward-Cf2KpA3x.js +0 -33
  41. package/dist/useReward-ClVShg45.js +0 -65
@@ -1,33 +0,0 @@
1
- import { formatAmount, getCurrencyAmountKey, getSupportedCurrency } from "@frak-labs/core-sdk";
2
- //#region src/utils/format/formatReward.ts
3
- /**
4
- * Format an {@link EstimatedReward} into a human-readable string.
5
- *
6
- * - `fixed` → e.g. `"5 €"`
7
- * - `percentage` → if `basketAmount` is provided, computes the actual value
8
- * (e.g. `"10 €"`), otherwise returns `"10 %"`
9
- * - `tiered` → max tier value, e.g. `"50 €"`
10
- */
11
- function formatEstimatedReward(reward, currency, basketAmount) {
12
- const supportedCurrency = getSupportedCurrency(currency);
13
- const key = getCurrencyAmountKey(supportedCurrency);
14
- switch (reward.payoutType) {
15
- case "fixed": return formatAmount(Math.round(reward.amount[key]), supportedCurrency);
16
- case "percentage":
17
- if (basketAmount !== void 0) return formatAmount(Math.round(reward.percent * basketAmount / 100), supportedCurrency);
18
- return `${reward.percent} %`;
19
- case "tiered": {
20
- const max = reward.tiers.reduce((acc, tier) => Math.max(acc, tier.amount[key]), 0);
21
- return formatAmount(Math.round(max), supportedCurrency);
22
- }
23
- }
24
- }
25
- /**
26
- * Replace the `{REWARD}` placeholder in a text string with a reward value.
27
- * If no reward is provided, returns the text with `{REWARD}` stripped.
28
- */
29
- function applyRewardPlaceholder(text, reward) {
30
- return reward ? text.replace("{REWARD}", reward) : text.replace("{REWARD}", "");
31
- }
32
- //#endregion
33
- export { formatEstimatedReward as n, applyRewardPlaceholder as t };
@@ -1,65 +0,0 @@
1
- import { n as formatEstimatedReward } from "./formatReward-Cf2KpA3x.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
- //#region src/hooks/useReward.ts
6
- /**
7
- * Get the comparable fiat value of a reward for ranking purposes.
8
- */
9
- function getRewardValue(reward, key) {
10
- switch (reward.payoutType) {
11
- case "fixed": return reward.amount[key];
12
- case "tiered": return reward.tiers.reduce((acc, tier) => Math.max(acc, tier.amount[key]), 0);
13
- case "percentage": return 0;
14
- }
15
- }
16
- /**
17
- * Pick the best referrer reward from merchant info and format it.
18
- * Returns `undefined` when no displayable reward is found.
19
- */
20
- function resolveBestReward({ rewards }, currency, targetInteraction) {
21
- const referrerRewards = (targetInteraction ? rewards.filter((r) => r.interactionTypeKey === targetInteraction) : rewards).map((r) => r.referrer).filter((r) => r !== void 0);
22
- if (referrerRewards.length === 0) return void 0;
23
- const key = getCurrencyAmountKey(getSupportedCurrency(currency));
24
- let bestReward = referrerRewards[0];
25
- let bestValue = getRewardValue(bestReward, key);
26
- for (let i = 1; i < referrerRewards.length; i++) {
27
- const value = getRewardValue(referrerRewards[i], key);
28
- if (value > bestValue) {
29
- bestReward = referrerRewards[i];
30
- bestValue = value;
31
- }
32
- }
33
- if (bestValue <= 0) {
34
- const percentageReward = referrerRewards.find((r) => r.payoutType === "percentage");
35
- if (!percentageReward) return void 0;
36
- bestReward = percentageReward;
37
- }
38
- return formatEstimatedReward(bestReward, currency);
39
- }
40
- /**
41
- * Hook to fetch and format the best referrer reward for a given interaction type.
42
- *
43
- * Calls `getMerchantInformation`, picks the highest-value referrer reward
44
- * across all matching campaigns, and returns it as a formatted string.
45
- *
46
- * @param shouldUseReward - Whether to fetch the reward at all
47
- * @param targetInteraction - Optional filter by interaction type (e.g. "purchase")
48
- * @returns Object containing the formatted reward string, or undefined if unavailable
49
- */
50
- function useReward(shouldUseReward, targetInteraction) {
51
- const [reward, setReward] = useState(void 0);
52
- useEffect(() => {
53
- if (!shouldUseReward) return;
54
- const client = window.FrakSetup?.client;
55
- if (!client) return;
56
- getMerchantInformation(client).then((merchantInfo) => {
57
- const currency = client.config.metadata?.currency;
58
- const formatted = resolveBestReward(merchantInfo, currency, targetInteraction);
59
- if (formatted) setReward(formatted);
60
- }).catch(() => {});
61
- }, [shouldUseReward, targetInteraction]);
62
- return { reward };
63
- }
64
- //#endregion
65
- export { useReward as t };