@coras-io/embed 0.13.0 → 0.13.2

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.
Files changed (31) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/contexts/basket/basket.provider.js +1 -17
  3. package/dist/core/color-scheme.d.ts +0 -1
  4. package/dist/core/color-scheme.js +4 -6
  5. package/dist/core/utils/mount-root.d.ts +1 -0
  6. package/dist/core/utils/mount-root.js +15 -0
  7. package/dist/core/utils/redaction.js +5 -0
  8. package/dist/errors.js +2 -2
  9. package/dist/mixins/coinbase.mixin.d.ts +12 -2
  10. package/dist/mixins/coinbase.mixin.js +23 -20
  11. package/dist/sdk/mount.js +15 -13
  12. package/dist/sdk/redaction.d.ts +7 -1
  13. package/dist/sdk/redaction.js +32 -1
  14. package/dist/sdk/validation.d.ts +1 -6
  15. package/dist/sdk/validation.js +7 -7
  16. package/dist/views/details-page/partials/location-highlights/location-highlights.component.js +0 -2
  17. package/dist/views/landing-page/landing-page.component.js +5 -2
  18. package/dist/views/payment-page/controllers/crypto-auth.controller.js +4 -4
  19. package/dist/views/payment-page/controllers/crypto-transfer.controller.d.ts +4 -4
  20. package/dist/views/payment-page/controllers/crypto-transfer.controller.js +9 -6
  21. package/dist/views/payment-page/controllers/stripe-payment.controller.d.ts +4 -1
  22. package/dist/views/payment-page/controllers/stripe-payment.controller.js +38 -10
  23. package/dist/views/payment-page/partials/activity-details/activity-details.component.js +1 -1
  24. package/dist/views/payment-page/partials/hotel-pickup-field/hotel-pickup-field.component.js +3 -1
  25. package/dist/views/payment-page/partials/hotel-pickup-list/hotel-pickup-list.component.js +1 -1
  26. package/dist/views/payment-page/payment-page.component.d.ts +2 -1
  27. package/dist/views/payment-page/payment-page.component.js +45 -25
  28. package/dist/views/payment-page/payment-page.utils.d.ts +2 -0
  29. package/dist/views/payment-page/payment-page.utils.js +5 -0
  30. package/dist/views/suggestion-widget/suggestion-widget.component.js +0 -2
  31. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @coras-io/embed
2
2
 
3
+ ## 0.13.2
4
+
5
+ ### Patch Changes
6
+
7
+ - ddb3a51: Stop adding a date to attraction card links when the visitor has not chosen dates. Cards on the landing page, the suggestion widget and the details page's highlights row linked to `?date=<first bookable day>`, so every attraction had a new URL each day for search engines to crawl. The details page already opens on the first bookable day without it. With a date filter applied, landing page cards keep the date
8
+
9
+ ## 0.13.1
10
+
11
+ ### Patch Changes
12
+
13
+ - dede3fc: Apply config and params updates that arrive while the chrome is still loading
14
+ - 590c9b1: Accept a trailing slash on `assetsUrl`: it is now removed, so icons, payment logos and the riyal font no longer request `//` paths that 404 on S3 and most CDNs.
15
+ - bd61a1c: Propagate a live colorScheme change to components inside shadow roots
16
+ - 6a63ce8: Transfer the exact FIDA amount shown when a basket has several reservations with decimal amounts, instead of a slightly larger amount from floating-point rounding
17
+ - c32851a: Fix the payment page so a chosen hotel pickup point is saved; tours with hotel pickup no longer fail with "This is a required field" on submit.
18
+ - 03b96ad: Redact personal data from everything passed to the host `logger`, so error reporters no longer receive end-user emails, phone numbers or SDK error details
19
+ - 07089d3: Redact phone numbers from API error payloads
20
+ - bb61396: Confirm the order instead of showing a failure when Stripe reports an error for a card or wallet payment that already succeeded, so charged customers are not told to book again, and show a failure when Stripe returns a payment that was not completed.
21
+
3
22
  ## 0.13.0
4
23
 
5
24
  ### Minor Changes
@@ -13,24 +13,8 @@ import { getBookingSession } from "../../core/api/middlewares/booking-session/bo
13
13
  import { distributorIdContext, localeContext } from "../properties.context.js";
14
14
  import { clientContext } from "../client.context.js";
15
15
  import { apiGet, apiDelete } from "../../core/api/queries.js";
16
+ import { findMountRoot } from "../../core/utils/mount-root.js";
16
17
  import styles from "./basket.styles.js";
