@pollar/react 0.12.1-rc.25 → 0.12.1-rc.26

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
@@ -1309,7 +1309,7 @@ var PollarModalFooter = ({ language: languageProp }) => {
1309
1309
  /* @__PURE__ */ jsx("img", { src: LOGO_POLLAR_WORDMARK_ON_DARK, alt: "Pollar", className: "pollar-footer-logo pollar-logo-on-dark" }),
1310
1310
  /* @__PURE__ */ jsxs("span", { className: "pollar-footer-version", children: [
1311
1311
  "v",
1312
- "0.12.1-rc.25"
1312
+ "0.12.1-rc.26"
1313
1313
  ] })
1314
1314
  ] });
1315
1315
  };
@@ -5511,6 +5511,7 @@ var RAMP_COPY = {
5511
5511
  SDK_RAMPS_QUOTE_EXPIRED: "This quote expired. Find a route again.",
5512
5512
  SDK_RAMPS_QUOTE_NOT_FOUND: "This quote is no longer available. Find a route again.",
5513
5513
  SDK_RAMPS_ACTION_STALE: "This step changed. It was refreshed; try again.",
5514
+ SDK_RAMPS_ORDER_NOT_CANCELLABLE: "This order can no longer be cancelled: its funds are already moving.",
5514
5515
  SDK_RAMPS_TX_NOT_FOUND: "This operation was not found.",
5515
5516
  SDK_RAMPS_WALLET_NOT_READY: "Approve the new wallet account on your device, then try again."
5516
5517
  },
