@mintmoney/react 0.2.0-alpha.2 → 0.2.0-alpha.4
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 +4 -0
- package/dist/docs/quickstart.md +2 -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 +36 -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 +19 -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 +54 -13
- package/dist/esm/checkout/index.js.map +1 -1
- package/dist/esm/checkout/modal.js +52 -23
- 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 +140 -44
- package/dist/esm/checkout/providers/checkout-wallet.js.map +1 -1
- package/dist/esm/checkout/providers/wagmi-config.js +6 -3
- 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 +207 -1
- 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 +11 -2
- package/dist/esm/checkout/views/amount-header.js.map +1 -1
- package/dist/esm/checkout/views/claimable-funds.js +21 -13
- package/dist/esm/checkout/views/claimable-funds.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/direct-details.js +288 -888
- package/dist/esm/checkout/views/crypto-intent/direct-details.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/manual-instruction-card.js +239 -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 +309 -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/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 +183 -32
- 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/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 +105 -627
- 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 +4 -11
- package/dist/esm/checkout/views/crypto-intent/wallet-select.js.map +1 -1
- package/dist/esm/checkout/views/failed.js +44 -55
- package/dist/esm/checkout/views/failed.js.map +1 -1
- package/dist/esm/checkout/views/funding-timeline.js +182 -0
- package/dist/esm/checkout/views/funding-timeline.js.map +1 -0
- package/dist/esm/checkout/views/initial.js +35 -46
- 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 +128 -0
- package/dist/esm/checkout/views/payment-follower.js.map +1 -0
- package/dist/esm/checkout/views/restart.js +17 -2
- package/dist/esm/checkout/views/restart.js.map +1 -1
- package/dist/esm/checkout/views/use-checkout-refund-status.js +75 -0
- package/dist/esm/checkout/views/use-checkout-refund-status.js.map +1 -0
- 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 +8 -14
- 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 +36 -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 +134 -45
- package/dist/esm/integrations/lifi.js.map +1 -1
- package/dist/esm/refund/index.js +237 -227
- package/dist/esm/refund/index.js.map +1 -1
- package/dist/esm/state/checkout/bitcoin-payment.js +254 -0
- package/dist/esm/state/checkout/bitcoin-payment.js.map +1 -0
- package/dist/esm/state/checkout/checkout-state.js +5 -11
- package/dist/esm/state/checkout/checkout-state.js.map +1 -1
- 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 +44 -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 +148 -0
- package/dist/esm/state/checkout/payment-observer.js.map +1 -0
- package/dist/esm/state/checkout/payment-phase.js +142 -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 +145 -144
- package/dist/esm/state/checkout/quote-lifecycle.js.map +1 -1
- 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 +348 -313
- package/dist/esm/state/checkout/store.js.map +1 -1
- package/dist/esm/state/checkout/wallet-payment.js +334 -37
- package/dist/esm/state/checkout/wallet-payment.js.map +1 -1
- package/dist/esm/state/checkout/wallet-transfer-receipt.js +68 -0
- package/dist/esm/state/checkout/wallet-transfer-receipt.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 -707
- package/dist/types/api/generated.d.ts.map +1 -1
- package/dist/types/api/payments.d.ts +22 -2
- 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 +30 -2
- package/dist/types/api/types.d.ts.map +1 -1
- package/dist/types/checkout/claimable-funds.d.ts +12 -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 +23 -2
- package/dist/types/checkout/index.d.ts.map +1 -1
- package/dist/types/checkout/modal.d.ts +5 -2
- 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 +2 -3
- package/dist/types/checkout/providers/checkout-wallet.d.ts.map +1 -1
- 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 +63 -1
- 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 +1 -0
- 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 +11 -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/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 +3 -2
- 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/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 +21 -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 +12 -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/checkout/views/use-checkout-refund-status.d.ts +74 -0
- package/dist/types/checkout/views/use-checkout-refund-status.d.ts.map +1 -0
- 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 +3 -1
- 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 -1
- package/dist/types/components/wallet-selector/wallets/wagmi/index.d.ts.map +1 -1
- package/dist/types/config.d.ts +2 -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 +42 -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 +46 -13
- package/dist/types/state/checkout/checkout-state.d.ts.map +1 -1
- 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 +19 -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 +42 -0
- package/dist/types/state/checkout/payment-observer.d.ts.map +1 -0
- package/dist/types/state/checkout/payment-phase.d.ts +118 -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 +17 -6
- package/dist/types/state/checkout/quote-lifecycle.d.ts.map +1 -1
- 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 +35 -15
- package/dist/types/state/checkout/store.d.ts.map +1 -1
- package/dist/types/state/checkout/wallet-payment.d.ts +15 -2
- package/dist/types/state/checkout/wallet-payment.d.ts.map +1 -1
- package/dist/types/state/checkout/wallet-transfer-receipt.d.ts +18 -0
- package/dist/types/state/checkout/wallet-transfer-receipt.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/refund/confirmation.js +0 -30
- package/dist/esm/refund/confirmation.js.map +0 -1
- package/dist/types/refund/confirmation.d.ts +0 -14
- package/dist/types/refund/confirmation.d.ts.map +0 -1
package/dist/esm/refund/index.js
CHANGED
|
@@ -2,19 +2,29 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { useAppKit } from "@reown/appkit/react";
|
|
4
4
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
5
|
-
import { disconnect, sendTransaction, switchChain, } from "@wagmi/core";
|
|
5
|
+
import { disconnect, getTransaction, getTransactionCount, sendTransaction, switchChain, } from "@wagmi/core";
|
|
6
6
|
import { useEffect, useRef, useState } from "react";
|
|
7
7
|
import { styled, ThemeProvider } from "styled-components";
|
|
8
|
+
import { BaseError, UserRejectedRequestError } from "viem";
|
|
8
9
|
import { useAccount, useConfig, WagmiProvider } from "wagmi";
|
|
10
|
+
import { getApiErrorCode } from "../api/errors.js";
|
|
9
11
|
import { confirmPaymentRefund, getPaymentRefundStatus, preparePaymentRefund, } from "../api/payments.js";
|
|
10
12
|
import { getAppKitWagmiConfig, } from "../checkout/providers/wagmi-config.js";
|
|
13
|
+
import { PaymentFundingTimeline } from "../checkout/views/funding-timeline.js";
|
|
11
14
|
import { StyledButton } from "../components/index.js";
|
|
12
15
|
import { WalletProvider } from "../components/wallet-selector/provider.js";
|
|
13
16
|
import { defaultTheme } from "../themes/default.js";
|
|
14
|
-
import {
|
|
17
|
+
import { formatShortAddress } from "../utils/string.js";
|
|
18
|
+
import { formatChainLabel, formatRefundAmount, transactionUrl, } from "../utils/token-amount.js";
|
|
15
19
|
import { buildRefundPrepareAttemptKey, claimRefundPrepareAttempt, normalizeComparableAddress, } from "./prepare-guard.js";
|
|
16
|
-
|
|
20
|
+
// Prepare and confirm return a default history page. Keep the preview until
|
|
21
|
+
// the next status read refreshes it.
|
|
22
|
+
const keepRefundPreview = (status, updated) => status.timeline?.has_hidden_transactions === undefined
|
|
23
|
+
? updated
|
|
24
|
+
: { ...updated, timeline: status.timeline };
|
|
17
25
|
const REFUND_SELECTOR = "0x590e1ae3";
|
|
26
|
+
// Late deposits and claims reach the refund status through the chain scanner.
|
|
27
|
+
const REFUND_STATUS_REFRESH_MS = 15_000;
|
|
18
28
|
const Shell = styled.div `
|
|
19
29
|
width: 100%;
|
|
20
30
|
display: flex;
|
|
@@ -22,19 +32,6 @@ const Shell = styled.div `
|
|
|
22
32
|
gap: 18px;
|
|
23
33
|
text-align: center;
|
|
24
34
|
`;
|
|
25
|
-
const StatusPill = styled.span `
|
|
26
|
-
display: inline-flex;
|
|
27
|
-
align-items: center;
|
|
28
|
-
align-self: center;
|
|
29
|
-
padding: 7px 14px;
|
|
30
|
-
border-radius: 999px;
|
|
31
|
-
background: rgba(24, 178, 138, 0.16);
|
|
32
|
-
color: #68e1c0;
|
|
33
|
-
font-size: 11px;
|
|
34
|
-
font-weight: 700;
|
|
35
|
-
letter-spacing: 0.08em;
|
|
36
|
-
text-transform: uppercase;
|
|
37
|
-
`;
|
|
38
35
|
const BalancePanel = styled.div `
|
|
39
36
|
padding: 18px;
|
|
40
37
|
border-radius: 16px;
|
|
@@ -56,35 +53,6 @@ const BalanceValue = styled.div `
|
|
|
56
53
|
font-weight: 800;
|
|
57
54
|
overflow-wrap: anywhere;
|
|
58
55
|
`;
|
|
59
|
-
const Details = styled.div `
|
|
60
|
-
display: flex;
|
|
61
|
-
flex-direction: column;
|
|
62
|
-
border: 1px solid rgba(148, 163, 184, 0.18);
|
|
63
|
-
border-radius: 14px;
|
|
64
|
-
overflow: hidden;
|
|
65
|
-
`;
|
|
66
|
-
const DetailRow = styled.div `
|
|
67
|
-
display: flex;
|
|
68
|
-
justify-content: space-between;
|
|
69
|
-
gap: 16px;
|
|
70
|
-
padding: 14px 16px;
|
|
71
|
-
border-bottom: 1px solid rgba(148, 163, 184, 0.18);
|
|
72
|
-
color: #9aa3b5;
|
|
73
|
-
font-size: 14px;
|
|
74
|
-
text-align: left;
|
|
75
|
-
background: rgba(17, 24, 39, 0.62);
|
|
76
|
-
|
|
77
|
-
strong {
|
|
78
|
-
color: #edf1f7;
|
|
79
|
-
font-weight: 600;
|
|
80
|
-
text-align: right;
|
|
81
|
-
word-break: break-word;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
&:last-child {
|
|
85
|
-
border-bottom: none;
|
|
86
|
-
}
|
|
87
|
-
`;
|
|
88
56
|
const ErrorText = styled.p `
|
|
89
57
|
margin: 0;
|
|
90
58
|
color: #d94b4b;
|
|
@@ -137,12 +105,14 @@ const Actions = styled.div `
|
|
|
137
105
|
gap: 10px;
|
|
138
106
|
`;
|
|
139
107
|
const Page = styled.div `
|
|
140
|
-
|
|
141
|
-
|
|
108
|
+
height: 100vh;
|
|
109
|
+
height: 100dvh;
|
|
110
|
+
overflow-y: auto;
|
|
111
|
+
overscroll-behavior: contain;
|
|
112
|
+
padding: 72px 20px 32px;
|
|
142
113
|
display: flex;
|
|
143
114
|
flex-direction: column;
|
|
144
115
|
align-items: center;
|
|
145
|
-
justify-content: center;
|
|
146
116
|
gap: 24px;
|
|
147
117
|
position: relative;
|
|
148
118
|
background: #0b0e16;
|
|
@@ -165,7 +135,8 @@ const PageMain = styled.main `
|
|
|
165
135
|
display: flex;
|
|
166
136
|
align-items: center;
|
|
167
137
|
justify-content: center;
|
|
168
|
-
|
|
138
|
+
flex: 0 0 auto;
|
|
139
|
+
margin-block: auto;
|
|
169
140
|
width: 100%;
|
|
170
141
|
`;
|
|
171
142
|
const PageCard = styled.div `
|
|
@@ -195,81 +166,13 @@ function caip2ToChainId(caip2) {
|
|
|
195
166
|
function isSubmittedRefundTxHash(value) {
|
|
196
167
|
return /^(?:0x)?[0-9a-fA-F]{64}$/.test(value);
|
|
197
168
|
}
|
|
198
|
-
function
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
return "Base";
|
|
206
|
-
if (chain === "eip155:84532")
|
|
207
|
-
return "Base Sepolia";
|
|
208
|
-
return chain;
|
|
209
|
-
}
|
|
210
|
-
function formatTokenLabel(token) {
|
|
211
|
-
if (/\/(native|slip44:60)$/.test(token))
|
|
212
|
-
return "ETH";
|
|
213
|
-
const erc20Match = /\/erc20:(0x[a-fA-F0-9]{40})$/.exec(token);
|
|
214
|
-
if (!erc20Match)
|
|
215
|
-
return token;
|
|
216
|
-
const address = erc20Match[1];
|
|
217
|
-
if (address.toLowerCase() === "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913") {
|
|
218
|
-
return "USDC";
|
|
219
|
-
}
|
|
220
|
-
return `ERC-20 ${shortAddress(address)}`;
|
|
221
|
-
}
|
|
222
|
-
function transactionUrl(chain, transactionHash) {
|
|
223
|
-
if (chain === "eip155:8453")
|
|
224
|
-
return `https://basescan.org/tx/${transactionHash}`;
|
|
225
|
-
if (chain === "eip155:84532")
|
|
226
|
-
return `https://sepolia.basescan.org/tx/${transactionHash}`;
|
|
227
|
-
if (chain === "eip155:1")
|
|
228
|
-
return `https://etherscan.io/tx/${transactionHash}`;
|
|
229
|
-
if (chain === "eip155:11155111")
|
|
230
|
-
return `https://sepolia.etherscan.io/tx/${transactionHash}`;
|
|
231
|
-
return null;
|
|
232
|
-
}
|
|
233
|
-
function tokenDecimals(refundStatus) {
|
|
234
|
-
if (refundStatus.token_decimals !== null)
|
|
235
|
-
return refundStatus.token_decimals;
|
|
236
|
-
const token = refundStatus.token;
|
|
237
|
-
if (/\/(native|slip44:60)$/.test(token))
|
|
238
|
-
return 18;
|
|
239
|
-
const erc20Match = /\/erc20:(0x[a-fA-F0-9]{40})$/.exec(token);
|
|
240
|
-
if (!erc20Match)
|
|
241
|
-
return 18;
|
|
242
|
-
const address = erc20Match[1];
|
|
243
|
-
if (address.toLowerCase() === "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913") {
|
|
244
|
-
return 6;
|
|
245
|
-
}
|
|
246
|
-
return 18;
|
|
247
|
-
}
|
|
248
|
-
function formatTokenAmount(rawAmount, decimals) {
|
|
249
|
-
let amount;
|
|
250
|
-
try {
|
|
251
|
-
amount = BigInt(rawAmount);
|
|
252
|
-
}
|
|
253
|
-
catch {
|
|
254
|
-
return rawAmount;
|
|
255
|
-
}
|
|
256
|
-
const negative = amount < 0n;
|
|
257
|
-
const value = negative ? -amount : amount;
|
|
258
|
-
const divisor = 10n ** BigInt(decimals);
|
|
259
|
-
const whole = value / divisor;
|
|
260
|
-
const fraction = value % divisor;
|
|
261
|
-
if (decimals === 0)
|
|
262
|
-
return `${negative ? "-" : ""}${whole.toString()}`;
|
|
263
|
-
const fractionText = fraction
|
|
264
|
-
.toString()
|
|
265
|
-
.padStart(decimals, "0")
|
|
266
|
-
.slice(0, 6)
|
|
267
|
-
.replace(/0+$/, "");
|
|
268
|
-
const displayFraction = fractionText.padEnd(2, "0");
|
|
269
|
-
return `${negative ? "-" : ""}${whole.toString()}.${displayFraction}`;
|
|
270
|
-
}
|
|
271
|
-
function formatRefundAmount(refundStatus) {
|
|
272
|
-
return `${formatTokenAmount(refundStatus.current_refundable_balance, tokenDecimals(refundStatus))} ${formatTokenLabel(refundStatus.token)}`;
|
|
169
|
+
function isRecordedRefund(status, hash) {
|
|
170
|
+
const normalized = hash.toLowerCase().replace(/^0x/, "");
|
|
171
|
+
return (status.refund_transaction_hash?.toLowerCase().replace(/^0x/, "") ===
|
|
172
|
+
normalized ||
|
|
173
|
+
(status.timeline?.items.some((item) => item.kind === "claim" &&
|
|
174
|
+
item.transaction_hash.toLowerCase().replace(/^0x/, "") === normalized) ??
|
|
175
|
+
false));
|
|
273
176
|
}
|
|
274
177
|
function refundUnlockDate(refundStatus) {
|
|
275
178
|
if (!refundStatus || refundStatus.payment_status === "paid")
|
|
@@ -296,7 +199,17 @@ function readSubmittedRefundTx(paymentId, attemptId) {
|
|
|
296
199
|
if (typeof parsed.hash === "string" &&
|
|
297
200
|
isSubmittedRefundTxHash(parsed.hash) &&
|
|
298
201
|
typeof parsed.submittedAt === "number") {
|
|
299
|
-
|
|
202
|
+
const { hash, submittedAt, identity } = parsed;
|
|
203
|
+
return {
|
|
204
|
+
hash,
|
|
205
|
+
submittedAt,
|
|
206
|
+
...(typeof identity?.from === "string" &&
|
|
207
|
+
/^0x[0-9a-f]{40}$/i.test(identity.from) &&
|
|
208
|
+
Number.isSafeInteger(identity.nonce) &&
|
|
209
|
+
identity.nonce >= 0
|
|
210
|
+
? { identity }
|
|
211
|
+
: {}),
|
|
212
|
+
};
|
|
300
213
|
}
|
|
301
214
|
}
|
|
302
215
|
catch {
|
|
@@ -304,17 +217,43 @@ function readSubmittedRefundTx(paymentId, attemptId) {
|
|
|
304
217
|
}
|
|
305
218
|
return null;
|
|
306
219
|
}
|
|
307
|
-
function writeSubmittedRefundTx(paymentId, attemptId,
|
|
220
|
+
function writeSubmittedRefundTx(paymentId, attemptId, submission) {
|
|
308
221
|
if (typeof window === "undefined")
|
|
309
222
|
return;
|
|
310
|
-
window.sessionStorage.setItem(refundSubmittedTxStorageKey(paymentId, attemptId), JSON.stringify(
|
|
223
|
+
window.sessionStorage.setItem(refundSubmittedTxStorageKey(paymentId, attemptId), JSON.stringify(submission));
|
|
311
224
|
}
|
|
312
225
|
function clearSubmittedRefundTx(paymentId, attemptId) {
|
|
313
226
|
if (typeof window === "undefined")
|
|
314
227
|
return;
|
|
315
228
|
window.sessionStorage.removeItem(refundSubmittedTxStorageKey(paymentId, attemptId));
|
|
316
229
|
}
|
|
317
|
-
|
|
230
|
+
async function reconcileRefundReplacement(config, status, submission) {
|
|
231
|
+
const chainId = caip2ToChainId(status.settlement_chain);
|
|
232
|
+
if (!chainId)
|
|
233
|
+
return { submission, replaced: false };
|
|
234
|
+
const lookup = (hash) => getTransaction(config, {
|
|
235
|
+
chainId,
|
|
236
|
+
hash: `0x${hash.replace(/^0x/i, "")}`,
|
|
237
|
+
}).catch(() => null);
|
|
238
|
+
// Keep the original sender and nonce even if the RPC forgets its hash after
|
|
239
|
+
// a speed-up. A different claim only resolves this submission if it used
|
|
240
|
+
// that same nonce, which makes it impossible for the original to mine too.
|
|
241
|
+
const original = submission.identity ?? (await lookup(submission.hash));
|
|
242
|
+
if (!original)
|
|
243
|
+
return { submission, replaced: false };
|
|
244
|
+
const identity = { from: original.from, nonce: original.nonce };
|
|
245
|
+
const confirmedHash = status.refund_transaction_hash;
|
|
246
|
+
const replacement = confirmedHash && isSubmittedRefundTxHash(confirmedHash)
|
|
247
|
+
? await lookup(confirmedHash)
|
|
248
|
+
: null;
|
|
249
|
+
return {
|
|
250
|
+
submission: { ...submission, identity },
|
|
251
|
+
replaced: Boolean(replacement?.blockNumber != null) &&
|
|
252
|
+
replacement?.from.toLowerCase() === identity.from.toLowerCase() &&
|
|
253
|
+
replacement?.nonce === identity.nonce,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
async function submitRefund(refundStatus, { address, wagmiConfig, }) {
|
|
318
257
|
if (!address) {
|
|
319
258
|
throw new Error("No wallet account connected.");
|
|
320
259
|
}
|
|
@@ -323,7 +262,7 @@ export async function claimPaymentRefund(refundStatus, { address, wagmiConfig, }
|
|
|
323
262
|
if (refundStatus.refund_to &&
|
|
324
263
|
normalizeComparableAddress(refundStatus.settlement_chain, address) !==
|
|
325
264
|
normalizeComparableAddress(refundStatus.settlement_chain, refundStatus.refund_to)) {
|
|
326
|
-
throw new Error(`Connected wallet ${
|
|
265
|
+
throw new Error(`Connected wallet ${formatShortAddress(address)} is not the refund recipient. Connect ${formatShortAddress(refundStatus.refund_to)} and try again.`);
|
|
327
266
|
}
|
|
328
267
|
const chainId = caip2ToChainId(refundStatus.settlement_chain);
|
|
329
268
|
if (!chainId) {
|
|
@@ -335,11 +274,25 @@ export async function claimPaymentRefund(refundStatus, { address, wagmiConfig, }
|
|
|
335
274
|
catch {
|
|
336
275
|
throw new Error(`Refunds are claimed on the merchant settlement chain (${refundStatus.settlement_chain}). Switch your wallet to that network and try again.`);
|
|
337
276
|
}
|
|
277
|
+
const from = address;
|
|
278
|
+
// The original hash may already be gone when the wallet returns control.
|
|
279
|
+
// Set the nonce on the send itself so a speed-up can still be identified.
|
|
280
|
+
const nonce = await getTransactionCount(wagmiConfig, {
|
|
281
|
+
address: from,
|
|
282
|
+
chainId,
|
|
283
|
+
blockTag: "pending",
|
|
284
|
+
});
|
|
338
285
|
const transactionHash = await sendTransaction(wagmiConfig, {
|
|
339
|
-
account:
|
|
286
|
+
account: from,
|
|
287
|
+
chainId,
|
|
288
|
+
nonce,
|
|
340
289
|
to: refundStatus.splitter_address,
|
|
341
290
|
data: REFUND_SELECTOR,
|
|
342
291
|
});
|
|
292
|
+
return { transactionHash, identity: { from, nonce } };
|
|
293
|
+
}
|
|
294
|
+
export async function claimPaymentRefund(refundStatus, wallet) {
|
|
295
|
+
const { transactionHash } = await submitRefund(refundStatus, wallet);
|
|
343
296
|
return { transactionHash };
|
|
344
297
|
}
|
|
345
298
|
export function RefundClaim({ paymentId, attemptId, apiUrl, className, }) {
|
|
@@ -351,64 +304,106 @@ export function RefundClaim({ paymentId, attemptId, apiUrl, className, }) {
|
|
|
351
304
|
const [busy, setBusy] = useState(false);
|
|
352
305
|
const [preparing, setPreparing] = useState(false);
|
|
353
306
|
const [error, setError] = useState(null);
|
|
354
|
-
const [
|
|
307
|
+
const [submittedClaim, setSubmittedClaim] = useState(null);
|
|
355
308
|
const [claimedAmountLabel, setClaimedAmountLabel] = useState(null);
|
|
356
309
|
const attemptedPrepareKeys = useRef(new Set());
|
|
357
310
|
const connectedAddress = account.address ?? null;
|
|
358
|
-
|
|
311
|
+
useEffect(() => {
|
|
359
312
|
setLoading(true);
|
|
360
313
|
setError(null);
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
314
|
+
}, [apiUrl, paymentId, attemptId, connectedAddress]);
|
|
315
|
+
useEffect(() => {
|
|
316
|
+
if (busy || preparing)
|
|
317
|
+
return;
|
|
318
|
+
const request = new AbortController();
|
|
319
|
+
let timer;
|
|
320
|
+
const options = {
|
|
321
|
+
attemptId,
|
|
322
|
+
apiUrl,
|
|
323
|
+
connectedAddress: connectedAddress ?? undefined,
|
|
324
|
+
signal: request.signal,
|
|
325
|
+
};
|
|
326
|
+
const poll = async () => {
|
|
327
|
+
try {
|
|
328
|
+
let status = await getPaymentRefundStatus(paymentId, {
|
|
329
|
+
...options,
|
|
330
|
+
timeline: "preview",
|
|
331
|
+
});
|
|
332
|
+
if (request.signal.aborted)
|
|
333
|
+
return;
|
|
334
|
+
const submitted = readSubmittedRefundTx(paymentId, status.attempt_id);
|
|
335
|
+
let hash = submitted?.hash ?? null;
|
|
336
|
+
let recorded = hash !== null && isRecordedRefund(status, hash);
|
|
337
|
+
if (hash && !recorded) {
|
|
382
338
|
try {
|
|
383
|
-
const
|
|
384
|
-
|
|
339
|
+
const confirmed = await confirmPaymentRefund(paymentId, {
|
|
340
|
+
...options,
|
|
385
341
|
attemptId: status.attempt_id,
|
|
386
|
-
|
|
387
|
-
apiUrl,
|
|
342
|
+
transactionHash: hash,
|
|
388
343
|
});
|
|
389
|
-
|
|
390
|
-
|
|
344
|
+
recorded = isRecordedRefund(confirmed, hash);
|
|
345
|
+
status = keepRefundPreview(status, confirmed);
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
if (request.signal.aborted)
|
|
349
|
+
return;
|
|
350
|
+
if (getApiErrorCode(error) === "REFUND_TRANSACTION_REVERTED") {
|
|
391
351
|
clearSubmittedRefundTx(paymentId, status.attempt_id);
|
|
352
|
+
hash = null;
|
|
353
|
+
setError("The refund transaction reverted. You can try again.");
|
|
392
354
|
}
|
|
393
355
|
}
|
|
394
|
-
|
|
356
|
+
}
|
|
357
|
+
if (request.signal.aborted)
|
|
358
|
+
return;
|
|
359
|
+
if (hash && submitted) {
|
|
360
|
+
const reconciled = recorded
|
|
361
|
+
? null
|
|
362
|
+
: await reconcileRefundReplacement(wagmiConfig, status, submitted);
|
|
363
|
+
if (request.signal.aborted)
|
|
364
|
+
return;
|
|
365
|
+
if (recorded || reconciled?.replaced) {
|
|
395
366
|
clearSubmittedRefundTx(paymentId, status.attempt_id);
|
|
396
|
-
|
|
397
|
-
|
|
367
|
+
hash = null;
|
|
368
|
+
}
|
|
369
|
+
else if (!submitted.identity && reconciled?.submission.identity) {
|
|
370
|
+
writeSubmittedRefundTx(paymentId, status.attempt_id, reconciled.submission);
|
|
398
371
|
}
|
|
399
372
|
}
|
|
373
|
+
setRefundStatus(status);
|
|
374
|
+
setSubmittedClaim(hash ? { attemptId: status.attempt_id, hash } : null);
|
|
375
|
+
setClaimedAmountLabel(window.sessionStorage.getItem(refundClaimedAmountStorageKey(paymentId, status.attempt_id)));
|
|
400
376
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
377
|
+
catch (err) {
|
|
378
|
+
if (request.signal.aborted)
|
|
379
|
+
return;
|
|
380
|
+
setError(err instanceof Error ? err.message : "Unable to load refund status.");
|
|
381
|
+
}
|
|
382
|
+
finally {
|
|
383
|
+
if (!request.signal.aborted) {
|
|
384
|
+
setLoading(false);
|
|
385
|
+
timer = setTimeout(poll, REFUND_STATUS_REFRESH_MS);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
void poll();
|
|
390
|
+
return () => {
|
|
391
|
+
request.abort();
|
|
392
|
+
clearTimeout(timer);
|
|
393
|
+
};
|
|
394
|
+
}, [
|
|
395
|
+
apiUrl,
|
|
396
|
+
attemptId,
|
|
397
|
+
busy,
|
|
398
|
+
connectedAddress,
|
|
399
|
+
paymentId,
|
|
400
|
+
preparing,
|
|
401
|
+
wagmiConfig,
|
|
402
|
+
]);
|
|
403
|
+
const submittedHash = refundStatus?.payment_id === paymentId &&
|
|
404
|
+
refundStatus.attempt_id === submittedClaim?.attemptId
|
|
405
|
+
? submittedClaim.hash
|
|
406
|
+
: null;
|
|
412
407
|
const connectWallet = async () => {
|
|
413
408
|
setError(null);
|
|
414
409
|
await open({ view: "Connect" });
|
|
@@ -416,7 +411,6 @@ export function RefundClaim({ paymentId, attemptId, apiUrl, className, }) {
|
|
|
416
411
|
const useAnotherWallet = async () => {
|
|
417
412
|
setBusy(true);
|
|
418
413
|
setError(null);
|
|
419
|
-
setTxHash(null);
|
|
420
414
|
try {
|
|
421
415
|
await disconnect(wagmiConfig);
|
|
422
416
|
}
|
|
@@ -448,7 +442,7 @@ export function RefundClaim({ paymentId, attemptId, apiUrl, className, }) {
|
|
|
448
442
|
connectedAddress: prepareConnectedAddress,
|
|
449
443
|
apiUrl,
|
|
450
444
|
});
|
|
451
|
-
setRefundStatus(prepared);
|
|
445
|
+
setRefundStatus(keepRefundPreview(refundStatus, prepared));
|
|
452
446
|
}
|
|
453
447
|
catch (err) {
|
|
454
448
|
setError(err instanceof Error
|
|
@@ -486,23 +480,30 @@ export function RefundClaim({ paymentId, attemptId, apiUrl, className, }) {
|
|
|
486
480
|
await connectWallet();
|
|
487
481
|
return;
|
|
488
482
|
}
|
|
489
|
-
const result = await
|
|
483
|
+
const result = await submitRefund(refundStatus, {
|
|
490
484
|
address: connectedAddress,
|
|
491
485
|
wagmiConfig,
|
|
492
486
|
});
|
|
493
|
-
|
|
494
|
-
writeSubmittedRefundTx(paymentId, refundStatus.attempt_id, result.transactionHash);
|
|
495
|
-
const recorded = await waitForRefundConfirmation(paymentId, {
|
|
496
|
-
transactionHash: result.transactionHash,
|
|
487
|
+
setSubmittedClaim({
|
|
497
488
|
attemptId: refundStatus.attempt_id,
|
|
498
|
-
|
|
499
|
-
|
|
489
|
+
hash: result.transactionHash,
|
|
490
|
+
});
|
|
491
|
+
writeSubmittedRefundTx(paymentId, refundStatus.attempt_id, {
|
|
492
|
+
hash: result.transactionHash,
|
|
493
|
+
submittedAt: Date.now(),
|
|
494
|
+
identity: result.identity,
|
|
500
495
|
});
|
|
501
|
-
setRefundStatus(recorded);
|
|
502
|
-
clearSubmittedRefundTx(paymentId, refundStatus.attempt_id);
|
|
503
496
|
}
|
|
504
497
|
catch (err) {
|
|
505
|
-
|
|
498
|
+
if (err instanceof BaseError) {
|
|
499
|
+
const rejected = err.walk((cause) => cause instanceof UserRejectedRequestError);
|
|
500
|
+
setError(rejected
|
|
501
|
+
? "Refund cancelled in wallet. You can try again."
|
|
502
|
+
: "Unable to submit the refund. Check your wallet and try again.");
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
505
|
+
setError(err instanceof Error ? err.message : "Refund transaction failed.");
|
|
506
|
+
}
|
|
506
507
|
}
|
|
507
508
|
finally {
|
|
508
509
|
setBusy(false);
|
|
@@ -531,62 +532,71 @@ export function RefundClaim({ paymentId, attemptId, apiUrl, className, }) {
|
|
|
531
532
|
Boolean(refundStatus &&
|
|
532
533
|
["refund_available", "surplus_available"].includes(refundStatus.attempt_status));
|
|
533
534
|
const isRefundUnavailable = Boolean(refundStatus) && !isClaimed && !hasRefundableBalance;
|
|
535
|
+
const refundPending = hasRefundableBalance &&
|
|
536
|
+
!["refund_available", "surplus_available"].includes(refundStatus?.attempt_status ?? "");
|
|
537
|
+
const isSurplus = refundStatus?.attempt_status === "surplus_available";
|
|
538
|
+
const isSubmitted = Boolean(submittedHash) && !isClaimed;
|
|
534
539
|
const balanceLabel = isClaimed
|
|
535
|
-
? "
|
|
536
|
-
:
|
|
537
|
-
? "
|
|
538
|
-
: "
|
|
539
|
-
const balanceValue =
|
|
540
|
-
?
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
const
|
|
545
|
-
|
|
546
|
-
|
|
540
|
+
? "Amount returned"
|
|
541
|
+
: refundPending
|
|
542
|
+
? "Amount received"
|
|
543
|
+
: "Amount available";
|
|
544
|
+
const balanceValue = isClaimed
|
|
545
|
+
? claimedAmountLabel
|
|
546
|
+
: refundStatus && hasRefundableBalance
|
|
547
|
+
? formatRefundAmount(refundStatus)
|
|
548
|
+
: null;
|
|
549
|
+
const transactionHash = isClaimed
|
|
550
|
+
? refundStatus.refund_transaction_hash
|
|
551
|
+
: isSubmitted
|
|
552
|
+
? submittedHash
|
|
553
|
+
: null;
|
|
554
|
+
const explorerUrl = refundStatus && transactionHash
|
|
555
|
+
? transactionUrl(refundStatus.settlement_chain, transactionHash)
|
|
547
556
|
: null;
|
|
548
|
-
const isSubmitted = Boolean(txHash) && !isClaimed;
|
|
549
557
|
const claimedAtLabel = refundStatus?.refund_claimed_at
|
|
550
558
|
? new Date(refundStatus.refund_claimed_at).toLocaleString()
|
|
551
559
|
: null;
|
|
552
|
-
return (_jsxs(Shell, { className: className, children: [_jsx(
|
|
553
|
-
? "Refund
|
|
554
|
-
:
|
|
555
|
-
? "Refund
|
|
556
|
-
:
|
|
557
|
-
? "Refund
|
|
558
|
-
:
|
|
559
|
-
?
|
|
560
|
-
:
|
|
561
|
-
|
|
562
|
-
|
|
560
|
+
return (_jsxs(Shell, { className: className, children: [_jsx(TitleText, { children: !refundStatus
|
|
561
|
+
? "Refund"
|
|
562
|
+
: isClaimed
|
|
563
|
+
? "Refund claimed"
|
|
564
|
+
: isSubmitted
|
|
565
|
+
? "Refund submitted"
|
|
566
|
+
: isRefundUnavailable
|
|
567
|
+
? "Refund unavailable"
|
|
568
|
+
: refundPending || waitingForRefundWindow
|
|
569
|
+
? "Refund pending"
|
|
570
|
+
: isSurplus
|
|
571
|
+
? "Surplus available"
|
|
572
|
+
: "Refund available" }), loading ? _jsx(SubtleText, { children: "Loading refund details\u2026" }) : null, refundStatus ? (_jsxs(_Fragment, { children: [balanceValue ? (_jsxs(BalancePanel, { children: [_jsx(BalanceLabel, { children: balanceLabel }), _jsx(BalanceValue, { children: balanceValue })] })) : null, _jsx(SubtleText, { children: formatChainLabel(refundStatus.settlement_chain) }), isClaimed ? (_jsxs(HelperText, { children: ["Returned to", " ", refundStatus.refund_to
|
|
573
|
+
? formatShortAddress(refundStatus.refund_to)
|
|
574
|
+
: "the refund wallet", claimedAtLabel ? ` on ${claimedAtLabel}` : "", "."] })) : isSubmitted ? (_jsx(HelperText, { children: "This page will update once the network confirms your transaction." })) : refundPending ? (_jsx(HelperText, { children: refundStatus.funding?.settlement_cutoff_at &&
|
|
575
|
+
Date.parse(refundStatus.funding.settlement_cutoff_at) > Date.now()
|
|
576
|
+
? "You can send the rest from your original payment link."
|
|
577
|
+
: "This page will update when the refund is available." })) : !hasRefundableBalance ? (_jsx(HelperText, { children: "There\u2019s no refundable balance for this payment." })) : !refundRecipient ? (_jsx(HelperText, { children: "This attempt needs merchant recovery before a refund can be claimed." })) : connectedAddress && !connectedMatchesRefundRecipient ? (_jsxs(HelperText, { children: ["Connected wallet ", formatShortAddress(connectedAddress), " is not the refund recipient. Connect ", formatShortAddress(refundRecipient), " to claim."] })) : connectedMatchesRefundRecipient ? (_jsx(HelperText, { children: waitingForRefundWindow
|
|
563
578
|
? `Refunds can be claimed after ${refundAvailableAt?.toLocaleString()} if this payment does not settle.`
|
|
564
579
|
: needsRefundSetup
|
|
565
|
-
?
|
|
566
|
-
|
|
567
|
-
: "Prepare the refund contract before claiming."
|
|
568
|
-
: `Connected refund wallet ${shortAddress(refundRecipient)} can claim this refund.` })) : (_jsxs(HelperText, { children: ["Connect refund wallet ", shortAddress(refundRecipient), " to claim."] }))] })) : null, error ? _jsx(ErrorText, { children: error }) : null, isClaimed && recordedTxHash ? (_jsxs(SuccessText, { children: ["Refund transaction:", " ", recordedTxUrl ? (_jsx(TransactionLink, { href: recordedTxUrl, target: "_blank", rel: "noreferrer", children: recordedTxHash })) : (recordedTxHash)] })) : txHash ? (_jsxs(SuccessText, { children: ["Refund transaction submitted:", " ", refundStatus &&
|
|
569
|
-
transactionUrl(refundStatus.settlement_chain, txHash) ? (_jsx(TransactionLink, { href: transactionUrl(refundStatus.settlement_chain, txHash) ??
|
|
570
|
-
undefined, target: "_blank", rel: "noreferrer", children: txHash })) : (txHash)] })) : null, isClaimed ||
|
|
580
|
+
? "Set up this wallet on the settlement network to continue."
|
|
581
|
+
: `Connected as ${formatShortAddress(refundRecipient)}.` })) : (_jsxs(HelperText, { children: ["Connect refund wallet ", formatShortAddress(refundRecipient), " to claim."] }))] })) : null, error && !isClaimed ? _jsx(ErrorText, { children: error }) : null, transactionHash ? (_jsx(SuccessText, { children: explorerUrl ? (_jsx(TransactionLink, { href: explorerUrl, target: "_blank", rel: "noreferrer", title: transactionHash, children: "View transaction" })) : (transactionHash) })) : null, isClaimed ||
|
|
571
582
|
isRefundUnavailable ||
|
|
583
|
+
refundPending ||
|
|
584
|
+
waitingForRefundWindow ||
|
|
572
585
|
isSubmitted ? null : !connectedAddress ? (_jsx(Actions, { children: _jsx(StyledButton, { onClick: () => void connectWallet(), disabled: busy, children: "Connect wallet" }) })) : (_jsxs(Actions, { children: [_jsx(StyledButton, { onClick: () => {
|
|
573
586
|
if (needsRefundSetup) {
|
|
574
587
|
retryRefundSetup();
|
|
575
588
|
return;
|
|
576
589
|
}
|
|
577
590
|
void claimRefund();
|
|
578
|
-
}, disabled: busy ||
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
: busy
|
|
588
|
-
? "Submitting..."
|
|
589
|
-
: "Claim refund" }), !canClaim && !needsRefundSetup && !waitingForRefundWindow ? (_jsx(StyledButton, { variant: "secondary", onClick: () => void useAnotherWallet(), disabled: busy, children: "Use another wallet" })) : null] }))] }));
|
|
591
|
+
}, disabled: busy || preparing || (!canClaim && !needsRefundSetup), children: preparing
|
|
592
|
+
? "Preparing refund…"
|
|
593
|
+
: needsRefundSetup
|
|
594
|
+
? "Prepare refund"
|
|
595
|
+
: busy
|
|
596
|
+
? "Submitting…"
|
|
597
|
+
: isSurplus
|
|
598
|
+
? "Claim surplus"
|
|
599
|
+
: "Claim refund" }), !canClaim && !needsRefundSetup ? (_jsx(StyledButton, { variant: "secondary", onClick: () => void useAnotherWallet(), disabled: busy, children: "Use another wallet" })) : null] })), refundStatus ? (_jsx(PaymentFundingTimeline, { funding: refundStatus.funding, timeline: refundStatus.timeline, tokenSymbol: refundStatus.token_symbol })) : null] }));
|
|
590
600
|
}
|
|
591
601
|
export function RefundClaimPage({ logoSrc = "/logo.svg", wagmiConfig, walletConnectProjectId, ...props }) {
|
|
592
602
|
const wagmi = useRef();
|