@mintmoney/react 0.2.0-alpha.0 → 0.2.0-alpha.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 (120) hide show
  1. package/dist/css/styles.css +10 -0
  2. package/dist/docs/customisation.md +8 -0
  3. package/dist/esm/api/generated.js.map +1 -1
  4. package/dist/esm/api/types.js +3 -0
  5. package/dist/esm/api/types.js.map +1 -1
  6. package/dist/esm/checkout/claimable-funds.js +26 -0
  7. package/dist/esm/checkout/claimable-funds.js.map +1 -0
  8. package/dist/esm/checkout/creation-error-modal.js +6 -0
  9. package/dist/esm/checkout/creation-error-modal.js.map +1 -0
  10. package/dist/esm/checkout/index.js +29 -3
  11. package/dist/esm/checkout/index.js.map +1 -1
  12. package/dist/esm/checkout/modal.js +71 -68
  13. package/dist/esm/checkout/modal.js.map +1 -1
  14. package/dist/esm/checkout/payment-status.js +55 -0
  15. package/dist/esm/checkout/payment-status.js.map +1 -0
  16. package/dist/esm/checkout/providers/checkout-wallet.js +219 -0
  17. package/dist/esm/checkout/providers/checkout-wallet.js.map +1 -0
  18. package/dist/esm/checkout/providers/wagmi-config.js +49 -46
  19. package/dist/esm/checkout/providers/wagmi-config.js.map +1 -1
  20. package/dist/esm/checkout/refund-availability.js +16 -0
  21. package/dist/esm/checkout/refund-availability.js.map +1 -0
  22. package/dist/esm/checkout/resume-state.js +5 -14
  23. package/dist/esm/checkout/resume-state.js.map +1 -1
  24. package/dist/esm/checkout/views/claimable-funds.js +29 -0
  25. package/dist/esm/checkout/views/claimable-funds.js.map +1 -0
  26. package/dist/esm/checkout/views/crypto-intent/direct-details.js +13 -2
  27. package/dist/esm/checkout/views/crypto-intent/direct-details.js.map +1 -1
  28. package/dist/esm/checkout/views/crypto-intent/methods.js +22 -123
  29. package/dist/esm/checkout/views/crypto-intent/methods.js.map +1 -1
  30. package/dist/esm/checkout/views/crypto-intent/processing.js +45 -58
  31. package/dist/esm/checkout/views/crypto-intent/processing.js.map +1 -1
  32. package/dist/esm/checkout/views/crypto-intent/success.js +23 -38
  33. package/dist/esm/checkout/views/crypto-intent/success.js.map +1 -1
  34. package/dist/esm/checkout/views/crypto-intent/test-payment.js +11 -1
  35. package/dist/esm/checkout/views/crypto-intent/test-payment.js.map +1 -1
  36. package/dist/esm/checkout/views/crypto-intent/wallet-payment-options.js +54 -565
  37. package/dist/esm/checkout/views/crypto-intent/wallet-payment-options.js.map +1 -1
  38. package/dist/esm/checkout/views/crypto-intent/wallet-select.js +10 -160
  39. package/dist/esm/checkout/views/crypto-intent/wallet-select.js.map +1 -1
  40. package/dist/esm/checkout/views/failed.js +22 -39
  41. package/dist/esm/checkout/views/failed.js.map +1 -1
  42. package/dist/esm/checkout/views/initial.js +13 -9
  43. package/dist/esm/checkout/views/initial.js.map +1 -1
  44. package/dist/esm/checkout/views/method-select.js +12 -7
  45. package/dist/esm/checkout/views/method-select.js.map +1 -1
  46. package/dist/esm/checkout/views/restart.js +4 -1
  47. package/dist/esm/checkout/views/restart.js.map +1 -1
  48. package/dist/esm/refund/index.js +1 -1
  49. package/dist/esm/refund/index.js.map +1 -1
  50. package/dist/esm/state/checkout/checkout-state.js +60 -0
  51. package/dist/esm/state/checkout/checkout-state.js.map +1 -0
  52. package/dist/esm/state/checkout/payment-attempt.js +6 -0
  53. package/dist/esm/state/checkout/payment-attempt.js.map +1 -1
  54. package/dist/esm/state/checkout/payment-lifecycle.js +13 -1
  55. package/dist/esm/state/checkout/payment-lifecycle.js.map +1 -1
  56. package/dist/esm/state/checkout/quote-lifecycle.js +377 -0
  57. package/dist/esm/state/checkout/quote-lifecycle.js.map +1 -0
  58. package/dist/esm/state/checkout/store.js +169 -495
  59. package/dist/esm/state/checkout/store.js.map +1 -1
  60. package/dist/esm/state/checkout/wallet-payment-options.js +0 -32
  61. package/dist/esm/state/checkout/wallet-payment-options.js.map +1 -1
  62. package/dist/esm/state/checkout/wallet-payment.js +158 -0
  63. package/dist/esm/state/checkout/wallet-payment.js.map +1 -0
  64. package/dist/types/api/generated.d.ts +55 -7
  65. package/dist/types/api/generated.d.ts.map +1 -1
  66. package/dist/types/api/types.d.ts +4 -1
  67. package/dist/types/api/types.d.ts.map +1 -1
  68. package/dist/types/checkout/claimable-funds.d.ts +9 -0
  69. package/dist/types/checkout/claimable-funds.d.ts.map +1 -0
  70. package/dist/types/checkout/creation-error-modal.d.ts +9 -0
  71. package/dist/types/checkout/creation-error-modal.d.ts.map +1 -0
  72. package/dist/types/checkout/index.d.ts.map +1 -1
  73. package/dist/types/checkout/modal.d.ts +1 -1
  74. package/dist/types/checkout/modal.d.ts.map +1 -1
  75. package/dist/types/checkout/payment-status.d.ts +23 -0
  76. package/dist/types/checkout/payment-status.d.ts.map +1 -0
  77. package/dist/types/checkout/providers/checkout-wallet.d.ts +24 -0
  78. package/dist/types/checkout/providers/checkout-wallet.d.ts.map +1 -0
  79. package/dist/types/checkout/providers/wagmi-config.d.ts +8 -2
  80. package/dist/types/checkout/providers/wagmi-config.d.ts.map +1 -1
  81. package/dist/types/checkout/refund-availability.d.ts +2 -0
  82. package/dist/types/checkout/refund-availability.d.ts.map +1 -0
  83. package/dist/types/checkout/resume-state.d.ts +0 -4
  84. package/dist/types/checkout/resume-state.d.ts.map +1 -1
  85. package/dist/types/checkout/views/claimable-funds.d.ts +2 -0
  86. package/dist/types/checkout/views/claimable-funds.d.ts.map +1 -0
  87. package/dist/types/checkout/views/crypto-intent/direct-details.d.ts.map +1 -1
  88. package/dist/types/checkout/views/crypto-intent/methods.d.ts.map +1 -1
  89. package/dist/types/checkout/views/crypto-intent/processing.d.ts +3 -5
  90. package/dist/types/checkout/views/crypto-intent/processing.d.ts.map +1 -1
  91. package/dist/types/checkout/views/crypto-intent/success.d.ts +1 -2
  92. package/dist/types/checkout/views/crypto-intent/success.d.ts.map +1 -1
  93. package/dist/types/checkout/views/crypto-intent/test-payment.d.ts.map +1 -1
  94. package/dist/types/checkout/views/crypto-intent/wallet-payment-options.d.ts.map +1 -1
  95. package/dist/types/checkout/views/crypto-intent/wallet-select.d.ts.map +1 -1
  96. package/dist/types/checkout/views/failed.d.ts.map +1 -1
  97. package/dist/types/checkout/views/initial.d.ts.map +1 -1
  98. package/dist/types/checkout/views/method-select.d.ts +2 -1
  99. package/dist/types/checkout/views/method-select.d.ts.map +1 -1
  100. package/dist/types/checkout/views/restart.d.ts.map +1 -1
  101. package/dist/types/components/wallet-selector/wallets/wagmi/index.d.ts +1 -1
  102. package/dist/types/state/checkout/checkout-state.d.ts +70 -0
  103. package/dist/types/state/checkout/checkout-state.d.ts.map +1 -0
  104. package/dist/types/state/checkout/payment-attempt.d.ts +1 -0
  105. package/dist/types/state/checkout/payment-attempt.d.ts.map +1 -1
  106. package/dist/types/state/checkout/payment-lifecycle.d.ts +2 -0
  107. package/dist/types/state/checkout/payment-lifecycle.d.ts.map +1 -1
  108. package/dist/types/state/checkout/quote-lifecycle.d.ts +28 -0
  109. package/dist/types/state/checkout/quote-lifecycle.d.ts.map +1 -0
  110. package/dist/types/state/checkout/store.d.ts +17 -84
  111. package/dist/types/state/checkout/store.d.ts.map +1 -1
  112. package/dist/types/state/checkout/wallet-payment-options.d.ts +0 -16
  113. package/dist/types/state/checkout/wallet-payment-options.d.ts.map +1 -1
  114. package/dist/types/state/checkout/wallet-payment.d.ts +13 -0
  115. package/dist/types/state/checkout/wallet-payment.d.ts.map +1 -0
  116. package/package.json +1 -1
  117. package/dist/esm/checkout/providers/wallet-connect-resume.js +0 -129
  118. package/dist/esm/checkout/providers/wallet-connect-resume.js.map +0 -1
  119. package/dist/types/checkout/providers/wallet-connect-resume.d.ts +0 -9
  120. package/dist/types/checkout/providers/wallet-connect-resume.d.ts.map +0 -1
