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