@@ -5531,6 +5532,7 @@ var RAMP_COPY = {
5531
5532
  resumeOrderFailed: "Could not resume the operation.",
5532
5533
  checkPaymentFailed: "Could not check the payment. Please try again.",
5533
5534
  retryOrderFailed: "Could not try again. Please try again.",
5535
+ cancelOrderFailed: "Could not cancel the order. Please try again.",
5534
5536
  refreshFailed: "Could not refresh.",
5535
5537
  copyFailed: "Could not copy.",
5536
5538
  awaitingAccount: "Approve the new account on your device. The order starts once it is approved.",
@@ -5628,15 +5630,33 @@ var RAMP_COPY = {
5628
5630
  startAnother: "Start another operation",
5629
5631
  newQuote: "Get a new quote",
5630
5632
  keepsGoing: "This one keeps going; you can resume it later.",
5633
+ leave: {
5634
+ title: "Leave this purchase?",
5635
+ note: "Your order keeps going. You can come back to it from Buy.",
5636
+ stay: "Stay here",
5637
+ exit: "Leave, keep the order",
5638
+ cancel: "Cancel the order",
5639
+ cancelling: "Cancelling\u2026"
5640
+ },
5631
5641
  screens: {
5632
5642
  pay: (amount, currency) => `Pay ${amount} ${currency}`,
5633
5643
  send: (amount, code) => `Send ${amount} ${code}`,
5634
5644
  delivering: (code) => `Your ${code} is on its way`,
5635
5645
  payingOut: (currency) => `Your ${currency} is on its way to your account`,
5636
- done: "Done",
5637
- toCurrent: "Go to the current step",
5646
+ next: "Next step",
5647
+ paidDone: (amount, currency) => `You paid ${amount} ${currency}.`,
5648
+ sentDone: (amount, code) => `You sent ${amount} ${code}.`,
5649
+ receivedDone: (amount, code, chain) => `You received ${amount} ${code} on ${chain}.`,
5650
+ payoutDone: (amount, currency) => `${amount} ${currency} were sent to your account.`,
5651
+ signedDone: "You approved this step.",
5652
+ ranDone: "This step is complete.",
5638
5653
  updatesItself: "This screen updates on its own.",
5639
5654
  preparing: "Preparing your payment\u2026",
5655
+ saveQr: "Save QR",
5656
+ savingQr: "Saving\u2026",
5657
+ savedQr: "QR saved",
5658
+ saveQrFailed: "Could not save the QR",
5659
+ qrFile: "payment",
5640
5660
  received: (amount) => `+${amount}`,
5641
5661
  arrived: (chain) => `It reached your wallet on ${chain}.`,
5642
5662
  paidOut: "It was sent to your account.",
@@ -5657,6 +5677,7 @@ var RAMP_COPY = {
5657
5677
  SDK_RAMPS_QUOTE_EXPIRED: "Esta cotizaci\xF3n venci\xF3. Busca una ruta de nuevo.",
5658
5678
  SDK_RAMPS_QUOTE_NOT_FOUND: "Esta cotizaci\xF3n ya no est\xE1 disponible. Busca una ruta de nuevo.",
5659
5679
  SDK_RAMPS_ACTION_STALE: "Este paso cambi\xF3 y se actualiz\xF3. Intenta de nuevo.",
5680
+ SDK_RAMPS_ORDER_NOT_CANCELLABLE: "Esta orden ya no se puede cancelar: sus fondos ya est\xE1n en movimiento.",
5660
5681
  SDK_RAMPS_TX_NOT_FOUND: "No se encontr\xF3 esta operaci\xF3n.",
5661
5682
  SDK_RAMPS_WALLET_NOT_READY: "Aprueba la nueva cuenta de la billetera en tu dispositivo e intenta de nuevo."
5662
5683
  },
@@ -5677,6 +5698,7 @@ var RAMP_COPY = {
5677
5698
  resumeOrderFailed: "No se pudo retomar la operaci\xF3n.",
5678
5699
  checkPaymentFailed: "No se pudo verificar el pago. Intenta de nuevo.",
5679
5700
  retryOrderFailed: "No se pudo reintentar. Intenta de nuevo.",
5701
+ cancelOrderFailed: "No se pudo cancelar la orden. Intenta de nuevo.",
5680
5702
  refreshFailed: "No se pudo actualizar.",
5681
5703
  copyFailed: "No se pudo copiar.",
5682
5704
  awaitingAccount: "Aprueba la nueva cuenta en tu dispositivo. La orden comienza cuando la apruebes.",
@@ -5774,15 +5796,33 @@ var RAMP_COPY = {
5774
5796
  startAnother: "Iniciar otra operaci\xF3n",
5775
5797
  newQuote: "Pedir nueva cotizaci\xF3n",
5776
5798
  keepsGoing: "Esta sigue en curso; puedes retomarla m\xE1s tarde.",
5799
+ leave: {
5800
+ title: "\xBFSalir de esta compra?",
5801
+ note: "Tu orden sigue activa. Puedes retomarla desde Comprar.",
5802
+ stay: "Seguir aqu\xED",
5803
+ exit: "Salir, la orden sigue",
5804
+ cancel: "Cancelar la orden",
5805
+ cancelling: "Cancelando\u2026"
5806
+ },
5777
5807
  screens: {
5778
5808
  pay: (amount, currency) => `Paga ${amount} ${currency}`,
5779
5809
  send: (amount, code) => `Env\xEDa ${amount} ${code}`,
5780
5810
  delivering: (code) => `Tu ${code} est\xE1 en camino`,
5781
5811
  payingOut: (currency) => `Tus ${currency} van en camino a tu cuenta`,
5782
- done: "Hecho",
5783
- toCurrent: "Ir al paso actual",
5812
+ next: "Paso siguiente",
5813
+ paidDone: (amount, currency) => `Pagaste ${amount} ${currency}.`,
5814
+ sentDone: (amount, code) => `Enviaste ${amount} ${code}.`,
5815
+ receivedDone: (amount, code, chain) => `Recibiste ${amount} ${code} en ${chain}.`,
5816
+ payoutDone: (amount, currency) => `Se enviaron ${amount} ${currency} a tu cuenta.`,
5817
+ signedDone: "Aprobaste este paso.",
5818
+ ranDone: "Este paso est\xE1 completo.",
5784
5819
  updatesItself: "Esta pantalla se actualiza sola.",
5785
5820
  preparing: "Preparando tu pago\u2026",
5821
+ saveQr: "Guardar QR",
5822
+ savingQr: "Guardando\u2026",
5823
+ savedQr: "QR guardado",
5824
+ saveQrFailed: "No se pudo guardar el QR",
5825
+ qrFile: "pago",
5786
5826
  received: (amount) => `+${amount}`,
5787
5827
  arrived: (chain) => `Lleg\xF3 a tu wallet en ${chain}.`,
5788
5828
  paidOut: "Se envi\xF3 a tu cuenta.",
@@ -5803,6 +5843,7 @@ var RAMP_COPY = {
5803
5843
  SDK_RAMPS_QUOTE_EXPIRED: "Esta cota\xE7\xE3o expirou. Busque uma rota de novo.",
5804
5844
  SDK_RAMPS_QUOTE_NOT_FOUND: "Esta cota\xE7\xE3o n\xE3o est\xE1 mais dispon\xEDvel. Busque uma rota de novo.",
5805
5845
  SDK_RAMPS_ACTION_STALE: "Esta etapa mudou e foi atualizada. Tente de novo.",
5846
+ SDK_RAMPS_ORDER_NOT_CANCELLABLE: "Esta ordem n\xE3o pode mais ser cancelada: os fundos j\xE1 est\xE3o em movimento.",
5806
5847
  SDK_RAMPS_TX_NOT_FOUND: "Esta opera\xE7\xE3o n\xE3o foi encontrada.",
5807
5848
  SDK_RAMPS_WALLET_NOT_READY: "Aprove a nova conta da carteira no seu dispositivo e tente de novo."
5808
5849
  },
@@ -5823,6 +5864,7 @@ var RAMP_COPY = {
5823
5864
  resumeOrderFailed: "N\xE3o foi poss\xEDvel retomar a opera\xE7\xE3o.",
5824
5865
  checkPaymentFailed: "N\xE3o foi poss\xEDvel verificar o pagamento. Tente de novo.",
5825
5866
  retryOrderFailed: "N\xE3o foi poss\xEDvel tentar de novo. Tente de novo.",
5867
+ cancelOrderFailed: "N\xE3o foi poss\xEDvel cancelar a ordem. Tente de novo.",
5826
5868
  refreshFailed: "N\xE3o foi poss\xEDvel atualizar.",
5827
5869
  copyFailed: "N\xE3o foi poss\xEDvel copiar.",
5828
5870
  awaitingAccount: "Aprove a nova conta no seu dispositivo. A ordem come\xE7a assim que voc\xEA aprovar.",
@@ -5920,15 +5962,33 @@ var RAMP_COPY = {
5920
5962
  startAnother: "Iniciar outra opera\xE7\xE3o",
5921
5963
  newQuote: "Pedir nova cota\xE7\xE3o",
5922
5964
  keepsGoing: "Esta continua em andamento; voc\xEA pode retom\xE1-la depois.",
5965
+ leave: {
5966
+ title: "Sair desta compra?",
5967
+ note: "Sua ordem continua ativa. Voc\xEA pode retom\xE1-la em Comprar.",
5968
+ stay: "Ficar aqui",
5969
+ exit: "Sair, manter a ordem",
5970
+ cancel: "Cancelar a ordem",
5971
+ cancelling: "Cancelando\u2026"
5972
+ },
5923
5973
  screens: {
5924
5974
  pay: (amount, currency) => `Pague ${amount} ${currency}`,
5925
5975
  send: (amount, code) => `Envie ${amount} ${code}`,
5926
5976
  delivering: (code) => `Seu ${code} est\xE1 a caminho`,
5927
5977
  payingOut: (currency) => `Seus ${currency} est\xE3o a caminho da sua conta`,
5928
- done: "Conclu\xEDdo",
5929
- toCurrent: "Ir para a etapa atual",
5978
+ next: "Pr\xF3xima etapa",
5979
+ paidDone: (amount, currency) => `Voc\xEA pagou ${amount} ${currency}.`,
5980
+ sentDone: (amount, code) => `Voc\xEA enviou ${amount} ${code}.`,
5981
+ receivedDone: (amount, code, chain) => `Voc\xEA recebeu ${amount} ${code} na ${chain}.`,
5982
+ payoutDone: (amount, currency) => `${amount} ${currency} foram enviados para a sua conta.`,
5983
+ signedDone: "Voc\xEA aprovou esta etapa.",
5984
+ ranDone: "Esta etapa est\xE1 conclu\xEDda.",
5930
5985
  updatesItself: "Esta tela se atualiza sozinha.",
5931
5986
  preparing: "Preparando o seu pagamento\u2026",
5987
+ saveQr: "Salvar QR",
5988
+ savingQr: "Salvando\u2026",
5989
+ savedQr: "QR salvo",
5990
+ saveQrFailed: "N\xE3o foi poss\xEDvel salvar o QR",
5991
+ qrFile: "pagamento",
5932
5992
  received: (amount) => `+${amount}`,
5933
5993
  arrived: (chain) => `Chegou \xE0 sua carteira na ${chain}.`,
5934
5994
  paidOut: "Foi enviado para a sua conta.",
@@ -6170,6 +6230,97 @@ function rampOrderScreens(order, language) {
6170
6230
  return { ...screen, status: stopped || rampLegStatus(screen.leg) === "failed" ? "failed" : "current" };
6171
6231
  });
6172
6232
  }
6233
+ var SVG_SIDE = 1024;
6234
+ function imageSrc(image) {
6235
+ return image.encoding === "base64" ? `data:${image.mediaType};base64,${image.data}` : `data:${image.mediaType};charset=utf-8,${encodeURIComponent(image.data)}`;
6236
+ }
6237
+ function base64Blob(data, type) {
6238
+ const bytes = Uint8Array.from(atob(data), (c) => c.charCodeAt(0));
6239
+ return new Blob([bytes], { type });
6240
+ }
6241
+ async function scannableFile(image) {
6242
+ if (image.encoding === "base64" && (image.mediaType === "image/png" || image.mediaType === "image/jpeg"))
6243
+ return base64Blob(image.data, image.mediaType);
6244
+ const element = new Image();
6245
+ element.decoding = "async";
6246
+ element.src = imageSrc(image);
6247
+ await element.decode();
6248
+ const svg = image.mediaType === "image/svg+xml";
6249
+ const width = svg ? SVG_SIDE : element.naturalWidth;
6250
+ const height = svg ? Math.round(SVG_SIDE * (element.naturalHeight || 1) / (element.naturalWidth || 1)) : element.naturalHeight;
6251
+ const canvas = document.createElement("canvas");
6252
+ canvas.width = width;
6253
+ canvas.height = height;
6254
+ const context = canvas.getContext("2d");
6255
+ if (!context) throw new Error("canvas unavailable");
6256
+ context.fillStyle = "#ffffff";
6257
+ context.fillRect(0, 0, width, height);
6258
+ context.drawImage(element, 0, 0, width, height);
6259
+ return new Promise(
6260
+ (resolve, reject) => canvas.toBlob((blob) => blob ? resolve(blob) : reject(new Error("png encoding failed")), "image/png")
6261
+ );
6262
+ }
6263
+ async function saveFile(blob, name) {
6264
+ const file = new File([blob], name, { type: blob.type });
6265
+ const touch = typeof window.matchMedia === "function" && window.matchMedia("(pointer: coarse)").matches;
6266
+ if (touch && navigator.canShare?.({ files: [file] })) {
6267
+ try {
6268
+ await navigator.share({ files: [file] });
6269
+ return "saved";
6270
+ } catch (error) {
6271
+ if (error.name === "AbortError") return "dismissed";
6272
+ }
6273
+ }
6274
+ const url = URL.createObjectURL(blob);
6275
+ const link = document.createElement("a");
6276
+ link.href = url;
6277
+ link.download = name;
6278
+ document.body.appendChild(link);
6279
+ link.click();
6280
+ link.remove();
6281
+ setTimeout(() => URL.revokeObjectURL(url), 1e4);
6282
+ return "saved";
6283
+ }
6284
+ function SaveQrButton({
6285
+ image,
6286
+ fileName,
6287
+ labels
6288
+ }) {
6289
+ const [state, setState] = useState("idle");
6290
+ const timer = useRef(null);
6291
+ useEffect(
6292
+ () => () => {
6293
+ if (timer.current) clearTimeout(timer.current);
6294
+ },
6295
+ []
6296
+ );
6297
+ async function save() {
6298
+ setState("saving");
6299
+ try {
6300
+ const blob = await scannableFile(image);
6301
+ const extension = blob.type === "image/jpeg" ? "jpg" : "png";
6302
+ const outcome = await saveFile(blob, `${fileName}.${extension}`);
6303
+ setState(outcome === "saved" ? "saved" : "idle");
6304
+ } catch {
6305
+ setState("failed");
6306
+ }
6307
+ if (timer.current) clearTimeout(timer.current);
6308
+ timer.current = setTimeout(() => setState("idle"), 2500);
6309
+ }
6310
+ return /* @__PURE__ */ jsxs("button", { type: "button", className: "pollar-btn-secondary pollar-ramp-save-qr", disabled: state === "saving", onClick: save, children: [
6311
+ /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx(
6312
+ "path",
6313
+ {
6314
+ d: "M8 2v8m0 0 3-3m-3 3L5 7M3 12.5h10",
6315
+ stroke: "currentColor",
6316
+ strokeWidth: "1.6",
6317
+ strokeLinecap: "round",
6318
+ strokeLinejoin: "round"
6319
+ }
6320
+ ) }),
6321
+ state === "saving" ? labels.saving : state === "saved" ? labels.saved : state === "failed" ? labels.failed : labels.save
6322
+ ] });
6323
+ }
6173
6324
  function scannableImageSrc(image) {
6174
6325
  return image.encoding === "base64" ? `data:${image.mediaType};base64,${image.data}` : `data:${image.mediaType};charset=utf-8,${encodeURIComponent(image.data)}`;
6175
6326
  }
@@ -6301,7 +6452,10 @@ function RampWidgetTemplate({
6301
6452
  onRefresh,
6302
6453
  onClose,
6303
6454
  language: languageProp,
6304
- confirmation = null
6455
+ confirmation = null,
6456
+ onCancelOrder,
6457
+ cancelling = false,
6458
+ cancelError = null
6305
6459
  }) {
6306
6460
  const language = useInheritedLanguage(languageProp);
6307
6461
  const cssVars = buildModalCssVars(theme, accentColor, styleOverrides, "hero");
@@ -6310,7 +6464,11 @@ function RampWidgetTemplate({
6310
6464
  const sendUnit = onramp ? fiat?.currency : asset?.code;
6311
6465
  const [detailsOpen, setDetailsOpen] = useState(false);
6312
6466
  const [viewing, setViewing] = useState(null);
6313
- useEffect(() => setViewing(null), [order?.id]);
6467
+ const [leaving, setLeaving] = useState(false);
6468
+ useEffect(() => {
6469
+ setViewing(null);
6470
+ setLeaving(false);
6471
+ }, [order?.id]);
6314
6472
  const routeName = (quote) => quote.legs.map((leg) => rampLegTitle(leg, language)).join(" \xB7 ");
6315
6473
  const rate = (() => {
6316
6474
  if (!chosenQuote) return null;
@@ -6397,9 +6555,24 @@ function RampWidgetTemplate({
6397
6555
  const shown = screens[shownScreen];
6398
6556
  const askedInstead = order?.pendingAction?.kind === "KYC" || !!shown?.key.endsWith(":pay") && order?.pendingAction?.legIndex === shown.leg.index && !["FIAT_PAYMENT", "NONE"].includes(order.pendingAction.kind);
6399
6557
  const firstLeg = order?.legs[0];
6558
+ const payment = order?.pendingAction?.kind === "FIAT_PAYMENT" ? order.pendingAction.instructions : null;
6559
+ const qrFileName = [copy.screens.qrFile, payment?.amount, payment?.currency, order?.id.slice(-8)].filter(Boolean).join("-");
6400
6560
  const orderSummary = firstLeg && receive ? `${amountText(firstLeg.amountInPlanned, language)} ${firstLeg.from.kind === "fiat" ? firstLeg.from.currency : firstLeg.from.code} \u2192 ${receive.estimated ? "~" : ""}${amountText(receive.amount, language)} ${receive.unit}` : null;
6401
6561
  const lastLeg = order?.legs[order.legs.length - 1];
6402
6562
  const arrivedText = lastLeg?.to.kind === "asset" ? copy.screens.arrived(CHAIN_NAME[lastLeg.to.chain] ?? lastLeg.to.chain) : copy.screens.paidOut;
6563
+ const requestClose = () => step === "status" && order && !settled ? setLeaving(true) : onClose();
6564
+ const cancellable = !!order && !settled && order.pendingAction?.kind !== "COSIGN_APPROVAL" && order.legs.every((leg) => leg.status !== "COMPLETED" && leg.status !== "HELD" && leg.paymentStatus !== "received");
6565
+ const doneText = (screen) => {
6566
+ const leg = screen.leg;
6567
+ const unit = (node) => node.kind === "fiat" ? node.currency : node.code;
6568
+ const inAmount = amountText(leg.amountInActual ?? leg.amountInPlanned, language);
6569
+ const outAmount = amountText(leg.amountOutActual ?? leg.amountOutPlanned, language);
6570
+ if (screen.key.endsWith(":pay"))
6571
+ return leg.kind === "PROVIDER_ONRAMP" ? copy.screens.paidDone(inAmount, unit(leg.from)) : copy.screens.sentDone(inAmount, unit(leg.from));
6572
+ if (screen.key.endsWith(":deliver"))
6573
+ return leg.to.kind === "asset" ? copy.screens.receivedDone(outAmount, leg.to.code, CHAIN_NAME[leg.to.chain] ?? leg.to.chain) : copy.screens.payoutDone(outAmount, leg.to.currency);
6574
+ return screen.kind === "action" ? copy.screens.signedDone : copy.screens.ranDone;
6575
+ };
6403
6576
  const finalNote = order?.legs.map((leg) => rampLegNote(leg, language)).find((note) => note !== null) ?? null;
6404
6577
  const screenRows = (screen) => screen.steps.length ? screen.steps.flatMap(
6405
6578
  (st) => st.hash ? [
@@ -6451,16 +6624,6 @@ function RampWidgetTemplate({
6451
6624
  children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M10 3 5 8l5 5", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
6452
6625
  }
6453
6626
  ),
6454
- step === "status" && shownScreen > 0 && shownScreen <= currentScreen && /* @__PURE__ */ jsx(
6455
- "button",
6456
- {
6457
- type: "button",
6458
- className: "pollar-back-btn pollar-ramp-back",
6459
- onClick: () => setViewing(shownScreen - 1),
6460
- "aria-label": copy.back,
6461
- children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M10 3 5 8l5 5", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
6462
- }
6463
- ),
6464
6627
  /* @__PURE__ */ jsxs("div", { className: "pollar-ramp-header-text", children: [
6465
6628
  /* @__PURE__ */ jsx("h2", { className: "pollar-modal-title", children: stepTitle[step] }),
6466
6629
  /* @__PURE__ */ jsx("p", { className: "pollar-ramp-subtitle", children: stepSubtitle[step] })
@@ -6497,7 +6660,7 @@ function RampWidgetTemplate({
6497
6660
  )
6498
6661
  }
6499
6662
  ),
6500
- /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-modal-close", onClick: onClose, "aria-label": copy.close, children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M2 2l12 12M14 2L2 14", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) }) })
6663
+ /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-modal-close", onClick: requestClose, "aria-label": copy.close, children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M2 2l12 12M14 2L2 14", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) }) })
6501
6664
  ] })
6502
6665
  ] }),