@@ -1,25 +1,18 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useAppKit } from "@reown/appkit/react";
3
- import { disconnect } from "@wagmi/core";
4
- import { useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
2
+ import { useEffect, useRef, useState } from "react";
5
3
  import { keyframes, styled } from "styled-components";
6
- import { useAccount, useConfig } from "wagmi";
7
- import { confirmPayment } from "../../../api/payments.js";
8
4
  import { EditIcon, LogOutIcon } from "../../../components/icons/index.js";
9
5
  import { QuoteExpiryCountdown, StyledButton, Text, useModalWithView, } from "../../../components/index.js";
10
- import { WalletContext } from "../../../components/wallet-selector/provider.js";
11
- import { useWalletActions } from "../../../components/wallet-selector/store.js";
12
- import { WagmiWalletInterface } from "../../../components/wallet-selector/wallets/wagmi/index.js";
13
6
  import { useMintMoneyConfig } from "../../../context.js";
14
- import { executeWalletPaymentOption, fetchWalletPaymentQuote, findWalletPaymentOptions, } from "../../../integrations/index.js";
15
- import { clearQuoteRefresh, checkChainStatus, configureWalletQuoteRefresh, createWalletOptionPaymentAttempt, executeTransfer, prepareWalletQuoteReplacement, resetWalletPaymentState, setProcessing, setSelectedCurrency, setWalletPaymentState, useCheckoutStore, } from "../../../state/checkout/store.js";
16
- import { buildWalletPaymentOptionsLoadKey, buildWalletQuoteLoadKey, buildWalletPaymentOptionsReadyState, NO_WALLET_PAYMENT_OPTIONS_DESCRIPTION, NO_WALLET_PAYMENT_OPTIONS_TITLE, } from "../../../state/checkout/wallet-payment-options.js";
7
+ import { clearQuoteRefresh, loadWalletPaymentQuote, prepareWalletQuoteReplacement, useCheckoutStore, } from "../../../state/checkout/store.js";
8
+ import { NO_WALLET_PAYMENT_OPTIONS_DESCRIPTION, NO_WALLET_PAYMENT_OPTIONS_TITLE, } from "../../../state/checkout/wallet-payment-options.js";
9
+ import { loadWalletPaymentOptions, payWithWallet, retryWalletPayment, } from "../../../state/checkout/wallet-payment.js";
17
10
  import { formatAddress } from "../../../utils/string.js";
18
- import { messageForWalletError } from "../../../utils/wallet-errors.js";
19
11
  import { ModalViewContainer } from "../../container.js";
20
- import { clearCheckoutResumeState, readCheckoutResumeState, writeCheckoutResumeState, writePendingWalletConnectionResumeState, } from "../../resume-state.js";
12
+ import { useCheckoutWallet, } from "../../providers/checkout-wallet.js";
21
13
  import { ModalBackButton } from "../back.js";
22
14
  import { resolveWalletPaymentConfirmationAmount } from "./wallet-payment-confirmation-amount.js";
15
+ import { CryptoIntentSelectWalletViewContent } from "./wallet-select.js";
23
16
  const QUOTE_COUNTDOWN_URGENT_THRESHOLD_RATIO = 0.25;
24
17
  const pillSlideIn = keyframes `
25
18
  from {
@@ -601,574 +594,75 @@ const getTokenMonogram = (tokenName, tokenSymbol) => {
601
594
  return tokenSymbol.slice(0, 2).toUpperCase();
602
595
  return tokenName.slice(0, 2).toUpperCase();
603
596
  };
604
- const buildDirectQuote = (option, context) => {
605
- const amount = String(context.cryptoPaymentAttempt.amount_formatted);
606
- const formattedAmount = formatDisplayAmount(amount) ?? amount;
607
- const amountDisplay = formatTokenBalance(option.fromTokenSymbol ?? option.fromTokenName, formattedAmount) ?? formattedAmount;
608
- return {
609
- quoteId: option.quoteId,
610
- routeId: option.routeId,
611
- toolName: "Direct transfer",
612
- fromAmount: amount,
613
- fromAmountDisplay: amountDisplay,
614
- toAmount: amount,
615
- toAmountDisplay: amountDisplay,
616
- estimatedDurationMinutes: 1,
617
- };
618
- };
619
- const CryptoIntentWalletPaymentOptionsAppKitViewContent = () => {
597
+ const ConnectedWalletPaymentOptions = ({ connection, }) => {
620
598
  const modalRef = useRef(null);
621
- const isChangingWalletRef = useRef(false);
622
- const lastWalletOptionsLoadKeyRef = useRef(null);
623
- const walletOptionsRequestRef = useRef(null);
624
- const lastQuoteLoadKeyRef = useRef(null);
625
599
  const { goToView } = useModalWithView();
626
- const { open } = useAppKit();
627
600
  const config = useMintMoneyConfig();
628
- const wagmiConfig = useConfig();
629
- const { wallet, setWallet } = useContext(WalletContext);
630
- const { initialiseWallets } = useWalletActions();
631
- const account = useAccount();
632
- const { payment, cryptoPaymentAttempt, cryptoCurrency, walletPayment, quote, loading, processing, } = useCheckoutStore();
633
- const [executingId, setExecutingId] = useState(null);
601
+ const session = useCheckoutWallet();
602
+ const { wallet: activeWallet, address: walletAddress, connectorIcon, } = connection;
603
+ const { payment, cryptoPaymentAttempt, cryptoCurrency, walletPayment, quote, processing, } = useCheckoutStore();
634
604
  const [paymentDetailsExpanded, setPaymentDetailsExpanded] = useState(false);
635
- const isWalletConnectionSettling = account.status === "connecting" || account.status === "reconnecting";
636
- const connectorName = account.connector?.name || "Connected wallet";
637
- const connectorIcon = typeof account.connector?.icon === "string"
638
- ? account.connector.icon
639
- : undefined;
640
- const connectedWagmiWallet = useMemo(() => {
641
- if (!account.isConnected || !account.address || !account.connector) {
642
- return null;
643
- }
644
- return new WagmiWalletInterface(account.connector, wagmiConfig);
645
- }, [account.address, account.connector, account.isConnected, wagmiConfig]);
646
- const activeWallet = connectedWagmiWallet ?? wallet;
647
- useEffect(() => {
648
- if (!connectedWagmiWallet) {
649
- return;
650
- }
651
- setWallet(connectedWagmiWallet);
652
- initialiseWallets([() => connectedWagmiWallet]);
653
- }, [connectedWagmiWallet, initialiseWallets, setWallet]);
654
- const buildContext = useCallback(async (currentPayment) => {
655
- const state = useCheckoutStore.getState();
656
- const currentCheckout = state.checkout;
657
- const currentCryptoCurrency = state.cryptoCurrency;
658
- if (!currentCheckout || !currentCryptoCurrency || !activeWallet) {
659
- throw new Error("Wallet payment context is not ready");
660
- }
661
- const resolvedPayment = currentPayment ?? state.payment;
662
- if (!resolvedPayment) {
663
- throw new Error("Missing payment");
664
- }
665
- const walletAddress = await activeWallet.getAddress();
666
- if (!walletAddress) {
667
- throw new Error("Failed to get wallet address");
668
- }
669
- return {
670
- checkout: currentCheckout,
671
- payment: resolvedPayment,
672
- settlementCurrency: currentCryptoCurrency,
673
- walletAddress,
674
- };
675
- }, [activeWallet]);
676
- const loadWalletPaymentOptions = useCallback(async (isCancelled, options = {}) => {
677
- const preparedContext = await buildContext();
678
- const loadKey = buildWalletPaymentOptionsLoadKey({
679
- paymentId: preparedContext.payment.id,
680
- settlementChain: preparedContext.settlementCurrency.chain,
681
- settlementAsset: preparedContext.settlementCurrency.asset,
682
- walletAddress: preparedContext.walletAddress,
683
- });
684
- if (!loadKey) {
685
- throw new Error("Wallet payment context is not ready");
686
- }
687
- const currentWalletPayment = useCheckoutStore.getState().walletPayment;
688
- const isSameWallet = currentWalletPayment.walletAddress?.toLowerCase() ===
689
- preparedContext.walletAddress.toLowerCase();
690
- const canReuseLoadedOptions = !options.force &&
691
- lastWalletOptionsLoadKeyRef.current === loadKey &&
692
- isSameWallet &&
693
- currentWalletPayment.status !== "failed";
694
- if (canReuseLoadedOptions) {
695
- return;
696
- }
697
- setProcessing(true);
698
- setSelectedCurrency(cryptoCurrency);
699
- const shouldPreserveVisibleOptions = isSameWallet &&
700
- currentWalletPayment.options.length > 0 &&
701
- currentWalletPayment.status !== "failed";
702
- if (shouldPreserveVisibleOptions) {
703
- setWalletPaymentState({ status: "ready", error: null });
704
- }
705
- else {
706
- resetWalletPaymentState();
707
- setWalletPaymentState({ status: "loading", error: null, options: [] });
708
- }
709
- writeCheckoutResumeState(preparedContext.payment.id, {
710
- view: "cryptoIntentWalletPaymentOptions",
711
- walletAddress: preparedContext.walletAddress,
712
- pendingWalletConnection: false,
713
- });
714
- const existingRequest = walletOptionsRequestRef.current;
715
- const request = existingRequest?.key === loadKey
716
- ? existingRequest.promise
717
- : findWalletPaymentOptions(preparedContext);
718
- if (existingRequest?.key !== loadKey) {
719
- walletOptionsRequestRef.current = {
720
- key: loadKey,
721
- promise: request,
722
- };
723
- void request
724
- .finally(() => {
725
- if (walletOptionsRequestRef.current?.key === loadKey) {
726
- walletOptionsRequestRef.current = null;
727
- }
728
- })
729
- .catch(() => undefined);
730
- }
731
- const providerOptions = await request;
732
- if (isCancelled()) {
733
- return;
734
- }
735
- const resumeState = readCheckoutResumeState(preparedContext.payment.id);
736
- const shouldRestoreSelectedOption = resumeState.walletAddress?.toLowerCase() ===
737
- preparedContext.walletAddress.toLowerCase() &&
738
- Boolean(resumeState.selectedWalletOptionId &&
739
- providerOptions.some((option) => option.id === resumeState.selectedWalletOptionId));
740
- setWalletPaymentState({
741
- ...buildWalletPaymentOptionsReadyState({
742
- walletAddress: preparedContext.walletAddress,
743
- options: providerOptions,
744
- }),
745
- selectedOptionId: shouldRestoreSelectedOption
746
- ? resumeState.selectedWalletOptionId || null
747
- : null,
748
- });
749
- lastWalletOptionsLoadKeyRef.current = loadKey;
750
- }, [buildContext, cryptoCurrency]);
751
- const handleMissingAccount = useCallback(() => {
752
- resetWalletPaymentState();
753
- clearQuoteRefresh();
754
- setProcessing(false);
755
- goToView("cryptoIntent");
756
- }, [goToView]);
757
- const handleMissingWalletConnection = useCallback(() => {
758
- goToView("failed", { reason: "wallet_not_connected" });
759
- }, [goToView]);
760
- const handleWalletPaymentOptionsError = useCallback((error) => {
761
- const message = error instanceof Error ? error.message : "Failed to load payment options";
762
- setWalletPaymentState({
763
- status: "failed",
764
- error: message,
765
- options: [],
766
- });
767
- }, []);
768
- const shouldPreserveSubmittedFailure = walletPayment.status === "failed" &&
769
- walletPayment.options.length > 0 &&
770
- Boolean(walletPayment.sourceTxHash);
771
605
  useEffect(() => {
772
- if (isWalletConnectionSettling) {
773
- setProcessing(true);
774
- return;
775
- }
776
- if (!account.isConnected || !account.address) {
777
- if (isChangingWalletRef.current) {
778
- setProcessing(false);
779
- return;
780
- }
781
- handleMissingAccount();
782
- return;
783
- }
784
- isChangingWalletRef.current = false;
785
- if (!activeWallet || !cryptoCurrency) {
786
- handleMissingWalletConnection();
787
- return;
788
- }
789
- if (shouldPreserveSubmittedFailure) {
790
- setProcessing(false);
791
- return;
792
- }
793
- const currentWalletPayment = useCheckoutStore.getState().walletPayment;
794
- if (currentWalletPayment.selectedOptionId ||
795
- currentWalletPayment.status === "executing" ||
796
- currentWalletPayment.status === "submitted") {
797
- if (currentWalletPayment.status !== "executing") {
798
- setProcessing(false);
799
- }
800
- return;
801
- }
802
- let cancelled = false;
803
- const loadOptions = async () => {
804
- try {
805
- await loadWalletPaymentOptions(() => cancelled);
806
- }
807
- catch (error) {
808
- if (cancelled)
809
- return;
810
- handleWalletPaymentOptionsError(error);
811
- }
812
- finally {
813
- if (!cancelled) {
814
- setProcessing(false);
815
- }
816
- }
817
- };
818
- void loadOptions();
819
- return () => {
820
- cancelled = true;
821
- clearQuoteRefresh();
822
- };
823
- }, [
824
- account.address,
825
- account.isConnected,
826
- activeWallet,
827
- cryptoCurrency,
828
- handleMissingAccount,
829
- handleMissingWalletConnection,
830
- handleWalletPaymentOptionsError,
831
- isWalletConnectionSettling,
832
- loadWalletPaymentOptions,
833
- shouldPreserveSubmittedFailure,
834
- walletPayment.selectedOptionId,
835
- ]);
606
+ if (cryptoCurrency)
607
+ void loadWalletPaymentOptions(walletAddress, session.capture());
608
+ }, [cryptoCurrency, walletAddress, session.capture]);
609
+ useEffect(() => () => clearQuoteRefresh({ preserveWalletAddress: true }), []);
836
610
  const selectedOption = walletPayment.options.find((option) => option.id === walletPayment.selectedOptionId) ?? null;
837
611
  const hasNoPaymentOptions = walletPayment.status === "ready" && walletPayment.options.length === 0;
838
- const unsupportedWalletAddress = walletPayment.walletAddress ?? account.address ?? null;
839
- const quoteLoadKey = buildWalletQuoteLoadKey({
840
- paymentId: payment?.id,
841
- paymentAmount: payment?.amount,
842
- paymentCurrency: payment?.currency,
843
- paymentExpiresAt: payment?.expires_at,
844
- settlementChain: cryptoCurrency?.chain,
845
- settlementAsset: cryptoCurrency?.asset,
846
- walletAddress: walletPayment.walletAddress ?? account.address,
847
- option: selectedOption,
848
- });
849
612
  const confirmationAmount = selectedOption && payment
850
613
  ? resolveWalletPaymentConfirmationAmount({
851
614
  option: selectedOption,
852
- quote: walletPayment.quote,
615
+ quote: quote.data,
853
616
  attempt: cryptoPaymentAttempt,
854
617
  })
855
618
  : null;
856
619
  const displayedPayAmount = confirmationAmount?.amount ??
857
- (selectedOption && walletPayment.quoteStatus === "loading"
620
+ (selectedOption && quote.status === "refreshing"
858
621
  ? "Fetching quote..."
859
- : selectedOption && walletPayment.quoteStatus === "failed"
622
+ : selectedOption && quote.status === "failed"
860
623
  ? "Unavailable"
861
624
  : null);
862
625
  const formattedCost = formatMoneyAmount(payment?.currency ?? "USD", Number(payment?.amount ?? 0));
863
626
  const handlePickOption = (option) => {
864
- lastQuoteLoadKeyRef.current = null;
865
- prepareWalletQuoteReplacement(walletPayment.walletAddress);
627
+ prepareWalletQuoteReplacement(walletAddress, option.id);
866
628
  setPaymentDetailsExpanded(false);
867
- writeCheckoutResumeState(payment?.id, {
868
- view: "cryptoIntentWalletPaymentOptions",
869
- walletAddress: walletPayment.walletAddress ?? account.address ?? null,
870
- selectedWalletOptionId: option.id,
871
- });
872
- setWalletPaymentState({
873
- selectedOptionId: option.id,
874
- error: null,
875
- quoteId: null,
876
- routeId: null,
877
- quoteStatus: "idle",
878
- quote: null,
879
- quoteError: null,
880
- });
881
629
  };
882
630
  const handleReturnToOptions = () => {
883
- lastQuoteLoadKeyRef.current = null;
884
- prepareWalletQuoteReplacement(walletPayment.walletAddress);
631
+ prepareWalletQuoteReplacement(walletAddress, null);
885
632
  setPaymentDetailsExpanded(false);
886
- writeCheckoutResumeState(payment?.id, {
887
- view: "cryptoIntentWalletPaymentOptions",
888
- walletAddress: walletPayment.walletAddress ?? account.address ?? null,
889
- selectedWalletOptionId: null,
890
- });
891
- setWalletPaymentState({
892
- selectedOptionId: null,
893
- error: null,
894
- quoteStatus: "idle",
895
- quote: null,
896
- quoteError: null,
897
- });
898
633
  };
899
- const handleChangeWallet = useCallback(() => {
900
- isChangingWalletRef.current = true;
901
- writePendingWalletConnectionResumeState(payment?.id, "cryptoIntentWalletPaymentOptions");
902
- void open({ view: "Connect", namespace: "eip155" });
903
- }, [open, payment?.id]);
904
- const handleDisconnectWallet = useCallback(() => {
905
- isChangingWalletRef.current = false;
906
- clearCheckoutResumeState(payment?.id);
907
- resetWalletPaymentState();
908
- clearQuoteRefresh();
909
- setWallet(null);
910
- setProcessing(false);
634
+ const handleChangeWallet = () => {
635
+ void session.connect();
636
+ };
637
+ const handleDisconnectWallet = () => {
638
+ void session.disconnect();
911
639
  goToView("cryptoIntent");
912
- void disconnect(wagmiConfig).catch((error) => {
913
- console.warn("Unable to disconnect wallet", error);
914
- });
915
- }, [goToView, payment?.id, setWallet, wagmiConfig]);
916
- const confirmDirectWalletPayment = async (txHash) => {
917
- if (!payment) {
918
- throw new Error("Missing payment");
919
- }
920
- try {
921
- await confirmPayment(payment.id, { txHash });
922
- }
923
- catch (error) {
924
- const message = messageForWalletError(error, "Failed to confirm wallet payment");
925
- setWalletPaymentState({
926
- status: "failed",
927
- error: message,
928
- });
929
- goToView("cryptoIntentWalletPaymentOptions");
930
- }
931
640
  };
641
+ const selectedOptionId = walletPayment.selectedOptionId;
932
642
  useEffect(() => {
933
- if (!selectedOption || !quoteLoadKey || !cryptoCurrency) {
934
- if (!selectedOption) {
935
- lastQuoteLoadKeyRef.current = null;
936
- }
937
- return;
938
- }
939
- if (lastQuoteLoadKeyRef.current === quoteLoadKey) {
643
+ if (!selectedOptionId)
940
644
  return;
941
- }
942
- lastQuoteLoadKeyRef.current = quoteLoadKey;
943
- let cancelled = false;
944
- const loadQuote = async () => {
945
- const currentPayment = useCheckoutStore.getState().payment;
946
- if (!currentPayment?.id) {
947
- return;
948
- }
949
- try {
950
- prepareWalletQuoteReplacement(walletPayment.walletAddress ?? account.address ?? null);
951
- setWalletPaymentState({
952
- quoteStatus: "loading",
953
- quote: null,
954
- quoteError: null,
955
- quoteId: null,
956
- routeId: null,
957
- });
958
- const preparedContext = await buildContext(currentPayment);
959
- const walletAddress = await activeWallet?.getAddress();
960
- if (!walletAddress) {
961
- throw new Error("Failed to get wallet address");
962
- }
963
- const ensuredAttempt = await createWalletOptionPaymentAttempt(selectedOption, walletAddress, null);
964
- if (cancelled) {
965
- return;
966
- }
967
- const quoteContext = {
968
- ...preparedContext,
969
- cryptoPaymentAttempt: ensuredAttempt,
970
- };
971
- if (selectedOption.kind === "direct") {
972
- const directQuote = buildDirectQuote(selectedOption, quoteContext);
973
- setWalletPaymentState({
974
- quoteStatus: "ready",
975
- quote: directQuote,
976
- quoteId: directQuote.quoteId,
977
- routeId: directQuote.routeId,
978
- quoteError: null,
979
- });
980
- configureWalletQuoteRefresh(walletAddress);
981
- return;
982
- }
983
- const quote = await fetchWalletPaymentQuote({
984
- option: selectedOption,
985
- context: quoteContext,
986
- });
987
- if (cancelled) {
988
- return;
989
- }
990
- setWalletPaymentState({
991
- quoteStatus: "ready",
992
- quote,
993
- quoteId: quote.quoteId,
994
- routeId: quote.routeId,
995
- quoteError: null,
996
- });
997
- configureWalletQuoteRefresh(walletAddress);
998
- }
999
- catch (error) {
1000
- if (cancelled) {
1001
- return;
1002
- }
1003
- const message = error instanceof Error ? error.message : "Failed to load route quote";
1004
- setWalletPaymentState({
1005
- quoteStatus: "failed",
1006
- quote: null,
1007
- quoteError: message,
1008
- });
1009
- clearQuoteRefresh({ preserveWalletAddress: true });
1010
- }
1011
- };
1012
- void loadQuote();
1013
- return () => {
1014
- cancelled = true;
1015
- };
1016
- }, [
1017
- account.address,
1018
- activeWallet,
1019
- buildContext,
1020
- cryptoCurrency,
1021
- goToView,
1022
- quoteLoadKey,
1023
- selectedOption,
1024
- walletPayment.walletAddress,
1025
- ]);
1026
- const handleSelectOption = async (option) => {
1027
- if (!activeWallet || !payment || !cryptoCurrency) {
1028
- goToView("failed", { reason: "wallet_not_connected" });
1029
- return;
1030
- }
1031
- try {
1032
- setExecutingId(option.id);
1033
- setProcessing(true);
1034
- setSelectedCurrency(cryptoCurrency);
1035
- setWalletPaymentState({
1036
- status: "executing",
1037
- selectedOptionId: option.id,
1038
- error: null,
1039
- quoteId: null,
1040
- routeId: null,
1041
- });
1042
- const walletAddress = await activeWallet.getAddress();
1043
- if (!walletAddress) {
1044
- throw new Error("Failed to get wallet address");
1045
- }
1046
- writeCheckoutResumeState(payment.id, {
1047
- view: "cryptoIntentWalletPaymentOptions",
1048
- walletAddress,
1049
- selectedWalletOptionId: option.id,
1050
- });
1051
- const ensuredAttempt = await createWalletOptionPaymentAttempt(option, walletAddress, option.kind === "direct" ? null : walletPayment.quote);
1052
- const preparedContext = {
1053
- ...(await buildContext(payment)),
1054
- cryptoPaymentAttempt: ensuredAttempt,
1055
- };
1056
- if (option.kind === "direct") {
1057
- const txHash = await executeTransfer(activeWallet);
1058
- if (!txHash) {
1059
- throw new Error("Failed to get transaction hash");
1060
- }
1061
- setWalletPaymentState({
1062
- status: "submitted",
1063
- sourceTxHash: txHash,
1064
- destinationTxHash: null,
1065
- quoteId: null,
1066
- routeId: null,
1067
- });
1068
- goToView("paymentStatus");
1069
- void (async () => {
1070
- try {
1071
- await checkChainStatus(activeWallet);
1072
- await confirmDirectWalletPayment(txHash);
1073
- }
1074
- catch (error) {
1075
- const message = messageForWalletError(error, "Failed to confirm wallet payment");
1076
- setWalletPaymentState({
1077
- status: "failed",
1078
- error: message,
1079
- });
1080
- goToView("cryptoIntentWalletPaymentOptions");
1081
- }
1082
- })();
1083
- return;
1084
- }
1085
- else {
1086
- const freshQuote = await fetchWalletPaymentQuote({
1087
- option,
1088
- context: preparedContext,
1089
- });
1090
- if (!freshQuote.quoteId) {
1091
- throw new Error("Missing LI.FI quote id for routed wallet payment");
1092
- }
1093
- setWalletPaymentState({
1094
- quoteStatus: "ready",
1095
- quote: freshQuote,
1096
- quoteId: freshQuote.quoteId,
1097
- routeId: freshQuote.routeId,
1098
- quoteError: null,
1099
- });
1100
- const result = await executeWalletPaymentOption({
1101
- option,
1102
- wallet: activeWallet,
1103
- context: preparedContext,
1104
- quote: freshQuote,
1105
- });
1106
- const confirmationTxHash = result?.destinationTxHash ?? null;
1107
- if (!confirmationTxHash) {
1108
- throw new Error("Missing destination transaction hash for routed wallet payment");
1109
- }
1110
- await confirmPayment(payment.id, {
1111
- txHash: confirmationTxHash,
1112
- lifiQuote: {
1113
- quote_id: freshQuote.quoteId,
1114
- route_id: freshQuote.routeId ?? null,
1115
- route: freshQuote.raw,
1116
- },
1117
- });
1118
- setWalletPaymentState({
1119
- status: "submitted",
1120
- sourceTxHash: result?.sourceTxHash ?? null,
1121
- destinationTxHash: confirmationTxHash,
1122
- quoteId: freshQuote.quoteId,
1123
- routeId: freshQuote.routeId,
1124
- });
1125
- }
1126
- goToView("paymentStatus");
1127
- }
1128
- catch (error) {
1129
- const message = messageForWalletError(error, "Failed to execute wallet payment");
1130
- setWalletPaymentState({
1131
- status: "failed",
1132
- error: message,
1133
- });
1134
- }
1135
- finally {
1136
- setExecutingId(null);
1137
- setProcessing(false);
1138
- }
645
+ // The lifecycle owns cancellation and renewal. Returned payment/attempt
646
+ // snapshots update the displayed quote without restarting this request.
647
+ void loadWalletPaymentQuote(walletAddress, session.capture());
648
+ }, [selectedOptionId, walletAddress, session.capture]);
649
+ const paymentSession = () => ({
650
+ wallet: activeWallet,
651
+ address: walletAddress,
652
+ ownsConnection: session.capture(),
653
+ onStatusChange: (status) => goToView(status === "submitted"
654
+ ? "paymentStatus"
655
+ : "cryptoIntentWalletPaymentOptions"),
656
+ });
657
+ const handleSelectOption = () => {
658
+ void payWithWallet(paymentSession());
1139
659
  };
1140
660
  const handleRetryWalletPayment = () => {
1141
- if (selectedOption) {
1142
- if (walletPayment.sourceTxHash &&
1143
- useCheckoutStore.getState().transfer.chainStatus === "confirmed") {
1144
- setWalletPaymentState({ status: "submitted", error: null });
1145
- goToView("paymentStatus");
1146
- void confirmDirectWalletPayment(walletPayment.sourceTxHash);
1147
- return;
1148
- }
1149
- setWalletPaymentState({ status: "ready", error: null });
1150
- void handleSelectOption(selectedOption);
1151
- return;
1152
- }
1153
- const retry = async () => {
1154
- try {
1155
- await loadWalletPaymentOptions(() => false, { force: true });
1156
- }
1157
- catch (error) {
1158
- handleWalletPaymentOptionsError(error);
1159
- }
1160
- finally {
1161
- setProcessing(false);
1162
- }
1163
- };
1164
- void retry();
661
+ void retryWalletPayment(paymentSession());
1165
662
  };
1166
- const showWalletPill = account.isConnected &&
1167
- Boolean(account.address) &&
1168
- walletPayment.status !== "loading" &&
1169
- walletPayment.status !== "failed";
1170
- const walletAddressForPill = walletPayment.walletAddress ?? account.address ?? null;
1171
- const walletAddressForHeader = walletPayment.walletAddress ?? account.address ?? null;
663
+ const showWalletPill = walletPayment.status !== "loading" && walletPayment.status !== "failed";
664
+ const walletAddressForPill = walletAddress;
665
+ const walletAddressForHeader = walletAddress;
1172
666
  return (_jsxs(ModalViewContainer, { ref: modalRef, children: [showWalletPill && walletAddressForPill && selectedOption ? (_jsxs(ContextStrip, { children: [_jsx(QuoteExpiryCountdown, { remainingMs: quote.remainingMs, totalDurationMs: quote.totalDurationMs, primaryColor: config.theme.btn.primary.default.backgroundColor, urgentThresholdRatio: QUOTE_COUNTDOWN_URGENT_THRESHOLD_RATIO }), _jsxs(ContextPill, { children: [_jsxs(ContextPillToggle, { type: "button", onClick: () => setPaymentDetailsExpanded((expanded) => !expanded), "aria-expanded": paymentDetailsExpanded, children: [_jsxs(PillIconWrap, { children: [_jsx(PillTokenIcon, { "$iconUrl": selectedOption.fromTokenIconUrl, children: !selectedOption.fromTokenIconUrl
1173
667
  ? getTokenMonogram(selectedOption.fromTokenName, selectedOption.fromTokenSymbol)
1174
668
  : null }), selectedOption.fromChainIconUrl ? (_jsx(PillChainBadge, { "$iconUrl": selectedOption.fromChainIconUrl })) : null] }), _jsxs(PillBody, { children: [_jsx(PillEyebrow, { children: "You send" }), _jsxs(PillTitle, { children: [selectedOption.fromTokenSymbol, " on", " ", selectedOption.fromChainName] })] }), _jsx(PillAction, { type: "button", onClick: (event) => {
@@ -1176,32 +670,27 @@ const CryptoIntentWalletPaymentOptionsAppKitViewContent = () => {
1176
670
  handleReturnToOptions();
1177
671
  }, disabled: processing, children: "Change" }), _jsx(PillCaret, { "$expanded": paymentDetailsExpanded, children: "\u25BE" })] }), paymentDetailsExpanded ? (_jsxs(PillDetails, { children: [_jsxs(PillDetailRow, { children: [_jsx(PillDetailLabel, { children: "Connected wallet" }), _jsxs(PillDetailValue, { children: [_jsx(WalletDot, { "$iconUrl": connectorIcon, "aria-hidden": "true" }), formatAddress(walletAddressForPill), _jsx(WalletSwitchLink, { type: "button", onClick: handleChangeWallet, disabled: processing, "aria-label": "Switch wallet", title: "Switch wallet", children: _jsx(EditIcon, { size: 12 }) }), _jsx(WalletDisconnectButton, { type: "button", onClick: handleDisconnectWallet, disabled: processing, "aria-label": "Disconnect wallet", title: "Disconnect wallet", children: _jsx(LogOutIcon, { size: 12 }) })] })] }), _jsxs(PillDetailRow, { children: [_jsx(PillDetailLabel, { children: "Route" }), _jsx(PillDetailValue, { children: selectedOption.kind === "direct"
1178
672
  ? "Direct transfer"
1179
- : "Routed transfer" })] })] })) : null] })] })) : null, walletPayment.status === "failed" ? (_jsxs(ContentStage, { "$mobileCentered": true, children: [account.isConnected && account.address ? (_jsx(FallbackTopActions, { children: _jsx(FallbackDisconnectButton, { type: "button", onClick: handleDisconnectWallet, disabled: processing, "aria-label": "Disconnect wallet", title: "Disconnect wallet", children: _jsx(LogOutIcon, { size: 16 }) }) })) : null, _jsx(EmptyState, { children: _jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: walletPayment.error ||
1180
- "We could not find wallet payment options right now." }) }), _jsx(StyledButton, { onClick: handleRetryWalletPayment, disabled: processing || loading.CREATE_PAYMENT_ATTEMPT, children: "Try again" }), _jsx(ModalBackButton, { view: "cryptoIntent", disabled: processing, label: "Choose another payment method" })] })) : null, walletPayment.status === "loading" ? (_jsxs(ContentStage, { children: [walletAddressForHeader ? (_jsxs(ConnectedWalletRow, { children: [_jsxs(ConnectedWalletIdentity, { children: [_jsx(WalletDot, { "$iconUrl": connectorIcon, "aria-hidden": "true" }), _jsx(ConnectedWalletAddress, { children: formatAddress(walletAddressForHeader) })] }), _jsxs(WalletRowActions, { children: [_jsx(WalletSwitchLink, { type: "button", onClick: handleChangeWallet, disabled: processing, "aria-label": "Switch wallet", title: "Switch wallet", children: _jsx(EditIcon, { size: 12 }) }), _jsx(WalletDisconnectButton, { type: "button", onClick: handleDisconnectWallet, disabled: processing, "aria-label": "Disconnect wallet", title: "Disconnect wallet", children: _jsx(LogOutIcon, { size: 12 }) })] })] })) : null, _jsx(SectionLabel, { children: "Checking your wallet" }), _jsxs(SkeletonContainer, { children: [_jsx(SkeletonRow, {}), _jsx(SkeletonRow, { style: { opacity: 0.7 } }), _jsx(SkeletonRow, { style: { opacity: 0.4 } })] })] })) : null, walletPayment.status === "ready" ||
1181
- walletPayment.status === "executing" ? (_jsx(ContentStage, { children: hasNoPaymentOptions ? (_jsxs(_Fragment, { children: [walletAddressForPill ? (_jsxs(ConnectedWalletRow, { children: [_jsxs(ConnectedWalletIdentity, { children: [_jsx(WalletDot, { "$iconUrl": connectorIcon, "aria-hidden": "true" }), _jsx(ConnectedWalletAddress, { children: formatAddress(walletAddressForPill) })] }), _jsxs(WalletRowActions, { children: [_jsx(WalletSwitchLink, { type: "button", onClick: handleChangeWallet, disabled: processing, "aria-label": "Switch wallet", title: "Switch wallet", children: _jsx(EditIcon, { size: 12 }) }), _jsx(WalletDisconnectButton, { type: "button", onClick: handleDisconnectWallet, disabled: processing, "aria-label": "Disconnect wallet", title: "Disconnect wallet", children: _jsx(LogOutIcon, { size: 12 }) })] })] })) : null, !walletAddressForPill &&
1182
- account.isConnected &&
1183
- account.address ? (_jsx(FallbackTopActions, { children: _jsx(FallbackDisconnectButton, { type: "button", onClick: handleDisconnectWallet, disabled: processing, "aria-label": "Disconnect wallet", title: "Disconnect wallet", children: _jsx(LogOutIcon, { size: 16 }) }) })) : null, _jsxs(EmptyState, { children: [_jsxs(EmptyHeadline, { children: [_jsx(Text, { size: "base", weight: "semibold", color: config.theme.font.color.primary, children: NO_WALLET_PAYMENT_OPTIONS_TITLE }), _jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: NO_WALLET_PAYMENT_OPTIONS_DESCRIPTION })] }), unsupportedWalletAddress && !walletAddressForPill ? (_jsxs(Text, { size: "xs", color: config.theme.font.color.tertiary, children: [connectorName, " ", formatAddress(unsupportedWalletAddress)] })) : null] }), _jsx(ModalBackButton, { view: "cryptoIntent", disabled: processing, label: "Choose another payment method" })] })) : !selectedOption ? (_jsxs(_Fragment, { children: [walletAddressForPill ? (_jsxs(ConnectedWalletRow, { children: [_jsxs(ConnectedWalletIdentity, { children: [_jsx(WalletDot, { "$iconUrl": connectorIcon, "aria-hidden": "true" }), _jsx(ConnectedWalletAddress, { children: formatAddress(walletAddressForPill) })] }), _jsxs(WalletRowActions, { children: [_jsx(WalletSwitchLink, { type: "button", onClick: handleChangeWallet, disabled: processing, "aria-label": "Switch wallet", title: "Switch wallet", children: _jsx(EditIcon, { size: 12 }) }), _jsx(WalletDisconnectButton, { type: "button", onClick: handleDisconnectWallet, disabled: processing, "aria-label": "Disconnect wallet", title: "Disconnect wallet", children: _jsx(LogOutIcon, { size: 12 }) })] })] })) : null, _jsxs(SectionRow, { children: [_jsx(SectionLabel, { children: "Pay with" }), _jsx(SectionLabel, { children: "Balance" })] }), _jsx(OptionsContainer, { children: walletPayment.options.map((option) => (_jsxs(OptionCard, { type: "button", onClick: () => handlePickOption(option), "aria-pressed": walletPayment.selectedOptionId === option.id, children: [_jsxs(OptionTokenIconWrap, { children: [_jsx(OptionTokenIcon, { "$token": option.fromTokenName === "ETH" ? "ETH" : "USD", "$iconUrl": option.fromTokenIconUrl, children: !option.fromTokenIconUrl
673
+ : "Routed transfer" })] })] })) : null] })] })) : null, walletPayment.status === "failed" ? (_jsxs(ContentStage, { "$mobileCentered": true, children: [walletAddress ? (_jsx(FallbackTopActions, { children: _jsx(FallbackDisconnectButton, { type: "button", onClick: handleDisconnectWallet, disabled: processing, "aria-label": "Disconnect wallet", title: "Disconnect wallet", children: _jsx(LogOutIcon, { size: 16 }) }) })) : null, _jsx(EmptyState, { children: _jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: walletPayment.error ||
674
+ "We could not find wallet payment options right now." }) }), _jsx(StyledButton, { onClick: handleRetryWalletPayment, disabled: processing, children: "Try again" }), _jsx(ModalBackButton, { view: "cryptoIntent", disabled: processing, label: "Choose another payment method" })] })) : null, walletPayment.status === "loading" ? (_jsxs(ContentStage, { children: [walletAddressForHeader ? (_jsxs(ConnectedWalletRow, { children: [_jsxs(ConnectedWalletIdentity, { children: [_jsx(WalletDot, { "$iconUrl": connectorIcon, "aria-hidden": "true" }), _jsx(ConnectedWalletAddress, { children: formatAddress(walletAddressForHeader) })] }), _jsxs(WalletRowActions, { children: [_jsx(WalletSwitchLink, { type: "button", onClick: handleChangeWallet, disabled: processing, "aria-label": "Switch wallet", title: "Switch wallet", children: _jsx(EditIcon, { size: 12 }) }), _jsx(WalletDisconnectButton, { type: "button", onClick: handleDisconnectWallet, disabled: processing, "aria-label": "Disconnect wallet", title: "Disconnect wallet", children: _jsx(LogOutIcon, { size: 12 }) })] })] })) : null, _jsx(SectionLabel, { children: "Checking your wallet" }), _jsxs(SkeletonContainer, { children: [_jsx(SkeletonRow, {}), _jsx(SkeletonRow, { style: { opacity: 0.7 } }), _jsx(SkeletonRow, { style: { opacity: 0.4 } })] })] })) : null, walletPayment.status === "ready" ||
675
+ walletPayment.status === "executing" ? (_jsx(ContentStage, { children: hasNoPaymentOptions ? (_jsxs(_Fragment, { children: [walletAddressForPill ? (_jsxs(ConnectedWalletRow, { children: [_jsxs(ConnectedWalletIdentity, { children: [_jsx(WalletDot, { "$iconUrl": connectorIcon, "aria-hidden": "true" }), _jsx(ConnectedWalletAddress, { children: formatAddress(walletAddressForPill) })] }), _jsxs(WalletRowActions, { children: [_jsx(WalletSwitchLink, { type: "button", onClick: handleChangeWallet, disabled: processing, "aria-label": "Switch wallet", title: "Switch wallet", children: _jsx(EditIcon, { size: 12 }) }), _jsx(WalletDisconnectButton, { type: "button", onClick: handleDisconnectWallet, disabled: processing, "aria-label": "Disconnect wallet", title: "Disconnect wallet", children: _jsx(LogOutIcon, { size: 12 }) })] })] })) : null, _jsx(EmptyState, { children: _jsxs(EmptyHeadline, { children: [_jsx(Text, { size: "base", weight: "semibold", color: config.theme.font.color.primary, children: NO_WALLET_PAYMENT_OPTIONS_TITLE }), _jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: NO_WALLET_PAYMENT_OPTIONS_DESCRIPTION })] }) }), _jsx(ModalBackButton, { view: "cryptoIntent", disabled: processing, label: "Choose another payment method" })] })) : !selectedOption ? (_jsxs(_Fragment, { children: [walletAddressForPill ? (_jsxs(ConnectedWalletRow, { children: [_jsxs(ConnectedWalletIdentity, { children: [_jsx(WalletDot, { "$iconUrl": connectorIcon, "aria-hidden": "true" }), _jsx(ConnectedWalletAddress, { children: formatAddress(walletAddressForPill) })] }), _jsxs(WalletRowActions, { children: [_jsx(WalletSwitchLink, { type: "button", onClick: handleChangeWallet, disabled: processing, "aria-label": "Switch wallet", title: "Switch wallet", children: _jsx(EditIcon, { size: 12 }) }), _jsx(WalletDisconnectButton, { type: "button", onClick: handleDisconnectWallet, disabled: processing, "aria-label": "Disconnect wallet", title: "Disconnect wallet", children: _jsx(LogOutIcon, { size: 12 }) })] })] })) : null, _jsxs(SectionRow, { children: [_jsx(SectionLabel, { children: "Pay with" }), _jsx(SectionLabel, { children: "Balance" })] }), _jsx(OptionsContainer, { children: walletPayment.options.map((option) => (_jsxs(OptionCard, { type: "button", onClick: () => handlePickOption(option), "aria-pressed": walletPayment.selectedOptionId === option.id, children: [_jsxs(OptionTokenIconWrap, { children: [_jsx(OptionTokenIcon, { "$token": option.fromTokenName === "ETH" ? "ETH" : "USD", "$iconUrl": option.fromTokenIconUrl, children: !option.fromTokenIconUrl
1184
676
  ? getTokenMonogram(option.fromTokenName, option.fromTokenSymbol)
1185
677
  : null }), option.fromChainIconUrl ? (_jsx(OptionChainBadge, { "$iconUrl": option.fromChainIconUrl })) : null] }), _jsxs(OptionIdentity, { children: [_jsx(Text, { size: "base", weight: "semibold", color: config.theme.font.color.primary, children: option.fromTokenName }), _jsxs(Text, { size: "sm", color: config.theme.font.color.secondary, children: ["On ", option.fromChainName] })] }), _jsxs(OptionBalance, { children: [_jsx(Text, { size: "base", weight: "semibold", color: config.theme.font.color.primary, children: formatTokenBalance(option.fromTokenName, option.fromAmount) ?? "0" }), option.kind === "direct" ? (_jsxs(FastBadge, { children: [_jsx("span", { children: "\u26A1" }), _jsx("span", { children: "Fast" })] })) : typeof option.estimatedDurationMinutes ===
1186
- "number" ? (_jsxs(RoutedBadge, { children: ["~", option.estimatedDurationMinutes, " min"] })) : null] })] }, option.id))) }), _jsx(ModalBackButton, { view: "cryptoIntent", disabled: processing })] })) : (_jsxs(_Fragment, { children: [_jsxs(QuoteCard, { children: [_jsxs(QuoteRow, { children: [_jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: "Cost" }), _jsx(Text, { size: "base", weight: "semibold", color: config.theme.font.color.primary, children: formattedCost })] }), displayedPayAmount ? (_jsxs(QuoteRow, { children: [_jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: "You pay" }), _jsx(Text, { size: "base", weight: "semibold", color: config.theme.font.color.primary, children: displayedPayAmount })] })) : null, typeof walletPayment.quote?.estimatedDurationMinutes ===
1187
- "number" ? (_jsxs(QuoteRow, { children: [_jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: "Estimated time" }), _jsxs(Text, { size: "sm", weight: "semibold", color: config.theme.font.color.primary, children: ["~", walletPayment.quote.estimatedDurationMinutes, " min"] })] })) : null, walletPayment.quoteStatus === "loading" ? (_jsxs(_Fragment, { children: [_jsx(QuoteHairline, {}), _jsx(QuoteFootnote, { children: "Fetching the freshest quote\u2026" })] })) : null, walletPayment.quoteStatus === "failed" ? (_jsxs(_Fragment, { children: [_jsx(QuoteHairline, {}), _jsx(QuoteFootnoteWarn, { children: walletPayment.quoteError ||
1188
- "We couldn't fetch a quote right now." })] })) : null] }), _jsx(StyledButton, { onClick: () => {
678
+ "number" ? (_jsxs(RoutedBadge, { children: ["~", option.estimatedDurationMinutes, " min"] })) : null] })] }, option.id))) }), _jsx(ModalBackButton, { view: "cryptoIntent", disabled: processing })] })) : (_jsxs(_Fragment, { children: [_jsxs(QuoteCard, { children: [_jsxs(QuoteRow, { children: [_jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: "Cost" }), _jsx(Text, { size: "base", weight: "semibold", color: config.theme.font.color.primary, children: formattedCost })] }), displayedPayAmount ? (_jsxs(QuoteRow, { children: [_jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: "You pay" }), _jsx(Text, { size: "base", weight: "semibold", color: config.theme.font.color.primary, children: displayedPayAmount })] })) : null, typeof quote.data?.estimatedDurationMinutes === "number" ? (_jsxs(QuoteRow, { children: [_jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: "Estimated time" }), _jsxs(Text, { size: "sm", weight: "semibold", color: config.theme.font.color.primary, children: ["~", quote.data.estimatedDurationMinutes, " min"] })] })) : null, quote.status === "refreshing" ? (_jsxs(_Fragment, { children: [_jsx(QuoteHairline, {}), _jsx(QuoteFootnote, { children: "Fetching the freshest quote\u2026" })] })) : null, quote.status === "failed" ? (_jsxs(_Fragment, { children: [_jsx(QuoteHairline, {}), _jsx(QuoteFootnoteWarn, { children: quote.error || "We couldn't fetch a quote right now." })] })) : null] }), _jsx(StyledButton, { onClick: () => {
1189
679
  if (selectedOption) {
1190
- void handleSelectOption(selectedOption);
680
+ void handleSelectOption();
1191
681
  }
1192
682
  }, disabled: processing ||
1193
- loading.CREATE_PAYMENT_ATTEMPT ||
1194
683
  !selectedOption ||
1195
- walletPayment.quoteStatus === "loading" ||
1196
- (selectedOption.kind !== "direct" &&
1197
- walletPayment.quoteStatus !== "ready"), children: executingId === selectedOption.id
684
+ quote.status === "refreshing" ||
685
+ (selectedOption.kind !== "direct" && quote.status !== "ready"), children: walletPayment.status === "executing"
1198
686
  ? "Preparing..."
1199
- : walletPayment.quoteStatus === "loading"
687
+ : quote.status === "refreshing"
1200
688
  ? "Fetching quote..."
1201
689
  : `Pay with ${selectedOption.fromTokenName}` }), _jsx(StyledButton, { variant: "secondary", onClick: handleReturnToOptions, disabled: processing, children: "Back" })] })) })) : null] }));
1202
690
  };
1203
691
  const CryptoIntentWalletPaymentOptionsViewContent = () => {
1204
- return _jsx(CryptoIntentWalletPaymentOptionsAppKitViewContent, {});
692
+ const { connection } = useCheckoutWallet();
693
+ return connection ? (_jsx(ConnectedWalletPaymentOptions, { connection: connection }, connection.identity)) : (_jsx(CryptoIntentSelectWalletViewContent, {}));
1205
694
  };
1206
695
  export { CryptoIntentWalletPaymentOptionsViewContent };
1207
696
  //# sourceMappingURL=wallet-payment-options.js.map