@pollar/react 0.10.1-rc.2 → 0.10.1-rc.3

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/dist/index.d.mts CHANGED
@@ -309,6 +309,13 @@ interface KycModalTemplateProps {
309
309
  declare function KycModalTemplate({ theme, accentColor, step, providers, selectedProvider, session, kycStatus, isLoading, onSelectProvider, onDoneVerifying, onClose, }: KycModalTemplateProps): react_jsx_runtime.JSX.Element;
310
310
 
311
311
  type RampStep = 'input' | 'loading_quote' | 'select_route' | 'contact' | 'status' | 'error';
312
+ /** A field a provider declares (via the quote) that the client must collect. */
313
+ interface RampFieldSpec {
314
+ key: string;
315
+ label: string;
316
+ type: 'text' | 'email' | 'tel';
317
+ bankType?: 'CLABE' | 'PIX' | 'PSE' | 'ACH';
318
+ }
312
319
  interface RampWidgetTemplateProps {
313
320
  theme: string;
314
321
  accentColor: string;
@@ -317,8 +324,8 @@ interface RampWidgetTemplateProps {
317
324
  amount: string;
318
325
  currency: string;
319
326
  country: string;
320
- email: string;
321
- fullName: string;
327
+ requiredFields: RampFieldSpec[];
328
+ fieldValues: Record<string, string>;
322
329
  countries: RampCountry[];
323
330
  countriesLoading: boolean;
324
331
  refreshing: boolean;
@@ -334,8 +341,7 @@ interface RampWidgetTemplateProps {
334
341
  errorMsg: string | null;
335
342
  onDirectionChange: (d: RampDirection) => void;
336
343
  onAmountChange: (v: string) => void;
337
- onEmailChange: (v: string) => void;
338
- onFullNameChange: (v: string) => void;
344
+ onFieldChange: (key: string, value: string) => void;
339
345
  onCountryChange: (v: string) => void;
340
346
  onFindRoute: () => void;
341
347
  onSelectQuote: (q: RampQuote) => void;
@@ -346,7 +352,7 @@ interface RampWidgetTemplateProps {
346
352
  onRefresh: () => void;
347
353
  onClose: () => void;
348
354
  }
349
- declare function RampWidgetTemplate({ theme, accentColor, step, direction, amount, currency, country, email, fullName, countries, countriesLoading, refreshing, quotes, isLoading, provider, txStatus, kycUrl, stellarTxHash, depositInstructions, canComplete, completing, errorMsg, onDirectionChange, onAmountChange, onEmailChange, onFullNameChange, onCountryChange, onFindRoute, onSelectQuote, onContactContinue, onOpenKyc, onCompleteWithdraw, onRetry, onRefresh, onClose, }: RampWidgetTemplateProps): react_jsx_runtime.JSX.Element;
355
+ declare function RampWidgetTemplate({ theme, accentColor, step, direction, amount, currency, country, requiredFields, fieldValues, countries, countriesLoading, refreshing, quotes, isLoading, provider, txStatus, kycUrl, stellarTxHash, depositInstructions, canComplete, completing, errorMsg, onDirectionChange, onAmountChange, onFieldChange, onCountryChange, onFindRoute, onSelectQuote, onContactContinue, onOpenKyc, onCompleteWithdraw, onRetry, onRefresh, onClose, }: RampWidgetTemplateProps): react_jsx_runtime.JSX.Element;
350
356
 
351
357
  interface TransactionModalTemplateProps {
352
358
  theme: string;
package/dist/index.d.ts CHANGED
@@ -309,6 +309,13 @@ interface KycModalTemplateProps {
309
309
  declare function KycModalTemplate({ theme, accentColor, step, providers, selectedProvider, session, kycStatus, isLoading, onSelectProvider, onDoneVerifying, onClose, }: KycModalTemplateProps): react_jsx_runtime.JSX.Element;
310
310
 
311
311
  type RampStep = 'input' | 'loading_quote' | 'select_route' | 'contact' | 'status' | 'error';
312
+ /** A field a provider declares (via the quote) that the client must collect. */
313
+ interface RampFieldSpec {
314
+ key: string;
315
+ label: string;
316
+ type: 'text' | 'email' | 'tel';
317
+ bankType?: 'CLABE' | 'PIX' | 'PSE' | 'ACH';
318
+ }
312
319
  interface RampWidgetTemplateProps {
313
320
  theme: string;
314
321
  accentColor: string;
@@ -317,8 +324,8 @@ interface RampWidgetTemplateProps {
317
324
  amount: string;
318
325
  currency: string;
319
326
  country: string;
320
- email: string;
321
- fullName: string;
327
+ requiredFields: RampFieldSpec[];
328
+ fieldValues: Record<string, string>;
322
329
  countries: RampCountry[];
323
330
  countriesLoading: boolean;
324
331
  refreshing: boolean;
@@ -334,8 +341,7 @@ interface RampWidgetTemplateProps {
334
341
  errorMsg: string | null;
335
342
  onDirectionChange: (d: RampDirection) => void;
336
343
  onAmountChange: (v: string) => void;
337
- onEmailChange: (v: string) => void;
338
- onFullNameChange: (v: string) => void;
344
+ onFieldChange: (key: string, value: string) => void;
339
345
  onCountryChange: (v: string) => void;
340
346
  onFindRoute: () => void;
341
347
  onSelectQuote: (q: RampQuote) => void;
@@ -346,7 +352,7 @@ interface RampWidgetTemplateProps {
346
352
  onRefresh: () => void;
347
353
  onClose: () => void;
348
354
  }
349
- declare function RampWidgetTemplate({ theme, accentColor, step, direction, amount, currency, country, email, fullName, countries, countriesLoading, refreshing, quotes, isLoading, provider, txStatus, kycUrl, stellarTxHash, depositInstructions, canComplete, completing, errorMsg, onDirectionChange, onAmountChange, onEmailChange, onFullNameChange, onCountryChange, onFindRoute, onSelectQuote, onContactContinue, onOpenKyc, onCompleteWithdraw, onRetry, onRefresh, onClose, }: RampWidgetTemplateProps): react_jsx_runtime.JSX.Element;
355
+ declare function RampWidgetTemplate({ theme, accentColor, step, direction, amount, currency, country, requiredFields, fieldValues, countries, countriesLoading, refreshing, quotes, isLoading, provider, txStatus, kycUrl, stellarTxHash, depositInstructions, canComplete, completing, errorMsg, onDirectionChange, onAmountChange, onFieldChange, onCountryChange, onFindRoute, onSelectQuote, onContactContinue, onOpenKyc, onCompleteWithdraw, onRetry, onRefresh, onClose, }: RampWidgetTemplateProps): react_jsx_runtime.JSX.Element;
350
356
 
351
357
  interface TransactionModalTemplateProps {
352
358
  theme: string;
package/dist/index.js CHANGED
@@ -1035,7 +1035,7 @@ var PollarModalFooter = () => {
1035
1035
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "pollar-footer-name", children: "Pollar" }),
1036
1036
  /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "pollar-footer-version", children: [
1037
1037
  "v",
1038
- "0.10.1-rc.2"
1038
+ "0.10.1-rc.3"
1039
1039
  ] })
1040
1040
  ] })
1041
1041
  ] });
@@ -2506,8 +2506,8 @@ function RampWidgetTemplate({
2506
2506
  amount,
2507
2507
  currency,
2508
2508
  country,
2509
- email,
2510
- fullName,
2509
+ requiredFields,
2510
+ fieldValues,
2511
2511
  countries,
2512
2512
  countriesLoading,
2513
2513
  refreshing,
@@ -2523,8 +2523,7 @@ function RampWidgetTemplate({
2523
2523
  errorMsg,
2524
2524
  onDirectionChange,
2525
2525
  onAmountChange,
2526
- onEmailChange,
2527
- onFullNameChange,
2526
+ onFieldChange,
2528
2527
  onCountryChange,
2529
2528
  onFindRoute,
2530
2529
  onSelectQuote,
@@ -2675,33 +2674,19 @@ function RampWidgetTemplate({
2675
2674
  /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "pollar-btn-secondary", onClick: onClose, children: "Cancel" })
2676
2675
  ] }),
2677
2676
  step === "contact" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2678
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pollar-ramp-field", children: [
2679
- /* @__PURE__ */ jsxRuntime.jsx("label", { className: "pollar-ramp-label", children: "Full name" }),
2677
+ requiredFields.map((f) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pollar-ramp-field", children: [
2678
+ /* @__PURE__ */ jsxRuntime.jsx("label", { className: "pollar-ramp-label", children: f.label }),
2680
2679
  /* @__PURE__ */ jsxRuntime.jsx(
2681
2680
  "input",
2682
2681
  {
2683
- type: "text",
2682
+ type: f.type,
2684
2683
  className: "pollar-ramp-input",
2685
- placeholder: "Jane Doe",
2686
- value: fullName,
2687
- onChange: (e) => onFullNameChange(e.target.value)
2684
+ value: fieldValues[f.key] ?? "",
2685
+ autoComplete: f.type === "email" ? "email" : "off",
2686
+ onChange: (e) => onFieldChange(f.key, e.target.value)
2688
2687
  }
2689
2688
  )
2690
- ] }),
2691
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pollar-ramp-field", children: [
2692
- /* @__PURE__ */ jsxRuntime.jsx("label", { className: "pollar-ramp-label", children: "Email" }),
2693
- /* @__PURE__ */ jsxRuntime.jsx(
2694
- "input",
2695
- {
2696
- type: "email",
2697
- className: "pollar-ramp-input",
2698
- placeholder: "jane@example.com",
2699
- value: email,
2700
- autoComplete: "email",
2701
- onChange: (e) => onEmailChange(e.target.value)
2702
- }
2703
- )
2704
- ] }),
2689
+ ] }, f.key)),
2705
2690
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "pollar-modal-actions", children: [
2706
2691
  /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "pollar-btn-secondary", onClick: onRetry, children: "Back" }),
