@coras-io/embed 0.12.0 → 0.13.1
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/CHANGELOG.md +19 -0
- package/README.md +18 -8
- package/dist/components/attraction-card/base/attraction-card.mixin.js +3 -3
- package/dist/components/attraction-card/base/attraction-card.styles.js +8 -0
- package/dist/components/button/button.component.d.ts +6 -0
- package/dist/components/button/button.component.js +31 -8
- package/dist/components/button/button.styles.js +8 -1
- package/dist/contexts/basket/basket.provider.js +1 -17
- package/dist/core/color-scheme.d.ts +0 -1
- package/dist/core/color-scheme.js +4 -6
- package/dist/core/utils/mount-root.d.ts +1 -0
- package/dist/core/utils/mount-root.js +15 -0
- package/dist/core/utils/redaction.js +5 -0
- package/dist/errors.js +2 -2
- package/dist/mixins/coinbase.mixin.d.ts +12 -2
- package/dist/mixins/coinbase.mixin.js +23 -20
- package/dist/sdk/mount.js +15 -13
- package/dist/sdk/redaction.d.ts +7 -1
- package/dist/sdk/redaction.js +32 -1
- package/dist/sdk/url.d.ts +44 -2
- package/dist/sdk/url.js +54 -6
- package/dist/sdk/validation.d.ts +1 -6
- package/dist/sdk/validation.js +7 -7
- package/dist/views/details-page/partials/location-categories/location-categories.component.d.ts +2 -1
- package/dist/views/details-page/partials/location-categories/location-categories.component.js +18 -5
- package/dist/views/payment-page/controllers/crypto-auth.controller.js +4 -4
- package/dist/views/payment-page/controllers/crypto-transfer.controller.d.ts +4 -4
- package/dist/views/payment-page/controllers/crypto-transfer.controller.js +9 -6
- package/dist/views/payment-page/controllers/stripe-payment.controller.d.ts +4 -1
- package/dist/views/payment-page/controllers/stripe-payment.controller.js +38 -10
- package/dist/views/payment-page/partials/activity-details/activity-details.component.js +1 -1
- package/dist/views/payment-page/partials/confirmation/confirmation.component.d.ts +2 -0
- package/dist/views/payment-page/partials/confirmation/confirmation.component.js +26 -6
- package/dist/views/payment-page/partials/confirmation/confirmation.styles.js +4 -0
- package/dist/views/payment-page/partials/hotel-pickup-field/hotel-pickup-field.component.js +3 -1
- package/dist/views/payment-page/partials/hotel-pickup-list/hotel-pickup-list.component.js +1 -1
- package/dist/views/payment-page/payment-page.component.d.ts +2 -1
- package/dist/views/payment-page/payment-page.component.js +45 -25
- package/dist/views/payment-page/payment-page.utils.d.ts +2 -0
- package/dist/views/payment-page/payment-page.utils.js +5 -0
- package/dist/views/suggestion-widget/suggestion-widget.component.d.ts +1 -1
- package/dist/views/suggestion-widget/suggestion-widget.component.js +11 -4
- package/package.json +1 -1
|
@@ -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 {
|
|
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: (
|
|
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
|
-
|
|
132
|
-
getCurrentCartTotal: () =>
|
|
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
|
-
|
|
410
|
-
|
|
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
|
-
|
|
444
|
-
.
|
|
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
|
-
|
|
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,
|
|
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
|
|
830
|
-
const formattedFidaAmount = new Intl.NumberFormat(this.locale).format(
|
|
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
|
|
839
|
-
|
|
840
|
-
|
|
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
|
|
1483
|
-
const
|
|
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
|
|
1497
|
-
|
|
1498
|
-
|
|
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.
|
|
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
|
*/
|
|
@@ -33,7 +33,7 @@ export declare class CorasSuggestionWidget extends CorasSuggestionWidget_base {
|
|
|
33
33
|
private humanize;
|
|
34
34
|
private suggestionsTask;
|
|
35
35
|
private cardTarget;
|
|
36
|
-
private
|
|
36
|
+
private exploreTarget;
|
|
37
37
|
private renderCard;
|
|
38
38
|
private renderExploreCard;
|
|
39
39
|
private renderContent;
|
|
@@ -22,6 +22,7 @@ import { BaseMixin } from "../../mixins/base.mixin.js";
|
|
|
22
22
|
import { apiGet } from "../../core/api/queries.js";
|
|
23
23
|
import { convertToLocaleCurrency } from "../../core/currency/index.js";
|
|
24
24
|
import { renderLoyaltyBadge } from "../../components/loyalty-badge/loyalty-badge.utils.js";
|
|
25
|
+
import { claimLinkClick } from "../../core/utils/link-click.js";
|
|
25
26
|
let CorasSuggestionWidget = class CorasSuggestionWidget extends BaseMixin(LitElement) {
|
|
26
27
|
constructor() {
|
|
27
28
|
super(...arguments);
|
|
@@ -70,14 +71,14 @@ let CorasSuggestionWidget = class CorasSuggestionWidget extends BaseMixin(LitEle
|
|
|
70
71
|
currency: this.currency,
|
|
71
72
|
};
|
|
72
73
|
}
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
exploreTarget(country, city) {
|
|
75
|
+
return {
|
|
75
76
|
page: "landing",
|
|
76
77
|
country,
|
|
77
78
|
city,
|
|
78
79
|
locale: this.locale,
|
|
79
80
|
currency: this.currency,
|
|
80
|
-
}
|
|
81
|
+
};
|
|
81
82
|
}
|
|
82
83
|
renderCard(card) {
|
|
83
84
|
const price = card.price[this.currency];
|
|
@@ -125,6 +126,8 @@ let CorasSuggestionWidget = class CorasSuggestionWidget extends BaseMixin(LitEle
|
|
|
125
126
|
imageExtension: "png",
|
|
126
127
|
params: { auto: "compress,format", ar: "2:3", fit: "crop" },
|
|
127
128
|
});
|
|
129
|
+
const target = this.exploreTarget(country, city);
|
|
130
|
+
const href = this.pageUpdateHref(target);
|
|
128
131
|
return html `
|
|
129
132
|
<coras-explore-card
|
|
130
133
|
image=${imageUrl}
|
|
@@ -134,7 +137,11 @@ let CorasSuggestionWidget = class CorasSuggestionWidget extends BaseMixin(LitEle
|
|
|
134
137
|
<coras-button
|
|
135
138
|
slot="button"
|
|
136
139
|
variant="outlined"
|
|
137
|
-
|
|
140
|
+
href=${ifDefined(href)}
|
|
141
|
+
@click=${(event) => {
|
|
142
|
+
if (!href || claimLinkClick(event))
|
|
143
|
+
this.dispatchPageUpdate(target);
|
|
144
|
+
}}
|
|
138
145
|
>
|
|
139
146
|
${msg("See all activities")}
|
|
140
147
|
</coras-button>
|