@crediball/react 0.6.0 → 0.7.0
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.
|
@@ -73,7 +73,12 @@ export interface CrediballProviderProps {
|
|
|
73
73
|
customMin?: number;
|
|
74
74
|
/** Override the custom-amount maximum (defaults to the dashboard's configured maximum). */
|
|
75
75
|
customMax?: number;
|
|
76
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Currency symbol shown in the paywall. Auto-derived (via Intl) from the ISO
|
|
78
|
+
* currency you configured on the dashboard's Packages page once packages load,
|
|
79
|
+
* so it never drifts out of sync if you switch currencies there. Pass this only
|
|
80
|
+
* to force a specific symbol instead. Falls back to "€" before the first fetch.
|
|
81
|
+
*/
|
|
77
82
|
currencySymbol?: string;
|
|
78
83
|
title?: string;
|
|
79
84
|
description?: string;
|
|
@@ -132,7 +137,7 @@ interface CrediballContextValue {
|
|
|
132
137
|
* SSE/streaming routes (text/event-stream, ndjson) are also handled automatically —
|
|
133
138
|
* the watcher scans each chunk for credit errors, so no manual wiring is needed.
|
|
134
139
|
*/
|
|
135
|
-
export declare function CrediballProvider({ children, publishableKey, userId, apiUrl, pollIntervalMs, lowCreditThreshold, amounts, onTopup, onSelectPackage, onSelectPlan, onCancelSubscription, watchFetch, allowCustom, customMin, customMax, currencySymbol, title, description, accentColor, }: CrediballProviderProps): import("react").JSX.Element;
|
|
140
|
+
export declare function CrediballProvider({ children, publishableKey, userId, apiUrl, pollIntervalMs, lowCreditThreshold, amounts, onTopup, onSelectPackage, onSelectPlan, onCancelSubscription, watchFetch, allowCustom, customMin, customMax, currencySymbol: currencySymbolProp, title, description, accentColor, }: CrediballProviderProps): import("react").JSX.Element;
|
|
136
141
|
/**
|
|
137
142
|
* Access the paywall + live data from anywhere inside <CrediballProvider>.
|
|
138
143
|
*
|
|
@@ -18,6 +18,22 @@ const EMPTY_SNAPSHOT = {
|
|
|
18
18
|
};
|
|
19
19
|
const noopSubscribe = () => () => { };
|
|
20
20
|
const getEmptySnapshot = () => EMPTY_SNAPSHOT;
|
|
21
|
+
/**
|
|
22
|
+
* Map an ISO 4217 code (as returned by the dashboard's packages config) to a
|
|
23
|
+
* display symbol via Intl, so the paywall doesn't need a hand-maintained
|
|
24
|
+
* currency → symbol table that can fall out of sync with the dashboard.
|
|
25
|
+
*/
|
|
26
|
+
function symbolForCurrency(iso) {
|
|
27
|
+
try {
|
|
28
|
+
const part = new Intl.NumberFormat(undefined, { style: "currency", currency: iso })
|
|
29
|
+
.formatToParts(0)
|
|
30
|
+
.find((p) => p.type === "currency");
|
|
31
|
+
return part?.value ?? iso;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return iso;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
21
37
|
/**
|
|
22
38
|
* Pattern B, automated. Wrap your app once:
|
|
23
39
|
*
|
|
@@ -38,7 +54,7 @@ const getEmptySnapshot = () => EMPTY_SNAPSHOT;
|
|
|
38
54
|
* SSE/streaming routes (text/event-stream, ndjson) are also handled automatically —
|
|
39
55
|
* the watcher scans each chunk for credit errors, so no manual wiring is needed.
|
|
40
56
|
*/
|
|
41
|
-
export function CrediballProvider({ children, publishableKey, userId, apiUrl, pollIntervalMs, lowCreditThreshold, amounts = [5, 10, 20], onTopup, onSelectPackage, onSelectPlan, onCancelSubscription, watchFetch = true, allowCustom, customMin, customMax, currencySymbol
|
|
57
|
+
export function CrediballProvider({ children, publishableKey, userId, apiUrl, pollIntervalMs, lowCreditThreshold, amounts = [5, 10, 20], onTopup, onSelectPackage, onSelectPlan, onCancelSubscription, watchFetch = true, allowCustom, customMin, customMax, currencySymbol: currencySymbolProp, title, description, accentColor, }) {
|
|
42
58
|
const [open, setOpen] = useState(false);
|
|
43
59
|
const showPaywall = useCallback(() => setOpen(true), []);
|
|
44
60
|
const hidePaywall = useCallback(() => setOpen(false), []);
|
|
@@ -193,6 +209,11 @@ export function CrediballProvider({ children, publishableKey, userId, apiUrl, po
|
|
|
193
209
|
await client?.refresh();
|
|
194
210
|
}
|
|
195
211
|
const pkgs = snapshot.packages;
|
|
212
|
+
// Follow the dashboard's configured currency once packages load, unless the
|
|
213
|
+
// host pins an explicit symbol. Falls back to "€" only until the first fetch
|
|
214
|
+
// resolves, so switching currencies on the Packages page never requires a
|
|
215
|
+
// matching code change/redeploy here.
|
|
216
|
+
const currencySymbol = currencySymbolProp ?? (pkgs?.currency ? symbolForCurrency(pkgs.currency) : "€");
|
|
196
217
|
// Auto-derive the custom-amount field from the dashboard's custom-topup config,
|
|
197
218
|
// so a developer who enabled it doesn't also have to pass allowCustom/min/max.
|
|
198
219
|
// Explicit props still win (allowCustom={false} force-hides it).
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crediball/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Drop-in React components for showing Crediball credits inside your AI app.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Filippo Rezzadore <filipporezzadore@gmail.com>",
|
|
7
|
-
"homepage": "https://crediball.
|
|
7
|
+
"homepage": "https://crediball.ai",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/filipporezzadore/Crediball.git",
|