6503
6666
  flowStepIndex >= 0 && flowSteps.length > 0 && /* @__PURE__ */ jsxs("div", { className: "pollar-ramp-steps", children: [
@@ -6517,15 +6680,41 @@ function RampWidgetTemplate({
6517
6680
  }
6518
6681
  ) }, label)) })
6519
6682
  ] }),
6520
- step === "status" && screens.length > 0 && /* @__PURE__ */ jsx("ol", { className: "pollar-ramp-screens-bar", "aria-label": copy.progress, children: [...screens.map((s) => s.key), "final"].map((key, i) => /* @__PURE__ */ jsx(
6521
- "li",
6522
- {
6523
- "data-done": i < currentScreen || completed && i === screens.length || void 0,
6524
- "data-shown": i === shownScreen || void 0,
6525
- "data-failed": screens[i]?.status === "failed" || void 0
6526
- },
6527
- key
6528
- )) }),
6683
+ step === "status" && screens.length > 0 && !(leaving && !settled) && /* @__PURE__ */ jsxs("div", { className: "pollar-ramp-screens-nav", children: [
6684
+ /* @__PURE__ */ jsx(
6685
+ "button",
6686
+ {
6687
+ type: "button",
6688
+ className: "pollar-ramp-screens-arrow",
6689
+ "data-hidden": shownScreen === 0 || void 0,
6690
+ disabled: shownScreen === 0,
6691
+ onClick: () => setViewing(shownScreen - 1),
6692
+ "aria-label": copy.back,
6693
+ children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "M10 3 5 8l5 5", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
6694
+ }
6695
+ ),
6696
+ /* @__PURE__ */ jsx("ol", { className: "pollar-ramp-screens-bar", "aria-label": copy.progress, children: [...screens.map((s) => s.key), "final"].map((key, i) => /* @__PURE__ */ jsx(
6697
+ "li",
6698
+ {
6699
+ "data-done": i < currentScreen || completed && i === screens.length || void 0,
6700
+ "data-shown": i === shownScreen || void 0,
6701
+ "data-failed": screens[i]?.status === "failed" || void 0
6702
+ },
6703
+ key
6704
+ )) }),
6705
+ /* @__PURE__ */ jsx(
6706
+ "button",
6707
+ {
6708
+ type: "button",
6709
+ className: "pollar-ramp-screens-arrow",
6710
+ "data-hidden": shownScreen >= currentScreen || void 0,
6711
+ disabled: shownScreen >= currentScreen,
6712
+ onClick: () => setViewing(shownScreen + 1 >= currentScreen ? null : shownScreen + 1),
6713
+ "aria-label": copy.screens.next,
6714
+ children: /* @__PURE__ */ jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx("path", { d: "m6 3 5 5-5 5", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) })
6715
+ }
6716
+ )
6717
+ ] }),
6529
6718
  step === "input" && pendingOrders.length > 0 && /* @__PURE__ */ jsxs("section", { className: "pollar-ramp-payment pollar-ramp-saved", "aria-label": copy.pendingAria, children: [
6530
6719
  /* @__PURE__ */ jsx("p", { className: "pollar-ramp-payment-note", children: copy.pendingNote }),
6531
6720
  pendingOrders.map((pending) => /* @__PURE__ */ jsx("div", { className: "pollar-ramp-saved-row", children: /* @__PURE__ */ jsx(
@@ -6813,7 +7002,30 @@ function RampWidgetTemplate({
6813
7002
  }
6814
7003
  ) })
6815
7004
  ] }),
6816
- step === "status" && order && view && /* @__PURE__ */ jsx("div", { className: "pollar-ramp-payment", children: shownScreen === screens.length ? /* @__PURE__ */ jsxs(Fragment, { children: [
7005
+ step === "status" && order && view && /* @__PURE__ */ jsx("div", { className: "pollar-ramp-payment", children: leaving && !settled ? /* @__PURE__ */ jsxs("div", { className: "pollar-ramp-leave", children: [
7006
+ /* @__PURE__ */ jsx("h3", { className: "pollar-ramp-screen-title", children: copy.leave.title }),
7007
+ /* @__PURE__ */ jsx("p", { className: "pollar-ramp-payment-note", children: copy.leave.note }),
7008
+ cancelError && /* @__PURE__ */ jsx("p", { className: "pollar-ramp-field-error", children: cancelError }),
7009
+ /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-btn-primary", onClick: () => setLeaving(false), children: copy.leave.stay }),
7010
+ /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-btn-secondary", onClick: onClose, children: copy.leave.exit }),
7011
+ /* @__PURE__ */ jsx(
7012
+ "button",
7013
+ {
7014
+ type: "button",
7015
+ className: "pollar-ramp-leave-link",
7016
+ onClick: () => {
7017
+ setLeaving(false);
7018
+ onNewOrder();
7019
+ },
7020
+ children: copy.startAnother
7021
+ }
7022
+ ),
7023
+ onCancelOrder && cancellable && /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-ramp-leave-cancel", disabled: cancelling, onClick: onCancelOrder, children: cancelling ? /* @__PURE__ */ jsxs(Fragment, { children: [
7024
+ /* @__PURE__ */ jsx("span", { className: "pollar-spinner pollar-spinner-sm" }),
7025
+ " ",
7026
+ copy.leave.cancelling
7027
+ ] }) : copy.leave.cancel })
7028
+ ] }) : shownScreen === screens.length ? /* @__PURE__ */ jsxs(Fragment, { children: [
6817
7029
  /* @__PURE__ */ jsxs("div", { className: "pollar-ramp-final", children: [
6818
7030
  /* @__PURE__ */ jsx("span", { className: "pollar-ramp-final-mark", "aria-hidden": true, children: /* @__PURE__ */ jsx("svg", { width: "28", height: "28", viewBox: "0 0 16 16", fill: "none", children: /* @__PURE__ */ jsx(
6819
7031
  "path",
@@ -6832,9 +7044,8 @@ function RampWidgetTemplate({
6832
7044
  /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-btn-primary", onClick: onClose, children: copy.screens.finish }),
6833
7045
  /* @__PURE__ */ jsx(TxReview, { data: { title: "", kind: "other", rows: orderRows }, language })
6834
7046
  ] }) : shownScreen < currentScreen ? /* @__PURE__ */ jsxs(Fragment, { children: [
6835
- /* @__PURE__ */ jsx("h3", { className: "pollar-ramp-screen-title", children: screens[shownScreen].title }),
6836
- /* @__PURE__ */ jsxs("p", { className: "pollar-ramp-screen-state", children: [
6837
- /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 16 16", fill: "none", "aria-hidden": true, children: /* @__PURE__ */ jsx(
7047
+ /* @__PURE__ */ jsxs("div", { className: "pollar-ramp-done", children: [
7048
+ /* @__PURE__ */ jsx("span", { className: "pollar-ramp-done-mark", "aria-hidden": true, children: /* @__PURE__ */ jsx("svg", { width: "30", height: "30", viewBox: "0 0 16 16", fill: "none", children: /* @__PURE__ */ jsx(
6838
7049
  "path",
6839
7050
  {
6840
7051
  d: "M3 8.5 6.5 12 13 4.5",
@@ -6843,11 +7054,11 @@ function RampWidgetTemplate({
6843
7054
  strokeLinecap: "round",
6844
7055
  strokeLinejoin: "round"
6845
7056
  }
6846
- ) }),
6847
- copy.screens.done
7057
+ ) }) }),
7058
+ /* @__PURE__ */ jsx("h3", { className: "pollar-ramp-done-title", children: screens[shownScreen].title }),
7059
+ /* @__PURE__ */ jsx("p", { className: "pollar-ramp-payment-note", children: doneText(screens[shownScreen]) })
6848
7060
  ] }),
6849
- screenRows(screens[shownScreen]).length > 0 && /* @__PURE__ */ jsx(TxReview, { data: { title: "", kind: "other", rows: screenRows(screens[shownScreen]) }, language }),
6850
- /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-btn-secondary", onClick: () => setViewing(null), children: copy.screens.toCurrent })
7061
+ screenRows(screens[shownScreen]).length > 0 && /* @__PURE__ */ jsx(TxReview, { data: { title: "", kind: "other", rows: screenRows(screens[shownScreen]) }, language })
6851
7062
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
6852
7063
  shown && /* @__PURE__ */ jsx("h3", { className: "pollar-ramp-screen-title", "data-status": shown.status, children: askedInstead ? view.title : shown.title }),
6853
7064
  shown?.status === "failed" && shown.leg.failure && /* @__PURE__ */ jsx("p", { className: "pollar-ramp-field-error", children: rampFailureReason(shown.leg.failure, language) }),
@@ -6908,7 +7119,20 @@ function RampWidgetTemplate({
6908
7119
  alt: copy.paymentQr,
6909
7120
  style: { width: "100%", maxWidth: 220, height: "auto", display: "block", margin: "0 auto" }
6910
7121
  }
6911
- ) })
7122
+ ) }),
7123
+ /* @__PURE__ */ jsx(
7124
+ SaveQrButton,
7125
+ {
7126
+ image: view.scannable.image,
7127
+ fileName: qrFileName,
7128
+ labels: {
7129
+ save: copy.screens.saveQr,
7130
+ saving: copy.screens.savingQr,
7131
+ saved: copy.screens.savedQr,
7132
+ failed: copy.screens.saveQrFailed
7133
+ }
7134
+ }
7135
+ )
6912
7136
  ] }),
6913
7137
  !settled && view.codeMissing && /* @__PURE__ */ jsx("p", { className: "pollar-ramp-payment-note", style: { color: "var(--pollar-error-text)" }, children: copy.codeMissing }),
6914
7138
  !settled && view.scannable?.payload && view.scannable.payloadLabel && /* @__PURE__ */ jsxs("div", { className: "pollar-ramp-payment-field", children: [
@@ -6967,8 +7191,7 @@ function RampWidgetTemplate({
6967
7191
  ),
6968
7192
  !settled && order.pendingAction?.kind === "KYC" && !view.link && /* @__PURE__ */ jsx("p", { className: "pollar-ramp-payment-note", children: view.note ?? copy.providerReviewing }),
6969
7193
  pollTrouble && !settled && /* @__PURE__ */ jsx("p", { className: "pollar-ramp-payment-note", children: copy.serverTrouble }),
6970
- errorMsg && /* @__PURE__ */ jsx("p", { className: "pollar-ramp-field-error", children: errorMsg }),
6971
- !settled && /* @__PURE__ */ jsx("div", { className: "pollar-ramp-explore", children: /* @__PURE__ */ jsx("button", { type: "button", className: "pollar-btn-secondary", onClick: onNewOrder, children: copy.startAnother }) })
7194
+ errorMsg && /* @__PURE__ */ jsx("p", { className: "pollar-ramp-field-error", children: errorMsg })
6972
7195
  ] }) }),
6973
7196
  step === "error" && /* @__PURE__ */ jsxs(Fragment, { children: [
6974
7197
  /* @__PURE__ */ jsx("div", { className: "pollar-modal-error", children: errorMsg ?? copy.somethingWrong }),
@@ -7691,6 +7914,8 @@ function RampWidget({ onClose, language: languageProp, initial }) {
7691
7914
  const [trustingAsset, setTrustingAsset] = useState(null);
7692
7915
  const [walletBusy, setWalletBusy] = useState(null);
7693
7916
  const [retrying, setRetrying] = useState(false);
7917
+ const [cancelling, setCancelling] = useState(false);
7918
+ const [cancelError, setCancelError] = useState(null);
7694
7919
  const [awaitingAccount, setAwaitingAccount] = useState(null);
7695
7920
  const [pollTrouble, setPollTrouble] = useState(false);
7696
7921
  const [pollKey, setPollKey] = useState(0);
@@ -8102,6 +8327,19 @@ function RampWidget({ onClose, language: languageProp, initial }) {
8102
8327
  setRetrying(false);
8103
8328
  }
8104
8329
  }
8330
+ async function handleCancelOrder() {
8331
+ if (!order || cancelling) return;
8332
+ setCancelling(true);
8333
+ setCancelError(null);
8334
+ try {
8335
+ setOrder(await client.cancelRampOrder(order.id));
8336
+ void loadPendingOrders();
8337
+ } catch (error) {
8338
+ setCancelError(rampErrorMessage(error, copy.cancelOrderFailed, copy, language));
8339
+ } finally {
8340
+ setCancelling(false);
8341
+ }
8342
+ }
8105
8343
  async function handleRequote() {
8106
8344
  setOrder(null);
8107
8345
  await handleFindRoute();
@@ -8272,7 +8510,10 @@ function RampWidget({ onClose, language: languageProp, initial }) {
8272
8510
  },
8273
8511
  onRefresh: () => void handleRefresh(),
8274
8512
  onClose,
8275
- confirmation
8513
+ confirmation,
8514
+ onCancelOrder: () => void handleCancelOrder(),
8515
+ cancelling,
8516
+ cancelError
8276
8517
  }
8277
8518
  ) });
8278
8519
  }