17
- // Walk up (crossing shadow boundaries) to the mount root the SDK marks with
18
- // `data-coras-root`. Null when rendered outside a mount (e.g. Storybook).
19
- function findMountRoot(start) {
20
- let node = start;
21
- while (node) {
22
- if (node instanceof HTMLElement && node.hasAttribute("data-coras-root")) {
23
- return node;
24
- }
25
- if (node.parentNode) {
26
- node = node.parentNode;
27
- continue;
28
- }
29
- const root = node.getRootNode();
30
- node = root instanceof ShadowRoot ? root.host : null;
31
- }
32
- return null;
33
- }
34
18
  export class CorasBasketProvider extends LitElement {
35
19
  static { this.styles = styles; }
36
20
  constructor() {
@@ -1,6 +1,5 @@
1
1
  import type { ReactiveController, ReactiveControllerHost } from "lit";
2
2
  export type ColorScheme = "light" | "dark";
3
- export declare function resolveColorScheme(element: Element): ColorScheme;
4
3
  export declare class ColorSchemeController implements ReactiveController {
5
4
  scheme: ColorScheme;
6
5
  private readonly host;
@@ -1,11 +1,9 @@
1
- function schemeRoot(el) {
2
- return el.closest("[data-coras-root]") ?? el.ownerDocument.documentElement;
3
- }
1
+ import { findMountRoot } from "./utils/mount-root.js";
4
2
  function prefersDark() {
5
3
  return (typeof matchMedia === "function" &&
6
4
  matchMedia("(prefers-color-scheme: dark)").matches);
7
5
  }
8
- export function resolveColorScheme(element) {
6
+ function resolveColorScheme(element) {
9
7
  const scheme = getComputedStyle(element).colorScheme.toLowerCase();
10
8
  const hasLight = scheme.includes("light");
11
9
  const hasDark = scheme.includes("dark");
@@ -28,9 +26,9 @@ export class ColorSchemeController {
28
26
  this.media.addEventListener("change", this.onChange);
29
27
  }
30
28
  this.observer = new MutationObserver(this.onChange);
31
- this.observer.observe(schemeRoot(this.host), {
29
+ this.observer.observe(findMountRoot(this.host) ?? this.host.ownerDocument.documentElement, {
32
30
  attributes: true,
33
- attributeFilter: ["style", "class", "data-coras-color-scheme"],
31
+ attributeFilter: ["style", "class"],
34
32
  });
35
33
  this.scheme = resolveColorScheme(this.host);
36
34
  }
@@ -0,0 +1 @@
1
+ export declare function findMountRoot(start: Node): HTMLElement | null;
@@ -0,0 +1,15 @@
1
+ export function findMountRoot(start) {
2
+ let node = start;
3
+ while (node) {
4
+ if (node instanceof HTMLElement && node.hasAttribute("data-coras-root")) {
5
+ return node;
6
+ }
7
+ if (node.parentNode) {
8
+ node = node.parentNode;
9
+ continue;
10
+ }
11
+ const root = node.getRootNode();
12
+ node = root instanceof ShadowRoot ? root.host : null;
13
+ }
14
+ return null;
15
+ }
@@ -13,6 +13,9 @@ const SENSITIVE_PATTERNS = [
13
13
  /client_secret["':=\s]+[a-z0-9_-]+/gi,
14
14
  // Bearer / access tokens.
15
15
  /\bBearer\s+[a-z0-9._-]+/gi,
16
+ // E.164 phone numbers. The leading "+" keeps ids and timestamps intact; see
17
+ // docs/SECURITY.md.
18
+ /\+\d(?:[\s().-]*\d){7,14}/g,
16
19
  ];
17
20
  // Card-like number runs (13-19 digits, optionally space/dash separated). A
18
21
  // millisecond timestamp is also 13 digits, so a run is only masked when it
@@ -47,6 +50,8 @@ export function redactValue(value) {
47
50
  return redactString(value);
48
51
  if (Array.isArray(value))
49
52
  return value.map(redactValue);
53
+ if (value instanceof Date)
54
+ return value;
50
55
  if (value && typeof value === "object") {
51
56
  const out = {};
52
57
  for (const [key, item] of Object.entries(value)) {
package/dist/errors.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { APIError } from "./core/api/api-error.js";
2
2
  export { setApiErrorReporter } from "./core/api/middlewares/error-handler/error-handler.js";
3
- // Recursive value redaction (emails, keys, tokens, card numbers) for callers
4
- // that forward an error body to logs or error tracking.
3
+ // Recursive value redaction (emails, phone numbers, keys, tokens, card
4
+ // numbers) for callers that forward an error body to logs or error tracking.
5
5
  export { redactValue } from "./sdk/redaction.js";
@@ -39,7 +39,7 @@ export interface CoinbaseMixinInterface {
39
39
  getUser(): Promise<CoinbaseSession | undefined>;
40
40
  getTokenBalance(address: `0x${string}`): Promise<bigint | null>;
41
41
  formatTokenBalance(balance: bigint): string;
42
- transferTokens(amount: string): Promise<TransferResult>;
42
+ transferTokens(amountWei: bigint): Promise<TransferResult>;
43
43
  coinbaseSession: CoinbaseSession | undefined;
44
44
  cdpProjectId: string;
45
45
  cryptoRpc?: string;
@@ -47,7 +47,7 @@ export interface CoinbaseMixinInterface {
47
47
  tokenContractAddress: `0x${string}`;
48
48
  recipientAddress: `0x${string}`;
49
49
  isTransferPending: boolean;
50
- pendingTransferAmount: string;
50
+ pendingTransferAmountWei: bigint;
51
51
  isMfaEnrolled: boolean;
52
52
  mfaEnrollmentCodeSent: boolean;
53
53
  mfaEnrollmentError: string;
@@ -61,6 +61,16 @@ export interface CoinbaseMixinInterface {
61
61
  resetMfaVerificationState(): void;
62
62
  getCoinbaseAccessToken(): Promise<string | null>;
63
63
  }
64
+ /**
65
+ * Token decimals for FIDA (standard ERC-20 is 18)
66
+ */
67
+ export declare const TOKEN_DECIMALS = 18;
68
+ /**
69
+ * Sums token amounts in base units so decimal amounts add up exactly.
70
+ * Throws when an amount is not a plain decimal, such as exponent form.
71
+ */
72
+ export declare function sumTokenAmountsInBaseUnits(amounts: ReadonlyArray<number | string>): bigint;
73
+ export declare function hasSufficientBalance(balanceWei: bigint, amountWei: bigint): boolean;
64
74
  export declare const CoinbaseMixin: <TBase extends Constructor<LitElement & {
65
75
  logger: Logger;
66
76
  }>>(Base: TBase) => Constructor<CoinbaseMixinInterface> & TBase;
@@ -52,12 +52,22 @@ const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12
52
52
  /**
53
53
  * Token decimals for FIDA (standard ERC-20 is 18)
54
54
  */
55
- const TOKEN_DECIMALS = 18;
55
+ export const TOKEN_DECIMALS = 18;
56
56
  /**
57
57
  * Maximum transfer amount in whole tokens (safety bound).
58
58
  */
59
59
  const MAX_TRANSFER_AMOUNT = 1_000_000;
60
60
  const MAX_TRANSFER_AMOUNT_WEI = parseUnits(String(MAX_TRANSFER_AMOUNT), TOKEN_DECIMALS);
61
+ /**
62
+ * Sums token amounts in base units so decimal amounts add up exactly.
63
+ * Throws when an amount is not a plain decimal, such as exponent form.
64
+ */
65
+ export function sumTokenAmountsInBaseUnits(amounts) {
66
+ return amounts.reduce((sum, amount) => sum + parseUnits(String(amount), TOKEN_DECIMALS), 0n);
67
+ }
68
+ export function hasSufficientBalance(balanceWei, amountWei) {
69
+ return balanceWei >= amountWei;
70
+ }
61
71
  /**
62
72
  * Maps a sendUserOperation rejection to a code. The SDK's MfaError carries
63
73
  * a `code` and names itself; anything else is opaque and reported as unknown.
@@ -93,7 +103,7 @@ export const CoinbaseMixin = (Base) => {
93
103
  this.walletEmail = "";
94
104
  this.walletEmailError = "";
95
105
  this.isTransferPending = false;
96
- this.pendingTransferAmount = "";
106
+ this.pendingTransferAmountWei = 0n;
97
107
  this.isMfaEnrolled = false;
98
108
  this.mfaEnrollmentCodeSent = false;
99
109
  this.mfaEnrollmentError = "";
@@ -363,7 +373,8 @@ export const CoinbaseMixin = (Base) => {
363
373
  this.logger.error("Failed to initiate MFA enrollment");
364
374
  this.mfaEnrollmentError =
365
375
  "Failed to send MFA verification code. Please try again.";
366
- throw new Error("Failed to send MFA verification code. Please try again.", { cause: error });
376
+ // eslint-disable-next-line preserve-caught-error -- the CDP error can echo the phone number, so it must not reach the host logger (docs/SECURITY.md)
377
+ throw new Error("Failed to send MFA verification code. Please try again.");
367
378
  }
368
379
  }
369
380
  /**
@@ -592,10 +603,10 @@ export const CoinbaseMixin = (Base) => {
592
603
  * The user will be prompted by CDP to confirm the transaction via SMS OTP.
593
604
  * Gas fees are sponsored by the CDP paymaster on Base Sepolia.
594
605
  *
595
- * @param amount - Amount of tokens to transfer (in human-readable format, e.g., "100")
606
+ * @param amountWei - Amount of tokens to transfer in base units
596
607
  * @returns Transfer result with transaction hash or error
597
608
  */
598
- async transferTokens(amount) {
609
+ async transferTokens(amountWei) {
599
610
  // Prevent concurrent transfers (double-click safety)
600
611
  if (this.isTransferPending) {
601
612
  return { success: false, error: "in_progress" };
@@ -614,16 +625,7 @@ export const CoinbaseMixin = (Base) => {
614
625
  catch {
615
626
  return { success: false, error: "invalid_address" };
616
627
  }
617
- // Exact decimal parsing: floats would drift (0.1 + 0.2) and stringify
618
- // tiny values in exponent form, which viem rejects.
619
- let amountInWei;
620
- try {
621
- amountInWei = parseUnits(amount, TOKEN_DECIMALS);
622
- }
623
- catch {
624
- return { success: false, error: "invalid_amount" };
625
- }
626
- if (amountInWei <= 0n || amountInWei > MAX_TRANSFER_AMOUNT_WEI) {
628
+ if (amountWei <= 0n || amountWei > MAX_TRANSFER_AMOUNT_WEI) {
627
629
  return { success: false, error: "invalid_amount" };
628
630
  }
629
631
  // Claimed synchronously, before the first await, so a second click
@@ -634,7 +636,7 @@ export const CoinbaseMixin = (Base) => {
634
636
  const abort = new AbortController();
635
637
  this._transferAbort = abort;
636
638
  this.isTransferPending = true;
637
- this.pendingTransferAmount = amount;
639
+ this.pendingTransferAmountWei = amountWei;
638
640
  try {
639
641
  // Gas sponsorship requires ERC-4337 smart accounts, not plain EOAs
640
642
  let smartAccountAddress = this.coinbaseSession.smartAccountAddress;
@@ -651,10 +653,11 @@ export const CoinbaseMixin = (Base) => {
651
653
  const data = encodeFunctionData({
652
654
  abi: ERC20_ABI,
653
655
  functionName: "transfer",
654
- args: [this.recipientAddress, amountInWei],
656
+ args: [this.recipientAddress, amountWei],
655
657
  });
656
658
  const smartAccountBalance = await this.getTokenBalance(smartAccountAddress);
657
- if (smartAccountBalance === null || smartAccountBalance < amountInWei) {
659
+ if (smartAccountBalance === null ||
660
+ !hasSufficientBalance(smartAccountBalance, amountWei)) {
658
661
  return { success: false, error: "insufficient_balance" };
659
662
  }
660
663
  const userOpResult = await this._cdpCore.sendUserOperation({
@@ -697,7 +700,7 @@ export const CoinbaseMixin = (Base) => {
697
700
  finally {
698
701
  if (attempt === this._transferSequence) {
699
702
  this.isTransferPending = false;
700
- this.pendingTransferAmount = "";
703
+ this.pendingTransferAmountWei = 0n;
701
704
  }
702
705
  if (this._transferAbort === abort) {
703
706
  this._transferAbort = null;
@@ -919,7 +922,7 @@ export const CoinbaseMixin = (Base) => {
919
922
  ], CoinbaseMixinClass.prototype, "isTransferPending", void 0);
920
923
  __decorate([
921
924
  state()
922
- ], CoinbaseMixinClass.prototype, "pendingTransferAmount", void 0);
925
+ ], CoinbaseMixinClass.prototype, "pendingTransferAmountWei", void 0);
923
926
  __decorate([
924
927
  state()
925
928
  ], CoinbaseMixinClass.prototype, "isMfaEnrolled", void 0);
package/dist/sdk/mount.js CHANGED
@@ -8,7 +8,7 @@ import { applyConfig, applyParams, captureConfigDefaults, captureParamDefaults,
8
8
  import { applyColorScheme, applyTheme, clearTheme } from "./theme.js";
9
9
  import { safeUrl, migrateBrandConfig, } from "@coras-io/brand-tokens";
10
10
  import { ensureTokensInjected } from "../styles/tokens.js";
11
- import { redactValue, toPublicErrorDetail } from "./redaction.js";
11
+ import { redactLogger, redactValue, toPublicErrorDetail } from "./redaction.js";
12
12
  import { assertValidPage, CorasValidationError, validateConfig, validateMountOptions, validatePageParams, } from "./validation.js";
13
13
  /**
14
14
  * Rejection reason of `ready` when `unmount()` runs before the first render
@@ -57,9 +57,10 @@ export function createMountWith(registry) {
57
57
  const strict = options.strict === true;
58
58
  const preview = options.preview === true;
59
59
  const container = options.container;
60
+ const logger = redactLogger(options.logger);
60
61
  // Dev-time diagnostics (see diagnostics.ts): active only when a logger is
61
62
  // wired or `strict` is on, so production stays silent.
62
- const diagnostics = createDiagnostics(options.logger, strict);
63
+ const diagnostics = createDiagnostics(logger, strict);
63
64
  // Mounting a second app into a container that already holds one silently
64
65
  // stacks two mounts - a common cause of "it renders twice" in effects that
65
66
  // forget to unmount.
@@ -129,13 +130,13 @@ export function createMountWith(registry) {
129
130
  });
130
131
  }
131
132
  catch (error) {
132
- options.logger?.error?.(error);
133
+ logger?.error?.(error);
133
134
  }
134
135
  }
135
136
  function reportError(error) {
136
137
  const detail = toPublicErrorDetail(error, currentPage);
137
138
  // Per-mount logging only; the SDK never writes unconditional console output.
138
- options.logger?.error?.(error);
139
+ logger?.error?.(error);
139
140
  // Deliver to `onError` via the `coras:error` event only: the callback
140
141
  // bridge routes it to `onError`, so calling `onError` here as well would
141
142
  // fire it twice for one error.
@@ -170,23 +171,24 @@ export function createMountWith(registry) {
170
171
  if (destroyed || generationToken !== generation)
171
172
  return;
172
173
  const element = document.createElement(entry.tagName);
173
- // Capture element defaults before applyConfig writes to them, so a later
174
- // update that clears an optional config value can restore the default.
175
- const configDefaults = captureConfigDefaults(element);
176
- applyConfig(element, currentConfig, configDefaults);
177
174
  // Preview is a mount-time rendering mode, not config or a param, so it is
178
175
  // set directly on the element; pages that honor it read their own property.
179
176
  element.preview = preview;
180
- element.logger = toLogger(options.logger);
177
+ element.logger = toLogger(logger);
181
178
  element.hrefFor = options.hrefFor ?? null;
182
- const paramDefaults = captureParamDefaults(element, entry);
183
- applyParams(element, entry, currentParams, paramDefaults);
184
179
  // Chrome is rebuilt per page rather than moved: the navbar/footer consume
185
180
  // the page's context (locale, dispatch, current page…) and re-parenting a
186
181
  // context consumer across providers leaves those bindings stale.
187
182
  const chrome = await createChrome(currentChrome, themeLogos());
188
183
  if (destroyed || generationToken !== generation)
189
184
  return;
185
+ // After the chrome await, so an update() made while it loads still lands.
186
+ // Capture element defaults before applyConfig writes to them, so a later
187
+ // update that clears an optional config value can restore the default.
188
+ const configDefaults = captureConfigDefaults(element);
189
+ applyConfig(element, currentConfig, configDefaults);
190
+ const paramDefaults = captureParamDefaults(element, entry);
191
+ applyParams(element, entry, currentParams, paramDefaults);
190
192
  for (const chromeElement of chrome) {
191
193
  element.appendChild(chromeElement);
192
194
  }
@@ -234,7 +236,7 @@ export function createMountWith(registry) {
234
236
  emitObservability("coras.page-loaded", { page: targetPage });
235
237
  }
236
238
  const bridge = attachCallbackBridge(root, options, {
237
- onListenerError: (error) => options.logger?.error?.(error),
239
+ onListenerError: (error) => logger?.error?.(error),
238
240
  });
239
241
  function startRender(targetPage, rollback) {
240
242
  const token = ++generation;
@@ -424,8 +426,8 @@ export function createMountWith(registry) {
424
426
  unmount() {
425
427
  if (destroyed)
426
428
  return;
427
- emitObservability("coras.unmounted");
428
429
  destroyed = true;
430
+ emitObservability("coras.unmounted");
429
431
  // Invalidate any in-flight render so late loads are ignored.
430
432
  generation += 1;
431
433
  bridge.dispose();
@@ -1,4 +1,4 @@
1
- import type { CorasPageName, CorasErrorDetail } from "./types.js";
1
+ import type { CorasErrorDetail, CorasLogger, CorasPageName } from "./types.js";
2
2
  export { redactString, redactValue } from "../core/utils/redaction.js";
3
3
  /**
4
4
  * Convert any thrown value into a safe, redacted public error. Validation
@@ -6,3 +6,9 @@ export { redactString, redactValue } from "../core/utils/redaction.js";
6
6
  * collapsed to a generic message so internal/provider details never leak.
7
7
  */
8
8
  export declare function toPublicErrorDetail(error: unknown, page?: CorasPageName): CorasErrorDetail;
9
+ /**
10
+ * Wrap a host logger so every argument is redacted before the host sees it.
11
+ * An `Error` is replaced by a copy with the same prototype, redacted message,
12
+ * stack, and own enumerable fields, and no `cause`.
13
+ */
14
+ export declare function redactLogger(logger: CorasLogger | undefined): CorasLogger | undefined;
@@ -1,4 +1,4 @@
1
- import { redactString } from "../core/utils/redaction.js";
1
+ import { redactString, redactValue } from "../core/utils/redaction.js";
2
2
  import { CorasValidationError } from "./validation.js";
3
3
  export { redactString, redactValue } from "../core/utils/redaction.js";
4
4
  /**
@@ -20,3 +20,34 @@ export function toPublicErrorDetail(error, page) {
20
20
  ...(page ? { page } : {}),
21
21
  };
22
22
  }
23
+ function redactLogArgument(value) {
24
+ if (!(value instanceof Error))
25
+ return redactValue(value);
26
+ const copy = new Error(redactString(value.message));
27
+ Object.setPrototypeOf(copy, Object.getPrototypeOf(value));
28
+ Object.assign(copy, redactValue(value));
29
+ copy.stack =
30
+ value.stack === undefined ? undefined : redactString(value.stack);
31
+ return copy;
32
+ }
33
+ /**
34
+ * Wrap a host logger so every argument is redacted before the host sees it.
35
+ * An `Error` is replaced by a copy with the same prototype, redacted message,
36
+ * stack, and own enumerable fields, and no `cause`.
37
+ */
38
+ export function redactLogger(logger) {
39
+ if (!logger)
40
+ return undefined;
41
+ return {
42
+ ...(logger.warn
43
+ ? {
44
+ warn: (message, data) => logger.warn?.(redactString(message), redactLogArgument(data)),
45
+ }
46
+ : {}),
47
+ ...(logger.error
48
+ ? {
49
+ error: (error, data) => logger.error?.(redactLogArgument(error), redactLogArgument(data)),
50
+ }
51
+ : {}),
52
+ };
53
+ }
@@ -1,11 +1,6 @@
1
1
  import type { CorasConfig, CorasMountOptions, CorasPageName } from "./types.js";
2
2
  export { assertValidPage, CorasValidationError, normalizeCurrency, normalizeLocale, PAGE_PARAM_KEYS, PUBLIC_PAGES, type CorasValidationErrorCode, } from "./params.js";
3
- /**
4
- * Require an https URL (http allowed only for localhost dev). Returns the
5
- * parsed origin-safe href, or throws.
6
- */
7
- export declare function assertSecureUrl(value: string, field: string): string;
8
- export type ValidatedMount = {
3
+ type ValidatedMount = {
9
4
  page: CorasPageName;
10
5
  config: CorasConfig;
11
6
  params: Record<string, unknown>;
@@ -37,10 +37,9 @@ function isLocalHost(hostname) {
37
37
  hostname.endsWith(".localhost"));
38
38
  }
39
39
  /**
40
- * Require an https URL (http allowed only for localhost dev). Returns the
41
- * parsed origin-safe href, or throws.
40
+ * Require an https URL (http allowed only for localhost dev), or throw.
42
41
  */
43
- export function assertSecureUrl(value, field) {
42
+ function assertSecureUrl(value, field) {
44
43
  let url;
45
44
  try {
46
45
  url = new URL(value);
@@ -49,9 +48,9 @@ export function assertSecureUrl(value, field) {
49
48
  throw new CorasValidationError("invalid_url", `${field} must be an absolute URL.`, field);
50
49
  }
51
50
  if (url.protocol === "https:")
52
- return url.href;
51
+ return;
53
52
  if (url.protocol === "http:" && isLocalHost(url.hostname))
54
- return url.href;
53
+ return;
55
54
  throw new CorasValidationError("invalid_url", `${field} must use https (http is only allowed for localhost).`, field);
56
55
  }
57
56
  /**
@@ -194,8 +193,9 @@ export function validateConfig(config, strict) {
194
193
  if (typeof config.assetsUrl !== "string" || config.assetsUrl.length === 0) {
195
194
  throw new CorasValidationError("invalid_config", "config.assetsUrl is required.", "config.assetsUrl");
196
195
  }
197
- validateAssetsUrl(config.assetsUrl);
198
- const normalized = { ...config };
196
+ const assetsUrl = config.assetsUrl.replace(/\/+$/, "");
197
+ validateAssetsUrl(assetsUrl);
198
+ const normalized = { ...config, assetsUrl };
199
199
  if (config.theme != null) {
200
200
  validateTheme(config.theme, strict);
201
201
  }
@@ -10,7 +10,6 @@ import { ifDefined } from "lit/directives/if-defined.js";
10
10
  import { consume } from "@lit/context";
11
11
  import { localized, msg, str } from "@lit/localize";
12
12
  import { Task } from "@lit/task";
13
- import { formatISO, parseISO } from "date-fns";
14
13
  import "../../../../components/attraction-card/short/attraction-short-card.js";
15
14
  import { apiGet } from "../../../../core/api/queries.js";
16
15
  import { APIError } from "../../../../core/api/api-error.js";
@@ -79,7 +78,6 @@ let CorasLocationHighlights = class CorasLocationHighlights extends LitElement {
79
78
  return {
80
79
  page: "details",
81
80
  id: card.id,
82
- date: formatISO(parseISO(card.date), { representation: "date" }),
83
81
  locale: this.locale,
84
82
  currency: this.currency,
85
83
  };
@@ -822,6 +822,7 @@ let CorasLandingPage = class CorasLandingPage extends ErrorModalMixin(LocationSe
822
822
  const currency = this.currency;
823
823
  const locale = this.locale;
824
824
  const cards = section.items;
825
+ const datesFiltered = Boolean(this.startDate || this.endDate);
825
826
  return html `
826
827
  <section>
827
828
  <header class="section-header">
@@ -836,8 +837,10 @@ let CorasLandingPage = class CorasLandingPage extends ErrorModalMixin(LocationSe
836
837
  currency: this.currency,
837
838
  page: "details",
838
839
  id: card.id,
839
- date: formatISO(parseISO(card.date), {
840
- representation: "date",
840
+ ...(datesFiltered && {
841
+ date: formatISO(parseISO(card.date), {
842
+ representation: "date",
843
+ }),
841
844
  }),
842
845
  };
843
846
  return html `
@@ -1,6 +1,6 @@
1
1
  import { msg, str } from "@lit/localize";
2
2
  import { OTP_INACTIVITY_TIMEOUT_MS, OTP_MIN_RESEND_INTERVAL_MS, OTP_MAX_ATTEMPTS_PER_SESSION, SMS_OTP_MIN_RESEND_INTERVAL_MS, SMS_OTP_MAX_ATTEMPTS_PER_SESSION, } from "../payment-page.constants.js";
3
- import { sanitizeErrorMessage, toE164 } from "../payment-page.utils.js";
3
+ import { redactedErrorMessage, sanitizeErrorMessage, toE164, } from "../payment-page.utils.js";
4
4
  /**
5
5
  * CryptoAuthController manages the OTP email authentication and MFA enrollment
6
6
  * flows for crypto payments.
@@ -101,7 +101,7 @@ export class CryptoAuthController {
101
101
  this.lastOtpSentTime = Date.now();
102
102
  }
103
103
  catch (error) {
104
- this.deps.logger.error("Error sending verification code:", error);
104
+ this.deps.logger.error("Error sending verification code:", redactedErrorMessage(error));
105
105
  setEmailError(sanitizeErrorMessage(error, msg("Failed to send verification code. Please try again.")));
106
106
  }
107
107
  finally {
@@ -127,7 +127,7 @@ export class CryptoAuthController {
127
127
  this.startOtpInactivityTimer(codeSent, hasSession);
128
128
  }
129
129
  catch (error) {
130
- this.deps.logger.error("Error resending verification code:", error);
130
+ this.deps.logger.error("Error resending verification code:", redactedErrorMessage(error));
131
131
  // The OTP step shows otpError; the email field error is not visible there.
132
132
  this.otpError = sanitizeErrorMessage(error, msg("Failed to resend the verification code. Please try again."));
133
133
  }
@@ -196,7 +196,7 @@ export class CryptoAuthController {
196
196
  this.mfaEnrollmentPhoneNumber = phoneNumber;
197
197
  }
198
198
  catch (error) {
199
- this.deps.logger.error("MFA enrollment initiation failed:", error);
199
+ this.deps.logger.error("MFA enrollment initiation failed:", redactedErrorMessage(error));
200
200
  setEnrollmentError(sanitizeErrorMessage(error, msg("Failed to initiate MFA enrollment")));
201
201
  }
202
202
  finally {
@@ -19,7 +19,7 @@ export type TransferOutcome = "completed" | "failed";
19
19
  */
20
20
  export interface CryptoTransferDeps {
21
21
  logger: Logger;
22
- transferTokens(amount: string): Promise<TransferResult>;
22
+ transferTokens(amountWei: bigint): Promise<TransferResult>;
23
23
  confirmReservation(): Promise<{
24
24
  transaction_id: string;
25
25
  user_id: string;
@@ -32,9 +32,9 @@ export interface CryptoTransferDeps {
32
32
  submitMfaVerification(code: string): Promise<boolean>;
33
33
  initiateMfaVerification(): Promise<void>;
34
34
  resetMfaVerificationState(): void;
35
- /** Returns the current pending transfer amount */
36
- getPendingTransferAmount(): string;
37
- /** Returns the current cart token total for amount matching */
35
+ /** Returns the current pending transfer amount in base units */
36
+ getPendingTransferAmountWei(): bigint;
37
+ /** Returns the current cart token total, formatted from base units, for amount matching */
38
38
  getCurrentCartTotal(): string;
39
39
  /** Setter for transactionId on the host */
40
40
  setTransactionId(id: string): void;
@@ -1,5 +1,7 @@
1
1
  import { msg } from "@lit/localize";
2
- import { isValidPendingTransferPayload, computeTransferChecksum, verifyTransferChecksum, sanitizeErrorMessage, } from "../payment-page.utils.js";
2
+ import { formatUnits } from "viem/utils";
3
+ import { TOKEN_DECIMALS } from "../../../mixins/coinbase.mixin.js";
4
+ import { isValidPendingTransferPayload, computeTransferChecksum, verifyTransferChecksum, sanitizeErrorMessage, redactedErrorMessage, } from "../payment-page.utils.js";
3
5
  const PENDING_TRANSFER_KEY = "coras-pending-crypto-transfer";
4
6
  const ONE_HOUR_MS = 60 * 60 * 1000;
5
7
  /**
@@ -37,9 +39,10 @@ export class CryptoTransferController {
37
39
  // Captured before the transfer: the mixin clears its pending amount once
38
40
  // the user operation settles, and the persisted payload must carry the
39
41
  // amount that actually left the wallet.
40
- const amount = this.deps.getPendingTransferAmount();
42
+ const amountWei = this.deps.getPendingTransferAmountWei();
43
+ const amount = formatUnits(amountWei, TOKEN_DECIMALS);
41
44
  try {
42
- const result = await this.deps.transferTokens(amount);
45
+ const result = await this.deps.transferTokens(amountWei);
43
46
  if (!result.success || !result.transactionHash) {
44
47
  this.showTransferModal = false;
45
48
  this.transferModalState = "mfa-verification";
@@ -50,7 +53,7 @@ export class CryptoTransferController {
50
53
  return await this.handleTransferSuccess(result.transactionHash, amount);
51
54
  }
52
55
  catch (error) {
53
- this.deps.logger.error("Transfer error:", error);
56
+ this.deps.logger.error("Transfer error:", redactedErrorMessage(error));
54
57
  this.showTransferModal = false;
55
58
  this.transferModalState = "mfa-verification";
56
59
  this.host.requestUpdate();
@@ -109,7 +112,7 @@ export class CryptoTransferController {
109
112
  this.transferModalState = "loading";
110
113
  }
111
114
  catch (error) {
112
- this.deps.logger.error("MFA verification error:", error);
115
+ this.deps.logger.error("MFA verification error:", redactedErrorMessage(error));
113
116
  this.mfaVerificationError = sanitizeErrorMessage(error, msg("Verification failed"));
114
117
  }
115
118
  finally {
@@ -124,7 +127,7 @@ export class CryptoTransferController {
124
127
  await this.deps.initiateMfaVerification();
125
128
  }
126
129
  catch (error) {
127
- this.deps.logger.error("Failed to resend MFA code:", error);
130
+ this.deps.logger.error("Failed to resend MFA code:", redactedErrorMessage(error));
128
131
  this.mfaVerificationError = sanitizeErrorMessage(error, msg("Failed to resend code"));
129
132
  this.host.requestUpdate();
130
133
  }
@@ -56,7 +56,10 @@ export declare class StripePaymentController implements ReactiveController {
56
56
  /**
57
57
  * Process a Stripe payment (card or Apple/Google Pay).
58
58
  *
59
- * Returns true if payment was successful, false otherwise.
59
+ * Returns true when the PaymentIntent succeeded or is still settling
60
+ * (`processing`, `requires_capture`), so the page polls the transaction,
61
+ * including when Stripe reports an error for an intent that already
62
+ * succeeded. Returns false otherwise.
60
63
  * Sets error state on the controller for the host to render.
61
64
  *
62
65
  * The charged amount is not checked here, and deliberately so. It is fixed by
@@ -1,5 +1,17 @@
1
1
  import { msg } from "@lit/localize";
2
2
  import { mapStripeErrorToField, extractPaymentIntentId, } from "../payment-page.utils.js";
3
+ const POLLABLE_PAYMENT_INTENT_STATUSES = new Set(["succeeded", "processing", "requires_capture"]);
4
+ function confirmedPaymentIntentStatus(result) {
5
+ return result.error
6
+ ? result.error.payment_intent?.status
7
+ : result.paymentIntent?.status;
8
+ }
9
+ function stripeErrorLogData(error) {
10
+ if (!error || typeof error !== "object")
11
+ return {};
12
+ const { code, decline_code, type } = error;
13
+ return { code, decline_code, type };
14
+ }
3
15
  /**
4
16
  * StripePaymentController manages Stripe-specific payment processing:
5
17
  * - Card payment confirmation
@@ -97,7 +109,10 @@ export class StripePaymentController {
97
109
  /**
98
110
  * Process a Stripe payment (card or Apple/Google Pay).
99
111
  *
100
- * Returns true if payment was successful, false otherwise.
112
+ * Returns true when the PaymentIntent succeeded or is still settling
113
+ * (`processing`, `requires_capture`), so the page polls the transaction,
114
+ * including when Stripe reports an error for an intent that already
115
+ * succeeded. Returns false otherwise.
101
116
  * Sets error state on the controller for the host to render.
102
117
  *
103
118
  * The charged amount is not checked here, and deliberately so. It is fixed by
@@ -162,8 +177,12 @@ export class StripePaymentController {
162
177
  payment_method: this.authorizedPaymentMethod.id,
163
178
  });
164
179
  if (result.error) {
165
- this.logger.error(`${this.authorizedPaymentEvent ? "wallet" : "card"} payment failed`);
166
- this.cardError = result.error.message || msg("Payment failed");
180
+ this.logger.error("Wallet payment confirmation returned an error", stripeErrorLogData(result.error));
181
+ }
182
+ const status = confirmedPaymentIntentStatus(result);
183
+ if (!POLLABLE_PAYMENT_INTENT_STATUSES.has(status)) {
184
+ this.logger.error("Wallet payment not completed", { status });
185
+ this.cardError = result.error?.message || msg("Payment failed");
167
186
  this.authorizedPaymentEvent.complete("fail");
168
187
  this.authorizedPaymentMethod = null;
169
188
  this.authorizedPaymentEvent = null;
@@ -176,8 +195,8 @@ export class StripePaymentController {
176
195
  this.host.requestUpdate();
177
196
  return true;
178
197
  }
179
- catch {
180
- this.logger.error("Error processing wallet payment");
198
+ catch (error) {
199
+ this.logger.error("Error processing wallet payment", stripeErrorLogData(error));
181
200
  this.cardError = msg("An error occurred while processing your payment. Please try again.");
182
201
  if (this.authorizedPaymentEvent) {
183
202
  this.authorizedPaymentEvent.complete("fail");
@@ -209,14 +228,23 @@ export class StripePaymentController {
209
228
  },
210
229
  });
211
230
  if (result.error) {
212
- this.logger.error("Card payment failed");
231
+ this.logger.error("Card payment confirmation returned an error", stripeErrorLogData(result.error));
232
+ }
233
+ const status = confirmedPaymentIntentStatus(result);
234
+ if (POLLABLE_PAYMENT_INTENT_STATUSES.has(status))
235
+ return true;
236
+ this.logger.error("Card payment not completed", { status });
237
+ if (result.error) {
213
238
  this.handleStripeValidationError(result.error);
214
- return false;
215
239
  }
216
- return !!result.paymentIntent;
240
+ else {
241
+ this.cardError = msg("Payment failed");
242
+ this.host.requestUpdate();
243
+ }
244
+ return false;
217
245
  }
218
- catch {
219
- this.logger.error("Error processing payment");
246
+ catch (error) {
247
+ this.logger.error("Error processing payment", stripeErrorLogData(error));
220
248
  this.cardError = msg("An error occurred while processing your payment. Please try again.");
221
249
  this.host.requestUpdate();
222
250
  return false;
@@ -153,7 +153,7 @@ let CorasActivityDetails = class CorasActivityDetails extends LitElement {
153
153
  assets-url=${this.assetsURL}
154
154
  @value-changed=${(e) => {
155
155
  e.stopPropagation();
156
- this.handleValueChanged(fieldName, e.detail.coras_pickup_id);
156
+ this.handleValueChanged(fieldName, e.detail.value);
157
157
  }}
158
158
  ></coras-hotel-pickup-field>
159
159
  `;
@@ -7,6 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  import { LitElement, html, nothing } from "lit";
8
8
  import { property, state } from "lit/decorators.js";
9
9
  import { localized, msg } from "@lit/localize";
10
+ import { fireInternalEvent } from "../../../../core/events.js";
10
11
  import "../../../../components/dropdown/dropdown.js";
11
12
  import "../../../../components/input-field/input-field.js";
12
13
  import "../../../../components/icon/icon.js";
@@ -70,8 +71,9 @@ let CorasHotelPickupField = class CorasHotelPickupField extends LitElement {
70
71
  <coras-hotel-pickup-list
71
72
  .options=${this.options}
72
73
  .value=${this.value}
73
- @value-changed=${() => {
74
+ @value-changed=${(e) => {
74
75
  this.dropdownOpen = false;
76
+ fireInternalEvent(this, "value-changed", { value: e.detail.value });
75
77
  }}
76
78
  ></coras-hotel-pickup-list>
77
79
  </coras-dropdown>
@@ -22,7 +22,7 @@ export class CorasHotelPickupList extends LitElement {
22
22
  <div
23
23
  class="pickup-item ${selected ? "selected" : ""}"
24
24
  @click=${() => {
25
- fireInternalEvent(this, "value-changed", option);
25
+ fireInternalEvent(this, "value-changed", { value });
26
26
  }}
27
27
  >
28
28
  ${option.pickup_name}
@@ -114,7 +114,8 @@ export declare class CorasPaymentPage extends CorasPaymentPage_base {
114
114
  private reservationsCheckTask;
115
115
  private reservationsTask;
116
116
  private hasReservations;
117
- private getReservationsLoyaltyTotal;
117
+ private getReservationsEarnTotal;
118
+ private getReservationsPayAmountWei;
118
119
  private formatEarnedTokens;
119
120
  private handlePhoneCodeSelection;
120
121
  private handleTermsChange;
@@ -27,7 +27,8 @@ import "../../components/transfer-modal/transfer-modal.js";
27
27
  import "../../components/crypto-auth-modal/crypto-auth-modal.js";
28
28
  import { BaseMixin } from "../../mixins/base.mixin.js";
29
29
  import { ErrorModalMixin } from "../../mixins/error-modal.mixin.js";
30
- import { CoinbaseMixin } from "../../mixins/coinbase.mixin.js";
30
+ import { formatUnits } from "viem/utils";
31
+ import { CoinbaseMixin, hasSufficientBalance, sumTokenAmountsInBaseUnits, TOKEN_DECIMALS, } from "../../mixins/coinbase.mixin.js";
31
32
  import styles from "./payment-page.styles.js";
32
33
  import "../../components/bottom-drawer/bottom-drawer.js";
33
34
  import "../../components/expiration-timer/expiration-timer.js";
@@ -105,7 +106,7 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
105
106
  });
106
107
  this.cryptoTransferController = new CryptoTransferController(this, {
107
108
  logger: this.controllerLogger,
108
- transferTokens: (amount) => this.transferTokens(amount),
109
+ transferTokens: (amountWei) => this.transferTokens(amountWei),
109
110
  confirmReservation: async () => {
110
111
  // Every controller-driven confirmation follows an on-chain transfer,
111
112
  // including recovery on page load where the selector still says card.
@@ -128,8 +129,8 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
128
129
  submitMfaVerification: (code) => this.submitMfaVerification(code),
129
130
  initiateMfaVerification: () => this.initiateMfaVerification(),
130
131
  resetMfaVerificationState: () => this.resetMfaVerificationState(),
131
- getPendingTransferAmount: () => this.pendingTransferAmount,
132
- getCurrentCartTotal: () => String(this.getReservationsLoyaltyTotal("pay")),
132
+ getPendingTransferAmountWei: () => this.pendingTransferAmountWei,
133
+ getCurrentCartTotal: () => formatUnits(this.getReservationsPayAmountWei() ?? 0n, TOKEN_DECIMALS),
133
134
  setTransactionId: (id) => {
134
135
  this.transactionId = id;
135
136
  },
@@ -311,8 +312,8 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
311
312
  const { data } = await this.getApiService().fetchReservations(bookingSession);
312
313
  return data || { reservations: [] };
313
314
  }
314
- catch {
315
- this.logger.error("Failed to fetch reservations");
315
+ catch (error) {
316
+ this.logger.error("Failed to fetch reservations", error);
316
317
  return { reservations: [] };
317
318
  }
318
319
  },
@@ -406,8 +407,8 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
406
407
  return;
407
408
  }
408
409
  await this.syncEmailFromCoinbase();
409
- const tokensAmount = String(this.getReservationsLoyaltyTotal("pay"));
410
- this.pendingTransferAmount = tokensAmount;
410
+ this.pendingTransferAmountWei =
411
+ this.getReservationsPayAmountWei() ?? 0n;
411
412
  // Check for a valid pending transfer from a previous attempt.
412
413
  // If found (same amount, not stale, checksum OK), retry the API
413
414
  // confirmation instead of initiating a new on-chain transfer.
@@ -440,8 +441,17 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
440
441
  this.dispatchPaymentFailure();
441
442
  return;
442
443
  }
443
- clientSecret = confirmationResult
444
- .client_secret;
444
+ if (confirmationResult.client_secret === null) {
445
+ this.logger.error("Stripe reservation returned no client secret", {
446
+ transactionId: confirmationResult.transaction_id,
447
+ });
448
+ this.stripeController.abortAuthorizedPayment();
449
+ this.stripeController.cardError = msg("An unexpected error occurred. Please try again.");
450
+ this.flowController.transition("failed");
451
+ this.dispatchPaymentFailure();
452
+ return;
453
+ }
454
+ clientSecret = confirmationResult.client_secret;
445
455
  }
446
456
  this.flowController.transition("processing_payment");
447
457
  {
@@ -634,11 +644,20 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
634
644
  hasReservations() {
635
645
  return (this.reservationsTask.value?.reservations?.length ?? 0) > 0;
636
646
  }
637
- getReservationsLoyaltyTotal(field) {
647
+ getReservationsEarnTotal() {
638
648
  const reservations = this.reservationsTask?.value?.reservations;
639
649
  if (!reservations?.length)
640
650
  return 0;
641
- return reservations.reduce((sum, reservation) => sum + getLoyaltyAmount(reservation.loyalty, field), 0);
651
+ return reservations.reduce((sum, reservation) => sum + getLoyaltyAmount(reservation.loyalty, "earn"), 0);
652
+ }
653
+ getReservationsPayAmountWei() {
654
+ const reservations = this.reservationsTask?.value?.reservations ?? [];
655
+ try {
656
+ return sumTokenAmountsInBaseUnits(reservations.map((reservation) => reservation.loyalty?.pay?.FIDA ?? 0));
657
+ }
658
+ catch {
659
+ return null;
660
+ }
642
661
  }
643
662
  formatEarnedTokens() {
644
663
  if (!this.earnedTokensToIssue)
@@ -826,8 +845,8 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
826
845
  return !!(this.formController.formValues.email || this.coinbaseSession?.email);
827
846
  }
828
847
  renderPaymentDetailsStep() {
829
- const fidaAmount = this.getReservationsLoyaltyTotal("pay");
830
- const formattedFidaAmount = new Intl.NumberFormat(this.locale).format(isNaN(fidaAmount) ? 0 : fidaAmount);
848
+ const fidaAmountWei = this.getReservationsPayAmountWei() ?? 0n;
849
+ const formattedFidaAmount = new Intl.NumberFormat(this.locale).format(Number(formatUnits(fidaAmountWei, TOKEN_DECIMALS)));
831
850
  const termsLabel = this.paymentType === "crypto"
832
851
  ? msg("I confirm I have read and accept FIDA's Terms & Conditions")
833
852
  : msg("I confirm I have read and accept Coras's Terms & Conditions");
@@ -835,9 +854,9 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
835
854
  const isLoggedIn = !!this.coinbaseSession;
836
855
  const isFullyAuthenticated = isLoggedIn && this.isMfaEnrolled;
837
856
  const balance = this.balanceTask.value;
838
- const formattedBalance = balance != null ? this.formatTokenBalance(balance) : "0";
839
- const currentBalance = Number(formattedBalance);
840
- const insufficientBalance = balance === null || balance === 0n || currentBalance < fidaAmount;
857
+ const insufficientBalance = balance === null ||
858
+ balance === 0n ||
859
+ !hasSufficientBalance(balance ?? 0n, fidaAmountWei);
841
860
  return html `
842
861
  ${this.renderBillingAddress()}
843
862
  <div class="footer">
@@ -1182,8 +1201,8 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
1182
1201
  });
1183
1202
  return null;
1184
1203
  }
1185
- catch {
1186
- this.logger.error("Failed to update pickup_id for reservation");
1204
+ catch (error) {
1205
+ this.logger.error("Failed to update pickup_id for reservation", error);
1187
1206
  return fieldName;
1188
1207
  }
1189
1208
  }));
@@ -1479,8 +1498,9 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
1479
1498
  }
1480
1499
  renderPaymentTypeSelector() {
1481
1500
  const data = this.reservationsTask.value;
1482
- const payWithTokens = String(this.getReservationsLoyaltyTotal("pay"));
1483
- const earnWithTokens = String(this.getReservationsLoyaltyTotal("earn"));
1501
+ const payAmountWei = this.getReservationsPayAmountWei() ?? 0n;
1502
+ const payWithTokens = formatUnits(payAmountWei, TOKEN_DECIMALS);
1503
+ const earnWithTokens = String(this.getReservationsEarnTotal());
1484
1504
  const price = convertToLocaleCurrency({
1485
1505
  value: data?.total_price || 0,
1486
1506
  locale: this.locale,
@@ -1493,9 +1513,9 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
1493
1513
  const balance = this.balanceTask.value;
1494
1514
  const hasBalance = balance != null;
1495
1515
  const formattedBalance = hasBalance ? this.formatTokenBalance(balance) : "";
1496
- const currentBalance = Number(formattedBalance || 0);
1497
- const fidaAmount = Number(payWithTokens || 0);
1498
- const insufficientBalance = !hasBalance || balance === 0n || currentBalance < fidaAmount;
1516
+ const insufficientBalance = !hasBalance ||
1517
+ balance === 0n ||
1518
+ !hasSufficientBalance(balance, payAmountWei);
1499
1519
  return html `
1500
1520
  <coras-payment-type-selector
1501
1521
  .currency=${this.currency}
@@ -1841,7 +1861,7 @@ let CorasPaymentPage = class CorasPaymentPage extends CoinbaseMixin(ErrorModalMi
1841
1861
  return html `
1842
1862
  <coras-transfer-modal
1843
1863
  ?open=${this.cryptoTransferController.showTransferModal}
1844
- amount=${this.pendingTransferAmount}
1864
+ amount=${formatUnits(this.pendingTransferAmountWei, TOKEN_DECIMALS)}
1845
1865
  masked-phone=${maskedPhone}
1846
1866
  modal-state=${this.cryptoTransferController.transferModalState}
1847
1867
  mfa-error=${this.cryptoTransferController.mfaVerificationError}
@@ -157,6 +157,8 @@ export declare const isApiError: (err: unknown) => err is ApiError;
157
157
  * Callers should provide a domain-specific fallback.
158
158
  */
159
159
  export declare function sanitizeErrorMessage(error: unknown, fallback: string): string;
160
+ /** A redacted message for logging an unknown error without the error object. */
161
+ export declare function redactedErrorMessage(error: unknown): string;
160
162
  /**
161
163
  * Handles API errors by mapping them to form fields
162
164
  */
@@ -1,6 +1,7 @@
1
1
  import { msg } from "@lit/localize";
2
2
  import { apiGet } from "../../core/api/queries.js";
3
3
  import { getLoyaltyAmount } from "../../core/utils/loyalty.js";
4
+ import { redactString } from "../../core/utils/redaction.js";
4
5
  import { getLoyaltyFieldName } from "./payment-page.loyalty.js";
5
6
  import { APIError } from "../../core/api/api-error.js";
6
7
  import { parsePhoneNumberFromString, } from "libphonenumber-js/min";
@@ -550,6 +551,10 @@ export function sanitizeErrorMessage(error, fallback) {
550
551
  }
551
552
  return message;
552
553
  }
554
+ /** A redacted message for logging an unknown error without the error object. */
555
+ export function redactedErrorMessage(error) {
556
+ return redactString(error instanceof Error ? error.message : String(error));
557
+ }
553
558
  /**
554
559
  * Handles API errors by mapping them to form fields
555
560
  */
@@ -9,7 +9,6 @@ import { property } from "lit/decorators.js";
9
9
  import { ifDefined } from "lit/directives/if-defined.js";
10
10
  import { localized, msg, str } from "@lit/localize";
11
11
  import { Task } from "@lit/task";
12
- import { formatISO, parseISO } from "date-fns";
13
12
  import { ExploreCardVariants } from "../../components/explore-card/explore-card.constants.js";
14
13
  import styles from "./suggestion-widget.styles.js";
15
14
  import "../../components/explore-card/explore-card.js";
@@ -66,7 +65,6 @@ let CorasSuggestionWidget = class CorasSuggestionWidget extends BaseMixin(LitEle
66
65
  return {
67
66
  page: "details",
68
67
  id: card.id,
69
- date: formatISO(parseISO(card.date), { representation: "date" }),
70
68
  locale: this.locale,
71
69
  currency: this.currency,
72
70
  };
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "engines": {
21
21
  "node": ">=22"
22
22
  },
23
- "version": "0.13.0",
23
+ "version": "0.13.2",
24
24
  "private": false,
25
25
  "homepage": "https://docs.coras.io",
26
26
  "bugs": {