@mintmoney/react 0.2.0-alpha.1 → 0.2.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/css/styles.css +12 -1
- package/dist/docs/customisation.md +8 -0
- package/dist/esm/api/errors.js +89 -0
- package/dist/esm/api/errors.js.map +1 -0
- package/dist/esm/api/generated.js +825 -65
- package/dist/esm/api/generated.js.map +1 -1
- package/dist/esm/api/payments.js +26 -2
- package/dist/esm/api/payments.js.map +1 -1
- package/dist/esm/api/tokens.js +34 -0
- package/dist/esm/api/tokens.js.map +1 -0
- package/dist/esm/api/types.js.map +1 -1
- package/dist/esm/checkout/claimable-funds.js +20 -10
- package/dist/esm/checkout/claimable-funds.js.map +1 -1
- package/dist/esm/checkout/creation-error-modal.js +2 -2
- package/dist/esm/checkout/creation-error-modal.js.map +1 -1
- package/dist/esm/checkout/index.js +48 -8
- package/dist/esm/checkout/index.js.map +1 -1
- package/dist/esm/checkout/modal.js +78 -78
- package/dist/esm/checkout/modal.js.map +1 -1
- package/dist/esm/checkout/payment-status.js +68 -28
- package/dist/esm/checkout/payment-status.js.map +1 -1
- package/dist/esm/checkout/provider-status.js +9 -0
- package/dist/esm/checkout/provider-status.js.map +1 -0
- package/dist/esm/checkout/providers/checkout-wallet.js +315 -0
- package/dist/esm/checkout/providers/checkout-wallet.js.map +1 -0
- package/dist/esm/checkout/providers/wagmi-config.js +55 -49
- package/dist/esm/checkout/providers/wagmi-config.js.map +1 -1
- package/dist/esm/checkout/refund-notice.js +16 -0
- package/dist/esm/checkout/refund-notice.js.map +1 -0
- package/dist/esm/checkout/resume-state.js +151 -13
- package/dist/esm/checkout/resume-state.js.map +1 -1
- package/dist/esm/checkout/surplus-refund.js +12 -0
- package/dist/esm/checkout/surplus-refund.js.map +1 -1
- package/dist/esm/checkout/views/amount-header.js +1 -1
- package/dist/esm/checkout/views/amount-header.js.map +1 -1
- package/dist/esm/checkout/views/claimable-funds.js +22 -13
- package/dist/esm/checkout/views/claimable-funds.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/direct-details.js +226 -887
- package/dist/esm/checkout/views/crypto-intent/direct-details.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/manual-instruction-card.js +235 -0
- package/dist/esm/checkout/views/crypto-intent/manual-instruction-card.js.map +1 -0
- package/dist/esm/checkout/views/crypto-intent/manual-payment-summary.js +2 -26
- package/dist/esm/checkout/views/crypto-intent/manual-payment-summary.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/manual-refresh.js +19 -0
- package/dist/esm/checkout/views/crypto-intent/manual-refresh.js.map +1 -0
- package/dist/esm/checkout/views/crypto-intent/manual-refund-preference.js +151 -23
- package/dist/esm/checkout/views/crypto-intent/manual-refund-preference.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/manual-route-picker.js +295 -0
- package/dist/esm/checkout/views/crypto-intent/manual-route-picker.js.map +1 -0
- package/dist/esm/checkout/views/crypto-intent/manual-sources.js +155 -0
- package/dist/esm/checkout/views/crypto-intent/manual-sources.js.map +1 -0
- package/dist/esm/checkout/views/crypto-intent/manual-transfer-instructions.js +84 -0
- package/dist/esm/checkout/views/crypto-intent/manual-transfer-instructions.js.map +1 -0
- package/dist/esm/checkout/views/crypto-intent/methods.js +22 -123
- package/dist/esm/checkout/views/crypto-intent/methods.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/payment-route-error.js +10 -0
- package/dist/esm/checkout/views/crypto-intent/payment-route-error.js.map +1 -0
- package/dist/esm/checkout/views/crypto-intent/processing.js +167 -25
- package/dist/esm/checkout/views/crypto-intent/processing.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/success.js +74 -46
- package/dist/esm/checkout/views/crypto-intent/success.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/test-payment.js +11 -1
- package/dist/esm/checkout/views/crypto-intent/test-payment.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/wallet-payment-confirmation-amount.js +14 -24
- package/dist/esm/checkout/views/crypto-intent/wallet-payment-confirmation-amount.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/wallet-payment-discovery.js +61 -0
- package/dist/esm/checkout/views/crypto-intent/wallet-payment-discovery.js.map +1 -0
- package/dist/esm/checkout/views/crypto-intent/wallet-payment-options.js +136 -1169
- package/dist/esm/checkout/views/crypto-intent/wallet-payment-options.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/wallet-payment-options.styles.js +506 -0
- package/dist/esm/checkout/views/crypto-intent/wallet-payment-options.styles.js.map +1 -0
- package/dist/esm/checkout/views/crypto-intent/wallet-select.js +7 -164
- package/dist/esm/checkout/views/crypto-intent/wallet-select.js.map +1 -1
- package/dist/esm/checkout/views/failed.js +62 -26
- package/dist/esm/checkout/views/failed.js.map +1 -1
- package/dist/esm/checkout/views/funding-timeline.js +255 -0
- package/dist/esm/checkout/views/funding-timeline.js.map +1 -0
- package/dist/esm/checkout/views/initial.js +25 -41
- package/dist/esm/checkout/views/initial.js.map +1 -1
- package/dist/esm/checkout/views/method-select.js +6 -4
- package/dist/esm/checkout/views/method-select.js.map +1 -1
- package/dist/esm/checkout/views/payment-follower.js +105 -0
- package/dist/esm/checkout/views/payment-follower.js.map +1 -0
- package/dist/esm/checkout/views/restart.js +11 -2
- package/dist/esm/checkout/views/restart.js.map +1 -1
- package/dist/esm/components/buttons/index.js +3 -2
- package/dist/esm/components/buttons/index.js.map +1 -1
- package/dist/esm/components/icons/search.js +5 -0
- package/dist/esm/components/icons/search.js.map +1 -0
- package/dist/esm/components/loading/index.js +2 -2
- package/dist/esm/components/loading/index.js.map +1 -1
- package/dist/esm/components/modals/modal-with-views.js +6 -12
- package/dist/esm/components/modals/modal-with-views.js.map +1 -1
- package/dist/esm/components/modals/modal.js +3 -3
- package/dist/esm/components/modals/modal.js.map +1 -1
- package/dist/esm/components/modals/transition-view.js +16 -0
- package/dist/esm/components/modals/transition-view.js.map +1 -0
- package/dist/esm/components/modals/use-modal-with-views.js +17 -19
- package/dist/esm/components/modals/use-modal-with-views.js.map +1 -1
- package/dist/esm/components/wallet-selector/wallets/wagmi/index.js +21 -2
- package/dist/esm/components/wallet-selector/wallets/wagmi/index.js.map +1 -1
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/integrations/bitcoin-metamask.js +87 -0
- package/dist/esm/integrations/bitcoin-metamask.js.map +1 -0
- package/dist/esm/integrations/bitcoin-network.js +59 -0
- package/dist/esm/integrations/bitcoin-network.js.map +1 -0
- package/dist/esm/integrations/bitcoin-psbt.js +4 -0
- package/dist/esm/integrations/bitcoin-psbt.js.map +1 -0
- package/dist/esm/integrations/bitcoin-source.js +12 -0
- package/dist/esm/integrations/bitcoin-source.js.map +1 -0
- package/dist/esm/integrations/bitcoin-wallet.js +225 -0
- package/dist/esm/integrations/bitcoin-wallet.js.map +1 -0
- package/dist/esm/integrations/evm-chain.js +18 -0
- package/dist/esm/integrations/evm-chain.js.map +1 -1
- package/dist/esm/integrations/guarded-wallet-client.js +19 -0
- package/dist/esm/integrations/guarded-wallet-client.js.map +1 -0
- package/dist/esm/integrations/lifi.js +85 -38
- package/dist/esm/integrations/lifi.js.map +1 -1
- package/dist/esm/refund/index.js +217 -226
- package/dist/esm/refund/index.js.map +1 -1
- package/dist/esm/state/checkout/bitcoin-payment.js +253 -0
- package/dist/esm/state/checkout/bitcoin-payment.js.map +1 -0
- package/dist/esm/state/checkout/checkout-state.js +54 -0
- package/dist/esm/state/checkout/checkout-state.js.map +1 -0
- package/dist/esm/state/checkout/funding.js +5 -0
- package/dist/esm/state/checkout/funding.js.map +1 -0
- package/dist/esm/state/checkout/issuance-conflicts.js +29 -0
- package/dist/esm/state/checkout/issuance-conflicts.js.map +1 -0
- package/dist/esm/state/checkout/manual-route.js +10 -0
- package/dist/esm/state/checkout/manual-route.js.map +1 -0
- package/dist/esm/state/checkout/payment-attempt.js +50 -20
- package/dist/esm/state/checkout/payment-attempt.js.map +1 -1
- package/dist/esm/state/checkout/payment-lifecycle.js +9 -15
- package/dist/esm/state/checkout/payment-lifecycle.js.map +1 -1
- package/dist/esm/state/checkout/payment-observer.js +147 -0
- package/dist/esm/state/checkout/payment-observer.js.map +1 -0
- package/dist/esm/state/checkout/payment-phase.js +131 -0
- package/dist/esm/state/checkout/payment-phase.js.map +1 -0
- package/dist/esm/state/checkout/quote-countdown.js +26 -0
- package/dist/esm/state/checkout/quote-countdown.js.map +1 -0
- package/dist/esm/state/checkout/quote-lifecycle.js +378 -0
- package/dist/esm/state/checkout/quote-lifecycle.js.map +1 -0
- package/dist/esm/state/checkout/route-estimate.js +77 -0
- package/dist/esm/state/checkout/route-estimate.js.map +1 -0
- package/dist/esm/state/checkout/store.js +350 -708
- package/dist/esm/state/checkout/store.js.map +1 -1
- package/dist/esm/state/checkout/wallet-payment-options.js +0 -32
- package/dist/esm/state/checkout/wallet-payment-options.js.map +1 -1
- package/dist/esm/state/checkout/wallet-payment.js +249 -0
- package/dist/esm/state/checkout/wallet-payment.js.map +1 -0
- package/dist/esm/utils/string.js +2 -0
- package/dist/esm/utils/string.js.map +1 -1
- package/dist/esm/utils/token-amount.js +88 -0
- package/dist/esm/utils/token-amount.js.map +1 -0
- package/dist/esm/utils/wallet-errors.js +21 -4
- package/dist/esm/utils/wallet-errors.js.map +1 -1
- package/dist/types/api/errors.d.ts +37 -0
- package/dist/types/api/errors.d.ts.map +1 -0
- package/dist/types/api/generated.d.ts +4570 -695
- package/dist/types/api/generated.d.ts.map +1 -1
- package/dist/types/api/payments.d.ts +28 -1
- package/dist/types/api/payments.d.ts.map +1 -1
- package/dist/types/api/tokens.d.ts +6 -0
- package/dist/types/api/tokens.d.ts.map +1 -0
- package/dist/types/api/types.d.ts +28 -2
- package/dist/types/api/types.d.ts.map +1 -1
- package/dist/types/checkout/claimable-funds.d.ts +15 -2
- package/dist/types/checkout/claimable-funds.d.ts.map +1 -1
- package/dist/types/checkout/creation-error-modal.d.ts +2 -1
- package/dist/types/checkout/creation-error-modal.d.ts.map +1 -1
- package/dist/types/checkout/index.d.ts +21 -1
- package/dist/types/checkout/index.d.ts.map +1 -1
- package/dist/types/checkout/modal.d.ts +4 -1
- package/dist/types/checkout/modal.d.ts.map +1 -1
- package/dist/types/checkout/payment-status.d.ts +10 -2
- package/dist/types/checkout/payment-status.d.ts.map +1 -1
- package/dist/types/checkout/provider-status.d.ts +11 -0
- package/dist/types/checkout/provider-status.d.ts.map +1 -0
- package/dist/types/checkout/providers/checkout-wallet.d.ts +23 -0
- package/dist/types/checkout/providers/checkout-wallet.d.ts.map +1 -0
- package/dist/types/checkout/providers/wagmi-config.d.ts +8 -2
- package/dist/types/checkout/providers/wagmi-config.d.ts.map +1 -1
- package/dist/types/checkout/refund-notice.d.ts +7 -0
- package/dist/types/checkout/refund-notice.d.ts.map +1 -0
- package/dist/types/checkout/resume-state.d.ts +41 -4
- package/dist/types/checkout/resume-state.d.ts.map +1 -1
- package/dist/types/checkout/surplus-refund.d.ts +8 -0
- package/dist/types/checkout/surplus-refund.d.ts.map +1 -1
- package/dist/types/checkout/views/amount-header.d.ts.map +1 -1
- package/dist/types/checkout/views/claimable-funds.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/direct-details.d.ts +3 -13
- package/dist/types/checkout/views/crypto-intent/direct-details.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/manual-instruction-card.d.ts +10 -0
- package/dist/types/checkout/views/crypto-intent/manual-instruction-card.d.ts.map +1 -0
- package/dist/types/checkout/views/crypto-intent/manual-payment-summary.d.ts +4 -11
- package/dist/types/checkout/views/crypto-intent/manual-payment-summary.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/manual-refresh.d.ts +4 -0
- package/dist/types/checkout/views/crypto-intent/manual-refresh.d.ts.map +1 -0
- package/dist/types/checkout/views/crypto-intent/manual-refund-preference.d.ts +14 -10
- package/dist/types/checkout/views/crypto-intent/manual-refund-preference.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/manual-route-picker.d.ts +18 -0
- package/dist/types/checkout/views/crypto-intent/manual-route-picker.d.ts.map +1 -0
- package/dist/types/checkout/views/crypto-intent/manual-sources.d.ts +33 -0
- package/dist/types/checkout/views/crypto-intent/manual-sources.d.ts.map +1 -0
- package/dist/types/checkout/views/crypto-intent/manual-transfer-instructions.d.ts +18 -0
- package/dist/types/checkout/views/crypto-intent/manual-transfer-instructions.d.ts.map +1 -0
- package/dist/types/checkout/views/crypto-intent/methods.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/payment-route-error.d.ts +2 -0
- package/dist/types/checkout/views/crypto-intent/payment-route-error.d.ts.map +1 -0
- package/dist/types/checkout/views/crypto-intent/processing.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/success.d.ts +2 -1
- package/dist/types/checkout/views/crypto-intent/success.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/test-payment.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/wallet-payment-confirmation-amount.d.ts +8 -8
- package/dist/types/checkout/views/crypto-intent/wallet-payment-confirmation-amount.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/wallet-payment-discovery.d.ts +17 -0
- package/dist/types/checkout/views/crypto-intent/wallet-payment-discovery.d.ts.map +1 -0
- package/dist/types/checkout/views/crypto-intent/wallet-payment-options.d.ts +2 -1
- package/dist/types/checkout/views/crypto-intent/wallet-payment-options.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/wallet-payment-options.styles.d.ts +61 -0
- package/dist/types/checkout/views/crypto-intent/wallet-payment-options.styles.d.ts.map +1 -0
- package/dist/types/checkout/views/crypto-intent/wallet-select.d.ts +1 -2
- package/dist/types/checkout/views/crypto-intent/wallet-select.d.ts.map +1 -1
- package/dist/types/checkout/views/failed.d.ts +6 -0
- package/dist/types/checkout/views/failed.d.ts.map +1 -1
- package/dist/types/checkout/views/funding-timeline.d.ts +49 -0
- package/dist/types/checkout/views/funding-timeline.d.ts.map +1 -0
- package/dist/types/checkout/views/initial.d.ts +2 -4
- package/dist/types/checkout/views/initial.d.ts.map +1 -1
- package/dist/types/checkout/views/method-select.d.ts +2 -1
- package/dist/types/checkout/views/method-select.d.ts.map +1 -1
- package/dist/types/checkout/views/payment-follower.d.ts +31 -0
- package/dist/types/checkout/views/payment-follower.d.ts.map +1 -0
- package/dist/types/checkout/views/restart.d.ts +1 -1
- package/dist/types/checkout/views/restart.d.ts.map +1 -1
- package/dist/types/components/buttons/index.d.ts.map +1 -1
- package/dist/types/components/icons/search.d.ts +2 -0
- package/dist/types/components/icons/search.d.ts.map +1 -0
- package/dist/types/components/loading/index.d.ts +6 -1
- package/dist/types/components/loading/index.d.ts.map +1 -1
- package/dist/types/components/modals/modal-with-views.d.ts +2 -0
- package/dist/types/components/modals/modal-with-views.d.ts.map +1 -1
- package/dist/types/components/modals/modal.d.ts +2 -1
- package/dist/types/components/modals/modal.d.ts.map +1 -1
- package/dist/types/components/modals/transition-view.d.ts +2 -0
- package/dist/types/components/modals/transition-view.d.ts.map +1 -0
- package/dist/types/components/modals/use-modal-with-views.d.ts +2 -1
- package/dist/types/components/modals/use-modal-with-views.d.ts.map +1 -1
- package/dist/types/components/wallet-selector/domain.d.ts +1 -1
- package/dist/types/components/wallet-selector/domain.d.ts.map +1 -1
- package/dist/types/components/wallet-selector/wallets/wagmi/index.d.ts +2 -2
- package/dist/types/components/wallet-selector/wallets/wagmi/index.d.ts.map +1 -1
- package/dist/types/config.d.ts +1 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/integrations/bitcoin-metamask.d.ts +11 -0
- package/dist/types/integrations/bitcoin-metamask.d.ts.map +1 -0
- package/dist/types/integrations/bitcoin-network.d.ts +13 -0
- package/dist/types/integrations/bitcoin-network.d.ts.map +1 -0
- package/dist/types/integrations/bitcoin-psbt.d.ts +5 -0
- package/dist/types/integrations/bitcoin-psbt.d.ts.map +1 -0
- package/dist/types/integrations/bitcoin-source.d.ts +12 -0
- package/dist/types/integrations/bitcoin-source.d.ts.map +1 -0
- package/dist/types/integrations/bitcoin-wallet.d.ts +63 -0
- package/dist/types/integrations/bitcoin-wallet.d.ts.map +1 -0
- package/dist/types/integrations/evm-chain.d.ts +5 -0
- package/dist/types/integrations/evm-chain.d.ts.map +1 -1
- package/dist/types/integrations/guarded-wallet-client.d.ts +4 -0
- package/dist/types/integrations/guarded-wallet-client.d.ts.map +1 -0
- package/dist/types/integrations/lifi.d.ts +22 -0
- package/dist/types/integrations/lifi.d.ts.map +1 -1
- package/dist/types/refund/index.d.ts +1 -1
- package/dist/types/refund/index.d.ts.map +1 -1
- package/dist/types/state/checkout/bitcoin-payment.d.ts +28 -0
- package/dist/types/state/checkout/bitcoin-payment.d.ts.map +1 -0
- package/dist/types/state/checkout/checkout-state.d.ts +102 -0
- package/dist/types/state/checkout/checkout-state.d.ts.map +1 -0
- package/dist/types/state/checkout/funding.d.ts +6 -0
- package/dist/types/state/checkout/funding.d.ts.map +1 -0
- package/dist/types/state/checkout/issuance-conflicts.d.ts +22 -0
- package/dist/types/state/checkout/issuance-conflicts.d.ts.map +1 -0
- package/dist/types/state/checkout/manual-route.d.ts +13 -0
- package/dist/types/state/checkout/manual-route.d.ts.map +1 -0
- package/dist/types/state/checkout/payment-attempt.d.ts +20 -1
- package/dist/types/state/checkout/payment-attempt.d.ts.map +1 -1
- package/dist/types/state/checkout/payment-lifecycle.d.ts +6 -8
- package/dist/types/state/checkout/payment-lifecycle.d.ts.map +1 -1
- package/dist/types/state/checkout/payment-observer.d.ts +41 -0
- package/dist/types/state/checkout/payment-observer.d.ts.map +1 -0
- package/dist/types/state/checkout/payment-phase.d.ts +116 -0
- package/dist/types/state/checkout/payment-phase.d.ts.map +1 -0
- package/dist/types/state/checkout/quote-countdown.d.ts +15 -0
- package/dist/types/state/checkout/quote-countdown.d.ts.map +1 -0
- package/dist/types/state/checkout/quote-lifecycle.d.ts +39 -0
- package/dist/types/state/checkout/quote-lifecycle.d.ts.map +1 -0
- package/dist/types/state/checkout/route-estimate.d.ts +38 -0
- package/dist/types/state/checkout/route-estimate.d.ts.map +1 -0
- package/dist/types/state/checkout/store.d.ts +38 -90
- package/dist/types/state/checkout/store.d.ts.map +1 -1
- package/dist/types/state/checkout/wallet-payment-options.d.ts +0 -16
- package/dist/types/state/checkout/wallet-payment-options.d.ts.map +1 -1
- package/dist/types/state/checkout/wallet-payment.d.ts +24 -0
- package/dist/types/state/checkout/wallet-payment.d.ts.map +1 -0
- package/dist/types/utils/string.d.ts +2 -0
- package/dist/types/utils/string.d.ts.map +1 -1
- package/dist/types/utils/token-amount.d.ts +18 -0
- package/dist/types/utils/token-amount.d.ts.map +1 -0
- package/dist/types/utils/wallet-errors.d.ts.map +1 -1
- package/package.json +3 -1
- package/dist/esm/checkout/providers/wallet-connect-resume.js +0 -129
- package/dist/esm/checkout/providers/wallet-connect-resume.js.map +0 -1
- package/dist/esm/refund/confirmation.js +0 -30
- package/dist/esm/refund/confirmation.js.map +0 -1
- package/dist/types/checkout/providers/wallet-connect-resume.d.ts +0 -9
- package/dist/types/checkout/providers/wallet-connect-resume.d.ts.map +0 -1
- package/dist/types/refund/confirmation.d.ts +0 -14
- package/dist/types/refund/confirmation.d.ts.map +0 -1
|
@@ -2,435 +2,146 @@ import { waitForTransactionReceipt } from "@wagmi/core";
|
|
|
2
2
|
import { create } from "zustand";
|
|
3
3
|
import { immer } from "zustand/middleware/immer";
|
|
4
4
|
import { getCheckoutCryptoCurrencies } from "../../api/checkouts.js";
|
|
5
|
-
import {
|
|
5
|
+
import { CheckoutRequestError, describeRequestFailure, getCryptoPayConflictCode, withConflictCopy, } from "../../api/errors.js";
|
|
6
|
+
import { createPaymentAttempt, createTestPaymentAttempt, estimateCryptoPay, getPaymentById, getRequiredSettlementConfig, } from "../../api/payments.js";
|
|
6
7
|
import { PaymentStatus, } from "../../api/types.js";
|
|
7
8
|
import { WagmiWalletInterface } from "../../components/wallet-selector/wallets/wagmi/index.js";
|
|
9
|
+
import { BITCOIN_CHAIN } from "../../integrations/bitcoin-source.js";
|
|
8
10
|
import { resolveEvmChainId, switchEvmWalletChain, } from "../../integrations/evm-chain.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
ACTIONS["CREATE_PAYMENT_ATTEMPT"] = "CREATE_PAYMENT_ATTEMPT";
|
|
20
|
-
ACTIONS["CREATE_TEST_PAYMENT_ATTEMPT"] = "CREATE_TEST_PAYMENT_ATTEMPT";
|
|
21
|
-
ACTIONS["EXECUTE_TRANSFER"] = "EXECUTE_TRANSFER";
|
|
22
|
-
ACTIONS["POLL_PAYMENT"] = "POLL_PAYMENT";
|
|
23
|
-
ACTIONS["CHECK_CHAIN_STATUS"] = "CHECK_CHAIN_STATUS";
|
|
24
|
-
})(ACTIONS || (ACTIONS = {}));
|
|
25
|
-
const initialWalletPaymentState = () => ({
|
|
26
|
-
status: "idle",
|
|
27
|
-
options: [],
|
|
28
|
-
walletAddress: null,
|
|
29
|
-
selectedOptionId: null,
|
|
30
|
-
quoteId: null,
|
|
31
|
-
routeId: null,
|
|
32
|
-
sourceTxHash: null,
|
|
33
|
-
destinationTxHash: null,
|
|
34
|
-
quoteStatus: "idle",
|
|
35
|
-
quote: null,
|
|
36
|
-
quoteError: null,
|
|
37
|
-
error: null,
|
|
38
|
-
});
|
|
39
|
-
const initialActionState = (initialValue) => Object.values(ACTIONS).reduce((acc, action) => {
|
|
40
|
-
acc[action] = initialValue;
|
|
41
|
-
return acc;
|
|
42
|
-
}, {});
|
|
43
|
-
export const useCheckoutStore = create()(immer((_set, _get) => ({
|
|
44
|
-
checkoutId: null,
|
|
45
|
-
selectedMethod: null,
|
|
46
|
-
selectedCurrency: null,
|
|
47
|
-
retrySession: false,
|
|
48
|
-
methods: null,
|
|
49
|
-
cryptoCurrency: null,
|
|
50
|
-
checkout: null,
|
|
51
|
-
payment: null,
|
|
52
|
-
cryptoPaymentAttempt: null,
|
|
53
|
-
loading: initialActionState(false),
|
|
54
|
-
error: initialActionState(null),
|
|
55
|
-
processing: false,
|
|
56
|
-
transfer: {
|
|
57
|
-
status: "idle",
|
|
58
|
-
error: null,
|
|
59
|
-
transactionHash: null,
|
|
60
|
-
chainStatus: "pending",
|
|
61
|
-
},
|
|
62
|
-
polling: {
|
|
63
|
-
isPolling: false,
|
|
64
|
-
pollCount: 0,
|
|
65
|
-
lastPollTime: null,
|
|
66
|
-
},
|
|
67
|
-
quote: {
|
|
68
|
-
status: "idle",
|
|
69
|
-
error: null,
|
|
70
|
-
expiresAt: null,
|
|
71
|
-
remainingMs: null,
|
|
72
|
-
totalDurationMs: null,
|
|
73
|
-
},
|
|
74
|
-
walletPayment: initialWalletPaymentState(),
|
|
75
|
-
})));
|
|
11
|
+
import { assertNoUncertainBitcoinSend, getUncertainBitcoinSend, isReturnedBitcoinRoute, observeBitcoinRecovery, retryBitcoinBroadcast, } from "./bitcoin-payment.js";
|
|
12
|
+
import { ACTIONS, createInitialCheckoutState, } from "./checkout-state.js";
|
|
13
|
+
import { createIssuanceConflictRecovery } from "./issuance-conflicts.js";
|
|
14
|
+
import { buildManualRoutePayload, buildWalletEstimatePayload, buildWalletPaymentAttemptPayload, } from "./payment-attempt.js";
|
|
15
|
+
import { canCreateFreshAttempt, isAttemptStale, PAYMENT_NO_LONGER_PAYABLE_MESSAGE, } from "./payment-lifecycle.js";
|
|
16
|
+
import { createPaymentObserver } from "./payment-observer.js";
|
|
17
|
+
import { createQuoteLifecycle, } from "./quote-lifecycle.js";
|
|
18
|
+
import { buildDirectWalletQuote, buildWalletQuoteTarget, priceBitcoinWalletEstimate, priceEstimate, } from "./route-estimate.js";
|
|
19
|
+
export { ACTIONS } from "./checkout-state.js";
|
|
20
|
+
export const useCheckoutStore = create()(immer(() => createInitialCheckoutState()));
|
|
76
21
|
const set = (fn) => {
|
|
77
22
|
useCheckoutStore.setState(fn);
|
|
78
23
|
};
|
|
79
24
|
const get = () => useCheckoutStore.getState();
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
if (quoteCountdownInterval) {
|
|
99
|
-
clearInterval(quoteCountdownInterval);
|
|
100
|
-
quoteCountdownInterval = null;
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
const clearQuoteAutoRefreshTimer = () => {
|
|
104
|
-
if (quoteExpiryTimer) {
|
|
105
|
-
clearTimeout(quoteExpiryTimer);
|
|
106
|
-
quoteExpiryTimer = null;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
const getPreservedRefreshingQuoteState = () => {
|
|
110
|
-
const currentQuote = get().quote;
|
|
111
|
-
if (currentQuote.remainingMs === null) {
|
|
112
|
-
return { status: "refreshing", error: null, ...clearQuoteTiming() };
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
status: "refreshing",
|
|
116
|
-
error: null,
|
|
117
|
-
expiresAt: currentQuote.expiresAt,
|
|
118
|
-
remainingMs: currentQuote.expiresAt !== null
|
|
119
|
-
? Math.max(0, currentQuote.expiresAt - Date.now())
|
|
120
|
-
: currentQuote.remainingMs,
|
|
121
|
-
totalDurationMs: currentQuote.totalDurationMs,
|
|
25
|
+
let checkoutOpening = 0;
|
|
26
|
+
let checkoutOwner = null;
|
|
27
|
+
// Store requests always belong to the opening that started them. Wallet and
|
|
28
|
+
// quote lifetimes may narrow ownership, but cannot bypass this boundary.
|
|
29
|
+
export const captureCheckoutOpening = (additional) => {
|
|
30
|
+
const opening = checkoutOpening;
|
|
31
|
+
return () => opening === checkoutOpening && (additional?.() ?? true);
|
|
32
|
+
};
|
|
33
|
+
export const beginCheckoutOpening = () => {
|
|
34
|
+
const owner = Symbol();
|
|
35
|
+
checkoutOwner = owner;
|
|
36
|
+
checkoutOpening += 1;
|
|
37
|
+
return () => {
|
|
38
|
+
if (checkoutOwner !== owner)
|
|
39
|
+
return;
|
|
40
|
+
checkoutOwner = null;
|
|
41
|
+
resetCheckoutStore();
|
|
122
42
|
};
|
|
123
43
|
};
|
|
44
|
+
const quoteLifecycle = createQuoteLifecycle({
|
|
45
|
+
get,
|
|
46
|
+
set,
|
|
47
|
+
captureOpening: captureCheckoutOpening,
|
|
48
|
+
priceWalletRoute: (...args) => priceWalletRoute(...args),
|
|
49
|
+
createManualAttempt: (...args) => createManualDirectPaymentAttempt(...args),
|
|
50
|
+
});
|
|
51
|
+
export const { refreshQuote, syncQuote, configureManualQuoteRefresh, prepareWalletQuoteReplacement, clearQuoteRefresh, loadWalletPaymentQuote, setWalletPaymentOptions, resetWalletPaymentState, beginBitcoinWalletPreparation, setWalletPaymentQuote, } = quoteLifecycle;
|
|
124
52
|
const getCurrentCheckoutAttempt = (state = get()) => {
|
|
125
53
|
return state.cryptoPaymentAttempt ?? state.payment?.payment_attempt ?? null;
|
|
126
54
|
};
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (!attemptMatchesSource(attempt, source))
|
|
138
|
-
return null;
|
|
139
|
-
return normalizeWalletAddress(attempt.refund_to) ===
|
|
140
|
-
normalizeWalletAddress(source.sendingAddress)
|
|
141
|
-
? attempt
|
|
142
|
-
: null;
|
|
143
|
-
};
|
|
144
|
-
const reuseCurrentAttempt = (attempt) => {
|
|
145
|
-
set((state) => {
|
|
146
|
-
state.cryptoPaymentAttempt = attempt;
|
|
147
|
-
state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = null;
|
|
148
|
-
state.loading[ACTIONS.CREATE_PAYMENT_ATTEMPT] = false;
|
|
149
|
-
});
|
|
150
|
-
syncQuote(get().payment, attempt);
|
|
151
|
-
return attempt;
|
|
152
|
-
};
|
|
55
|
+
/**
|
|
56
|
+
* A payment is issued once its only attempt exists (QCT D1). From then on its
|
|
57
|
+
* terms, including the refund recipient, are fixed.
|
|
58
|
+
*/
|
|
59
|
+
export const isCheckoutIssued = (state = get()) => Boolean(getCurrentCheckoutAttempt(state));
|
|
60
|
+
/** The refund recipient frozen at issuance, or null before issuance. */
|
|
61
|
+
export const getFrozenRefundRecipient = (state = get()) => getCurrentCheckoutAttempt(state)?.refund_to ?? null;
|
|
62
|
+
/** Routes are priced against an issued payment's frozen asset, else the checkout's. */
|
|
63
|
+
const getRouteSettlement = (payment, state = get()) => getCurrentCheckoutAttempt(state)?.settlement_config ??
|
|
64
|
+
getRequiredSettlementConfig(payment);
|
|
153
65
|
const withFreshAttempt = (payment, attempt) => {
|
|
154
66
|
if (!payment) {
|
|
155
67
|
return payment;
|
|
156
68
|
}
|
|
157
69
|
return {
|
|
158
70
|
...payment,
|
|
71
|
+
// Public-key calls receive the public attempt shape the payment read uses.
|
|
159
72
|
payment_attempt: attempt,
|
|
160
73
|
};
|
|
161
74
|
};
|
|
162
|
-
|
|
75
|
+
// A read that has already observed newer instructions takes precedence over
|
|
76
|
+
// the issuing response. Matching timestamps cannot order two different quotes.
|
|
77
|
+
const reconcileIssuedAttempt = (issued, observed) => {
|
|
78
|
+
if (!observed)
|
|
79
|
+
return issued;
|
|
80
|
+
const issuedAt = Date.parse(issued.updated_at);
|
|
81
|
+
const observedAt = Date.parse(observed.updated_at);
|
|
82
|
+
const differentQuote = observed.attempt_id !== issued.attempt_id ||
|
|
83
|
+
(Boolean(observed.quote_request_id) &&
|
|
84
|
+
observed.quote_request_id !== issued.quote_request_id);
|
|
85
|
+
return observedAt > issuedAt || (differentQuote && !(observedAt < issuedAt))
|
|
86
|
+
? observed
|
|
87
|
+
: issued;
|
|
88
|
+
};
|
|
89
|
+
const changedQuoteError = (message = "The payment quote changed. Try again for a fresh quote.") => new CheckoutRequestError(message, "PAYMENT_QUOTE_CHANGED");
|
|
90
|
+
export const assertWalletAttemptCurrent = (attempt) => {
|
|
91
|
+
const { payment } = get();
|
|
92
|
+
if (!payment || !canCreateFreshAttempt(payment)) {
|
|
93
|
+
throw new Error(PAYMENT_NO_LONGER_PAYABLE_MESSAGE);
|
|
94
|
+
}
|
|
95
|
+
assertNoUncertainBitcoinSend(payment.id);
|
|
96
|
+
if (isAttemptStale(attempt) ||
|
|
97
|
+
reconcileIssuedAttempt(attempt, getCurrentCheckoutAttempt()) !== attempt) {
|
|
98
|
+
quoteLifecycle.clearWalletQuoteRequestId(attempt.quote_request_id ?? "");
|
|
99
|
+
throw changedQuoteError();
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const getPaymentSnapshotAfterAttempt = async (paymentId, fallbackPayment) => {
|
|
103
|
+
const beforeRead = get().payment;
|
|
163
104
|
try {
|
|
164
|
-
|
|
105
|
+
const read = await getPaymentById(paymentId);
|
|
106
|
+
const current = get().payment;
|
|
107
|
+
if (current?.id !== paymentId || current === beforeRead)
|
|
108
|
+
return read;
|
|
109
|
+
const snapshot = current.status === "pending" && read.status !== "pending"
|
|
110
|
+
? read
|
|
111
|
+
: current;
|
|
112
|
+
const attempt = current.payment_attempt
|
|
113
|
+
? reconcileIssuedAttempt(current.payment_attempt, read.payment_attempt)
|
|
114
|
+
: read.payment_attempt;
|
|
115
|
+
return attempt
|
|
116
|
+
? { ...snapshot, payment_attempt: attempt }
|
|
117
|
+
: snapshot;
|
|
165
118
|
}
|
|
166
119
|
catch {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const clearQuoteTiming = () => ({
|
|
192
|
-
expiresAt: null,
|
|
193
|
-
remainingMs: null,
|
|
194
|
-
totalDurationMs: null,
|
|
195
|
-
});
|
|
196
|
-
const refreshQuoteCountdown = (expiresAt) => {
|
|
197
|
-
if (expiresAt === null)
|
|
198
|
-
return;
|
|
199
|
-
setQuote({
|
|
200
|
-
remainingMs: Math.max(0, expiresAt - Date.now()),
|
|
201
|
-
});
|
|
202
|
-
};
|
|
203
|
-
const getWalletQuoteLoadingState = () => ({
|
|
204
|
-
quoteStatus: "loading",
|
|
205
|
-
quote: null,
|
|
206
|
-
quoteError: null,
|
|
207
|
-
quoteId: null,
|
|
208
|
-
routeId: null,
|
|
209
|
-
});
|
|
210
|
-
const getWalletQuoteReadyState = (quote) => ({
|
|
211
|
-
quoteStatus: "ready",
|
|
212
|
-
quote,
|
|
213
|
-
quoteId: quote.quoteId,
|
|
214
|
-
routeId: quote.routeId,
|
|
215
|
-
quoteError: null,
|
|
216
|
-
});
|
|
217
|
-
const getWalletQuoteFailedState = (message) => ({
|
|
218
|
-
quoteStatus: "failed",
|
|
219
|
-
quote: null,
|
|
220
|
-
quoteError: message,
|
|
221
|
-
});
|
|
222
|
-
const getWalletAttemptRefreshContext = () => {
|
|
223
|
-
const state = get();
|
|
224
|
-
const payment = state.payment;
|
|
225
|
-
const checkout = state.checkout;
|
|
226
|
-
const settlementCurrency = state.cryptoCurrency;
|
|
227
|
-
const selectedOption = state.walletPayment.options.find((option) => option.id === state.walletPayment.selectedOptionId);
|
|
228
|
-
const walletAddress = state.walletPayment.walletAddress;
|
|
229
|
-
if (!payment || !checkout || !settlementCurrency) {
|
|
230
|
-
throw new Error("Wallet payment context is not ready");
|
|
231
|
-
}
|
|
232
|
-
if (!selectedOption || !walletAddress) {
|
|
233
|
-
throw new Error("Missing wallet payment selection for quote refresh");
|
|
234
|
-
}
|
|
235
|
-
return {
|
|
236
|
-
payment,
|
|
237
|
-
checkout,
|
|
238
|
-
settlementCurrency,
|
|
239
|
-
selectedOption,
|
|
240
|
-
walletAddress,
|
|
241
|
-
};
|
|
242
|
-
};
|
|
243
|
-
const resolveRefreshedWalletQuote = async ({ selectedOption, checkout, payment, settlementCurrency, walletAddress, attempt, }) => {
|
|
244
|
-
if (selectedOption.kind === "direct") {
|
|
245
|
-
return buildDirectWalletQuote(selectedOption, attempt);
|
|
246
|
-
}
|
|
247
|
-
// Keep routed-quote loading behind a dynamic import so the checkout store
|
|
248
|
-
// does not eagerly pull the LI.FI integration path into manual-only flows.
|
|
249
|
-
const { fetchWalletPaymentQuote } = await import("../../integrations/index.js");
|
|
250
|
-
return fetchWalletPaymentQuote({
|
|
251
|
-
option: selectedOption,
|
|
252
|
-
context: {
|
|
253
|
-
checkout,
|
|
254
|
-
payment: get().payment ?? payment,
|
|
255
|
-
settlementCurrency,
|
|
256
|
-
walletAddress,
|
|
257
|
-
cryptoPaymentAttempt: attempt,
|
|
258
|
-
},
|
|
259
|
-
});
|
|
260
|
-
};
|
|
261
|
-
const refreshWalletPaymentAttempt = async () => {
|
|
262
|
-
const context = getWalletAttemptRefreshContext();
|
|
263
|
-
const attempt = await createWalletOptionPaymentAttempt(context.selectedOption, context.walletAddress, null);
|
|
264
|
-
const quote = await resolveRefreshedWalletQuote({
|
|
265
|
-
...context,
|
|
266
|
-
attempt,
|
|
267
|
-
});
|
|
268
|
-
// Only the wallet-quote payload is set here; refreshQuote settles quote.status
|
|
269
|
-
// (ready + expiry timer) from the freshly created attempt once the rebuild ends.
|
|
270
|
-
setWalletPaymentState(getWalletQuoteReadyState(quote));
|
|
271
|
-
};
|
|
272
|
-
/**
|
|
273
|
-
* Settle the displayed quote state from the active attempt and arm a single
|
|
274
|
-
* expiry timer for a live quote. It never triggers a refresh — the caller
|
|
275
|
-
* decides what to do with a "stale" result — so it is safe to reuse mid-refresh
|
|
276
|
-
* without recursion.
|
|
277
|
-
*/
|
|
278
|
-
const settleQuoteFromAttempt = (payment, attempt) => {
|
|
279
|
-
clearQuoteExpiryTimer();
|
|
280
|
-
if (refreshMode === "none" || !attempt || !canCreateFreshAttempt(payment)) {
|
|
281
|
-
setQuote({ status: "idle", error: null, ...clearQuoteTiming() });
|
|
282
|
-
return "idle";
|
|
283
|
-
}
|
|
284
|
-
if (isAttemptStale(attempt)) {
|
|
285
|
-
return "stale";
|
|
286
|
-
}
|
|
287
|
-
const timing = getAttemptQuoteTiming(attempt);
|
|
288
|
-
setQuote({ status: "ready", error: null, ...timing });
|
|
289
|
-
// One-shot timer: when the live quote crosses its window we refresh
|
|
290
|
-
// so the payer always sees a payable amount instead of an expiry dead-end.
|
|
291
|
-
const expiresAt = timing.expiresAt ?? getAttemptExpiry(attempt);
|
|
292
|
-
if (expiresAt !== null) {
|
|
293
|
-
quoteExpiryTimer = setTimeout(() => {
|
|
294
|
-
void refreshQuote();
|
|
295
|
-
}, Math.max(0, expiresAt - Date.now()));
|
|
296
|
-
quoteCountdownInterval = setInterval(() => {
|
|
297
|
-
refreshQuoteCountdown(expiresAt);
|
|
298
|
-
}, 1000);
|
|
299
|
-
}
|
|
300
|
-
return "ready";
|
|
301
|
-
};
|
|
302
|
-
/**
|
|
303
|
-
* Fetch a fresh payable amount for the active flow. Driven both by the silent
|
|
304
|
-
* expiry timer and by the payer's explicit "Try again" — a stale or missing
|
|
305
|
-
* quote is always recoverable, never terminal.
|
|
306
|
-
*/
|
|
307
|
-
export const refreshQuote = async () => {
|
|
308
|
-
if (refreshMode === "none" || isRefreshing)
|
|
309
|
-
return;
|
|
310
|
-
if (refreshMode === "wallet" && !get().walletPayment.selectedOptionId) {
|
|
311
|
-
// Wallet refresh needs a chosen option to know which quote to rebuild, so
|
|
312
|
-
// skip ticks that land before the payer picked one (or after returning to
|
|
313
|
-
// the option list).
|
|
314
|
-
setQuote({ status: "idle", error: null, ...clearQuoteTiming() });
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
if (!canCreateFreshAttempt(get().payment)) {
|
|
318
|
-
setQuote({
|
|
319
|
-
status: "failed",
|
|
320
|
-
error: PAYMENT_NO_LONGER_PAYABLE_MESSAGE,
|
|
321
|
-
...clearQuoteTiming(),
|
|
322
|
-
});
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
// Never refresh out from under an in-flight payment: the execution already
|
|
326
|
-
// captured the quote it is paying, so swapping the attempt would churn the UI
|
|
327
|
-
// and orphan an extra attempt. The view tears down the refresh context when it
|
|
328
|
-
// leaves the pay screen.
|
|
329
|
-
if (get().processing)
|
|
330
|
-
return;
|
|
331
|
-
isRefreshing = true;
|
|
332
|
-
clearQuoteExpiryTimer();
|
|
333
|
-
setQuote(getPreservedRefreshingQuoteState(), refreshMode === "wallet" ? getWalletQuoteLoadingState() : undefined);
|
|
334
|
-
try {
|
|
335
|
-
if (refreshMode === "wallet") {
|
|
336
|
-
await refreshWalletPaymentAttempt();
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
// The replacement attempt must keep the refund recipient the payer bound
|
|
340
|
-
// to the expiring attempt: refund_to exists precisely for the expiry case,
|
|
341
|
-
// and an automatic refresh gives the payer no chance to re-enter it.
|
|
342
|
-
const currentAttempt = get().cryptoPaymentAttempt;
|
|
343
|
-
await createManualDirectPaymentAttempt("", 1, currentAttempt?.refund_to ?? null, {
|
|
344
|
-
...(currentAttempt?.payment_provider === "relay"
|
|
345
|
-
? {
|
|
346
|
-
mode: "relay_deposit",
|
|
347
|
-
source: {
|
|
348
|
-
asset: currentAttempt.routing.source.token,
|
|
349
|
-
chain: currentAttempt.routing.source.chain,
|
|
350
|
-
},
|
|
351
|
-
}
|
|
352
|
-
: {}),
|
|
353
|
-
});
|
|
354
|
-
}
|
|
120
|
+
const current = get().payment;
|
|
121
|
+
return current?.id === paymentId ? current : fallbackPayment;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const updatePaymentSnapshot = (payment, attempt, extra, syncQuoteWithSnapshot = true, verifiedRefund) => {
|
|
125
|
+
if (payment) {
|
|
126
|
+
const { walletPayment, cryptoPaymentAttempt } = get();
|
|
127
|
+
const submission = walletPayment.submission;
|
|
128
|
+
const returnedQuote = payment.payment_attempt?.quote_request_id;
|
|
129
|
+
const retireWallet = isReturnedBitcoinRoute(payment) &&
|
|
130
|
+
Boolean(returnedQuote) &&
|
|
131
|
+
returnedQuote === cryptoPaymentAttempt?.quote_request_id &&
|
|
132
|
+
walletPayment.status === "submitted" &&
|
|
133
|
+
(!submission || submission.kind === "bitcoin");
|
|
134
|
+
const resolvedQuote = observeBitcoinRecovery(payment, retireWallet && submission?.kind === "bitcoin"
|
|
135
|
+
? submission.quoteId
|
|
136
|
+
: undefined, verifiedRefund);
|
|
137
|
+
if (walletPayment.status === "submitted" &&
|
|
138
|
+
(resolvedQuote
|
|
139
|
+
? !submission ||
|
|
140
|
+
(submission.kind === "bitcoin" &&
|
|
141
|
+
submission.quoteId === resolvedQuote)
|
|
142
|
+
: retireWallet && !getUncertainBitcoinSend(payment)))
|
|
143
|
+
resetWalletPaymentState();
|
|
355
144
|
}
|
|
356
|
-
catch (error) {
|
|
357
|
-
isRefreshing = false;
|
|
358
|
-
const message = error instanceof Error
|
|
359
|
-
? error.message
|
|
360
|
-
: "Failed to refresh payment quote";
|
|
361
|
-
setQuote({ status: "failed", error: message, ...clearQuoteTiming() }, refreshMode === "wallet" ? getWalletQuoteFailedState(message) : undefined);
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
isRefreshing = false;
|
|
365
|
-
if (settleQuoteFromAttempt(get().payment, get().cryptoPaymentAttempt) ===
|
|
366
|
-
"stale") {
|
|
367
|
-
setQuote({
|
|
368
|
-
status: "failed",
|
|
369
|
-
error: STALE_REPLACEMENT_QUOTE_MESSAGE,
|
|
370
|
-
...clearQuoteTiming(),
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
/**
|
|
375
|
-
* Re-sync the quote lifecycle whenever the payment snapshot or active attempt
|
|
376
|
-
* changes. A fresh attempt arms the expiry refresh timer; a stale or missing
|
|
377
|
-
* one triggers an immediate refresh. This is the only entrypoint used
|
|
378
|
-
* after loading a payment, creating an attempt, or configuring a refresh mode.
|
|
379
|
-
*/
|
|
380
|
-
export const syncQuote = (payment, attempt) => {
|
|
381
|
-
// A refresh in flight settles the final state itself; ignore the intermediate
|
|
382
|
-
// snapshot it emits while rebuilding the attempt.
|
|
383
|
-
if (isRefreshing)
|
|
384
|
-
return;
|
|
385
|
-
if (settleQuoteFromAttempt(payment, attempt ?? null) === "stale") {
|
|
386
|
-
void refreshQuote();
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
|
-
export const configureWalletQuoteRefresh = (walletAddress) => {
|
|
390
|
-
// Wallet refresh replaces a stale attempt by creating a fresh crypto payment
|
|
391
|
-
// attempt and reloading the wallet quote for the selected route.
|
|
392
|
-
refreshMode = "wallet";
|
|
393
|
-
set((state) => {
|
|
394
|
-
state.quote.error = null;
|
|
395
|
-
state.walletPayment.walletAddress = walletAddress;
|
|
396
|
-
});
|
|
397
|
-
syncQuote(get().payment, get().cryptoPaymentAttempt);
|
|
398
|
-
};
|
|
399
|
-
export const prepareWalletQuoteReplacement = (walletAddress = null) => {
|
|
400
|
-
// A payer-triggered wallet quote replacement is already fetching a new
|
|
401
|
-
// attempt/route, so pause only the automatic expiry refresh. Keep the
|
|
402
|
-
// countdown visible until the replacement quote is ready or fails.
|
|
403
|
-
refreshMode = "wallet";
|
|
404
|
-
clearQuoteAutoRefreshTimer();
|
|
405
|
-
set((state) => {
|
|
406
|
-
state.quote.error = null;
|
|
407
|
-
state.walletPayment.walletAddress =
|
|
408
|
-
walletAddress ?? state.walletPayment.walletAddress;
|
|
409
|
-
});
|
|
410
|
-
};
|
|
411
|
-
export const configureManualQuoteRefresh = () => {
|
|
412
|
-
// Manual refresh reuses the same lifecycle but only needs a fresh direct/relay
|
|
413
|
-
// address — no wallet quote metadata.
|
|
414
|
-
refreshMode = "manual";
|
|
415
|
-
set((state) => {
|
|
416
|
-
state.quote.error = null;
|
|
417
|
-
});
|
|
418
|
-
syncQuote(get().payment, get().cryptoPaymentAttempt);
|
|
419
|
-
};
|
|
420
|
-
export const clearQuoteRefresh = (options = {}) => {
|
|
421
|
-
// Drop the refresh mode before returning to method selection or closing the
|
|
422
|
-
// checkout so future expiry events do not reuse stale wallet/manual context.
|
|
423
|
-
refreshMode = "none";
|
|
424
|
-
isRefreshing = false;
|
|
425
|
-
clearQuoteExpiryTimer();
|
|
426
|
-
set((state) => {
|
|
427
|
-
state.quote = { status: "idle", error: null, ...clearQuoteTiming() };
|
|
428
|
-
if (!options.preserveWalletAddress) {
|
|
429
|
-
state.walletPayment.walletAddress = null;
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
};
|
|
433
|
-
const updatePaymentSnapshot = (payment, attempt, extra) => {
|
|
434
145
|
set((state) => {
|
|
435
146
|
state.payment = payment;
|
|
436
147
|
state.cryptoPaymentAttempt =
|
|
@@ -441,8 +152,16 @@ const updatePaymentSnapshot = (payment, attempt, extra) => {
|
|
|
441
152
|
});
|
|
442
153
|
// Hydrate the current attempt from the payment snapshot so retry can resume
|
|
443
154
|
// the existing quote context and refresh it instead of restarting selection.
|
|
444
|
-
|
|
445
|
-
|
|
155
|
+
if (syncQuoteWithSnapshot)
|
|
156
|
+
syncQuote(payment, get().cryptoPaymentAttempt);
|
|
157
|
+
};
|
|
158
|
+
export const { followPayment } = createPaymentObserver({
|
|
159
|
+
get,
|
|
160
|
+
captureOpening: captureCheckoutOpening,
|
|
161
|
+
updatePaymentSnapshot: (payment, attempt, syncQuote, verifiedRefund) => updatePaymentSnapshot(payment, attempt, undefined, syncQuote, verifiedRefund),
|
|
162
|
+
hydrateCheckout: (payment) => hydrateCheckoutFromPayment(payment),
|
|
163
|
+
});
|
|
164
|
+
const recoverFromIssuanceConflict = createIssuanceConflictRecovery((payment) => updatePaymentSnapshot(payment));
|
|
446
165
|
export const clearErrors = () => {
|
|
447
166
|
set((state) => {
|
|
448
167
|
Object.values(ACTIONS).forEach((action) => {
|
|
@@ -451,41 +170,55 @@ export const clearErrors = () => {
|
|
|
451
170
|
});
|
|
452
171
|
};
|
|
453
172
|
export const initialiseStore = async (payment) => {
|
|
454
|
-
resetCheckoutStore();
|
|
455
|
-
|
|
173
|
+
resetCheckoutStore(payment);
|
|
174
|
+
const canUpdate = captureCheckoutOpening();
|
|
456
175
|
try {
|
|
457
176
|
const refreshedPayment = await getPaymentById(payment.id);
|
|
177
|
+
if (!canUpdate())
|
|
178
|
+
return;
|
|
458
179
|
updatePaymentSnapshot(refreshedPayment);
|
|
459
180
|
hydrateCheckoutFromPayment(refreshedPayment);
|
|
181
|
+
// Pending payments use their submission to resume the status view, which
|
|
182
|
+
// retries while polling. A settled payment might never start polling.
|
|
183
|
+
if (refreshedPayment.status !== PaymentStatus.PENDING) {
|
|
184
|
+
void retryBitcoinBroadcast(payment.id);
|
|
185
|
+
}
|
|
460
186
|
}
|
|
461
187
|
catch (err) {
|
|
188
|
+
if (!canUpdate())
|
|
189
|
+
return;
|
|
462
190
|
set((state) => {
|
|
463
191
|
state.error[ACTIONS.GET_CHECKOUT_CONFIG] = "Failed to load checkout";
|
|
464
192
|
});
|
|
465
193
|
}
|
|
466
194
|
};
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
const
|
|
473
|
-
if (!
|
|
195
|
+
/**
|
|
196
|
+
* The checks every issuing call shares: the opening (and the caller's own
|
|
197
|
+
* lifetime) still owns the request, and the payment still takes instructions.
|
|
198
|
+
*/
|
|
199
|
+
const beginIssuance = (owns) => {
|
|
200
|
+
const canUpdate = captureCheckoutOpening(owns);
|
|
201
|
+
if (!canUpdate())
|
|
202
|
+
throw new Error("Checkout is no longer active");
|
|
203
|
+
const payment = get().payment;
|
|
204
|
+
if (!payment?.id) {
|
|
474
205
|
throw Error("Cannot create payment attempt without payment object.");
|
|
475
206
|
}
|
|
476
207
|
if (!canCreateFreshAttempt(payment)) {
|
|
477
208
|
throw Error(PAYMENT_NO_LONGER_PAYABLE_MESSAGE);
|
|
478
209
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
210
|
+
assertNoUncertainBitcoinSend(payment.id);
|
|
211
|
+
return { canUpdate, payment, paymentId: payment.id };
|
|
212
|
+
};
|
|
213
|
+
export const createWalletOptionPaymentAttempt = async (
|
|
214
|
+
// "direct" is a routing classification: the payer sends the settlement
|
|
215
|
+
// asset on the settlement chain. It is not tied to manual vs wallet UX.
|
|
216
|
+
option, sendingAddress, quote, ownsWallet) => {
|
|
217
|
+
const { canUpdate, payment, paymentId } = beginIssuance(ownsWallet);
|
|
218
|
+
const quoteRequestId = quoteLifecycle.getWalletQuoteRequestId();
|
|
219
|
+
// The refund recipient is frozen at issuance: the first wallet Pay names the
|
|
220
|
+
// connected wallet, and later calls never send it (QCT D1, D7).
|
|
221
|
+
const refundTo = isCheckoutIssued() ? null : sendingAddress;
|
|
489
222
|
try {
|
|
490
223
|
set((state) => {
|
|
491
224
|
state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = null;
|
|
@@ -496,108 +229,141 @@ option, sendingAddress, quote) => {
|
|
|
496
229
|
sendingAddress,
|
|
497
230
|
quote,
|
|
498
231
|
requiredConfirmations: 1,
|
|
232
|
+
quoteRequestId,
|
|
233
|
+
refundTo,
|
|
499
234
|
});
|
|
500
235
|
const attempt = await createPaymentAttempt(paymentId, attemptPayload, 1);
|
|
501
|
-
|
|
502
|
-
|
|
236
|
+
if (!canUpdate())
|
|
237
|
+
return attempt;
|
|
238
|
+
if (attempt.quote_request_id !== quoteRequestId) {
|
|
239
|
+
throw changedQuoteError("Could not get a fresh payment quote. Please try again.");
|
|
240
|
+
}
|
|
241
|
+
const refreshedPayment = await getPaymentSnapshotAfterAttempt(paymentId, payment);
|
|
242
|
+
if (!canUpdate())
|
|
243
|
+
return attempt;
|
|
244
|
+
const currentAttempt = reconcileIssuedAttempt(attempt, refreshedPayment.payment_attempt);
|
|
245
|
+
updatePaymentSnapshot(withFreshAttempt(refreshedPayment, currentAttempt), currentAttempt, (state) => {
|
|
503
246
|
state.retrySession = false;
|
|
504
247
|
state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = null;
|
|
505
248
|
state.loading[ACTIONS.CREATE_PAYMENT_ATTEMPT] = false;
|
|
506
249
|
});
|
|
250
|
+
if (currentAttempt !== attempt)
|
|
251
|
+
throw changedQuoteError();
|
|
507
252
|
return attempt;
|
|
508
253
|
}
|
|
509
254
|
catch (err) {
|
|
510
|
-
|
|
255
|
+
if (!canUpdate())
|
|
256
|
+
throw err;
|
|
257
|
+
if (getCryptoPayConflictCode(err) === "PAYMENT_QUOTE_CHANGED") {
|
|
258
|
+
quoteLifecycle.clearWalletQuoteRequestId(quoteRequestId);
|
|
259
|
+
}
|
|
260
|
+
const error = await recoverFromIssuanceConflict(err, paymentId, canUpdate, [
|
|
261
|
+
"REFUND_RECIPIENT_FIXED",
|
|
262
|
+
]);
|
|
263
|
+
if (!canUpdate())
|
|
264
|
+
throw error;
|
|
511
265
|
set((state) => {
|
|
512
|
-
state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = error
|
|
266
|
+
state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = describeRequestFailure(error, "Failed to create payment attempt");
|
|
513
267
|
state.loading[ACTIONS.CREATE_PAYMENT_ATTEMPT] = false;
|
|
514
268
|
});
|
|
515
269
|
throw error;
|
|
516
270
|
}
|
|
517
271
|
};
|
|
518
|
-
export const createManualDirectPaymentAttempt = async (sendingAddress = "", confirmations = 1, refundTo, options = {}) => {
|
|
519
|
-
const payment =
|
|
520
|
-
const
|
|
521
|
-
if (!paymentId) {
|
|
522
|
-
throw Error("Cannot create payment attempt without payment object.");
|
|
523
|
-
}
|
|
524
|
-
if (!canCreateFreshAttempt(payment)) {
|
|
525
|
-
throw Error(PAYMENT_NO_LONGER_PAYABLE_MESSAGE);
|
|
526
|
-
}
|
|
527
|
-
const settlementConfig = getRequiredSettlementConfig(payment);
|
|
272
|
+
export const createManualDirectPaymentAttempt = async (sendingAddress = "", confirmations = 1, refundTo, options = {}, ownsQuote) => {
|
|
273
|
+
const { canUpdate, payment, paymentId } = beginIssuance(ownsQuote);
|
|
274
|
+
const settlementConfig = getRouteSettlement(payment);
|
|
528
275
|
const source = options.source ?? {
|
|
529
276
|
asset: settlementConfig.asset,
|
|
530
277
|
chain: settlementConfig.chain,
|
|
531
278
|
};
|
|
532
279
|
const normalizedSendingAddress = sendingAddress.trim();
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
280
|
+
// The refund recipient is frozen at issuance: only the first issuing call
|
|
281
|
+
// names it (the manual refund field, else the checkout fallback). Later
|
|
282
|
+
// reveals and refreshes never send it (QCT D1, D7).
|
|
283
|
+
const refundRecipient = isCheckoutIssued()
|
|
284
|
+
? {}
|
|
285
|
+
: { refund_to: refundTo?.trim() || normalizedSendingAddress || null };
|
|
539
286
|
const attemptPayload = {
|
|
540
|
-
|
|
287
|
+
...buildManualRoutePayload(source, settlementConfig, options.mode),
|
|
541
288
|
...(normalizedSendingAddress
|
|
542
289
|
? { sendingAddress: normalizedSendingAddress }
|
|
543
290
|
: {}),
|
|
544
|
-
|
|
291
|
+
...refundRecipient,
|
|
545
292
|
required_confirmations: confirmations,
|
|
546
|
-
source: options.mode === "relay_deposit"
|
|
547
|
-
? {
|
|
548
|
-
token: source.asset,
|
|
549
|
-
chain: source.chain,
|
|
550
|
-
}
|
|
551
|
-
: undefined,
|
|
552
|
-
routing: {
|
|
553
|
-
type: routingType,
|
|
554
|
-
source: {
|
|
555
|
-
token: source.asset,
|
|
556
|
-
chain: source.chain,
|
|
557
|
-
},
|
|
558
|
-
},
|
|
559
293
|
};
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
294
|
+
let attempt;
|
|
295
|
+
try {
|
|
296
|
+
attempt = await createPaymentAttempt(paymentId, attemptPayload);
|
|
297
|
+
}
|
|
298
|
+
catch (err) {
|
|
299
|
+
if (!canUpdate())
|
|
300
|
+
throw err;
|
|
301
|
+
// Revealed instructions refresh through this call, so a closed payment is
|
|
302
|
+
// read again: it may hold the payer's funds rather than need a new link.
|
|
303
|
+
throw await recoverFromIssuanceConflict(err, paymentId, canUpdate, [
|
|
304
|
+
"REFUND_RECIPIENT_FIXED",
|
|
305
|
+
"PAYMENT_REQUIRES_NEW_LINK",
|
|
306
|
+
]);
|
|
307
|
+
}
|
|
308
|
+
if (!canUpdate())
|
|
309
|
+
return attempt;
|
|
310
|
+
const refreshedPayment = await getPaymentSnapshotAfterAttempt(paymentId, payment);
|
|
311
|
+
if (!canUpdate())
|
|
312
|
+
return attempt;
|
|
313
|
+
const currentAttempt = reconcileIssuedAttempt(attempt, refreshedPayment.payment_attempt);
|
|
314
|
+
updatePaymentSnapshot(withFreshAttempt(refreshedPayment, currentAttempt), currentAttempt, (state) => {
|
|
563
315
|
state.retrySession = false;
|
|
564
316
|
});
|
|
565
317
|
return attempt;
|
|
566
318
|
};
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
319
|
+
/** Prices a selected wallet route without issuing payment instructions. */
|
|
320
|
+
export const priceWalletRoute = async (option, walletAddress, ownsQuote) => {
|
|
321
|
+
const canUpdate = captureCheckoutOpening(ownsQuote);
|
|
322
|
+
if (!canUpdate())
|
|
323
|
+
throw new Error("Checkout is no longer active");
|
|
324
|
+
const payment = get().payment;
|
|
325
|
+
if (!payment) {
|
|
326
|
+
throw new Error("Cannot price a route without payment object.");
|
|
571
327
|
}
|
|
328
|
+
let estimate;
|
|
572
329
|
try {
|
|
573
|
-
|
|
574
|
-
state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = null;
|
|
575
|
-
state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = true;
|
|
576
|
-
});
|
|
577
|
-
const currentPayment = useCheckoutStore.getState().payment;
|
|
578
|
-
if (!currentPayment) {
|
|
579
|
-
throw Error("Cannot create test payment attempt without payment object.");
|
|
580
|
-
}
|
|
581
|
-
const attempt = await createTestPaymentAttempt(paymentId, "0xsuccess", currentPayment);
|
|
582
|
-
const payment = await getPaymentById(paymentId);
|
|
583
|
-
updatePaymentSnapshot(payment, attempt, (state) => {
|
|
584
|
-
state.retrySession = false;
|
|
585
|
-
state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = null;
|
|
586
|
-
state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = false;
|
|
587
|
-
});
|
|
330
|
+
estimate = await estimateCryptoPay(payment.id, buildWalletEstimatePayload({ option, sendingAddress: walletAddress }));
|
|
588
331
|
}
|
|
589
332
|
catch (err) {
|
|
590
|
-
|
|
591
|
-
set((state) => {
|
|
592
|
-
state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = error.message;
|
|
593
|
-
state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = false;
|
|
594
|
-
});
|
|
595
|
-
throw error;
|
|
333
|
+
throw withConflictCopy(err);
|
|
596
334
|
}
|
|
335
|
+
assertNoUncertainBitcoinSend(payment.id);
|
|
336
|
+
if (option.fromChain === BITCOIN_CHAIN) {
|
|
337
|
+
return priceBitcoinWalletEstimate(estimate);
|
|
338
|
+
}
|
|
339
|
+
const attempt = getCurrentCheckoutAttempt();
|
|
340
|
+
const priced = await priceEstimate(estimate, getRouteSettlement(payment), attempt);
|
|
341
|
+
if (option.kind === "direct") {
|
|
342
|
+
return {
|
|
343
|
+
quote: { kind: "quoted", quote: buildDirectWalletQuote(option, priced) },
|
|
344
|
+
expiresAt: priced.expiresAt,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
// Keep routed-quote loading behind a dynamic import so the checkout store
|
|
348
|
+
// does not eagerly pull the LI.FI integration path into manual-only flows.
|
|
349
|
+
const { fetchWalletRouteQuote } = await import("../../integrations/index.js");
|
|
350
|
+
const quote = await fetchWalletRouteQuote({
|
|
351
|
+
option,
|
|
352
|
+
walletAddress,
|
|
353
|
+
target: buildWalletQuoteTarget({
|
|
354
|
+
priced,
|
|
355
|
+
attempt: getCurrentCheckoutAttempt(),
|
|
356
|
+
settlement: getRouteSettlement(payment),
|
|
357
|
+
walletAddress,
|
|
358
|
+
}),
|
|
359
|
+
});
|
|
360
|
+
return { quote: { kind: "quoted", quote }, expiresAt: priced.expiresAt };
|
|
597
361
|
};
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
362
|
+
// A test payment settles or fails through the transaction hash it reports.
|
|
363
|
+
const createSimulatedTestPaymentAttempt = async (txHash) => {
|
|
364
|
+
const canUpdate = captureCheckoutOpening();
|
|
365
|
+
const payment = get().payment;
|
|
366
|
+
if (!payment?.id) {
|
|
601
367
|
throw Error("Cannot create test payment attempt without payment object.");
|
|
602
368
|
}
|
|
603
369
|
try {
|
|
@@ -605,19 +371,21 @@ export const createFailedTestPaymentAttempt = async () => {
|
|
|
605
371
|
state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = null;
|
|
606
372
|
state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = true;
|
|
607
373
|
});
|
|
608
|
-
const
|
|
609
|
-
if (!
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
updatePaymentSnapshot(
|
|
374
|
+
const attempt = await createTestPaymentAttempt(payment.id, txHash, payment);
|
|
375
|
+
if (!canUpdate())
|
|
376
|
+
return;
|
|
377
|
+
const refreshedPayment = await getPaymentById(payment.id);
|
|
378
|
+
if (!canUpdate())
|
|
379
|
+
return;
|
|
380
|
+
updatePaymentSnapshot(refreshedPayment, attempt, (state) => {
|
|
615
381
|
state.retrySession = false;
|
|
616
382
|
state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = null;
|
|
617
383
|
state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = false;
|
|
618
384
|
});
|
|
619
385
|
}
|
|
620
386
|
catch (err) {
|
|
387
|
+
if (!canUpdate())
|
|
388
|
+
return;
|
|
621
389
|
const error = err;
|
|
622
390
|
set((state) => {
|
|
623
391
|
state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = error.message;
|
|
@@ -626,6 +394,8 @@ export const createFailedTestPaymentAttempt = async () => {
|
|
|
626
394
|
throw error;
|
|
627
395
|
}
|
|
628
396
|
};
|
|
397
|
+
export const createSuccessfulTestPaymentAttempt = () => createSimulatedTestPaymentAttempt("0xsuccess");
|
|
398
|
+
export const createFailedTestPaymentAttempt = () => createSimulatedTestPaymentAttempt("0xfail");
|
|
629
399
|
export function getAvailableCheckoutMethods(checkout) {
|
|
630
400
|
const methods = [];
|
|
631
401
|
if (checkout.checkout_config.crypto?.enabled) {
|
|
@@ -666,48 +436,10 @@ export const hydrateCheckoutFromPayment = (payment) => {
|
|
|
666
436
|
});
|
|
667
437
|
}
|
|
668
438
|
};
|
|
669
|
-
export const
|
|
670
|
-
const
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
state.error[ACTION] = null;
|
|
674
|
-
});
|
|
675
|
-
const payment = get().payment;
|
|
676
|
-
if (!payment) {
|
|
677
|
-
set((state) => {
|
|
678
|
-
state.loading[ACTION] = false;
|
|
679
|
-
state.error[ACTION] = "No payment found";
|
|
680
|
-
});
|
|
681
|
-
return null;
|
|
682
|
-
}
|
|
683
|
-
try {
|
|
684
|
-
const resp = await getPaymentById(payment.id);
|
|
685
|
-
if (resp) {
|
|
686
|
-
updatePaymentSnapshot(resp);
|
|
687
|
-
set((state) => {
|
|
688
|
-
state.loading[ACTION] = false;
|
|
689
|
-
state.error[ACTION] = null;
|
|
690
|
-
});
|
|
691
|
-
hydrateCheckoutFromPayment(resp);
|
|
692
|
-
return resp;
|
|
693
|
-
}
|
|
694
|
-
else {
|
|
695
|
-
set((state) => {
|
|
696
|
-
state.loading[ACTION] = false;
|
|
697
|
-
state.error[ACTION] = "Failed to load payment";
|
|
698
|
-
});
|
|
699
|
-
return null;
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
catch (error) {
|
|
703
|
-
set((state) => {
|
|
704
|
-
state.loading[ACTION] = false;
|
|
705
|
-
state.error[ACTION] = "Failed to load payment";
|
|
706
|
-
});
|
|
707
|
-
return null;
|
|
708
|
-
}
|
|
709
|
-
};
|
|
710
|
-
export const executeTransfer = async (wallet) => {
|
|
439
|
+
export const executeTransfer = async (wallet, ownsWallet, beforeSign) => {
|
|
440
|
+
const canExecute = captureCheckoutOpening(ownsWallet);
|
|
441
|
+
if (!canExecute())
|
|
442
|
+
throw new Error("Checkout is no longer active");
|
|
711
443
|
const ACTION = ACTIONS.EXECUTE_TRANSFER;
|
|
712
444
|
const state = get();
|
|
713
445
|
if (!state.cryptoPaymentAttempt) {
|
|
@@ -722,6 +454,7 @@ export const executeTransfer = async (wallet) => {
|
|
|
722
454
|
state.transfer.chainStatus = "pending";
|
|
723
455
|
});
|
|
724
456
|
try {
|
|
457
|
+
beforeSign?.();
|
|
725
458
|
const settlementChainHex = state.cryptoPaymentAttempt.settlement_config.chain_hex;
|
|
726
459
|
const targetChainId = resolveEvmChainId(settlementChainHex);
|
|
727
460
|
if (targetChainId && wallet.switchChain) {
|
|
@@ -737,13 +470,20 @@ export const executeTransfer = async (wallet) => {
|
|
|
737
470
|
const transfer = {
|
|
738
471
|
sendingAddress: address,
|
|
739
472
|
destinationAddress: state.cryptoPaymentAttempt.destination_address,
|
|
740
|
-
amount: state.cryptoPaymentAttempt.
|
|
473
|
+
amount: state.cryptoPaymentAttempt.amount_to_pay ??
|
|
474
|
+
state.cryptoPaymentAttempt.amount,
|
|
741
475
|
evm: {
|
|
742
476
|
implementationAddress: state.cryptoPaymentAttempt.settlement_token_address,
|
|
743
477
|
assetName: state.cryptoPaymentAttempt.settlement_config.asset_name,
|
|
744
478
|
},
|
|
745
479
|
};
|
|
746
|
-
|
|
480
|
+
if (!canExecute()) {
|
|
481
|
+
throw new Error("Wallet connection changed. Connect again before paying.");
|
|
482
|
+
}
|
|
483
|
+
beforeSign?.();
|
|
484
|
+
const txHash = await wallet.executeTransfer(transfer, beforeSign);
|
|
485
|
+
if (!canExecute())
|
|
486
|
+
return txHash;
|
|
747
487
|
if (!txHash) {
|
|
748
488
|
throw new Error("Failed to get transaction hash");
|
|
749
489
|
}
|
|
@@ -756,6 +496,8 @@ export const executeTransfer = async (wallet) => {
|
|
|
756
496
|
return txHash;
|
|
757
497
|
}
|
|
758
498
|
catch (error) {
|
|
499
|
+
if (!canExecute())
|
|
500
|
+
throw error;
|
|
759
501
|
const errorMessage = error instanceof Error ? error.message : "Failed to execute transfer";
|
|
760
502
|
set((state) => {
|
|
761
503
|
state.transfer.status = "failed";
|
|
@@ -766,52 +508,64 @@ export const executeTransfer = async (wallet) => {
|
|
|
766
508
|
throw error instanceof Error ? error : new Error(errorMessage);
|
|
767
509
|
}
|
|
768
510
|
};
|
|
769
|
-
export
|
|
511
|
+
export class TransferRevertedError extends Error {
|
|
512
|
+
constructor() {
|
|
513
|
+
super("Transaction reverted before confirmation");
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
export const checkChainStatus = async (wallet, submitted) => {
|
|
770
517
|
const ACTION = ACTIONS.CHECK_CHAIN_STATUS;
|
|
771
518
|
const state = get();
|
|
772
|
-
|
|
519
|
+
const hash = submitted?.hash ?? state.transfer.transactionHash;
|
|
520
|
+
const canUpdate = captureCheckoutOpening(submitted?.canUpdate);
|
|
521
|
+
if (!hash || (!submitted && state.transfer.status !== "success")) {
|
|
773
522
|
return;
|
|
774
523
|
}
|
|
775
524
|
// Check if the wallet is a WagmiWalletInterface
|
|
776
525
|
if (!(wallet instanceof WagmiWalletInterface)) {
|
|
777
526
|
const error = new Error("Wallet does not support chain status checks");
|
|
778
527
|
console.error(error.message);
|
|
779
|
-
|
|
780
|
-
state
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
528
|
+
if (canUpdate())
|
|
529
|
+
set((state) => {
|
|
530
|
+
state.transfer.status = "failed";
|
|
531
|
+
state.transfer.error = error.message;
|
|
532
|
+
state.transfer.chainStatus = "failed";
|
|
533
|
+
state.error[ACTION] = error.message;
|
|
534
|
+
});
|
|
785
535
|
throw error;
|
|
786
536
|
}
|
|
787
|
-
|
|
788
|
-
state
|
|
789
|
-
|
|
790
|
-
|
|
537
|
+
if (canUpdate())
|
|
538
|
+
set((state) => {
|
|
539
|
+
state.loading[ACTION] = true;
|
|
540
|
+
state.error[ACTION] = null;
|
|
541
|
+
});
|
|
791
542
|
try {
|
|
792
543
|
const receipt = await waitForTransactionReceipt(wallet.wagmiConfig, {
|
|
793
|
-
hash:
|
|
544
|
+
hash: hash,
|
|
545
|
+
chainId: submitted?.chainId,
|
|
794
546
|
confirmations: 1,
|
|
795
547
|
});
|
|
796
548
|
if (receipt.status === "reverted") {
|
|
797
|
-
throw new
|
|
549
|
+
throw new TransferRevertedError();
|
|
798
550
|
}
|
|
799
|
-
|
|
800
|
-
state
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
551
|
+
if (canUpdate())
|
|
552
|
+
set((state) => {
|
|
553
|
+
state.transfer.chainStatus = "confirmed";
|
|
554
|
+
state.loading[ACTION] = false;
|
|
555
|
+
state.error[ACTION] = null;
|
|
556
|
+
});
|
|
804
557
|
}
|
|
805
558
|
catch (error) {
|
|
806
559
|
console.error("Error checking transaction status:", error);
|
|
807
560
|
const errorMessage = error instanceof Error ? error.message : "Failed to check chain status";
|
|
808
|
-
|
|
809
|
-
state
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
561
|
+
if (canUpdate())
|
|
562
|
+
set((state) => {
|
|
563
|
+
state.transfer.status = "failed";
|
|
564
|
+
state.transfer.error = errorMessage;
|
|
565
|
+
state.transfer.chainStatus = "failed";
|
|
566
|
+
state.loading[ACTION] = false;
|
|
567
|
+
state.error[ACTION] = errorMessage;
|
|
568
|
+
});
|
|
815
569
|
throw error instanceof Error ? error : new Error(errorMessage);
|
|
816
570
|
}
|
|
817
571
|
};
|
|
@@ -825,147 +579,40 @@ export const resetTransfer = () => {
|
|
|
825
579
|
};
|
|
826
580
|
});
|
|
827
581
|
};
|
|
828
|
-
export const
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
let pollInterval = null;
|
|
832
|
-
const pollPaymentStatus = async () => {
|
|
833
|
-
const state = get();
|
|
834
|
-
if (!state.polling.isPolling)
|
|
835
|
-
return;
|
|
836
|
-
set((state) => {
|
|
837
|
-
state.polling.pollCount++;
|
|
838
|
-
state.polling.lastPollTime = Date.now();
|
|
839
|
-
});
|
|
840
|
-
try {
|
|
841
|
-
const updatedPayment = await getPayment();
|
|
842
|
-
if (!updatedPayment) {
|
|
843
|
-
return;
|
|
844
|
-
}
|
|
845
|
-
if (isPaymentPollingTerminal(updatedPayment.status, confirmationStatus)) {
|
|
846
|
-
onPaymentStatusChange(updatedPayment.status);
|
|
847
|
-
stopPaymentPolling();
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
catch (error) {
|
|
851
|
-
console.error(`[Payment Poll] Error fetching payment status (poll #${state.polling.pollCount}):`, error);
|
|
852
|
-
}
|
|
853
|
-
};
|
|
854
|
-
const stopPolling = () => {
|
|
855
|
-
if (pollInterval) {
|
|
856
|
-
clearInterval(pollInterval);
|
|
857
|
-
pollInterval = null;
|
|
858
|
-
}
|
|
859
|
-
set((state) => {
|
|
860
|
-
state.polling.isPolling = false;
|
|
861
|
-
});
|
|
862
|
-
};
|
|
863
|
-
set((state) => {
|
|
864
|
-
state.polling.isPolling = true;
|
|
865
|
-
state.polling.pollCount = 0;
|
|
866
|
-
state.polling.lastPollTime = null;
|
|
867
|
-
state.loading[ACTION] = true;
|
|
868
|
-
state.error[ACTION] = null;
|
|
869
|
-
});
|
|
870
|
-
// Start polling immediately
|
|
871
|
-
void pollPaymentStatus();
|
|
872
|
-
// Set up interval for subsequent polls
|
|
873
|
-
pollInterval = setInterval(pollPaymentStatus, POLL_INTERVAL);
|
|
874
|
-
return {
|
|
875
|
-
stop: stopPolling,
|
|
876
|
-
};
|
|
877
|
-
};
|
|
878
|
-
export const stopPaymentPolling = () => {
|
|
879
|
-
set((state) => {
|
|
880
|
-
state.polling.isPolling = false;
|
|
881
|
-
state.polling.pollCount = 0;
|
|
882
|
-
state.polling.lastPollTime = null;
|
|
883
|
-
state.loading[ACTIONS.POLL_PAYMENT] = false;
|
|
884
|
-
});
|
|
885
|
-
};
|
|
886
|
-
export const resetCheckoutStore = () => {
|
|
887
|
-
refreshMode = "none";
|
|
888
|
-
isRefreshing = false;
|
|
889
|
-
clearQuoteExpiryTimer();
|
|
582
|
+
export const resetCheckoutStore = (payment = null) => {
|
|
583
|
+
checkoutOpening += 1;
|
|
584
|
+
quoteLifecycle.dispose();
|
|
890
585
|
set((state) => {
|
|
891
|
-
Object.assign(state, {
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
selectedMethod: null,
|
|
895
|
-
selectedCurrency: null,
|
|
896
|
-
retrySession: false,
|
|
897
|
-
methods: null,
|
|
898
|
-
cryptoCurrency: null,
|
|
899
|
-
checkout: null,
|
|
900
|
-
payment: null,
|
|
901
|
-
cryptoPaymentAttempt: null,
|
|
902
|
-
quote: {
|
|
903
|
-
status: "idle",
|
|
904
|
-
error: null,
|
|
905
|
-
expiresAt: null,
|
|
906
|
-
remainingMs: null,
|
|
907
|
-
totalDurationMs: null,
|
|
908
|
-
},
|
|
909
|
-
loading: initialActionState(false),
|
|
910
|
-
error: initialActionState(null),
|
|
911
|
-
transfer: {
|
|
912
|
-
status: "idle",
|
|
913
|
-
error: null,
|
|
914
|
-
transactionHash: null,
|
|
915
|
-
chainStatus: "pending",
|
|
916
|
-
},
|
|
917
|
-
polling: {
|
|
918
|
-
isPolling: false,
|
|
919
|
-
pollCount: 0,
|
|
920
|
-
lastPollTime: null,
|
|
921
|
-
},
|
|
922
|
-
walletPayment: initialWalletPaymentState(),
|
|
586
|
+
Object.assign(state, createInitialCheckoutState(), {
|
|
587
|
+
payment,
|
|
588
|
+
cryptoPaymentAttempt: payment?.payment_attempt ?? null,
|
|
923
589
|
});
|
|
924
590
|
});
|
|
925
591
|
};
|
|
926
592
|
export const resetCheckoutSessionForRetry = () => {
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
593
|
+
checkoutOpening += 1;
|
|
594
|
+
quoteLifecycle.dispose();
|
|
595
|
+
const initial = createInitialCheckoutState();
|
|
930
596
|
set((state) => {
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
};
|
|
951
|
-
state.walletPayment = initialWalletPaymentState();
|
|
952
|
-
state.quote = {
|
|
953
|
-
status: "idle",
|
|
954
|
-
error: null,
|
|
955
|
-
expiresAt: null,
|
|
956
|
-
remainingMs: null,
|
|
957
|
-
totalDurationMs: null,
|
|
958
|
-
};
|
|
959
|
-
state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = null;
|
|
960
|
-
state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = null;
|
|
961
|
-
state.error[ACTIONS.EXECUTE_TRANSFER] = null;
|
|
962
|
-
state.error[ACTIONS.POLL_PAYMENT] = null;
|
|
963
|
-
state.error[ACTIONS.CHECK_CHAIN_STATUS] = null;
|
|
964
|
-
state.loading[ACTIONS.CREATE_PAYMENT_ATTEMPT] = false;
|
|
965
|
-
state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = false;
|
|
966
|
-
state.loading[ACTIONS.EXECUTE_TRANSFER] = false;
|
|
967
|
-
state.loading[ACTIONS.POLL_PAYMENT] = false;
|
|
968
|
-
state.loading[ACTIONS.CHECK_CHAIN_STATUS] = false;
|
|
597
|
+
Object.assign(state, {
|
|
598
|
+
selectedMethod: initial.selectedMethod,
|
|
599
|
+
selectedCurrency: initial.selectedCurrency,
|
|
600
|
+
retrySession: true,
|
|
601
|
+
cryptoPaymentAttempt: initial.cryptoPaymentAttempt,
|
|
602
|
+
processing: initial.processing,
|
|
603
|
+
transfer: initial.transfer,
|
|
604
|
+
walletPayment: initial.walletPayment,
|
|
605
|
+
quote: initial.quote,
|
|
606
|
+
});
|
|
607
|
+
for (const action of [
|
|
608
|
+
ACTIONS.CREATE_PAYMENT_ATTEMPT,
|
|
609
|
+
ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT,
|
|
610
|
+
ACTIONS.EXECUTE_TRANSFER,
|
|
611
|
+
ACTIONS.CHECK_CHAIN_STATUS,
|
|
612
|
+
]) {
|
|
613
|
+
state.error[action] = initial.error[action];
|
|
614
|
+
state.loading[action] = initial.loading[action];
|
|
615
|
+
}
|
|
969
616
|
});
|
|
970
617
|
};
|
|
971
618
|
export const setCheckoutMethod = (method) => {
|
|
@@ -998,9 +645,4 @@ export const setWalletPaymentState = (update) => {
|
|
|
998
645
|
Object.assign(state.walletPayment, update);
|
|
999
646
|
});
|
|
1000
647
|
};
|
|
1001
|
-
export const resetWalletPaymentState = () => {
|
|
1002
|
-
set((state) => {
|
|
1003
|
-
state.walletPayment = initialWalletPaymentState();
|
|
1004
|
-
});
|
|
1005
|
-
};
|
|
1006
648
|
//# sourceMappingURL=store.js.map
|