@pollar/react 0.10.1-rc.7 → 0.10.1-rc.9

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.mjs CHANGED
@@ -1033,7 +1033,7 @@ var PollarModalFooter = () => {
1033
1033
  /* @__PURE__ */ jsx("span", { className: "pollar-footer-name", children: "Pollar" }),
1034
1034
  /* @__PURE__ */ jsxs("span", { className: "pollar-footer-version", children: [
1035
1035
  "v",
1036
- "0.10.1-rc.7"
1036
+ "0.10.1-rc.9"
1037
1037
  ] })
1038
1038
  ] })
1039
1039
  ] });
@@ -2524,6 +2524,13 @@ function RouteDisplay({ quote, onSelect }) {
2524
2524
  }
2525
2525
  );
2526
2526
  }
2527
+ var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
2528
+ function isFieldValid(spec, raw) {
2529
+ const value = (raw ?? "").trim();
2530
+ if (!value) return false;
2531
+ if (spec.type === "email") return EMAIL_RE.test(value);
2532
+ return true;
2533
+ }
2527
2534
  var LOADING_STEPS = ["Detecting your country\u2026", "Consulting providers\u2026", "Route found!"];
2528
2535
  function flagEmoji(code) {
2529
2536
  const cc = code.trim().toUpperCase();
@@ -2594,6 +2601,7 @@ function RampWidgetTemplate({
2594
2601
  kycUrl,
2595
2602
  tosUrl,
2596
2603
  stellarTxHash,
2604
+ explorerUrl,
2597
2605
  depositInstructions,
2598
2606
  canComplete,
2599
2607
  completing,
@@ -2754,7 +2762,18 @@ function RampWidgetTemplate({
2754
2762
  step === "contact" && /* @__PURE__ */ jsxs(Fragment, { children: [
2755
2763
  requiredFields.map((f) => /* @__PURE__ */ jsxs("div", { className: "pollar-ramp-field", children: [
2756
2764
  /* @__PURE__ */ jsx("label", { className: "pollar-ramp-label", children: f.label }),
2757
- /* @__PURE__ */ jsx(
2765
+ f.type === "select" ? /* @__PURE__ */ jsxs(
2766
+ "select",
2767
+ {
2768
+ className: "pollar-ramp-input",
2769
+ value: fieldValues[f.key] ?? "",
2770
+ onChange: (e) => onFieldChange(f.key, e.target.value),
2771
+ children: [
2772
+ /* @__PURE__ */ jsx("option", { value: "", disabled: true, children: "Select\u2026" }),
2773
+ (f.options ?? []).map((o) => /* @__PURE__ */ jsx("option", { value: o.value, children: o.label }, o.value))
2774
+ ]
2775
+ }
2776
+ ) : /* @__PURE__ */ jsx(
2758
2777
  "input",
2759
2778
  {
2760
2779
  type: f.type,
@@ -2763,7 +2782,8 @@ function RampWidgetTemplate({
2763
2782
  autoComplete: f.type === "email" ? "email" : "off",
2764
2783
  onChange: (e) => onFieldChange(f.key, e.target.value)
2765
2784
  }
2766
- )
2785
+ ),
2786
+ f.type === "email" && (fieldValues[f.key] ?? "").trim() !== "" && !isFieldValid(f, fieldValues[f.key]) && /* @__PURE__ */ jsx("span", { className: "pollar-ramp-field-error", children: "Enter a valid email address." })
2767
2787
  ] }, f.key)),
2768
2788
  /* @__PURE__ */ jsxs("div", { className: "pollar-modal-actions", children: [
2769
2789
  /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-btn-secondary", onClick: onRetry, children: "Back" }),
@@ -2772,7 +2792,7 @@ function RampWidgetTemplate({
2772
2792
  {
2773
2793
  type: "button",
2774
2794
  className: "pollar-btn-primary",
2775
- disabled: requiredFields.some((f) => !(fieldValues[f.key] ?? "").trim()) || isLoading,
2795
+ disabled: requiredFields.some((f) => !isFieldValid(f, fieldValues[f.key])) || isLoading,
2776
2796
  onClick: onContactContinue,
2777
2797
  children: isLoading ? "Starting\u2026" : "Continue"
2778
2798
  }
@@ -2790,11 +2810,29 @@ function RampWidgetTemplate({
2790
2810
  ] }),
2791
2811
  stellarTxHash && /* @__PURE__ */ jsxs("div", { className: "pollar-ramp-payment-field", children: [
2792
2812
  /* @__PURE__ */ jsx("span", { className: "pollar-ramp-payment-label", children: "Stellar tx" }),
2793
- /* @__PURE__ */ jsx("div", { className: "pollar-ramp-payment-value", children: /* @__PURE__ */ jsxs("code", { children: [
2794
- stellarTxHash.slice(0, 8),
2795
- "\u2026",
2796
- stellarTxHash.slice(-8)
2797
- ] }) })
2813
+ /* @__PURE__ */ jsxs("div", { className: "pollar-ramp-payment-value", style: { display: "flex", alignItems: "center", gap: 6 }, children: [
2814
+ /* @__PURE__ */ jsxs("code", { style: { flex: 1, wordBreak: "break-all" }, children: [
2815
+ stellarTxHash.slice(0, 8),
2816
+ "\u2026",
2817
+ stellarTxHash.slice(-8)
2818
+ ] }),
2819
+ /* @__PURE__ */ jsx(CopyButton, { value: stellarTxHash, label: "Copy transaction hash" }),
2820
+ explorerUrl && /* @__PURE__ */ jsx(
2821
+ "a",
2822
+ {
2823
+ href: explorerUrl,
2824
+ target: "_blank",
2825
+ rel: "noopener noreferrer",
2826
+ className: "pollar-copy-btn",
2827
+ "aria-label": "View on Stellar Expert",
2828
+ title: "View on Stellar Expert",
2829
+ children: /* @__PURE__ */ jsxs("svg", { width: "13", height: "13", viewBox: "0 0 14 14", fill: "none", "aria-hidden": true, children: [
2830
+ /* @__PURE__ */ jsx("path", { d: "M6 3H3v8h8V8", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }),
2831
+ /* @__PURE__ */ jsx("path", { d: "M8.5 2.5h3v3M11 3L6.5 7.5", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" })
2832
+ ] })
2833
+ }
2834
+ )
2835
+ ] })
2798
2836
  ] }),
2799
2837
  depositInstructions && txStatus !== "completed" && flattenInstructions(depositInstructions).map(({ key, label, value, kind }) => /* @__PURE__ */ jsxs("div", { className: "pollar-ramp-payment-field", children: [
2800
2838
  /* @__PURE__ */ jsx("span", { className: "pollar-ramp-payment-label", children: label }),
@@ -2805,7 +2843,10 @@ function RampWidgetTemplate({
2805
2843
  alt: label,
2806
2844
  style: { width: "100%", maxWidth: 220, height: "auto", display: "block", margin: "0 auto" }
2807
2845
  }
2808
- ) : kind === "datetime" ? /* @__PURE__ */ jsx("span", { children: value }) : /* @__PURE__ */ jsx("code", { style: { wordBreak: "break-all" }, children: value }) })
2846
+ ) : kind === "datetime" ? /* @__PURE__ */ jsx("span", { children: value }) : /* @__PURE__ */ jsxs("span", { style: { display: "flex", alignItems: "center", gap: 6 }, children: [
2847
+ /* @__PURE__ */ jsx("code", { style: { flex: 1, wordBreak: "break-all" }, children: value }),
2848
+ /* @__PURE__ */ jsx(CopyButton, { value, label: `Copy ${label}` })
2849
+ ] }) })
2809
2850
  ] }, key)),
2810
2851
  tosUrl && !depositInstructions && txStatus !== "completed" && /* @__PURE__ */ jsxs("button", { type: "button", className: "pollar-btn-primary", onClick: onOpenTos, children: [
2811
2852
  "Accept terms at ",
@@ -2833,7 +2874,7 @@ function requiredFieldsOf(quote) {
2833
2874
  return quote.requiredFields ?? [];
2834
2875
  }
2835
2876
  function RampWidget({ onClose }) {
2836
- const { getClient, signTx, wallet, styles } = usePollar();
2877
+ const { getClient, signTx, wallet, styles, network } = usePollar();
2837
2878
  const walletAddress = wallet?.address ?? "";
2838
2879
  const client = getClient();
2839
2880
  const { theme = "light", accentColor = "#005DB4" } = styles;
@@ -2931,6 +2972,7 @@ function RampWidget({ onClose }) {
2931
2972
  setStep("input");
2932
2973
  setQuotes([]);
2933
2974
  setSelectedQuote(null);
2975
+ setFieldValues({});
2934
2976
  setTxId(null);
2935
2977
  setProvider("");
2936
2978
  setKycUrl(null);
@@ -3008,12 +3050,16 @@ function RampWidget({ onClose }) {
3008
3050
  try {
3009
3051
  const base = { quoteId: quote.quoteId, amount: Number(amount), currency, country };
3010
3052
  if (walletAddress) base.walletAddress = walletAddress;
3053
+ const STANDARD_BODY_KEYS = /* @__PURE__ */ new Set(["email", "fullName", "taxId", "qrCode"]);
3054
+ const extraFields = {};
3011
3055
  for (const f of requiredFieldsOf(quote)) {
3012
3056
  const val = (fieldValues[f.key] ?? "").trim();
3013
3057
  if (!val) continue;
3014
3058
  if (f.bankType) base.bankDetails = { type: f.bankType, value: val };
3015
- else base[f.key] = val;
3059
+ else if (STANDARD_BODY_KEYS.has(f.key)) base[f.key] = val;
3060
+ else extraFields[f.key] = val;
3016
3061
  }
3062
+ if (Object.keys(extraFields).length > 0) base.fields = extraFields;
3017
3063
  const result = direction === "onramp" ? await client.createOnRamp(base) : await client.createOffRamp(base);
3018
3064
  await applyResult(result);
3019
3065
  } catch (e) {
@@ -3073,6 +3119,7 @@ function RampWidget({ onClose }) {
3073
3119
  kycUrl,
3074
3120
  tosUrl,
3075
3121
  stellarTxHash,
3122
+ explorerUrl: stellarTxHash ? `https://stellar.expert/explorer/${network === "mainnet" ? "public" : "testnet"}/tx/${stellarTxHash}` : null,
3076
3123
  depositInstructions,
3077
3124
  canComplete,
3078
3125
  completing,