2707
2692
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -2709,7 +2694,7 @@ function RampWidgetTemplate({
2709
2694
  {
2710
2695
  type: "button",
2711
2696
  className: "pollar-btn-primary",
2712
- disabled: !fullName.trim() || !email.trim() || isLoading,
2697
+ disabled: requiredFields.some((f) => !(fieldValues[f.key] ?? "").trim()) || isLoading,
2713
2698
  onClick: onContactContinue,
2714
2699
  children: isLoading ? "Starting\u2026" : "Continue"
2715
2700
  }
@@ -2755,6 +2740,9 @@ function RampWidgetTemplate({
2755
2740
  ] });
2756
2741
  }
2757
2742
  var TERMINAL = ["completed", "failed"];
2743
+ function requiredFieldsOf(quote) {
2744
+ return quote.requiredFields ?? [];
2745
+ }
2758
2746
  function RampWidget({ onClose }) {
2759
2747
  const { getClient, signTx, wallet, styles } = usePollar();
2760
2748
  const walletAddress = wallet?.address ?? "";
@@ -2765,8 +2753,8 @@ function RampWidget({ onClose }) {
2765
2753
  const [amount, setAmount] = react.useState("");
2766
2754
  const [currency, setCurrency] = react.useState("");
2767
2755
  const [country, setCountry] = react.useState("");
2768
- const [email, setEmail] = react.useState("");
2769
- const [fullName, setFullName] = react.useState("");
2756
+ const [fieldValues, setFieldValues] = react.useState({});
2757
+ const setFieldValue = (key, value) => setFieldValues((v) => ({ ...v, [key]: value }));
2770
2758
  const [countries, setCountries] = react.useState([]);
2771
2759
  const [countriesLoading, setCountriesLoading] = react.useState(true);
2772
2760
  const [refreshing, setRefreshing] = react.useState(false);
@@ -2913,8 +2901,9 @@ function RampWidget({ onClose }) {
2913
2901
  function handleSelectQuote(quote) {
2914
2902
  setSelectedQuote(quote);
2915
2903
  setErrorMsg(null);
2916
- const requiresContact = quote.requiresContact ?? false;
2917
- if (requiresContact && (!email.trim() || !fullName.trim())) {
2904
+ const fields = requiredFieldsOf(quote);
2905
+ const missing = fields.some((f) => !(fieldValues[f.key] ?? "").trim());
2906
+ if (fields.length > 0 && missing) {
2918
2907
  setStep("contact");
2919
2908
  return;
2920
2909
  }
@@ -2927,15 +2916,14 @@ function RampWidget({ onClose }) {
2927
2916
  setIsLoading(true);
2928
2917
  setErrorMsg(null);
2929
2918
  try {
2930
- const base = {
2931
- quoteId: quote.quoteId,
2932
- amount: Number(amount),
2933
- currency,
2934
- country,
2935
- ...email.trim() ? { email: email.trim() } : {},
2936
- ...fullName.trim() ? { fullName: fullName.trim() } : {},
2937
- ...walletAddress ? { walletAddress } : {}
2938
- };
2919
+ const base = { quoteId: quote.quoteId, amount: Number(amount), currency, country };
2920
+ if (walletAddress) base.walletAddress = walletAddress;
2921
+ for (const f of requiredFieldsOf(quote)) {
2922
+ const val = (fieldValues[f.key] ?? "").trim();
2923
+ if (!val) continue;
2924
+ if (f.bankType) base.bankDetails = { type: f.bankType, value: val };
2925
+ else base[f.key] = val;
2926
+ }
2939
2927
  const result = direction === "onramp" ? await client.createOnRamp(base) : await client.createOffRamp(base);
2940
2928
  await applyResult(result);
2941
2929
  } catch (e) {
@@ -2980,8 +2968,8 @@ function RampWidget({ onClose }) {
2980
2968
  amount,
2981
2969
  currency,
2982
2970
  country,
2983
- email,
2984
- fullName,
2971
+ requiredFields: selectedQuote ? requiredFieldsOf(selectedQuote) : [],
2972
+ fieldValues,
2985
2973
  countries,
2986
2974
  countriesLoading,
2987
2975
  refreshing,
@@ -2997,8 +2985,7 @@ function RampWidget({ onClose }) {
2997
2985
  errorMsg,
2998
2986
  onDirectionChange: setDirection,
2999
2987
  onAmountChange: setAmount,
3000
- onEmailChange: setEmail,
3001
- onFullNameChange: setFullName,
2988
+ onFieldChange: setFieldValue,
3002
2989
  onCountryChange: handleCountryChange,
3003
2990
  onFindRoute: handleFindRoute,
3004
2991
  onSelectQuote: handleSelectQuote,