@mintmoney/react 0.1.0-alpha.32 → 0.1.0-alpha.34
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 +41 -13
- package/dist/esm/api/generated.js +31 -0
- package/dist/esm/api/generated.js.map +1 -1
- package/dist/esm/api/index.js +1 -0
- package/dist/esm/api/index.js.map +1 -1
- package/dist/esm/api/payments.js +39 -0
- package/dist/esm/api/payments.js.map +1 -1
- package/dist/esm/checkout/index.js +22 -18
- package/dist/esm/checkout/index.js.map +1 -1
- package/dist/esm/checkout/modal.js +24 -4
- package/dist/esm/checkout/modal.js.map +1 -1
- package/dist/esm/checkout/providers/wagmi-config.js +108 -0
- package/dist/esm/checkout/providers/wagmi-config.js.map +1 -0
- package/dist/esm/checkout/providers/wallet-connect-resume.js +129 -0
- package/dist/esm/checkout/providers/wallet-connect-resume.js.map +1 -0
- package/dist/esm/checkout/resume-state.js +82 -0
- package/dist/esm/checkout/resume-state.js.map +1 -0
- package/dist/esm/checkout/surplus-refund.js +38 -0
- package/dist/esm/checkout/surplus-refund.js.map +1 -0
- package/dist/esm/checkout/views/back.js +2 -2
- package/dist/esm/checkout/views/back.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/direct-details.js +941 -102
- package/dist/esm/checkout/views/crypto-intent/direct-details.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/methods.js +153 -31
- package/dist/esm/checkout/views/crypto-intent/methods.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/processing.js +51 -3
- package/dist/esm/checkout/views/crypto-intent/processing.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/success.js +60 -9
- package/dist/esm/checkout/views/crypto-intent/success.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/wallet-payment-options.js +848 -222
- package/dist/esm/checkout/views/crypto-intent/wallet-payment-options.js.map +1 -1
- package/dist/esm/checkout/views/crypto-intent/wallet-select.js +151 -20
- package/dist/esm/checkout/views/crypto-intent/wallet-select.js.map +1 -1
- package/dist/esm/checkout/views/failed.js +83 -1
- package/dist/esm/checkout/views/failed.js.map +1 -1
- package/dist/esm/checkout/views/initial.js +61 -6
- package/dist/esm/checkout/views/initial.js.map +1 -1
- package/dist/esm/checkout/views/method-select.js +16 -4
- package/dist/esm/checkout/views/method-select.js.map +1 -1
- package/dist/esm/checkout/views/restart.js +1 -1
- package/dist/esm/checkout/views/restart.js.map +1 -1
- package/dist/esm/components/buttons/index.js +4 -1
- package/dist/esm/components/buttons/index.js.map +1 -1
- package/dist/esm/components/icons/clock.js +4 -0
- package/dist/esm/components/icons/clock.js.map +1 -0
- package/dist/esm/components/icons/edit.js +6 -0
- package/dist/esm/components/icons/edit.js.map +1 -0
- package/dist/esm/components/icons/index.js +4 -0
- package/dist/esm/components/icons/index.js.map +1 -1
- package/dist/esm/components/icons/log-out.js +6 -0
- package/dist/esm/components/icons/log-out.js.map +1 -0
- package/dist/esm/components/icons/send.js +6 -0
- package/dist/esm/components/icons/send.js.map +1 -0
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/components/modals/modal-with-views.js +5 -2
- package/dist/esm/components/modals/modal-with-views.js.map +1 -1
- package/dist/esm/components/modals/modal.js +1 -1
- package/dist/esm/components/modals/modal.js.map +1 -1
- package/dist/esm/components/modals/use-modal-with-views.js +0 -1
- package/dist/esm/components/modals/use-modal-with-views.js.map +1 -1
- package/dist/esm/components/quote-expiry/index.js +2 -0
- package/dist/esm/components/quote-expiry/index.js.map +1 -0
- package/dist/esm/components/quote-expiry/quote-expiry-countdown.js +35 -0
- package/dist/esm/components/quote-expiry/quote-expiry-countdown.js.map +1 -0
- package/dist/esm/components/quote-expiry/styles.js +109 -0
- package/dist/esm/components/quote-expiry/styles.js.map +1 -0
- package/dist/esm/components/quote-expiry/tiers.js +31 -0
- package/dist/esm/components/quote-expiry/tiers.js.map +1 -0
- package/dist/esm/components/wallet-selector/component.js +3 -5
- package/dist/esm/components/wallet-selector/component.js.map +1 -1
- package/dist/esm/components/wallet-selector/provider.js +1 -1
- package/dist/esm/components/wallet-selector/provider.js.map +1 -1
- package/dist/esm/components/wallet-selector/wallets/wagmi/index.js.map +1 -1
- package/dist/esm/config.js.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/integrations/lifi.js +52 -34
- package/dist/esm/integrations/lifi.js.map +1 -1
- package/dist/esm/refund/index.js +791 -0
- package/dist/esm/refund/index.js.map +1 -0
- package/dist/esm/state/checkout/payment-attempt.js +3 -0
- package/dist/esm/state/checkout/payment-attempt.js.map +1 -1
- package/dist/esm/state/checkout/payment-lifecycle.js +43 -35
- package/dist/esm/state/checkout/payment-lifecycle.js.map +1 -1
- package/dist/esm/state/checkout/store.js +318 -198
- package/dist/esm/state/checkout/store.js.map +1 -1
- package/dist/esm/state/checkout/wallet-payment-options.js +44 -0
- package/dist/esm/state/checkout/wallet-payment-options.js.map +1 -0
- package/dist/esm/themes/default.js +6 -0
- package/dist/esm/themes/default.js.map +1 -1
- package/dist/esm/utils/string.js +1 -0
- package/dist/esm/utils/string.js.map +1 -1
- package/dist/esm/utils/wallet-errors.js +15 -0
- package/dist/esm/utils/wallet-errors.js.map +1 -0
- package/dist/types/api/generated.d.ts +207 -4
- package/dist/types/api/generated.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +2 -1
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/payments.d.ts +36 -1
- package/dist/types/api/payments.d.ts.map +1 -1
- package/dist/types/api/types.d.ts +4 -0
- package/dist/types/api/types.d.ts.map +1 -1
- package/dist/types/checkout/index.d.ts +4 -1
- package/dist/types/checkout/index.d.ts.map +1 -1
- package/dist/types/checkout/modal.d.ts.map +1 -1
- package/dist/types/checkout/providers/wagmi-config.d.ts +18 -0
- package/dist/types/checkout/providers/wagmi-config.d.ts.map +1 -0
- package/dist/types/checkout/providers/wallet-connect-resume.d.ts +9 -0
- package/dist/types/checkout/providers/wallet-connect-resume.d.ts.map +1 -0
- package/dist/types/checkout/resume-state.d.ts +13 -0
- package/dist/types/checkout/resume-state.d.ts.map +1 -0
- package/dist/types/checkout/surplus-refund.d.ts +10 -0
- package/dist/types/checkout/surplus-refund.d.ts.map +1 -0
- package/dist/types/checkout/views/back.d.ts +2 -1
- package/dist/types/checkout/views/back.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/direct-details.d.ts +10 -1
- package/dist/types/checkout/views/crypto-intent/direct-details.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/methods.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/processing.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/success.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/wallet-payment-options.d.ts.map +1 -1
- package/dist/types/checkout/views/crypto-intent/wallet-select.d.ts.map +1 -1
- package/dist/types/checkout/views/failed.d.ts.map +1 -1
- package/dist/types/checkout/views/initial.d.ts +4 -0
- package/dist/types/checkout/views/initial.d.ts.map +1 -1
- package/dist/types/checkout/views/method-select.d.ts +2 -0
- package/dist/types/checkout/views/method-select.d.ts.map +1 -1
- package/dist/types/components/buttons/index.d.ts.map +1 -1
- package/dist/types/components/icons/clock.d.ts +6 -0
- package/dist/types/components/icons/clock.d.ts.map +1 -0
- package/dist/types/components/icons/edit.d.ts +6 -0
- package/dist/types/components/icons/edit.d.ts.map +1 -0
- package/dist/types/components/icons/index.d.ts +4 -0
- package/dist/types/components/icons/index.d.ts.map +1 -1
- package/dist/types/components/icons/log-out.d.ts +6 -0
- package/dist/types/components/icons/log-out.d.ts.map +1 -0
- package/dist/types/components/icons/send.d.ts +6 -0
- package/dist/types/components/icons/send.d.ts.map +1 -0
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/components/index.d.ts.map +1 -1
- package/dist/types/components/modals/modal-with-views.d.ts +1 -0
- package/dist/types/components/modals/modal-with-views.d.ts.map +1 -1
- package/dist/types/components/modals/modal.d.ts.map +1 -1
- package/dist/types/components/modals/use-modal-with-views.d.ts.map +1 -1
- package/dist/types/components/quote-expiry/index.d.ts +2 -0
- package/dist/types/components/quote-expiry/index.d.ts.map +1 -0
- package/dist/types/components/quote-expiry/quote-expiry-countdown.d.ts +15 -0
- package/dist/types/components/quote-expiry/quote-expiry-countdown.d.ts.map +1 -0
- package/dist/types/components/quote-expiry/styles.d.ts +22 -0
- package/dist/types/components/quote-expiry/styles.d.ts.map +1 -0
- package/dist/types/components/quote-expiry/tiers.d.ts +10 -0
- package/dist/types/components/quote-expiry/tiers.d.ts.map +1 -0
- package/dist/types/components/wallet-selector/component.d.ts +1 -2
- package/dist/types/components/wallet-selector/component.d.ts.map +1 -1
- package/dist/types/components/wallet-selector/domain.d.ts +3 -2
- package/dist/types/components/wallet-selector/domain.d.ts.map +1 -1
- package/dist/types/components/wallet-selector/provider.d.ts +3 -3
- package/dist/types/components/wallet-selector/provider.d.ts.map +1 -1
- package/dist/types/components/wallet-selector/wallets/wagmi/index.d.ts +41 -5
- package/dist/types/components/wallet-selector/wallets/wagmi/index.d.ts.map +1 -1
- package/dist/types/config.d.ts +3 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/integrations/lifi.d.ts.map +1 -1
- package/dist/types/refund/index.d.ts +82 -0
- package/dist/types/refund/index.d.ts.map +1 -0
- package/dist/types/state/checkout/payment-attempt.d.ts.map +1 -1
- package/dist/types/state/checkout/payment-lifecycle.d.ts +27 -10
- package/dist/types/state/checkout/payment-lifecycle.d.ts.map +1 -1
- package/dist/types/state/checkout/store.d.ts +35 -16
- package/dist/types/state/checkout/store.d.ts.map +1 -1
- package/dist/types/state/checkout/wallet-payment-options.d.ts +24 -0
- package/dist/types/state/checkout/wallet-payment-options.d.ts.map +1 -0
- package/dist/types/themes/default.d.ts.map +1 -1
- package/dist/types/themes/types.d.ts +11 -0
- package/dist/types/themes/types.d.ts.map +1 -1
- package/dist/types/utils/string.d.ts +1 -0
- package/dist/types/utils/string.d.ts.map +1 -1
- package/dist/types/utils/wallet-errors.d.ts +2 -0
- package/dist/types/utils/wallet-errors.d.ts.map +1 -0
- package/package.json +25 -18
- package/LICENSE +0 -21
|
@@ -1,61 +1,381 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useAppKit } from "@reown/appkit/react";
|
|
3
|
+
import { disconnect } from "@wagmi/core";
|
|
4
|
+
import { useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
|
|
3
5
|
import { keyframes, styled } from "styled-components";
|
|
6
|
+
import { useAccount, useConfig } from "wagmi";
|
|
4
7
|
import { confirmPayment } from "../../../api/payments.js";
|
|
5
|
-
import {
|
|
8
|
+
import { EditIcon, LogOutIcon } from "../../../components/icons/index.js";
|
|
9
|
+
import { QuoteExpiryCountdown, StyledButton, Text, useModalWithView, } from "../../../components/index.js";
|
|
6
10
|
import { WalletContext } from "../../../components/wallet-selector/provider.js";
|
|
11
|
+
import { useWalletActions } from "../../../components/wallet-selector/store.js";
|
|
12
|
+
import { WagmiWalletInterface } from "../../../components/wallet-selector/wallets/wagmi/index.js";
|
|
7
13
|
import { useMintMoneyConfig } from "../../../context.js";
|
|
8
14
|
import { executeWalletPaymentOption, fetchWalletPaymentQuote, findWalletPaymentOptions, } from "../../../integrations/index.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
15
|
+
import { clearQuoteRefresh, checkChainStatus, configureWalletQuoteRefresh, createWalletOptionPaymentAttempt, executeTransfer, prepareWalletQuoteReplacement, resetWalletPaymentState, setProcessing, setSelectedCurrency, setWalletPaymentState, useCheckoutStore, } from "../../../state/checkout/store.js";
|
|
16
|
+
import { buildWalletPaymentOptionsLoadKey, buildWalletQuoteLoadKey, buildWalletPaymentOptionsReadyState, NO_WALLET_PAYMENT_OPTIONS_DESCRIPTION, NO_WALLET_PAYMENT_OPTIONS_TITLE, } from "../../../state/checkout/wallet-payment-options.js";
|
|
17
|
+
import { formatAddress } from "../../../utils/string.js";
|
|
18
|
+
import { messageForWalletError } from "../../../utils/wallet-errors.js";
|
|
11
19
|
import { ModalViewContainer } from "../../container.js";
|
|
20
|
+
import { clearCheckoutResumeState, readCheckoutResumeState, writeCheckoutResumeState, writePendingWalletConnectionResumeState, } from "../../resume-state.js";
|
|
12
21
|
import { ModalBackButton } from "../back.js";
|
|
13
22
|
import { resolveWalletPaymentConfirmationAmount } from "./wallet-payment-confirmation-amount.js";
|
|
14
|
-
const
|
|
23
|
+
const QUOTE_COUNTDOWN_URGENT_THRESHOLD_RATIO = 0.25;
|
|
24
|
+
const pillSlideIn = keyframes `
|
|
25
|
+
from {
|
|
26
|
+
opacity: 0;
|
|
27
|
+
transform: translateY(-6px);
|
|
28
|
+
}
|
|
29
|
+
to {
|
|
30
|
+
opacity: 1;
|
|
31
|
+
transform: translateY(0);
|
|
32
|
+
}
|
|
33
|
+
`;
|
|
34
|
+
const ContextStrip = styled.div `
|
|
15
35
|
display: flex;
|
|
16
36
|
flex-direction: column;
|
|
17
|
-
gap:
|
|
18
|
-
max-height: min(360px, 48vh);
|
|
19
|
-
overflow-y: auto;
|
|
20
|
-
padding-right: 4px;
|
|
21
|
-
overscroll-behavior: contain;
|
|
37
|
+
gap: 8px;
|
|
22
38
|
`;
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
39
|
+
const ContextPill = styled.div `
|
|
40
|
+
overflow: hidden;
|
|
41
|
+
padding: 12px 14px;
|
|
42
|
+
border-radius: 14px;
|
|
43
|
+
background: ${({ $accent }) => ($accent ? "#f8fffc" : "#ffffff")};
|
|
44
|
+
border: 1px solid ${({ $accent }) => ($accent ? "#bbf7d0" : "#eef2f6")};
|
|
45
|
+
box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
|
|
46
|
+
animation: ${pillSlideIn} 200ms cubic-bezier(0.22, 1, 0.36, 1);
|
|
47
|
+
`;
|
|
48
|
+
const ContextPillToggle = styled.button `
|
|
49
|
+
width: 100%;
|
|
50
|
+
border: 0;
|
|
51
|
+
background: transparent;
|
|
52
|
+
color: inherit;
|
|
53
|
+
padding: 0;
|
|
54
|
+
display: flex;
|
|
55
|
+
align-items: center;
|
|
56
|
+
gap: 12px;
|
|
57
|
+
cursor: pointer;
|
|
58
|
+
text-align: left;
|
|
59
|
+
|
|
60
|
+
&:focus-visible {
|
|
61
|
+
outline: 2px solid #a7f3d0;
|
|
62
|
+
outline-offset: 4px;
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
const PillIconWrap = styled.div `
|
|
66
|
+
position: relative;
|
|
67
|
+
width: 40px;
|
|
68
|
+
height: 40px;
|
|
69
|
+
flex-shrink: 0;
|
|
70
|
+
`;
|
|
71
|
+
const PillTokenIcon = styled.div `
|
|
72
|
+
width: 100%;
|
|
73
|
+
height: 100%;
|
|
74
|
+
border-radius: 999px;
|
|
75
|
+
display: inline-flex;
|
|
76
|
+
align-items: center;
|
|
77
|
+
justify-content: center;
|
|
78
|
+
font-size: 11px;
|
|
79
|
+
font-weight: 700;
|
|
80
|
+
color: #1d4ed8;
|
|
81
|
+
background: linear-gradient(135deg, #dbeafe, #bfdbfe);
|
|
82
|
+
background-image: ${({ $iconUrl }) => $iconUrl ? `url(${$iconUrl})` : "none"};
|
|
83
|
+
background-size: cover;
|
|
84
|
+
background-position: center;
|
|
85
|
+
`;
|
|
86
|
+
const PillChainBadge = styled.div `
|
|
87
|
+
position: absolute;
|
|
88
|
+
right: -2px;
|
|
89
|
+
bottom: -2px;
|
|
90
|
+
width: 14px;
|
|
91
|
+
height: 14px;
|
|
92
|
+
border-radius: 999px;
|
|
93
|
+
border: 1.5px solid #ffffff;
|
|
27
94
|
background: #ffffff;
|
|
95
|
+
background-image: ${({ $iconUrl }) => $iconUrl ? `url(${$iconUrl})` : "none"};
|
|
96
|
+
background-size: 85%;
|
|
97
|
+
background-position: center;
|
|
98
|
+
background-repeat: no-repeat;
|
|
99
|
+
box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
|
|
100
|
+
`;
|
|
101
|
+
const WalletDot = styled.div `
|
|
102
|
+
width: 22px;
|
|
103
|
+
height: 22px;
|
|
104
|
+
border-radius: 999px;
|
|
105
|
+
flex-shrink: 0;
|
|
106
|
+
background:
|
|
107
|
+
${({ $iconUrl }) => ($iconUrl ? `url(${$iconUrl})` : "none")},
|
|
108
|
+
linear-gradient(135deg, #22c55e, #60a5fa);
|
|
109
|
+
background-size: cover;
|
|
110
|
+
background-position: center;
|
|
111
|
+
`;
|
|
112
|
+
const WalletSwitchLink = styled.button `
|
|
113
|
+
flex-shrink: 0;
|
|
114
|
+
border: none;
|
|
115
|
+
background: transparent;
|
|
116
|
+
color: #94a3b8;
|
|
117
|
+
display: inline-flex;
|
|
118
|
+
align-items: center;
|
|
119
|
+
justify-content: center;
|
|
120
|
+
width: 24px;
|
|
121
|
+
height: 24px;
|
|
122
|
+
margin: -2px -2px -2px -6px;
|
|
123
|
+
padding: 0;
|
|
28
124
|
cursor: pointer;
|
|
125
|
+
border-radius: 999px;
|
|
29
126
|
transition:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
transform 120ms ease;
|
|
127
|
+
color 120ms ease,
|
|
128
|
+
background-color 120ms ease;
|
|
33
129
|
|
|
34
130
|
&:hover {
|
|
35
|
-
|
|
36
|
-
|
|
131
|
+
color: #0f172a;
|
|
132
|
+
background: #f1f5f9;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
&:focus-visible {
|
|
136
|
+
outline: 2px solid #a7f3d0;
|
|
137
|
+
outline-offset: 2px;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
&:disabled {
|
|
141
|
+
opacity: 0.5;
|
|
142
|
+
cursor: not-allowed;
|
|
143
|
+
}
|
|
144
|
+
`;
|
|
145
|
+
const WalletDisconnectButton = styled.button `
|
|
146
|
+
flex-shrink: 0;
|
|
147
|
+
border: none;
|
|
148
|
+
background: transparent;
|
|
149
|
+
color: #dc2626;
|
|
150
|
+
display: inline-flex;
|
|
151
|
+
align-items: center;
|
|
152
|
+
justify-content: center;
|
|
153
|
+
width: 24px;
|
|
154
|
+
height: 24px;
|
|
155
|
+
margin: -2px -2px -2px -4px;
|
|
156
|
+
padding: 0;
|
|
157
|
+
border-radius: 999px;
|
|
158
|
+
cursor: pointer;
|
|
159
|
+
transition:
|
|
160
|
+
background-color 120ms ease,
|
|
161
|
+
color 120ms ease;
|
|
162
|
+
|
|
163
|
+
&:hover {
|
|
164
|
+
background: #fee2e2;
|
|
165
|
+
color: #b91c1c;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
&:focus-visible {
|
|
169
|
+
outline: 2px solid #fecaca;
|
|
170
|
+
outline-offset: 2px;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
&:disabled {
|
|
174
|
+
opacity: 0.5;
|
|
175
|
+
cursor: not-allowed;
|
|
176
|
+
}
|
|
177
|
+
`;
|
|
178
|
+
const WalletRowActions = styled.div `
|
|
179
|
+
display: inline-flex;
|
|
180
|
+
align-items: center;
|
|
181
|
+
gap: 6px;
|
|
182
|
+
flex-shrink: 0;
|
|
183
|
+
`;
|
|
184
|
+
const PillBody = styled.div `
|
|
185
|
+
display: flex;
|
|
186
|
+
flex-direction: column;
|
|
187
|
+
gap: 2px;
|
|
188
|
+
min-width: 0;
|
|
189
|
+
flex: 1;
|
|
190
|
+
`;
|
|
191
|
+
const PillEyebrow = styled.span `
|
|
192
|
+
font-size: 12px;
|
|
193
|
+
line-height: 1.2;
|
|
194
|
+
color: ${({ theme }) => theme.font.color.tertiary};
|
|
195
|
+
white-space: nowrap;
|
|
196
|
+
overflow: hidden;
|
|
197
|
+
text-overflow: ellipsis;
|
|
198
|
+
`;
|
|
199
|
+
const PillTitle = styled.span `
|
|
200
|
+
font-size: 14px;
|
|
201
|
+
font-weight: 600;
|
|
202
|
+
color: ${({ theme }) => theme.font.color.primary};
|
|
203
|
+
line-height: 1.3;
|
|
204
|
+
white-space: nowrap;
|
|
205
|
+
overflow: hidden;
|
|
206
|
+
text-overflow: ellipsis;
|
|
207
|
+
`;
|
|
208
|
+
const PillAction = styled.button `
|
|
209
|
+
flex-shrink: 0;
|
|
210
|
+
border: none;
|
|
211
|
+
background: transparent;
|
|
212
|
+
color: ${({ theme }) => theme.font.color.secondary};
|
|
213
|
+
font-size: 14px;
|
|
214
|
+
font-weight: 600;
|
|
215
|
+
padding: 6px 10px;
|
|
216
|
+
border-radius: 999px;
|
|
217
|
+
cursor: pointer;
|
|
218
|
+
transition:
|
|
219
|
+
background-color 120ms ease,
|
|
220
|
+
color 120ms ease;
|
|
221
|
+
|
|
222
|
+
&:hover {
|
|
223
|
+
background: #f1f5f9;
|
|
224
|
+
color: #0f172a;
|
|
37
225
|
}
|
|
226
|
+
|
|
227
|
+
&:focus-visible {
|
|
228
|
+
outline: 2px solid #a7f3d0;
|
|
229
|
+
outline-offset: 2px;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
&:disabled {
|
|
233
|
+
opacity: 0.5;
|
|
234
|
+
cursor: not-allowed;
|
|
235
|
+
}
|
|
236
|
+
`;
|
|
237
|
+
const PillCaret = styled.span `
|
|
238
|
+
width: 24px;
|
|
239
|
+
height: 24px;
|
|
240
|
+
border-radius: 999px;
|
|
241
|
+
background: #f1f3fb;
|
|
242
|
+
display: inline-flex;
|
|
243
|
+
align-items: center;
|
|
244
|
+
justify-content: center;
|
|
245
|
+
font-size: 13px;
|
|
246
|
+
line-height: 1;
|
|
247
|
+
color: #6b7280;
|
|
248
|
+
transform: rotate(${({ $expanded }) => ($expanded ? "180deg" : "0deg")});
|
|
249
|
+
transition:
|
|
250
|
+
transform 0.15s ease,
|
|
251
|
+
background 0.15s ease;
|
|
252
|
+
flex-shrink: 0;
|
|
38
253
|
`;
|
|
39
|
-
const
|
|
254
|
+
const PillDetails = styled.div `
|
|
255
|
+
border-top: 1px solid #edf1f5;
|
|
256
|
+
margin-top: 12px;
|
|
257
|
+
padding-top: 12px;
|
|
40
258
|
display: flex;
|
|
259
|
+
flex-direction: column;
|
|
260
|
+
`;
|
|
261
|
+
const PillDetailRow = styled.div `
|
|
262
|
+
display: flex;
|
|
263
|
+
align-items: center;
|
|
264
|
+
justify-content: space-between;
|
|
265
|
+
gap: 12px;
|
|
266
|
+
border-bottom: 1px solid #edf1f5;
|
|
267
|
+
padding: 9px 0;
|
|
268
|
+
|
|
269
|
+
&:last-child {
|
|
270
|
+
border-bottom: 0;
|
|
271
|
+
padding-bottom: 0;
|
|
272
|
+
}
|
|
273
|
+
`;
|
|
274
|
+
const PillDetailLabel = styled.span `
|
|
275
|
+
font-size: 13px;
|
|
276
|
+
line-height: 1.3;
|
|
277
|
+
color: #475569;
|
|
278
|
+
`;
|
|
279
|
+
const PillDetailValue = styled.span `
|
|
280
|
+
display: inline-flex;
|
|
41
281
|
align-items: center;
|
|
282
|
+
justify-content: flex-end;
|
|
283
|
+
gap: 6px;
|
|
284
|
+
min-width: 0;
|
|
285
|
+
font-size: 13px;
|
|
286
|
+
line-height: 1.3;
|
|
287
|
+
font-weight: 600;
|
|
288
|
+
color: #0f172a;
|
|
289
|
+
text-align: right;
|
|
290
|
+
`;
|
|
291
|
+
const SectionLabel = styled.div `
|
|
292
|
+
font-size: 11px;
|
|
293
|
+
font-weight: 600;
|
|
294
|
+
letter-spacing: 0.06em;
|
|
295
|
+
text-transform: uppercase;
|
|
296
|
+
color: #94a3b8;
|
|
297
|
+
padding: 0 2px;
|
|
298
|
+
`;
|
|
299
|
+
const SectionRow = styled.div `
|
|
300
|
+
display: flex;
|
|
301
|
+
align-items: baseline;
|
|
42
302
|
justify-content: space-between;
|
|
43
303
|
gap: 12px;
|
|
304
|
+
padding: 0 2px;
|
|
44
305
|
`;
|
|
45
|
-
const
|
|
306
|
+
const ConnectedWalletRow = styled.div `
|
|
46
307
|
display: flex;
|
|
47
308
|
align-items: center;
|
|
309
|
+
justify-content: space-between;
|
|
310
|
+
gap: 12px;
|
|
311
|
+
padding: 2px 4px;
|
|
312
|
+
`;
|
|
313
|
+
const ConnectedWalletIdentity = styled.div `
|
|
314
|
+
display: inline-flex;
|
|
315
|
+
align-items: center;
|
|
48
316
|
gap: 10px;
|
|
49
317
|
min-width: 0;
|
|
318
|
+
font-size: 14px;
|
|
319
|
+
line-height: 1.4;
|
|
320
|
+
color: #64748b;
|
|
321
|
+
`;
|
|
322
|
+
const ConnectedWalletAddress = styled.span `
|
|
323
|
+
min-width: 0;
|
|
324
|
+
overflow: hidden;
|
|
325
|
+
text-overflow: ellipsis;
|
|
326
|
+
white-space: nowrap;
|
|
327
|
+
`;
|
|
328
|
+
const OptionsContainer = styled.div `
|
|
329
|
+
display: flex;
|
|
330
|
+
flex-direction: column;
|
|
50
331
|
flex: 1;
|
|
332
|
+
gap: 8px;
|
|
333
|
+
min-height: 0;
|
|
334
|
+
overflow-y: auto;
|
|
335
|
+
margin: -4px -4px -6px;
|
|
336
|
+
padding: 4px 4px 6px;
|
|
337
|
+
overscroll-behavior: contain;
|
|
338
|
+
scrollbar-width: none;
|
|
339
|
+
|
|
340
|
+
&::-webkit-scrollbar {
|
|
341
|
+
display: none;
|
|
342
|
+
}
|
|
51
343
|
`;
|
|
52
|
-
const
|
|
344
|
+
const OptionCard = styled.button `
|
|
345
|
+
border: 1px solid #eef2f6;
|
|
346
|
+
border-radius: 16px;
|
|
347
|
+
padding: 12px 14px;
|
|
348
|
+
background: #ffffff;
|
|
349
|
+
cursor: pointer;
|
|
350
|
+
width: 100%;
|
|
351
|
+
text-align: left;
|
|
352
|
+
display: flex;
|
|
353
|
+
align-items: center;
|
|
354
|
+
gap: 12px;
|
|
355
|
+
transition:
|
|
356
|
+
border-color 140ms ease,
|
|
357
|
+
box-shadow 140ms ease,
|
|
358
|
+
transform 140ms ease,
|
|
359
|
+
background-color 140ms ease;
|
|
360
|
+
|
|
361
|
+
&:hover {
|
|
362
|
+
border-color: #cdd9e3;
|
|
363
|
+
box-shadow: 0 6px 14px rgba(15, 23, 42, 0.05);
|
|
364
|
+
transform: translateY(-1px);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
&:focus-visible {
|
|
368
|
+
outline: 2px solid #a7f3d0;
|
|
369
|
+
outline-offset: 2px;
|
|
370
|
+
}
|
|
371
|
+
`;
|
|
372
|
+
const OptionTokenIconWrap = styled.div `
|
|
53
373
|
position: relative;
|
|
54
|
-
width:
|
|
55
|
-
height:
|
|
374
|
+
width: 40px;
|
|
375
|
+
height: 40px;
|
|
56
376
|
flex-shrink: 0;
|
|
57
377
|
`;
|
|
58
|
-
const
|
|
378
|
+
const OptionTokenIcon = styled.div `
|
|
59
379
|
width: 100%;
|
|
60
380
|
height: 100%;
|
|
61
381
|
border-radius: 999px;
|
|
@@ -73,7 +393,7 @@ const TokenIcon = styled.div `
|
|
|
73
393
|
background-position: center;
|
|
74
394
|
overflow: hidden;
|
|
75
395
|
`;
|
|
76
|
-
const
|
|
396
|
+
const OptionChainBadge = styled.div `
|
|
77
397
|
position: absolute;
|
|
78
398
|
right: -2px;
|
|
79
399
|
bottom: -2px;
|
|
@@ -100,24 +420,9 @@ const OptionBalance = styled.div `
|
|
|
100
420
|
display: flex;
|
|
101
421
|
flex-direction: column;
|
|
102
422
|
align-items: flex-end;
|
|
103
|
-
gap:
|
|
423
|
+
gap: 4px;
|
|
104
424
|
flex-shrink: 0;
|
|
105
425
|
`;
|
|
106
|
-
const OptionsHeaderRow = styled.div `
|
|
107
|
-
display: flex;
|
|
108
|
-
align-items: baseline;
|
|
109
|
-
justify-content: space-between;
|
|
110
|
-
gap: 12px;
|
|
111
|
-
`;
|
|
112
|
-
const OptionsHeaderLabel = styled.div `
|
|
113
|
-
font-size: 11px;
|
|
114
|
-
line-height: 1;
|
|
115
|
-
color: #64748b;
|
|
116
|
-
letter-spacing: 0.02em;
|
|
117
|
-
text-transform: none;
|
|
118
|
-
white-space: nowrap;
|
|
119
|
-
padding-right: 8px;
|
|
120
|
-
`;
|
|
121
426
|
const FastBadge = styled.span `
|
|
122
427
|
display: inline-flex;
|
|
123
428
|
align-items: center;
|
|
@@ -125,95 +430,123 @@ const FastBadge = styled.span `
|
|
|
125
430
|
gap: 4px;
|
|
126
431
|
background: #ecfdf5;
|
|
127
432
|
color: #047857;
|
|
128
|
-
font-size:
|
|
433
|
+
font-size: 11px;
|
|
129
434
|
font-weight: 600;
|
|
130
435
|
line-height: 1;
|
|
131
|
-
padding:
|
|
436
|
+
padding: 4px 8px;
|
|
132
437
|
white-space: nowrap;
|
|
133
438
|
`;
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
background: #f9fafb;
|
|
140
|
-
`;
|
|
141
|
-
const confirmTrayEnter = keyframes `
|
|
142
|
-
from {
|
|
143
|
-
opacity: 0;
|
|
144
|
-
transform: perspective(1000px) rotateY(-86deg) scale(0.96);
|
|
145
|
-
transform-origin: center;
|
|
146
|
-
}
|
|
147
|
-
to {
|
|
148
|
-
opacity: 1;
|
|
149
|
-
opacity: 1;
|
|
150
|
-
transform: perspective(1000px) rotateY(0deg) scale(1);
|
|
151
|
-
}
|
|
439
|
+
const RoutedBadge = styled.span `
|
|
440
|
+
font-size: 11px;
|
|
441
|
+
font-weight: 500;
|
|
442
|
+
color: #94a3b8;
|
|
443
|
+
white-space: nowrap;
|
|
152
444
|
`;
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
border: 1px solid #
|
|
156
|
-
border-radius:
|
|
157
|
-
padding:
|
|
158
|
-
background: linear-gradient(180deg, #ecfdf5 0%, #dcfce7 100%);
|
|
159
|
-
box-shadow: 0 14px 30px rgba(16, 185, 129, 0.12);
|
|
445
|
+
const QuoteCard = styled.div `
|
|
446
|
+
background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
|
|
447
|
+
border: 1px solid #eef2f6;
|
|
448
|
+
border-radius: 18px;
|
|
449
|
+
padding: 16px 18px;
|
|
160
450
|
display: flex;
|
|
161
451
|
flex-direction: column;
|
|
162
|
-
gap:
|
|
163
|
-
|
|
452
|
+
gap: 10px;
|
|
453
|
+
box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
|
|
164
454
|
`;
|
|
165
|
-
const
|
|
455
|
+
const QuoteRow = styled.div `
|
|
166
456
|
display: flex;
|
|
167
|
-
align-items:
|
|
457
|
+
align-items: baseline;
|
|
168
458
|
justify-content: space-between;
|
|
169
|
-
gap:
|
|
459
|
+
gap: 16px;
|
|
170
460
|
`;
|
|
171
|
-
const
|
|
461
|
+
const QuoteHairline = styled.div `
|
|
462
|
+
height: 1px;
|
|
463
|
+
background: #eef2f6;
|
|
464
|
+
margin: 2px 0;
|
|
465
|
+
`;
|
|
466
|
+
const QuoteFootnote = styled.div `
|
|
172
467
|
display: flex;
|
|
173
468
|
align-items: center;
|
|
174
|
-
gap:
|
|
469
|
+
gap: 6px;
|
|
470
|
+
font-size: 12px;
|
|
471
|
+
color: #94a3b8;
|
|
472
|
+
|
|
473
|
+
&::before {
|
|
474
|
+
content: "";
|
|
475
|
+
display: inline-block;
|
|
476
|
+
width: 6px;
|
|
477
|
+
height: 6px;
|
|
478
|
+
border-radius: 999px;
|
|
479
|
+
background: #22c55e;
|
|
480
|
+
box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18);
|
|
481
|
+
}
|
|
175
482
|
`;
|
|
176
|
-
const
|
|
483
|
+
const QuoteFootnoteWarn = styled(QuoteFootnote) `
|
|
484
|
+
color: #b45309;
|
|
485
|
+
|
|
486
|
+
&::before {
|
|
487
|
+
background: #f59e0b;
|
|
488
|
+
box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18);
|
|
489
|
+
}
|
|
490
|
+
`;
|
|
491
|
+
const SkeletonContainer = styled.div `
|
|
177
492
|
display: flex;
|
|
178
493
|
flex-direction: column;
|
|
179
|
-
gap:
|
|
494
|
+
gap: 8px;
|
|
495
|
+
`;
|
|
496
|
+
const skeletonShimmer = keyframes `
|
|
497
|
+
0% { background-position: -120% 0; }
|
|
498
|
+
100% { background-position: 220% 0; }
|
|
180
499
|
`;
|
|
181
|
-
const
|
|
500
|
+
const SkeletonRow = styled.div `
|
|
501
|
+
height: 64px;
|
|
502
|
+
border-radius: 16px;
|
|
503
|
+
border: 1px solid #eef2f6;
|
|
504
|
+
background: linear-gradient(90deg, #f8fafc 0%, #f1f5f9 50%, #f8fafc 100%);
|
|
505
|
+
background-size: 220% 100%;
|
|
506
|
+
animation: ${skeletonShimmer} 1.4s ease-in-out infinite;
|
|
507
|
+
`;
|
|
508
|
+
const EmptyState = styled.div `
|
|
509
|
+
position: relative;
|
|
510
|
+
border-radius: 22px;
|
|
511
|
+
padding: 22px 20px;
|
|
512
|
+
background: #ffffff;
|
|
513
|
+
border: 1px solid #ecf1ee;
|
|
182
514
|
display: flex;
|
|
183
515
|
flex-direction: column;
|
|
516
|
+
align-items: center;
|
|
184
517
|
gap: 10px;
|
|
518
|
+
text-align: center;
|
|
519
|
+
box-shadow: 0 14px 32px rgba(15, 23, 42, 0.05);
|
|
185
520
|
`;
|
|
186
|
-
const
|
|
521
|
+
const EmptyHeadline = styled.div `
|
|
187
522
|
display: flex;
|
|
188
523
|
flex-direction: column;
|
|
189
|
-
gap:
|
|
524
|
+
gap: 4px;
|
|
525
|
+
max-width: 300px;
|
|
190
526
|
`;
|
|
191
|
-
const
|
|
527
|
+
const FallbackTopActions = styled.div `
|
|
192
528
|
display: flex;
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
529
|
+
justify-content: flex-end;
|
|
530
|
+
min-height: 32px;
|
|
531
|
+
`;
|
|
532
|
+
const FallbackDisconnectButton = styled(WalletDisconnectButton) `
|
|
533
|
+
width: 32px;
|
|
534
|
+
height: 32px;
|
|
535
|
+
margin: 0;
|
|
536
|
+
border: 1px solid #fee2e2;
|
|
537
|
+
background: #ffffff;
|
|
196
538
|
`;
|
|
197
539
|
const ContentStage = styled.div `
|
|
198
540
|
display: flex;
|
|
199
541
|
flex-direction: column;
|
|
200
|
-
|
|
542
|
+
flex: 1;
|
|
543
|
+
gap: 14px;
|
|
201
544
|
min-height: 0;
|
|
545
|
+
|
|
546
|
+
@media (max-width: 768px) {
|
|
547
|
+
justify-content: ${({ $mobileCentered }) => $mobileCentered ? "center" : "flex-start"};
|
|
548
|
+
}
|
|
202
549
|
`;
|
|
203
|
-
const buildDefaultOption = (context) => ({
|
|
204
|
-
id: "direct-settlement",
|
|
205
|
-
label: `${context.settlementCurrency.asset_name} on ${context.settlementCurrency.chain_name}`,
|
|
206
|
-
subtitle: "Fastest Route. You can pay directly without needing to swap.",
|
|
207
|
-
badge: "Fastest",
|
|
208
|
-
fromChain: context.settlementCurrency.chain,
|
|
209
|
-
fromChainName: context.settlementCurrency.chain_name,
|
|
210
|
-
fromToken: context.settlementCurrency.asset,
|
|
211
|
-
fromTokenName: context.settlementCurrency.asset_name,
|
|
212
|
-
fromAmount: null,
|
|
213
|
-
quoteId: null,
|
|
214
|
-
routeId: null,
|
|
215
|
-
kind: "direct",
|
|
216
|
-
});
|
|
217
550
|
const formatDisplayAmount = (amount, maximumFractionDigits = 4) => {
|
|
218
551
|
if (!amount)
|
|
219
552
|
return null;
|
|
@@ -283,25 +616,53 @@ const buildDirectQuote = (option, context) => {
|
|
|
283
616
|
estimatedDurationMinutes: 1,
|
|
284
617
|
};
|
|
285
618
|
};
|
|
286
|
-
const
|
|
619
|
+
const CryptoIntentWalletPaymentOptionsAppKitViewContent = () => {
|
|
287
620
|
const modalRef = useRef(null);
|
|
621
|
+
const isChangingWalletRef = useRef(false);
|
|
622
|
+
const lastWalletOptionsLoadKeyRef = useRef(null);
|
|
623
|
+
const walletOptionsRequestRef = useRef(null);
|
|
624
|
+
const lastQuoteLoadKeyRef = useRef(null);
|
|
288
625
|
const { goToView } = useModalWithView();
|
|
626
|
+
const { open } = useAppKit();
|
|
289
627
|
const config = useMintMoneyConfig();
|
|
290
|
-
const
|
|
291
|
-
const {
|
|
628
|
+
const wagmiConfig = useConfig();
|
|
629
|
+
const { wallet, setWallet } = useContext(WalletContext);
|
|
630
|
+
const { initialiseWallets } = useWalletActions();
|
|
631
|
+
const account = useAccount();
|
|
632
|
+
const { payment, cryptoPaymentAttempt, cryptoCurrency, walletPayment, quote, loading, processing, } = useCheckoutStore();
|
|
292
633
|
const [executingId, setExecutingId] = useState(null);
|
|
634
|
+
const [paymentDetailsExpanded, setPaymentDetailsExpanded] = useState(false);
|
|
635
|
+
const isWalletConnectionSettling = account.status === "connecting" || account.status === "reconnecting";
|
|
636
|
+
const connectorName = account.connector?.name || "Connected wallet";
|
|
637
|
+
const connectorIcon = typeof account.connector?.icon === "string"
|
|
638
|
+
? account.connector.icon
|
|
639
|
+
: undefined;
|
|
640
|
+
const connectedWagmiWallet = useMemo(() => {
|
|
641
|
+
if (!account.isConnected || !account.address || !account.connector) {
|
|
642
|
+
return null;
|
|
643
|
+
}
|
|
644
|
+
return new WagmiWalletInterface(account.connector, wagmiConfig);
|
|
645
|
+
}, [account.address, account.connector, account.isConnected, wagmiConfig]);
|
|
646
|
+
const activeWallet = connectedWagmiWallet ?? wallet;
|
|
647
|
+
useEffect(() => {
|
|
648
|
+
if (!connectedWagmiWallet) {
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
setWallet(connectedWagmiWallet);
|
|
652
|
+
initialiseWallets([() => connectedWagmiWallet]);
|
|
653
|
+
}, [connectedWagmiWallet, initialiseWallets, setWallet]);
|
|
293
654
|
const buildContext = useCallback(async (currentPayment) => {
|
|
294
655
|
const state = useCheckoutStore.getState();
|
|
295
656
|
const currentCheckout = state.checkout;
|
|
296
657
|
const currentCryptoCurrency = state.cryptoCurrency;
|
|
297
|
-
if (!currentCheckout || !currentCryptoCurrency || !
|
|
658
|
+
if (!currentCheckout || !currentCryptoCurrency || !activeWallet) {
|
|
298
659
|
throw new Error("Wallet payment context is not ready");
|
|
299
660
|
}
|
|
300
661
|
const resolvedPayment = currentPayment ?? state.payment;
|
|
301
662
|
if (!resolvedPayment) {
|
|
302
663
|
throw new Error("Missing payment");
|
|
303
664
|
}
|
|
304
|
-
const walletAddress = await
|
|
665
|
+
const walletAddress = await activeWallet.getAddress();
|
|
305
666
|
if (!walletAddress) {
|
|
306
667
|
throw new Error("Failed to get wallet address");
|
|
307
668
|
}
|
|
@@ -311,46 +672,142 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
|
|
|
311
672
|
settlementCurrency: currentCryptoCurrency,
|
|
312
673
|
walletAddress,
|
|
313
674
|
};
|
|
314
|
-
}, [
|
|
675
|
+
}, [activeWallet]);
|
|
676
|
+
const loadWalletPaymentOptions = useCallback(async (isCancelled, options = {}) => {
|
|
677
|
+
const preparedContext = await buildContext();
|
|
678
|
+
const loadKey = buildWalletPaymentOptionsLoadKey({
|
|
679
|
+
paymentId: preparedContext.payment.id,
|
|
680
|
+
settlementChain: preparedContext.settlementCurrency.chain,
|
|
681
|
+
settlementAsset: preparedContext.settlementCurrency.asset,
|
|
682
|
+
walletAddress: preparedContext.walletAddress,
|
|
683
|
+
});
|
|
684
|
+
if (!loadKey) {
|
|
685
|
+
throw new Error("Wallet payment context is not ready");
|
|
686
|
+
}
|
|
687
|
+
const currentWalletPayment = useCheckoutStore.getState().walletPayment;
|
|
688
|
+
const isSameWallet = currentWalletPayment.walletAddress?.toLowerCase() ===
|
|
689
|
+
preparedContext.walletAddress.toLowerCase();
|
|
690
|
+
const canReuseLoadedOptions = !options.force &&
|
|
691
|
+
lastWalletOptionsLoadKeyRef.current === loadKey &&
|
|
692
|
+
isSameWallet &&
|
|
693
|
+
currentWalletPayment.status !== "failed";
|
|
694
|
+
if (canReuseLoadedOptions) {
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
setProcessing(true);
|
|
698
|
+
setSelectedCurrency(cryptoCurrency);
|
|
699
|
+
const shouldPreserveVisibleOptions = isSameWallet &&
|
|
700
|
+
currentWalletPayment.options.length > 0 &&
|
|
701
|
+
currentWalletPayment.status !== "failed";
|
|
702
|
+
if (shouldPreserveVisibleOptions) {
|
|
703
|
+
setWalletPaymentState({ status: "ready", error: null });
|
|
704
|
+
}
|
|
705
|
+
else {
|
|
706
|
+
resetWalletPaymentState();
|
|
707
|
+
setWalletPaymentState({ status: "loading", error: null, options: [] });
|
|
708
|
+
}
|
|
709
|
+
writeCheckoutResumeState(preparedContext.payment.id, {
|
|
710
|
+
view: "cryptoIntentWalletPaymentOptions",
|
|
711
|
+
walletAddress: preparedContext.walletAddress,
|
|
712
|
+
pendingWalletConnection: false,
|
|
713
|
+
});
|
|
714
|
+
const existingRequest = walletOptionsRequestRef.current;
|
|
715
|
+
const request = existingRequest?.key === loadKey
|
|
716
|
+
? existingRequest.promise
|
|
717
|
+
: findWalletPaymentOptions(preparedContext);
|
|
718
|
+
if (existingRequest?.key !== loadKey) {
|
|
719
|
+
walletOptionsRequestRef.current = {
|
|
720
|
+
key: loadKey,
|
|
721
|
+
promise: request,
|
|
722
|
+
};
|
|
723
|
+
void request
|
|
724
|
+
.finally(() => {
|
|
725
|
+
if (walletOptionsRequestRef.current?.key === loadKey) {
|
|
726
|
+
walletOptionsRequestRef.current = null;
|
|
727
|
+
}
|
|
728
|
+
})
|
|
729
|
+
.catch(() => undefined);
|
|
730
|
+
}
|
|
731
|
+
const providerOptions = await request;
|
|
732
|
+
if (isCancelled()) {
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
const resumeState = readCheckoutResumeState(preparedContext.payment.id);
|
|
736
|
+
const shouldRestoreSelectedOption = resumeState.walletAddress?.toLowerCase() ===
|
|
737
|
+
preparedContext.walletAddress.toLowerCase() &&
|
|
738
|
+
Boolean(resumeState.selectedWalletOptionId &&
|
|
739
|
+
providerOptions.some((option) => option.id === resumeState.selectedWalletOptionId));
|
|
740
|
+
setWalletPaymentState({
|
|
741
|
+
...buildWalletPaymentOptionsReadyState({
|
|
742
|
+
walletAddress: preparedContext.walletAddress,
|
|
743
|
+
options: providerOptions,
|
|
744
|
+
}),
|
|
745
|
+
selectedOptionId: shouldRestoreSelectedOption
|
|
746
|
+
? resumeState.selectedWalletOptionId || null
|
|
747
|
+
: null,
|
|
748
|
+
});
|
|
749
|
+
lastWalletOptionsLoadKeyRef.current = loadKey;
|
|
750
|
+
}, [buildContext, cryptoCurrency]);
|
|
751
|
+
const handleMissingAccount = useCallback(() => {
|
|
752
|
+
resetWalletPaymentState();
|
|
753
|
+
clearQuoteRefresh();
|
|
754
|
+
setProcessing(false);
|
|
755
|
+
goToView("cryptoIntent");
|
|
756
|
+
}, [goToView]);
|
|
757
|
+
const handleMissingWalletConnection = useCallback(() => {
|
|
758
|
+
goToView("failed", { reason: "wallet_not_connected" });
|
|
759
|
+
}, [goToView]);
|
|
760
|
+
const handleWalletPaymentOptionsError = useCallback((error) => {
|
|
761
|
+
const message = error instanceof Error ? error.message : "Failed to load payment options";
|
|
762
|
+
setWalletPaymentState({
|
|
763
|
+
status: "failed",
|
|
764
|
+
error: message,
|
|
765
|
+
options: [],
|
|
766
|
+
});
|
|
767
|
+
}, []);
|
|
768
|
+
const shouldPreserveSubmittedFailure = walletPayment.status === "failed" &&
|
|
769
|
+
walletPayment.options.length > 0 &&
|
|
770
|
+
Boolean(walletPayment.sourceTxHash);
|
|
315
771
|
useEffect(() => {
|
|
316
|
-
if (
|
|
317
|
-
|
|
772
|
+
if (isWalletConnectionSettling) {
|
|
773
|
+
setProcessing(true);
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
if (!account.isConnected || !account.address) {
|
|
777
|
+
if (isChangingWalletRef.current) {
|
|
778
|
+
setProcessing(false);
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
handleMissingAccount();
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
isChangingWalletRef.current = false;
|
|
785
|
+
if (!activeWallet || !cryptoCurrency) {
|
|
786
|
+
handleMissingWalletConnection();
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
if (shouldPreserveSubmittedFailure) {
|
|
790
|
+
setProcessing(false);
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
const currentWalletPayment = useCheckoutStore.getState().walletPayment;
|
|
794
|
+
if (currentWalletPayment.selectedOptionId ||
|
|
795
|
+
currentWalletPayment.status === "executing" ||
|
|
796
|
+
currentWalletPayment.status === "submitted") {
|
|
797
|
+
if (currentWalletPayment.status !== "executing") {
|
|
798
|
+
setProcessing(false);
|
|
799
|
+
}
|
|
318
800
|
return;
|
|
319
801
|
}
|
|
320
802
|
let cancelled = false;
|
|
321
803
|
const loadOptions = async () => {
|
|
322
804
|
try {
|
|
323
|
-
|
|
324
|
-
setSelectedCurrency(cryptoCurrency);
|
|
325
|
-
resetWalletPaymentState();
|
|
326
|
-
setWalletPaymentState({ status: "loading", error: null, options: [] });
|
|
327
|
-
const preparedContext = await buildContext();
|
|
328
|
-
const providerOptions = await findWalletPaymentOptions(preparedContext);
|
|
329
|
-
const options = providerOptions.length > 0
|
|
330
|
-
? providerOptions
|
|
331
|
-
: [buildDefaultOption(preparedContext)];
|
|
332
|
-
if (cancelled)
|
|
333
|
-
return;
|
|
334
|
-
configureWalletAttemptRefresh(preparedContext.walletAddress);
|
|
335
|
-
setWalletPaymentState({
|
|
336
|
-
status: "ready",
|
|
337
|
-
walletAddress: preparedContext.walletAddress,
|
|
338
|
-
options,
|
|
339
|
-
selectedOptionId: null,
|
|
340
|
-
error: null,
|
|
341
|
-
});
|
|
805
|
+
await loadWalletPaymentOptions(() => cancelled);
|
|
342
806
|
}
|
|
343
807
|
catch (error) {
|
|
344
808
|
if (cancelled)
|
|
345
809
|
return;
|
|
346
|
-
|
|
347
|
-
? error.message
|
|
348
|
-
: "Failed to load payment options";
|
|
349
|
-
setWalletPaymentState({
|
|
350
|
-
status: "failed",
|
|
351
|
-
error: message,
|
|
352
|
-
options: [],
|
|
353
|
-
});
|
|
810
|
+
handleWalletPaymentOptionsError(error);
|
|
354
811
|
}
|
|
355
812
|
finally {
|
|
356
813
|
if (!cancelled) {
|
|
@@ -361,10 +818,34 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
|
|
|
361
818
|
void loadOptions();
|
|
362
819
|
return () => {
|
|
363
820
|
cancelled = true;
|
|
364
|
-
|
|
821
|
+
clearQuoteRefresh();
|
|
365
822
|
};
|
|
366
|
-
}, [
|
|
823
|
+
}, [
|
|
824
|
+
account.address,
|
|
825
|
+
account.isConnected,
|
|
826
|
+
activeWallet,
|
|
827
|
+
cryptoCurrency,
|
|
828
|
+
handleMissingAccount,
|
|
829
|
+
handleMissingWalletConnection,
|
|
830
|
+
handleWalletPaymentOptionsError,
|
|
831
|
+
isWalletConnectionSettling,
|
|
832
|
+
loadWalletPaymentOptions,
|
|
833
|
+
shouldPreserveSubmittedFailure,
|
|
834
|
+
walletPayment.selectedOptionId,
|
|
835
|
+
]);
|
|
367
836
|
const selectedOption = walletPayment.options.find((option) => option.id === walletPayment.selectedOptionId) ?? null;
|
|
837
|
+
const hasNoPaymentOptions = walletPayment.status === "ready" && walletPayment.options.length === 0;
|
|
838
|
+
const unsupportedWalletAddress = walletPayment.walletAddress ?? account.address ?? null;
|
|
839
|
+
const quoteLoadKey = buildWalletQuoteLoadKey({
|
|
840
|
+
paymentId: payment?.id,
|
|
841
|
+
paymentAmount: payment?.amount,
|
|
842
|
+
paymentCurrency: payment?.currency,
|
|
843
|
+
paymentExpiresAt: payment?.expires_at,
|
|
844
|
+
settlementChain: cryptoCurrency?.chain,
|
|
845
|
+
settlementAsset: cryptoCurrency?.asset,
|
|
846
|
+
walletAddress: walletPayment.walletAddress ?? account.address,
|
|
847
|
+
option: selectedOption,
|
|
848
|
+
});
|
|
368
849
|
const confirmationAmount = selectedOption && payment
|
|
369
850
|
? resolveWalletPaymentConfirmationAmount({
|
|
370
851
|
option: selectedOption,
|
|
@@ -372,8 +853,22 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
|
|
|
372
853
|
attempt: cryptoPaymentAttempt,
|
|
373
854
|
})
|
|
374
855
|
: null;
|
|
856
|
+
const displayedPayAmount = confirmationAmount?.amount ??
|
|
857
|
+
(selectedOption && walletPayment.quoteStatus === "loading"
|
|
858
|
+
? "Fetching quote..."
|
|
859
|
+
: selectedOption && walletPayment.quoteStatus === "failed"
|
|
860
|
+
? "Unavailable"
|
|
861
|
+
: null);
|
|
375
862
|
const formattedCost = formatMoneyAmount(payment?.currency ?? "USD", Number(payment?.amount ?? 0));
|
|
376
863
|
const handlePickOption = (option) => {
|
|
864
|
+
lastQuoteLoadKeyRef.current = null;
|
|
865
|
+
prepareWalletQuoteReplacement(walletPayment.walletAddress);
|
|
866
|
+
setPaymentDetailsExpanded(false);
|
|
867
|
+
writeCheckoutResumeState(payment?.id, {
|
|
868
|
+
view: "cryptoIntentWalletPaymentOptions",
|
|
869
|
+
walletAddress: walletPayment.walletAddress ?? account.address ?? null,
|
|
870
|
+
selectedWalletOptionId: option.id,
|
|
871
|
+
});
|
|
377
872
|
setWalletPaymentState({
|
|
378
873
|
selectedOptionId: option.id,
|
|
379
874
|
error: null,
|
|
@@ -385,6 +880,14 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
|
|
|
385
880
|
});
|
|
386
881
|
};
|
|
387
882
|
const handleReturnToOptions = () => {
|
|
883
|
+
lastQuoteLoadKeyRef.current = null;
|
|
884
|
+
prepareWalletQuoteReplacement(walletPayment.walletAddress);
|
|
885
|
+
setPaymentDetailsExpanded(false);
|
|
886
|
+
writeCheckoutResumeState(payment?.id, {
|
|
887
|
+
view: "cryptoIntentWalletPaymentOptions",
|
|
888
|
+
walletAddress: walletPayment.walletAddress ?? account.address ?? null,
|
|
889
|
+
selectedWalletOptionId: null,
|
|
890
|
+
});
|
|
388
891
|
setWalletPaymentState({
|
|
389
892
|
selectedOptionId: null,
|
|
390
893
|
error: null,
|
|
@@ -393,65 +896,135 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
|
|
|
393
896
|
quoteError: null,
|
|
394
897
|
});
|
|
395
898
|
};
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
899
|
+
const handleChangeWallet = useCallback(() => {
|
|
900
|
+
isChangingWalletRef.current = true;
|
|
901
|
+
writePendingWalletConnectionResumeState(payment?.id, "cryptoIntentWalletPaymentOptions");
|
|
902
|
+
void open({ view: "Connect", namespace: "eip155" });
|
|
903
|
+
}, [open, payment?.id]);
|
|
904
|
+
const handleDisconnectWallet = useCallback(() => {
|
|
905
|
+
isChangingWalletRef.current = false;
|
|
906
|
+
clearCheckoutResumeState(payment?.id);
|
|
907
|
+
resetWalletPaymentState();
|
|
908
|
+
clearQuoteRefresh();
|
|
909
|
+
setWallet(null);
|
|
910
|
+
setProcessing(false);
|
|
911
|
+
goToView("cryptoIntent");
|
|
912
|
+
void disconnect(wagmiConfig).catch((error) => {
|
|
913
|
+
console.warn("Unable to disconnect wallet", error);
|
|
914
|
+
});
|
|
915
|
+
}, [goToView, payment?.id, setWallet, wagmiConfig]);
|
|
916
|
+
const confirmDirectWalletPayment = async (txHash) => {
|
|
917
|
+
if (!payment) {
|
|
918
|
+
throw new Error("Missing payment");
|
|
399
919
|
}
|
|
400
920
|
try {
|
|
921
|
+
await confirmPayment(payment.id, { txHash });
|
|
922
|
+
}
|
|
923
|
+
catch (error) {
|
|
924
|
+
const message = messageForWalletError(error, "Failed to confirm wallet payment");
|
|
401
925
|
setWalletPaymentState({
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
quoteError: null,
|
|
405
|
-
quoteId: null,
|
|
406
|
-
routeId: null,
|
|
926
|
+
status: "failed",
|
|
927
|
+
error: message,
|
|
407
928
|
});
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
929
|
+
goToView("cryptoIntentWalletPaymentOptions");
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
useEffect(() => {
|
|
933
|
+
if (!selectedOption || !quoteLoadKey || !cryptoCurrency) {
|
|
934
|
+
if (!selectedOption) {
|
|
935
|
+
lastQuoteLoadKeyRef.current = null;
|
|
412
936
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
if (lastQuoteLoadKeyRef.current === quoteLoadKey) {
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
lastQuoteLoadKeyRef.current = quoteLoadKey;
|
|
943
|
+
let cancelled = false;
|
|
944
|
+
const loadQuote = async () => {
|
|
945
|
+
const currentPayment = useCheckoutStore.getState().payment;
|
|
946
|
+
if (!currentPayment?.id) {
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
try {
|
|
950
|
+
prepareWalletQuoteReplacement(walletPayment.walletAddress ?? account.address ?? null);
|
|
951
|
+
setWalletPaymentState({
|
|
952
|
+
quoteStatus: "loading",
|
|
953
|
+
quote: null,
|
|
954
|
+
quoteError: null,
|
|
955
|
+
quoteId: null,
|
|
956
|
+
routeId: null,
|
|
957
|
+
});
|
|
958
|
+
const preparedContext = await buildContext(currentPayment);
|
|
959
|
+
const walletAddress = await activeWallet?.getAddress();
|
|
960
|
+
if (!walletAddress) {
|
|
961
|
+
throw new Error("Failed to get wallet address");
|
|
962
|
+
}
|
|
963
|
+
const ensuredAttempt = await createWalletOptionPaymentAttempt(selectedOption, walletAddress, null);
|
|
964
|
+
if (cancelled) {
|
|
965
|
+
return;
|
|
966
|
+
}
|
|
967
|
+
const quoteContext = {
|
|
968
|
+
...preparedContext,
|
|
969
|
+
cryptoPaymentAttempt: ensuredAttempt,
|
|
970
|
+
};
|
|
971
|
+
if (selectedOption.kind === "direct") {
|
|
972
|
+
const directQuote = buildDirectQuote(selectedOption, quoteContext);
|
|
973
|
+
setWalletPaymentState({
|
|
974
|
+
quoteStatus: "ready",
|
|
975
|
+
quote: directQuote,
|
|
976
|
+
quoteId: directQuote.quoteId,
|
|
977
|
+
routeId: directQuote.routeId,
|
|
978
|
+
quoteError: null,
|
|
979
|
+
});
|
|
980
|
+
configureWalletQuoteRefresh(walletAddress);
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
const quote = await fetchWalletPaymentQuote({
|
|
984
|
+
option: selectedOption,
|
|
985
|
+
context: quoteContext,
|
|
986
|
+
});
|
|
987
|
+
if (cancelled) {
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
420
990
|
setWalletPaymentState({
|
|
421
991
|
quoteStatus: "ready",
|
|
422
|
-
quote
|
|
423
|
-
quoteId:
|
|
424
|
-
routeId:
|
|
992
|
+
quote,
|
|
993
|
+
quoteId: quote.quoteId,
|
|
994
|
+
routeId: quote.routeId,
|
|
425
995
|
quoteError: null,
|
|
426
996
|
});
|
|
427
|
-
|
|
997
|
+
configureWalletQuoteRefresh(walletAddress);
|
|
428
998
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
999
|
+
catch (error) {
|
|
1000
|
+
if (cancelled) {
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
const message = error instanceof Error ? error.message : "Failed to load route quote";
|
|
1004
|
+
setWalletPaymentState({
|
|
1005
|
+
quoteStatus: "failed",
|
|
1006
|
+
quote: null,
|
|
1007
|
+
quoteError: message,
|
|
1008
|
+
});
|
|
1009
|
+
clearQuoteRefresh({ preserveWalletAddress: true });
|
|
1010
|
+
}
|
|
1011
|
+
};
|
|
1012
|
+
void loadQuote();
|
|
1013
|
+
return () => {
|
|
1014
|
+
cancelled = true;
|
|
1015
|
+
};
|
|
1016
|
+
}, [
|
|
1017
|
+
account.address,
|
|
1018
|
+
activeWallet,
|
|
1019
|
+
buildContext,
|
|
1020
|
+
cryptoCurrency,
|
|
1021
|
+
goToView,
|
|
1022
|
+
quoteLoadKey,
|
|
1023
|
+
selectedOption,
|
|
1024
|
+
walletPayment.walletAddress,
|
|
1025
|
+
]);
|
|
453
1026
|
const handleSelectOption = async (option) => {
|
|
454
|
-
if (!
|
|
1027
|
+
if (!activeWallet || !payment || !cryptoCurrency) {
|
|
455
1028
|
goToView("failed", { reason: "wallet_not_connected" });
|
|
456
1029
|
return;
|
|
457
1030
|
}
|
|
@@ -466,22 +1039,25 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
|
|
|
466
1039
|
quoteId: null,
|
|
467
1040
|
routeId: null,
|
|
468
1041
|
});
|
|
469
|
-
const walletAddress = await
|
|
1042
|
+
const walletAddress = await activeWallet.getAddress();
|
|
470
1043
|
if (!walletAddress) {
|
|
471
1044
|
throw new Error("Failed to get wallet address");
|
|
472
1045
|
}
|
|
1046
|
+
writeCheckoutResumeState(payment.id, {
|
|
1047
|
+
view: "cryptoIntentWalletPaymentOptions",
|
|
1048
|
+
walletAddress,
|
|
1049
|
+
selectedWalletOptionId: option.id,
|
|
1050
|
+
});
|
|
473
1051
|
const ensuredAttempt = await createWalletOptionPaymentAttempt(option, walletAddress, option.kind === "direct" ? null : walletPayment.quote);
|
|
474
1052
|
const preparedContext = {
|
|
475
1053
|
...(await buildContext(payment)),
|
|
476
1054
|
cryptoPaymentAttempt: ensuredAttempt,
|
|
477
1055
|
};
|
|
478
1056
|
if (option.kind === "direct") {
|
|
479
|
-
await
|
|
480
|
-
const txHash = useCheckoutStore.getState().transfer.transactionHash;
|
|
1057
|
+
const txHash = await executeTransfer(activeWallet);
|
|
481
1058
|
if (!txHash) {
|
|
482
|
-
throw new Error("
|
|
1059
|
+
throw new Error("Failed to get transaction hash");
|
|
483
1060
|
}
|
|
484
|
-
await confirmPayment(payment.id, { txHash });
|
|
485
1061
|
setWalletPaymentState({
|
|
486
1062
|
status: "submitted",
|
|
487
1063
|
sourceTxHash: txHash,
|
|
@@ -489,6 +1065,22 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
|
|
|
489
1065
|
quoteId: null,
|
|
490
1066
|
routeId: null,
|
|
491
1067
|
});
|
|
1068
|
+
goToView("paymentStatus");
|
|
1069
|
+
void (async () => {
|
|
1070
|
+
try {
|
|
1071
|
+
await checkChainStatus(activeWallet);
|
|
1072
|
+
await confirmDirectWalletPayment(txHash);
|
|
1073
|
+
}
|
|
1074
|
+
catch (error) {
|
|
1075
|
+
const message = messageForWalletError(error, "Failed to confirm wallet payment");
|
|
1076
|
+
setWalletPaymentState({
|
|
1077
|
+
status: "failed",
|
|
1078
|
+
error: message,
|
|
1079
|
+
});
|
|
1080
|
+
goToView("cryptoIntentWalletPaymentOptions");
|
|
1081
|
+
}
|
|
1082
|
+
})();
|
|
1083
|
+
return;
|
|
492
1084
|
}
|
|
493
1085
|
else {
|
|
494
1086
|
const freshQuote = await fetchWalletPaymentQuote({
|
|
@@ -507,7 +1099,7 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
|
|
|
507
1099
|
});
|
|
508
1100
|
const result = await executeWalletPaymentOption({
|
|
509
1101
|
option,
|
|
510
|
-
wallet,
|
|
1102
|
+
wallet: activeWallet,
|
|
511
1103
|
context: preparedContext,
|
|
512
1104
|
quote: freshQuote,
|
|
513
1105
|
});
|
|
@@ -534,48 +1126,82 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
|
|
|
534
1126
|
goToView("paymentStatus");
|
|
535
1127
|
}
|
|
536
1128
|
catch (error) {
|
|
537
|
-
const message = error
|
|
538
|
-
? error.message
|
|
539
|
-
: "Failed to execute wallet payment";
|
|
1129
|
+
const message = messageForWalletError(error, "Failed to execute wallet payment");
|
|
540
1130
|
setWalletPaymentState({
|
|
541
1131
|
status: "failed",
|
|
542
1132
|
error: message,
|
|
543
1133
|
});
|
|
544
|
-
goToView("failed", { reason: message });
|
|
545
1134
|
}
|
|
546
1135
|
finally {
|
|
547
1136
|
setExecutingId(null);
|
|
548
1137
|
setProcessing(false);
|
|
549
1138
|
}
|
|
550
1139
|
};
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
1140
|
+
const handleRetryWalletPayment = () => {
|
|
1141
|
+
if (selectedOption) {
|
|
1142
|
+
if (walletPayment.sourceTxHash &&
|
|
1143
|
+
useCheckoutStore.getState().transfer.chainStatus === "confirmed") {
|
|
1144
|
+
setWalletPaymentState({ status: "submitted", error: null });
|
|
1145
|
+
goToView("paymentStatus");
|
|
1146
|
+
void confirmDirectWalletPayment(walletPayment.sourceTxHash);
|
|
1147
|
+
return;
|
|
1148
|
+
}
|
|
1149
|
+
setWalletPaymentState({ status: "ready", error: null });
|
|
1150
|
+
void handleSelectOption(selectedOption);
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
const retry = async () => {
|
|
1154
|
+
try {
|
|
1155
|
+
await loadWalletPaymentOptions(() => false, { force: true });
|
|
1156
|
+
}
|
|
1157
|
+
catch (error) {
|
|
1158
|
+
handleWalletPaymentOptionsError(error);
|
|
1159
|
+
}
|
|
1160
|
+
finally {
|
|
1161
|
+
setProcessing(false);
|
|
1162
|
+
}
|
|
1163
|
+
};
|
|
1164
|
+
void retry();
|
|
1165
|
+
};
|
|
1166
|
+
const showWalletPill = account.isConnected &&
|
|
1167
|
+
Boolean(account.address) &&
|
|
1168
|
+
walletPayment.status !== "loading" &&
|
|
1169
|
+
walletPayment.status !== "failed";
|
|
1170
|
+
const walletAddressForPill = walletPayment.walletAddress ?? account.address ?? null;
|
|
1171
|
+
const walletAddressForHeader = walletPayment.walletAddress ?? account.address ?? null;
|
|
1172
|
+
return (_jsxs(ModalViewContainer, { ref: modalRef, children: [showWalletPill && walletAddressForPill && selectedOption ? (_jsxs(ContextStrip, { children: [_jsx(QuoteExpiryCountdown, { remainingMs: quote.remainingMs, totalDurationMs: quote.totalDurationMs, primaryColor: config.theme.btn.primary.default.backgroundColor, urgentThresholdRatio: QUOTE_COUNTDOWN_URGENT_THRESHOLD_RATIO }), _jsxs(ContextPill, { children: [_jsxs(ContextPillToggle, { type: "button", onClick: () => setPaymentDetailsExpanded((expanded) => !expanded), "aria-expanded": paymentDetailsExpanded, children: [_jsxs(PillIconWrap, { children: [_jsx(PillTokenIcon, { "$iconUrl": selectedOption.fromTokenIconUrl, children: !selectedOption.fromTokenIconUrl
|
|
559
1173
|
? getTokenMonogram(selectedOption.fromTokenName, selectedOption.fromTokenSymbol)
|
|
560
|
-
: null }), _jsx(
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
(
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
1174
|
+
: null }), selectedOption.fromChainIconUrl ? (_jsx(PillChainBadge, { "$iconUrl": selectedOption.fromChainIconUrl })) : null] }), _jsxs(PillBody, { children: [_jsx(PillEyebrow, { children: "You send" }), _jsxs(PillTitle, { children: [selectedOption.fromTokenSymbol, " on", " ", selectedOption.fromChainName] })] }), _jsx(PillAction, { type: "button", onClick: (event) => {
|
|
1175
|
+
event.stopPropagation();
|
|
1176
|
+
handleReturnToOptions();
|
|
1177
|
+
}, disabled: processing, children: "Change" }), _jsx(PillCaret, { "$expanded": paymentDetailsExpanded, children: "\u25BE" })] }), paymentDetailsExpanded ? (_jsxs(PillDetails, { children: [_jsxs(PillDetailRow, { children: [_jsx(PillDetailLabel, { children: "Connected wallet" }), _jsxs(PillDetailValue, { children: [_jsx(WalletDot, { "$iconUrl": connectorIcon, "aria-hidden": "true" }), formatAddress(walletAddressForPill), _jsx(WalletSwitchLink, { type: "button", onClick: handleChangeWallet, disabled: processing, "aria-label": "Switch wallet", title: "Switch wallet", children: _jsx(EditIcon, { size: 12 }) }), _jsx(WalletDisconnectButton, { type: "button", onClick: handleDisconnectWallet, disabled: processing, "aria-label": "Disconnect wallet", title: "Disconnect wallet", children: _jsx(LogOutIcon, { size: 12 }) })] })] }), _jsxs(PillDetailRow, { children: [_jsx(PillDetailLabel, { children: "Route" }), _jsx(PillDetailValue, { children: selectedOption.kind === "direct"
|
|
1178
|
+
? "Direct transfer"
|
|
1179
|
+
: "Routed transfer" })] })] })) : null] })] })) : null, walletPayment.status === "failed" ? (_jsxs(ContentStage, { "$mobileCentered": true, children: [account.isConnected && account.address ? (_jsx(FallbackTopActions, { children: _jsx(FallbackDisconnectButton, { type: "button", onClick: handleDisconnectWallet, disabled: processing, "aria-label": "Disconnect wallet", title: "Disconnect wallet", children: _jsx(LogOutIcon, { size: 16 }) }) })) : null, _jsx(EmptyState, { children: _jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: walletPayment.error ||
|
|
1180
|
+
"We could not find wallet payment options right now." }) }), _jsx(StyledButton, { onClick: handleRetryWalletPayment, disabled: processing || loading.CREATE_PAYMENT_ATTEMPT, children: "Try again" }), _jsx(ModalBackButton, { view: "cryptoIntent", disabled: processing, label: "Choose another payment method" })] })) : null, walletPayment.status === "loading" ? (_jsxs(ContentStage, { children: [walletAddressForHeader ? (_jsxs(ConnectedWalletRow, { children: [_jsxs(ConnectedWalletIdentity, { children: [_jsx(WalletDot, { "$iconUrl": connectorIcon, "aria-hidden": "true" }), _jsx(ConnectedWalletAddress, { children: formatAddress(walletAddressForHeader) })] }), _jsxs(WalletRowActions, { children: [_jsx(WalletSwitchLink, { type: "button", onClick: handleChangeWallet, disabled: processing, "aria-label": "Switch wallet", title: "Switch wallet", children: _jsx(EditIcon, { size: 12 }) }), _jsx(WalletDisconnectButton, { type: "button", onClick: handleDisconnectWallet, disabled: processing, "aria-label": "Disconnect wallet", title: "Disconnect wallet", children: _jsx(LogOutIcon, { size: 12 }) })] })] })) : null, _jsx(SectionLabel, { children: "Checking your wallet" }), _jsxs(SkeletonContainer, { children: [_jsx(SkeletonRow, {}), _jsx(SkeletonRow, { style: { opacity: 0.7 } }), _jsx(SkeletonRow, { style: { opacity: 0.4 } })] })] })) : null, walletPayment.status === "ready" ||
|
|
1181
|
+
walletPayment.status === "executing" ? (_jsx(ContentStage, { children: hasNoPaymentOptions ? (_jsxs(_Fragment, { children: [walletAddressForPill ? (_jsxs(ConnectedWalletRow, { children: [_jsxs(ConnectedWalletIdentity, { children: [_jsx(WalletDot, { "$iconUrl": connectorIcon, "aria-hidden": "true" }), _jsx(ConnectedWalletAddress, { children: formatAddress(walletAddressForPill) })] }), _jsxs(WalletRowActions, { children: [_jsx(WalletSwitchLink, { type: "button", onClick: handleChangeWallet, disabled: processing, "aria-label": "Switch wallet", title: "Switch wallet", children: _jsx(EditIcon, { size: 12 }) }), _jsx(WalletDisconnectButton, { type: "button", onClick: handleDisconnectWallet, disabled: processing, "aria-label": "Disconnect wallet", title: "Disconnect wallet", children: _jsx(LogOutIcon, { size: 12 }) })] })] })) : null, !walletAddressForPill &&
|
|
1182
|
+
account.isConnected &&
|
|
1183
|
+
account.address ? (_jsx(FallbackTopActions, { children: _jsx(FallbackDisconnectButton, { type: "button", onClick: handleDisconnectWallet, disabled: processing, "aria-label": "Disconnect wallet", title: "Disconnect wallet", children: _jsx(LogOutIcon, { size: 16 }) }) })) : null, _jsxs(EmptyState, { children: [_jsxs(EmptyHeadline, { children: [_jsx(Text, { size: "base", weight: "semibold", color: config.theme.font.color.primary, children: NO_WALLET_PAYMENT_OPTIONS_TITLE }), _jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: NO_WALLET_PAYMENT_OPTIONS_DESCRIPTION })] }), unsupportedWalletAddress && !walletAddressForPill ? (_jsxs(Text, { size: "xs", color: config.theme.font.color.tertiary, children: [connectorName, " ", formatAddress(unsupportedWalletAddress)] })) : null] }), _jsx(ModalBackButton, { view: "cryptoIntent", disabled: processing, label: "Choose another payment method" })] })) : !selectedOption ? (_jsxs(_Fragment, { children: [walletAddressForPill ? (_jsxs(ConnectedWalletRow, { children: [_jsxs(ConnectedWalletIdentity, { children: [_jsx(WalletDot, { "$iconUrl": connectorIcon, "aria-hidden": "true" }), _jsx(ConnectedWalletAddress, { children: formatAddress(walletAddressForPill) })] }), _jsxs(WalletRowActions, { children: [_jsx(WalletSwitchLink, { type: "button", onClick: handleChangeWallet, disabled: processing, "aria-label": "Switch wallet", title: "Switch wallet", children: _jsx(EditIcon, { size: 12 }) }), _jsx(WalletDisconnectButton, { type: "button", onClick: handleDisconnectWallet, disabled: processing, "aria-label": "Disconnect wallet", title: "Disconnect wallet", children: _jsx(LogOutIcon, { size: 12 }) })] })] })) : null, _jsxs(SectionRow, { children: [_jsx(SectionLabel, { children: "Pay with" }), _jsx(SectionLabel, { children: "Balance" })] }), _jsx(OptionsContainer, { children: walletPayment.options.map((option) => (_jsxs(OptionCard, { type: "button", onClick: () => handlePickOption(option), "aria-pressed": walletPayment.selectedOptionId === option.id, children: [_jsxs(OptionTokenIconWrap, { children: [_jsx(OptionTokenIcon, { "$token": option.fromTokenName === "ETH" ? "ETH" : "USD", "$iconUrl": option.fromTokenIconUrl, children: !option.fromTokenIconUrl
|
|
1184
|
+
? getTokenMonogram(option.fromTokenName, option.fromTokenSymbol)
|
|
1185
|
+
: null }), option.fromChainIconUrl ? (_jsx(OptionChainBadge, { "$iconUrl": option.fromChainIconUrl })) : null] }), _jsxs(OptionIdentity, { children: [_jsx(Text, { size: "base", weight: "semibold", color: config.theme.font.color.primary, children: option.fromTokenName }), _jsxs(Text, { size: "sm", color: config.theme.font.color.secondary, children: ["On ", option.fromChainName] })] }), _jsxs(OptionBalance, { children: [_jsx(Text, { size: "base", weight: "semibold", color: config.theme.font.color.primary, children: formatTokenBalance(option.fromTokenName, option.fromAmount) ?? "0" }), option.kind === "direct" ? (_jsxs(FastBadge, { children: [_jsx("span", { children: "\u26A1" }), _jsx("span", { children: "Fast" })] })) : typeof option.estimatedDurationMinutes ===
|
|
1186
|
+
"number" ? (_jsxs(RoutedBadge, { children: ["~", option.estimatedDurationMinutes, " min"] })) : null] })] }, option.id))) }), _jsx(ModalBackButton, { view: "cryptoIntent", disabled: processing })] })) : (_jsxs(_Fragment, { children: [_jsxs(QuoteCard, { children: [_jsxs(QuoteRow, { children: [_jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: "Cost" }), _jsx(Text, { size: "base", weight: "semibold", color: config.theme.font.color.primary, children: formattedCost })] }), displayedPayAmount ? (_jsxs(QuoteRow, { children: [_jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: "You pay" }), _jsx(Text, { size: "base", weight: "semibold", color: config.theme.font.color.primary, children: displayedPayAmount })] })) : null, typeof walletPayment.quote?.estimatedDurationMinutes ===
|
|
1187
|
+
"number" ? (_jsxs(QuoteRow, { children: [_jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: "Estimated time" }), _jsxs(Text, { size: "sm", weight: "semibold", color: config.theme.font.color.primary, children: ["~", walletPayment.quote.estimatedDurationMinutes, " min"] })] })) : null, walletPayment.quoteStatus === "loading" ? (_jsxs(_Fragment, { children: [_jsx(QuoteHairline, {}), _jsx(QuoteFootnote, { children: "Fetching the freshest quote\u2026" })] })) : null, walletPayment.quoteStatus === "failed" ? (_jsxs(_Fragment, { children: [_jsx(QuoteHairline, {}), _jsx(QuoteFootnoteWarn, { children: walletPayment.quoteError ||
|
|
1188
|
+
"We couldn't fetch a quote right now." })] })) : null] }), _jsx(StyledButton, { onClick: () => {
|
|
1189
|
+
if (selectedOption) {
|
|
1190
|
+
void handleSelectOption(selectedOption);
|
|
1191
|
+
}
|
|
1192
|
+
}, disabled: processing ||
|
|
1193
|
+
loading.CREATE_PAYMENT_ATTEMPT ||
|
|
1194
|
+
!selectedOption ||
|
|
1195
|
+
walletPayment.quoteStatus === "loading" ||
|
|
1196
|
+
(selectedOption.kind !== "direct" &&
|
|
1197
|
+
walletPayment.quoteStatus !== "ready"), children: executingId === selectedOption.id
|
|
1198
|
+
? "Preparing..."
|
|
1199
|
+
: walletPayment.quoteStatus === "loading"
|
|
1200
|
+
? "Fetching quote..."
|
|
1201
|
+
: `Pay with ${selectedOption.fromTokenName}` }), _jsx(StyledButton, { variant: "secondary", onClick: handleReturnToOptions, disabled: processing, children: "Back" })] })) })) : null] }));
|
|
1202
|
+
};
|
|
1203
|
+
const CryptoIntentWalletPaymentOptionsViewContent = () => {
|
|
1204
|
+
return _jsx(CryptoIntentWalletPaymentOptionsAppKitViewContent, {});
|
|
579
1205
|
};
|
|
580
1206
|
export { CryptoIntentWalletPaymentOptionsViewContent };
|
|
581
1207
|
//# sourceMappingURL=wallet-payment-options.js.map
|