@mintmoney/react 0.1.0-alpha.31 → 0.1.0-alpha.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/dist/css/styles.css +8 -6
  2. package/dist/esm/api/generated.js +31 -0
  3. package/dist/esm/api/generated.js.map +1 -1
  4. package/dist/esm/api/index.js +1 -0
  5. package/dist/esm/api/index.js.map +1 -1
  6. package/dist/esm/api/payments.js +39 -0
  7. package/dist/esm/api/payments.js.map +1 -1
  8. package/dist/esm/checkout/index.js +41 -19
  9. package/dist/esm/checkout/index.js.map +1 -1
  10. package/dist/esm/checkout/modal.js +4 -3
  11. package/dist/esm/checkout/modal.js.map +1 -1
  12. package/dist/esm/checkout/providers/wagmi-config.js +82 -0
  13. package/dist/esm/checkout/providers/wagmi-config.js.map +1 -0
  14. package/dist/esm/checkout/surplus-refund.js +38 -0
  15. package/dist/esm/checkout/surplus-refund.js.map +1 -0
  16. package/dist/esm/checkout/views/back.js +2 -2
  17. package/dist/esm/checkout/views/back.js.map +1 -1
  18. package/dist/esm/checkout/views/crypto-intent/direct-details.js +945 -96
  19. package/dist/esm/checkout/views/crypto-intent/direct-details.js.map +1 -1
  20. package/dist/esm/checkout/views/crypto-intent/methods.js +84 -31
  21. package/dist/esm/checkout/views/crypto-intent/methods.js.map +1 -1
  22. package/dist/esm/checkout/views/crypto-intent/processing.js +51 -3
  23. package/dist/esm/checkout/views/crypto-intent/processing.js.map +1 -1
  24. package/dist/esm/checkout/views/crypto-intent/success.js +58 -9
  25. package/dist/esm/checkout/views/crypto-intent/success.js.map +1 -1
  26. package/dist/esm/checkout/views/crypto-intent/wallet-payment-options.js +641 -282
  27. package/dist/esm/checkout/views/crypto-intent/wallet-payment-options.js.map +1 -1
  28. package/dist/esm/checkout/views/crypto-intent/wallet-select.js +104 -20
  29. package/dist/esm/checkout/views/crypto-intent/wallet-select.js.map +1 -1
  30. package/dist/esm/checkout/views/failed.js +83 -1
  31. package/dist/esm/checkout/views/failed.js.map +1 -1
  32. package/dist/esm/checkout/views/initial.js +46 -6
  33. package/dist/esm/checkout/views/initial.js.map +1 -1
  34. package/dist/esm/checkout/views/method-select.js +16 -4
  35. package/dist/esm/checkout/views/method-select.js.map +1 -1
  36. package/dist/esm/checkout/views/restart.js +3 -1
  37. package/dist/esm/checkout/views/restart.js.map +1 -1
  38. package/dist/esm/components/buttons/index.js +4 -1
  39. package/dist/esm/components/buttons/index.js.map +1 -1
  40. package/dist/esm/components/icons/clock.js +4 -0
  41. package/dist/esm/components/icons/clock.js.map +1 -0
  42. package/dist/esm/components/icons/edit.js +6 -0
  43. package/dist/esm/components/icons/edit.js.map +1 -0
  44. package/dist/esm/components/icons/index.js +3 -0
  45. package/dist/esm/components/icons/index.js.map +1 -1
  46. package/dist/esm/components/icons/send.js +6 -0
  47. package/dist/esm/components/icons/send.js.map +1 -0
  48. package/dist/esm/components/index.js +1 -0
  49. package/dist/esm/components/index.js.map +1 -1
  50. package/dist/esm/components/quote-expiry/index.js +2 -0
  51. package/dist/esm/components/quote-expiry/index.js.map +1 -0
  52. package/dist/esm/components/quote-expiry/quote-expiry-countdown.js +35 -0
  53. package/dist/esm/components/quote-expiry/quote-expiry-countdown.js.map +1 -0
  54. package/dist/esm/components/quote-expiry/styles.js +109 -0
  55. package/dist/esm/components/quote-expiry/styles.js.map +1 -0
  56. package/dist/esm/components/quote-expiry/tiers.js +31 -0
  57. package/dist/esm/components/quote-expiry/tiers.js.map +1 -0
  58. package/dist/esm/components/text/index.js +1 -0
  59. package/dist/esm/components/text/index.js.map +1 -1
  60. package/dist/esm/components/wallet-selector/component.js +3 -5
  61. package/dist/esm/components/wallet-selector/component.js.map +1 -1
  62. package/dist/esm/components/wallet-selector/wallets/wagmi/index.js.map +1 -1
  63. package/dist/esm/config.js.map +1 -1
  64. package/dist/esm/index.js +2 -1
  65. package/dist/esm/index.js.map +1 -1
  66. package/dist/esm/integrations/lifi.js +52 -34
  67. package/dist/esm/integrations/lifi.js.map +1 -1
  68. package/dist/esm/refund/index.js +791 -0
  69. package/dist/esm/refund/index.js.map +1 -0
  70. package/dist/esm/state/checkout/payment-attempt.js +3 -0
  71. package/dist/esm/state/checkout/payment-attempt.js.map +1 -1
  72. package/dist/esm/state/checkout/payment-lifecycle.js +66 -0
  73. package/dist/esm/state/checkout/payment-lifecycle.js.map +1 -0
  74. package/dist/esm/state/checkout/store.js +508 -55
  75. package/dist/esm/state/checkout/store.js.map +1 -1
  76. package/dist/esm/state/checkout/wallet-payment-options.js +30 -0
  77. package/dist/esm/state/checkout/wallet-payment-options.js.map +1 -0
  78. package/dist/esm/themes/default.js +6 -0
  79. package/dist/esm/themes/default.js.map +1 -1
  80. package/dist/esm/utils/string.js +1 -0
  81. package/dist/esm/utils/string.js.map +1 -1
  82. package/dist/esm/utils/wallet-errors.js +15 -0
  83. package/dist/esm/utils/wallet-errors.js.map +1 -0
  84. package/dist/types/api/generated.d.ts +207 -4
  85. package/dist/types/api/generated.d.ts.map +1 -1
  86. package/dist/types/api/index.d.ts +2 -1
  87. package/dist/types/api/index.d.ts.map +1 -1
  88. package/dist/types/api/payments.d.ts +36 -1
  89. package/dist/types/api/payments.d.ts.map +1 -1
  90. package/dist/types/api/types.d.ts +4 -0
  91. package/dist/types/api/types.d.ts.map +1 -1
  92. package/dist/types/checkout/index.d.ts +4 -1
  93. package/dist/types/checkout/index.d.ts.map +1 -1
  94. package/dist/types/checkout/modal.d.ts.map +1 -1
  95. package/dist/types/checkout/providers/wagmi-config.d.ts +12 -0
  96. package/dist/types/checkout/providers/wagmi-config.d.ts.map +1 -0
  97. package/dist/types/checkout/surplus-refund.d.ts +10 -0
  98. package/dist/types/checkout/surplus-refund.d.ts.map +1 -0
  99. package/dist/types/checkout/views/back.d.ts +2 -1
  100. package/dist/types/checkout/views/back.d.ts.map +1 -1
  101. package/dist/types/checkout/views/crypto-intent/direct-details.d.ts +10 -1
  102. package/dist/types/checkout/views/crypto-intent/direct-details.d.ts.map +1 -1
  103. package/dist/types/checkout/views/crypto-intent/methods.d.ts.map +1 -1
  104. package/dist/types/checkout/views/crypto-intent/processing.d.ts.map +1 -1
  105. package/dist/types/checkout/views/crypto-intent/success.d.ts.map +1 -1
  106. package/dist/types/checkout/views/crypto-intent/wallet-payment-options.d.ts.map +1 -1
  107. package/dist/types/checkout/views/crypto-intent/wallet-select.d.ts.map +1 -1
  108. package/dist/types/checkout/views/failed.d.ts.map +1 -1
  109. package/dist/types/checkout/views/initial.d.ts +2 -0
  110. package/dist/types/checkout/views/initial.d.ts.map +1 -1
  111. package/dist/types/checkout/views/method-select.d.ts +2 -0
  112. package/dist/types/checkout/views/method-select.d.ts.map +1 -1
  113. package/dist/types/checkout/views/restart.d.ts.map +1 -1
  114. package/dist/types/components/buttons/index.d.ts.map +1 -1
  115. package/dist/types/components/icons/clock.d.ts +6 -0
  116. package/dist/types/components/icons/clock.d.ts.map +1 -0
  117. package/dist/types/components/icons/edit.d.ts +6 -0
  118. package/dist/types/components/icons/edit.d.ts.map +1 -0
  119. package/dist/types/components/icons/index.d.ts +3 -0
  120. package/dist/types/components/icons/index.d.ts.map +1 -1
  121. package/dist/types/components/icons/send.d.ts +6 -0
  122. package/dist/types/components/icons/send.d.ts.map +1 -0
  123. package/dist/types/components/index.d.ts +1 -0
  124. package/dist/types/components/index.d.ts.map +1 -1
  125. package/dist/types/components/quote-expiry/index.d.ts +2 -0
  126. package/dist/types/components/quote-expiry/index.d.ts.map +1 -0
  127. package/dist/types/components/quote-expiry/quote-expiry-countdown.d.ts +15 -0
  128. package/dist/types/components/quote-expiry/quote-expiry-countdown.d.ts.map +1 -0
  129. package/dist/types/components/quote-expiry/styles.d.ts +22 -0
  130. package/dist/types/components/quote-expiry/styles.d.ts.map +1 -0
  131. package/dist/types/components/quote-expiry/tiers.d.ts +10 -0
  132. package/dist/types/components/quote-expiry/tiers.d.ts.map +1 -0
  133. package/dist/types/components/text/index.d.ts.map +1 -1
  134. package/dist/types/components/wallet-selector/component.d.ts +1 -2
  135. package/dist/types/components/wallet-selector/component.d.ts.map +1 -1
  136. package/dist/types/components/wallet-selector/domain.d.ts +3 -2
  137. package/dist/types/components/wallet-selector/domain.d.ts.map +1 -1
  138. package/dist/types/components/wallet-selector/wallets/wagmi/index.d.ts +41 -5
  139. package/dist/types/components/wallet-selector/wallets/wagmi/index.d.ts.map +1 -1
  140. package/dist/types/config.d.ts +4 -0
  141. package/dist/types/config.d.ts.map +1 -1
  142. package/dist/types/index.d.ts +2 -1
  143. package/dist/types/index.d.ts.map +1 -1
  144. package/dist/types/integrations/lifi.d.ts.map +1 -1
  145. package/dist/types/refund/index.d.ts +82 -0
  146. package/dist/types/refund/index.d.ts.map +1 -0
  147. package/dist/types/state/checkout/payment-attempt.d.ts.map +1 -1
  148. package/dist/types/state/checkout/payment-lifecycle.d.ts +37 -0
  149. package/dist/types/state/checkout/payment-lifecycle.d.ts.map +1 -0
  150. package/dist/types/state/checkout/store.d.ts +40 -2
  151. package/dist/types/state/checkout/store.d.ts.map +1 -1
  152. package/dist/types/state/checkout/wallet-payment-options.d.ts +18 -0
  153. package/dist/types/state/checkout/wallet-payment-options.d.ts.map +1 -0
  154. package/dist/types/themes/default.d.ts.map +1 -1
  155. package/dist/types/themes/types.d.ts +11 -0
  156. package/dist/types/themes/types.d.ts.map +1 -1
  157. package/dist/types/utils/string.d.ts +1 -0
  158. package/dist/types/utils/string.d.ts.map +1 -1
  159. package/dist/types/utils/wallet-errors.d.ts +2 -0
  160. package/dist/types/utils/wallet-errors.d.ts.map +1 -0
  161. package/package.json +25 -18
  162. package/LICENSE +0 -21
@@ -1,61 +1,339 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useCallback, useContext, useEffect, useRef, useState } from "react";
2
+ import { useAppKit } from "@reown/appkit/react";
3
+ import { useCallback, useContext, useEffect, useMemo, useRef, useState, } from "react";
3
4
  import { keyframes, styled } from "styled-components";
5
+ import { useAccount, useConfig } from "wagmi";
4
6
  import { confirmPayment } from "../../../api/payments.js";
5
- import { PaymentStatus } from "../../../api/types.js";
6
- import { StyledButton, Text, useModalWithView, } from "../../../components/index.js";
7
+ import { EditIcon } from "../../../components/icons/index.js";
8
+ import { QuoteExpiryCountdown, StyledButton, Text, useModalWithView, } from "../../../components/index.js";
7
9
  import { WalletContext } from "../../../components/wallet-selector/provider.js";
10
+ import { useWalletActions } from "../../../components/wallet-selector/store.js";
11
+ import { WagmiWalletInterface } from "../../../components/wallet-selector/wallets/wagmi/index.js";
8
12
  import { useMintMoneyConfig } from "../../../context.js";
9
13
  import { executeWalletPaymentOption, fetchWalletPaymentQuote, findWalletPaymentOptions, } from "../../../integrations/index.js";
10
- import { createWalletOptionPaymentAttempt, executeConnectedWalletPayment, resetWalletPaymentState, setProcessing, setSelectedCurrency, setWalletPaymentState, startPaymentPolling, stopPaymentPolling, useCheckoutStore, } from "../../../state/checkout/store.js";
14
+ import { clearQuoteRefresh, checkChainStatus, configureWalletQuoteRefresh, createWalletOptionPaymentAttempt, executeTransfer, prepareWalletQuoteReplacement, resetWalletPaymentState, setProcessing, setSelectedCurrency, setWalletPaymentState, useCheckoutStore, } from "../../../state/checkout/store.js";
15
+ import { buildWalletQuoteLoadKey, buildWalletPaymentOptionsReadyState, NO_WALLET_PAYMENT_OPTIONS_DESCRIPTION, NO_WALLET_PAYMENT_OPTIONS_TITLE, } from "../../../state/checkout/wallet-payment-options.js";
16
+ import { formatAddress } from "../../../utils/string.js";
17
+ import { messageForWalletError } from "../../../utils/wallet-errors.js";
11
18
  import { ModalViewContainer } from "../../container.js";
12
19
  import { ModalBackButton } from "../back.js";
13
20
  import { resolveWalletPaymentConfirmationAmount } from "./wallet-payment-confirmation-amount.js";
14
- const OptionsContainer = styled.div `
21
+ const QUOTE_COUNTDOWN_URGENT_THRESHOLD_RATIO = 0.25;
22
+ const pillSlideIn = keyframes `
23
+ from {
24
+ opacity: 0;
25
+ transform: translateY(-6px);
26
+ }
27
+ to {
28
+ opacity: 1;
29
+ transform: translateY(0);
30
+ }
31
+ `;
32
+ const ContextStrip = styled.div `
15
33
  display: flex;
16
34
  flex-direction: column;
17
- gap: 10px;
18
- max-height: min(360px, 48vh);
19
- overflow-y: auto;
20
- padding-right: 4px;
21
- overscroll-behavior: contain;
35
+ gap: 8px;
22
36
  `;
23
- const OptionCard = styled.div `
24
- border: 1px solid #e5e7eb;
25
- border-radius: 16px;
26
- padding: 14px;
37
+ const ContextPill = styled.div `
38
+ overflow: hidden;
39
+ padding: 12px 14px;
40
+ border-radius: 14px;
41
+ background: ${({ $accent }) => ($accent ? "#f8fffc" : "#ffffff")};
42
+ border: 1px solid ${({ $accent }) => ($accent ? "#bbf7d0" : "#eef2f6")};
43
+ box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
44
+ animation: ${pillSlideIn} 200ms cubic-bezier(0.22, 1, 0.36, 1);
45
+ `;
46
+ const ContextPillToggle = styled.button `
47
+ width: 100%;
48
+ border: 0;
49
+ background: transparent;
50
+ color: inherit;
51
+ padding: 0;
52
+ display: flex;
53
+ align-items: center;
54
+ gap: 12px;
55
+ cursor: pointer;
56
+ text-align: left;
57
+
58
+ &:focus-visible {
59
+ outline: 2px solid #a7f3d0;
60
+ outline-offset: 4px;
61
+ }
62
+ `;
63
+ const PillIconWrap = styled.div `
64
+ position: relative;
65
+ width: 40px;
66
+ height: 40px;
67
+ flex-shrink: 0;
68
+ `;
69
+ const PillTokenIcon = styled.div `
70
+ width: 100%;
71
+ height: 100%;
72
+ border-radius: 999px;
73
+ display: inline-flex;
74
+ align-items: center;
75
+ justify-content: center;
76
+ font-size: 11px;
77
+ font-weight: 700;
78
+ color: #1d4ed8;
79
+ background: linear-gradient(135deg, #dbeafe, #bfdbfe);
80
+ background-image: ${({ $iconUrl }) => $iconUrl ? `url(${$iconUrl})` : "none"};
81
+ background-size: cover;
82
+ background-position: center;
83
+ `;
84
+ const PillChainBadge = styled.div `
85
+ position: absolute;
86
+ right: -2px;
87
+ bottom: -2px;
88
+ width: 14px;
89
+ height: 14px;
90
+ border-radius: 999px;
91
+ border: 1.5px solid #ffffff;
27
92
  background: #ffffff;
93
+ background-image: ${({ $iconUrl }) => $iconUrl ? `url(${$iconUrl})` : "none"};
94
+ background-size: 85%;
95
+ background-position: center;
96
+ background-repeat: no-repeat;
97
+ box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
98
+ `;
99
+ const WalletDot = styled.div `
100
+ width: 18px;
101
+ height: 18px;
102
+ border-radius: 999px;
103
+ flex-shrink: 0;
104
+ background:
105
+ ${({ $iconUrl }) => ($iconUrl ? `url(${$iconUrl})` : "none")},
106
+ linear-gradient(135deg, #22c55e, #60a5fa);
107
+ background-size: cover;
108
+ background-position: center;
109
+ `;
110
+ const WalletSwitchLink = styled.button `
111
+ flex-shrink: 0;
112
+ border: none;
113
+ background: transparent;
114
+ color: #94a3b8;
115
+ display: inline-flex;
116
+ align-items: center;
117
+ justify-content: center;
118
+ width: 20px;
119
+ height: 20px;
120
+ margin: -2px -2px -2px -6px;
121
+ padding: 0;
28
122
  cursor: pointer;
123
+ border-radius: 999px;
29
124
  transition:
30
- border-color 120ms ease,
31
- box-shadow 120ms ease,
32
- transform 120ms ease;
125
+ color 120ms ease,
126
+ background-color 120ms ease;
33
127
 
34
128
  &:hover {
35
- border-color: #cbd5e1;
36
- transform: translateY(-1px);
129
+ color: #0f172a;
130
+ background: #f1f5f9;
131
+ }
132
+
133
+ &:focus-visible {
134
+ outline: 2px solid #a7f3d0;
135
+ outline-offset: 2px;
136
+ }
137
+
138
+ &:disabled {
139
+ opacity: 0.5;
140
+ cursor: not-allowed;
37
141
  }
38
142
  `;
39
- const OptionHeader = styled.div `
143
+ const PillBody = styled.div `
144
+ display: flex;
145
+ flex-direction: column;
146
+ gap: 2px;
147
+ min-width: 0;
148
+ flex: 1;
149
+ `;
150
+ const PillEyebrow = styled.span `
151
+ font-size: 12px;
152
+ line-height: 1.2;
153
+ color: ${({ theme }) => theme.font.color.tertiary};
154
+ white-space: nowrap;
155
+ overflow: hidden;
156
+ text-overflow: ellipsis;
157
+ `;
158
+ const PillTitle = styled.span `
159
+ font-size: 14px;
160
+ font-weight: 600;
161
+ color: ${({ theme }) => theme.font.color.primary};
162
+ line-height: 1.3;
163
+ white-space: nowrap;
164
+ overflow: hidden;
165
+ text-overflow: ellipsis;
166
+ `;
167
+ const PillAction = styled.button `
168
+ flex-shrink: 0;
169
+ border: none;
170
+ background: transparent;
171
+ color: ${({ theme }) => theme.font.color.secondary};
172
+ font-size: 14px;
173
+ font-weight: 600;
174
+ padding: 6px 10px;
175
+ border-radius: 999px;
176
+ cursor: pointer;
177
+ transition:
178
+ background-color 120ms ease,
179
+ color 120ms ease;
180
+
181
+ &:hover {
182
+ background: #f1f5f9;
183
+ color: #0f172a;
184
+ }
185
+
186
+ &:focus-visible {
187
+ outline: 2px solid #a7f3d0;
188
+ outline-offset: 2px;
189
+ }
190
+
191
+ &:disabled {
192
+ opacity: 0.5;
193
+ cursor: not-allowed;
194
+ }
195
+ `;
196
+ const PillCaret = styled.span `
197
+ width: 24px;
198
+ height: 24px;
199
+ border-radius: 999px;
200
+ background: #f1f3fb;
201
+ display: inline-flex;
202
+ align-items: center;
203
+ justify-content: center;
204
+ font-size: 13px;
205
+ line-height: 1;
206
+ color: #6b7280;
207
+ transform: rotate(${({ $expanded }) => ($expanded ? "180deg" : "0deg")});
208
+ transition:
209
+ transform 0.15s ease,
210
+ background 0.15s ease;
211
+ flex-shrink: 0;
212
+ `;
213
+ const PillDetails = styled.div `
214
+ border-top: 1px solid #edf1f5;
215
+ margin-top: 12px;
216
+ padding-top: 12px;
217
+ display: flex;
218
+ flex-direction: column;
219
+ `;
220
+ const PillDetailRow = styled.div `
40
221
  display: flex;
41
222
  align-items: center;
42
223
  justify-content: space-between;
43
224
  gap: 12px;
225
+ border-bottom: 1px solid #edf1f5;
226
+ padding: 9px 0;
227
+
228
+ &:last-child {
229
+ border-bottom: 0;
230
+ padding-bottom: 0;
231
+ }
232
+ `;
233
+ const PillDetailLabel = styled.span `
234
+ font-size: 13px;
235
+ line-height: 1.3;
236
+ color: #475569;
237
+ `;
238
+ const PillDetailValue = styled.span `
239
+ display: inline-flex;
240
+ align-items: center;
241
+ justify-content: flex-end;
242
+ gap: 6px;
243
+ min-width: 0;
244
+ font-size: 13px;
245
+ line-height: 1.3;
246
+ font-weight: 600;
247
+ color: #0f172a;
248
+ text-align: right;
249
+ `;
250
+ const SectionLabel = styled.div `
251
+ font-size: 11px;
252
+ font-weight: 600;
253
+ letter-spacing: 0.06em;
254
+ text-transform: uppercase;
255
+ color: #94a3b8;
256
+ padding: 0 2px;
44
257
  `;
45
- const OptionHeaderLeft = styled.div `
258
+ const SectionRow = styled.div `
259
+ display: flex;
260
+ align-items: baseline;
261
+ justify-content: space-between;
262
+ gap: 12px;
263
+ padding: 0 2px;
264
+ `;
265
+ const ConnectedWalletRow = styled.div `
46
266
  display: flex;
47
267
  align-items: center;
48
- gap: 10px;
268
+ justify-content: space-between;
269
+ gap: 12px;
270
+ padding: 2px 4px;
271
+ `;
272
+ const ConnectedWalletIdentity = styled.div `
273
+ display: inline-flex;
274
+ align-items: center;
275
+ gap: 8px;
49
276
  min-width: 0;
50
- flex: 1;
277
+ font-size: 12px;
278
+ line-height: 1.4;
279
+ color: #64748b;
280
+ `;
281
+ const ConnectedWalletAddress = styled.span `
282
+ min-width: 0;
283
+ overflow: hidden;
284
+ text-overflow: ellipsis;
285
+ white-space: nowrap;
286
+ `;
287
+ const OptionsContainer = styled.div `
288
+ display: flex;
289
+ flex-direction: column;
290
+ gap: 8px;
291
+ max-height: min(300px, 34vh);
292
+ overflow-y: auto;
293
+ margin: -4px -4px -6px;
294
+ padding: 4px 4px 6px;
295
+ overscroll-behavior: contain;
296
+ scrollbar-width: none;
297
+
298
+ &::-webkit-scrollbar {
299
+ display: none;
300
+ }
301
+ `;
302
+ const OptionCard = styled.button `
303
+ border: 1px solid #eef2f6;
304
+ border-radius: 16px;
305
+ padding: 12px 14px;
306
+ background: #ffffff;
307
+ cursor: pointer;
308
+ width: 100%;
309
+ text-align: left;
310
+ display: flex;
311
+ align-items: center;
312
+ gap: 12px;
313
+ transition:
314
+ border-color 140ms ease,
315
+ box-shadow 140ms ease,
316
+ transform 140ms ease,
317
+ background-color 140ms ease;
318
+
319
+ &:hover {
320
+ border-color: #cdd9e3;
321
+ box-shadow: 0 6px 14px rgba(15, 23, 42, 0.05);
322
+ transform: translateY(-1px);
323
+ }
324
+
325
+ &:focus-visible {
326
+ outline: 2px solid #a7f3d0;
327
+ outline-offset: 2px;
328
+ }
51
329
  `;
52
- const TokenIconWrap = styled.div `
330
+ const OptionTokenIconWrap = styled.div `
53
331
  position: relative;
54
- width: 38px;
55
- height: 38px;
332
+ width: 40px;
333
+ height: 40px;
56
334
  flex-shrink: 0;
57
335
  `;
58
- const TokenIcon = styled.div `
336
+ const OptionTokenIcon = styled.div `
59
337
  width: 100%;
60
338
  height: 100%;
61
339
  border-radius: 999px;
@@ -73,7 +351,7 @@ const TokenIcon = styled.div `
73
351
  background-position: center;
74
352
  overflow: hidden;
75
353
  `;
76
- const ChainBadge = styled.div `
354
+ const OptionChainBadge = styled.div `
77
355
  position: absolute;
78
356
  right: -2px;
79
357
  bottom: -2px;
@@ -100,24 +378,9 @@ const OptionBalance = styled.div `
100
378
  display: flex;
101
379
  flex-direction: column;
102
380
  align-items: flex-end;
103
- gap: 2px;
381
+ gap: 4px;
104
382
  flex-shrink: 0;
105
383
  `;
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
384
  const FastBadge = styled.span `
122
385
  display: inline-flex;
123
386
  align-items: center;
@@ -125,95 +388,106 @@ const FastBadge = styled.span `
125
388
  gap: 4px;
126
389
  background: #ecfdf5;
127
390
  color: #047857;
128
- font-size: 12px;
391
+ font-size: 11px;
129
392
  font-weight: 600;
130
393
  line-height: 1;
131
- padding: 6px 9px;
394
+ padding: 4px 8px;
132
395
  white-space: nowrap;
133
396
  `;
134
- const EmptyState = styled.div `
135
- border: 1px dashed #d1d5db;
136
- border-radius: 16px;
137
- padding: 18px;
138
- text-align: center;
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
- }
397
+ const RoutedBadge = styled.span `
398
+ font-size: 11px;
399
+ font-weight: 500;
400
+ color: #94a3b8;
401
+ white-space: nowrap;
152
402
  `;
153
- const ConfirmScreen = styled.div `
154
- margin-top: 8px;
155
- border: 1px solid #b7efd1;
156
- border-radius: 22px;
157
- padding: 18px 16px 16px;
158
- background: linear-gradient(180deg, #ecfdf5 0%, #dcfce7 100%);
159
- box-shadow: 0 14px 30px rgba(16, 185, 129, 0.12);
403
+ const QuoteCard = styled.div `
404
+ background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
405
+ border: 1px solid #eef2f6;
406
+ border-radius: 18px;
407
+ padding: 16px 18px;
160
408
  display: flex;
161
409
  flex-direction: column;
162
- gap: 16px;
163
- animation: ${confirmTrayEnter} 220ms cubic-bezier(0.22, 1, 0.36, 1);
410
+ gap: 10px;
411
+ box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
164
412
  `;
165
- const ConfirmMeta = styled.div `
413
+ const QuoteRow = styled.div `
166
414
  display: flex;
167
- align-items: center;
415
+ align-items: baseline;
168
416
  justify-content: space-between;
169
- gap: 12px;
417
+ gap: 16px;
170
418
  `;
171
- const ConfirmAmount = styled.div `
419
+ const QuoteHairline = styled.div `
420
+ height: 1px;
421
+ background: #eef2f6;
422
+ margin: 2px 0;
423
+ `;
424
+ const QuoteFootnote = styled.div `
172
425
  display: flex;
173
426
  align-items: center;
174
- gap: 10px;
427
+ gap: 6px;
428
+ font-size: 12px;
429
+ color: #94a3b8;
430
+
431
+ &::before {
432
+ content: "";
433
+ display: inline-block;
434
+ width: 6px;
435
+ height: 6px;
436
+ border-radius: 999px;
437
+ background: #22c55e;
438
+ box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.18);
439
+ }
175
440
  `;
176
- const ConfirmTextBlock = styled.div `
177
- display: flex;
178
- flex-direction: column;
179
- gap: 2px;
441
+ const QuoteFootnoteWarn = styled(QuoteFootnote) `
442
+ color: #b45309;
443
+
444
+ &::before {
445
+ background: #f59e0b;
446
+ box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18);
447
+ }
180
448
  `;
181
- const ConfirmActions = styled.div `
449
+ const SkeletonContainer = styled.div `
182
450
  display: flex;
183
451
  flex-direction: column;
184
- gap: 10px;
452
+ gap: 8px;
453
+ `;
454
+ const skeletonShimmer = keyframes `
455
+ 0% { background-position: -120% 0; }
456
+ 100% { background-position: 220% 0; }
185
457
  `;
186
- const QuoteBlock = styled.div `
458
+ const SkeletonRow = styled.div `
459
+ height: 64px;
460
+ border-radius: 16px;
461
+ border: 1px solid #eef2f6;
462
+ background: linear-gradient(90deg, #f8fafc 0%, #f1f5f9 50%, #f8fafc 100%);
463
+ background-size: 220% 100%;
464
+ animation: ${skeletonShimmer} 1.4s ease-in-out infinite;
465
+ `;
466
+ const EmptyState = styled.div `
467
+ position: relative;
468
+ border-radius: 22px;
469
+ padding: 22px 20px;
470
+ background: #ffffff;
471
+ border: 1px solid #ecf1ee;
187
472
  display: flex;
188
473
  flex-direction: column;
474
+ align-items: center;
189
475
  gap: 10px;
476
+ text-align: center;
477
+ box-shadow: 0 14px 32px rgba(15, 23, 42, 0.05);
190
478
  `;
191
- const QuoteRow = styled.div `
479
+ const EmptyHeadline = styled.div `
192
480
  display: flex;
193
- align-items: flex-start;
194
- justify-content: space-between;
195
- gap: 12px;
481
+ flex-direction: column;
482
+ gap: 4px;
483
+ max-width: 300px;
196
484
  `;
197
485
  const ContentStage = styled.div `
198
486
  display: flex;
199
487
  flex-direction: column;
200
- gap: 16px;
488
+ gap: 14px;
201
489
  min-height: 0;
202
490
  `;
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
491
  const formatDisplayAmount = (amount, maximumFractionDigits = 4) => {
218
492
  if (!amount)
219
493
  return null;
@@ -283,40 +557,50 @@ const buildDirectQuote = (option, context) => {
283
557
  estimatedDurationMinutes: 1,
284
558
  };
285
559
  };
286
- const PAYMENT_QUOTE_EXPIRED_MESSAGE = "This payment quote has expired. Please create a new payment.";
287
- const PAYMENT_NO_LONGER_PAYABLE_MESSAGE = "This payment is no longer payable. Please create a new payment.";
288
- const parseExpiryTime = (value) => {
289
- if (!value)
290
- return null;
291
- const parsed = Date.parse(value);
292
- return Number.isFinite(parsed) ? parsed : null;
293
- };
294
- const getActiveAttemptExpiryTime = (payment, attempt) => {
295
- return parseExpiryTime(attempt?.expires_at ?? payment?.expires_at);
296
- };
297
- const hasExpiredAttempt = (payment, attempt) => {
298
- const expiryTime = getActiveAttemptExpiryTime(payment, attempt);
299
- return expiryTime !== null && Date.now() >= expiryTime;
300
- };
301
- const CryptoIntentWalletPaymentOptionsViewContent = () => {
560
+ const CryptoIntentWalletPaymentOptionsAppKitViewContent = () => {
302
561
  const modalRef = useRef(null);
562
+ const isChangingWalletRef = useRef(false);
563
+ const lastQuoteLoadKeyRef = useRef(null);
303
564
  const { goToView } = useModalWithView();
565
+ const { open } = useAppKit();
304
566
  const config = useMintMoneyConfig();
305
- const { wallet } = useContext(WalletContext);
306
- const { payment, cryptoPaymentAttempt, cryptoCurrency, walletPayment, loading, processing, } = useCheckoutStore();
567
+ const wagmiConfig = useConfig();
568
+ const { wallet, setWallet } = useContext(WalletContext);
569
+ const { initialiseWallets } = useWalletActions();
570
+ const account = useAccount();
571
+ const { payment, cryptoPaymentAttempt, cryptoCurrency, walletPayment, quote, loading, processing, } = useCheckoutStore();
307
572
  const [executingId, setExecutingId] = useState(null);
573
+ const [paymentDetailsExpanded, setPaymentDetailsExpanded] = useState(false);
574
+ const connectorName = account.connector?.name || "Connected wallet";
575
+ const connectorIcon = typeof account.connector?.icon === "string"
576
+ ? account.connector.icon
577
+ : undefined;
578
+ const connectedWagmiWallet = useMemo(() => {
579
+ if (!account.isConnected || !account.address || !account.connector) {
580
+ return null;
581
+ }
582
+ return new WagmiWalletInterface(account.connector, wagmiConfig);
583
+ }, [account.address, account.connector, account.isConnected, wagmiConfig]);
584
+ const activeWallet = connectedWagmiWallet ?? wallet;
585
+ useEffect(() => {
586
+ if (!connectedWagmiWallet) {
587
+ return;
588
+ }
589
+ setWallet(connectedWagmiWallet);
590
+ initialiseWallets([() => connectedWagmiWallet]);
591
+ }, [connectedWagmiWallet, initialiseWallets, setWallet]);
308
592
  const buildContext = useCallback(async (currentPayment) => {
309
593
  const state = useCheckoutStore.getState();
310
594
  const currentCheckout = state.checkout;
311
595
  const currentCryptoCurrency = state.cryptoCurrency;
312
- if (!currentCheckout || !currentCryptoCurrency || !wallet) {
596
+ if (!currentCheckout || !currentCryptoCurrency || !activeWallet) {
313
597
  throw new Error("Wallet payment context is not ready");
314
598
  }
315
599
  const resolvedPayment = currentPayment ?? state.payment;
316
600
  if (!resolvedPayment) {
317
601
  throw new Error("Missing payment");
318
602
  }
319
- const walletAddress = await wallet.getAddress();
603
+ const walletAddress = await activeWallet.getAddress();
320
604
  if (!walletAddress) {
321
605
  throw new Error("Failed to get wallet address");
322
606
  }
@@ -326,44 +610,69 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
326
610
  settlementCurrency: currentCryptoCurrency,
327
611
  walletAddress,
328
612
  };
329
- }, [wallet]);
613
+ }, [activeWallet]);
614
+ const loadWalletPaymentOptions = useCallback(async (isCancelled) => {
615
+ setProcessing(true);
616
+ setSelectedCurrency(cryptoCurrency);
617
+ resetWalletPaymentState();
618
+ setWalletPaymentState({ status: "loading", error: null, options: [] });
619
+ const preparedContext = await buildContext();
620
+ const providerOptions = await findWalletPaymentOptions(preparedContext);
621
+ if (isCancelled()) {
622
+ return;
623
+ }
624
+ setWalletPaymentState(buildWalletPaymentOptionsReadyState({
625
+ walletAddress: preparedContext.walletAddress,
626
+ options: providerOptions,
627
+ }));
628
+ }, [buildContext, cryptoCurrency]);
629
+ const handleMissingAccount = useCallback(() => {
630
+ resetWalletPaymentState();
631
+ clearQuoteRefresh();
632
+ setProcessing(false);
633
+ goToView("cryptoIntent");
634
+ }, [goToView]);
635
+ const handleMissingWalletConnection = useCallback(() => {
636
+ goToView("failed", { reason: "wallet_not_connected" });
637
+ }, [goToView]);
638
+ const handleWalletPaymentOptionsError = useCallback((error) => {
639
+ const message = error instanceof Error ? error.message : "Failed to load payment options";
640
+ setWalletPaymentState({
641
+ status: "failed",
642
+ error: message,
643
+ options: [],
644
+ });
645
+ }, []);
646
+ const shouldPreserveSubmittedFailure = walletPayment.status === "failed" &&
647
+ walletPayment.options.length > 0 &&
648
+ Boolean(walletPayment.sourceTxHash);
330
649
  useEffect(() => {
331
- if (!wallet || !cryptoCurrency) {
332
- goToView("failed", { reason: "wallet_not_connected" });
650
+ if (!account.isConnected || !account.address) {
651
+ if (isChangingWalletRef.current) {
652
+ setProcessing(false);
653
+ return;
654
+ }
655
+ handleMissingAccount();
656
+ return;
657
+ }
658
+ isChangingWalletRef.current = false;
659
+ if (!activeWallet || !cryptoCurrency) {
660
+ handleMissingWalletConnection();
661
+ return;
662
+ }
663
+ if (shouldPreserveSubmittedFailure) {
664
+ setProcessing(false);
333
665
  return;
334
666
  }
335
667
  let cancelled = false;
336
668
  const loadOptions = async () => {
337
669
  try {
338
- setProcessing(true);
339
- setSelectedCurrency(cryptoCurrency);
340
- resetWalletPaymentState();
341
- setWalletPaymentState({ status: "loading", error: null, options: [] });
342
- const preparedContext = await buildContext();
343
- const providerOptions = await findWalletPaymentOptions(preparedContext);
344
- const options = providerOptions.length > 0
345
- ? providerOptions
346
- : [buildDefaultOption(preparedContext)];
347
- if (cancelled)
348
- return;
349
- setWalletPaymentState({
350
- status: "ready",
351
- options,
352
- selectedOptionId: null,
353
- error: null,
354
- });
670
+ await loadWalletPaymentOptions(() => cancelled);
355
671
  }
356
672
  catch (error) {
357
673
  if (cancelled)
358
674
  return;
359
- const message = error instanceof Error
360
- ? error.message
361
- : "Failed to load payment options";
362
- setWalletPaymentState({
363
- status: "failed",
364
- error: message,
365
- options: [],
366
- });
675
+ handleWalletPaymentOptionsError(error);
367
676
  }
368
677
  finally {
369
678
  if (!cancelled) {
@@ -374,9 +683,32 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
374
683
  void loadOptions();
375
684
  return () => {
376
685
  cancelled = true;
686
+ clearQuoteRefresh();
377
687
  };
378
- }, [buildContext, goToView, payment?.id, wallet]);
688
+ }, [
689
+ account.address,
690
+ account.isConnected,
691
+ activeWallet,
692
+ cryptoCurrency,
693
+ handleMissingAccount,
694
+ handleMissingWalletConnection,
695
+ handleWalletPaymentOptionsError,
696
+ loadWalletPaymentOptions,
697
+ shouldPreserveSubmittedFailure,
698
+ ]);
379
699
  const selectedOption = walletPayment.options.find((option) => option.id === walletPayment.selectedOptionId) ?? null;
700
+ const hasNoPaymentOptions = walletPayment.status === "ready" && walletPayment.options.length === 0;
701
+ const unsupportedWalletAddress = walletPayment.walletAddress ?? account.address ?? null;
702
+ const quoteLoadKey = buildWalletQuoteLoadKey({
703
+ paymentId: payment?.id,
704
+ paymentAmount: payment?.amount,
705
+ paymentCurrency: payment?.currency,
706
+ paymentExpiresAt: payment?.expires_at,
707
+ settlementChain: cryptoCurrency?.chain,
708
+ settlementAsset: cryptoCurrency?.asset,
709
+ walletAddress: walletPayment.walletAddress ?? account.address,
710
+ option: selectedOption,
711
+ });
380
712
  const confirmationAmount = selectedOption && payment
381
713
  ? resolveWalletPaymentConfirmationAmount({
382
714
  option: selectedOption,
@@ -384,59 +716,17 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
384
716
  attempt: cryptoPaymentAttempt,
385
717
  })
386
718
  : null;
719
+ const displayedPayAmount = confirmationAmount?.amount ??
720
+ (selectedOption && walletPayment.quoteStatus === "loading"
721
+ ? "Fetching quote..."
722
+ : selectedOption && walletPayment.quoteStatus === "failed"
723
+ ? "Unavailable"
724
+ : null);
387
725
  const formattedCost = formatMoneyAmount(payment?.currency ?? "USD", Number(payment?.amount ?? 0));
388
- useEffect(() => {
389
- if (!payment)
390
- return;
391
- if (payment.status === PaymentStatus.FAILED) {
392
- setWalletPaymentState({
393
- status: "failed",
394
- error: PAYMENT_NO_LONGER_PAYABLE_MESSAGE,
395
- });
396
- goToView("failed", { reason: PAYMENT_NO_LONGER_PAYABLE_MESSAGE });
397
- return;
398
- }
399
- if (hasExpiredAttempt(payment, cryptoPaymentAttempt ?? payment.payment_attempt)) {
400
- setWalletPaymentState({
401
- status: "failed",
402
- error: PAYMENT_QUOTE_EXPIRED_MESSAGE,
403
- });
404
- goToView("failed", { reason: PAYMENT_QUOTE_EXPIRED_MESSAGE });
405
- }
406
- }, [
407
- cryptoPaymentAttempt?.expires_at,
408
- goToView,
409
- payment,
410
- payment?.payment_attempt?.expires_at,
411
- payment?.status,
412
- ]);
413
- useEffect(() => {
414
- if (!payment?.id)
415
- return;
416
- const confirmationStatus = config.cryptoCheckoutConfig.paymentConfirmationStatus;
417
- const poller = startPaymentPolling((status) => {
418
- if (status === PaymentStatus.PAID || status === confirmationStatus) {
419
- goToView("paymentSuccess");
420
- return;
421
- }
422
- if (status === PaymentStatus.FAILED) {
423
- setWalletPaymentState({
424
- status: "failed",
425
- error: PAYMENT_NO_LONGER_PAYABLE_MESSAGE,
426
- });
427
- goToView("failed", { reason: PAYMENT_NO_LONGER_PAYABLE_MESSAGE });
428
- }
429
- }, confirmationStatus);
430
- return () => {
431
- poller.stop();
432
- stopPaymentPolling();
433
- };
434
- }, [
435
- config.cryptoCheckoutConfig.paymentConfirmationStatus,
436
- goToView,
437
- payment?.id,
438
- ]);
439
726
  const handlePickOption = (option) => {
727
+ lastQuoteLoadKeyRef.current = null;
728
+ prepareWalletQuoteReplacement(walletPayment.walletAddress);
729
+ setPaymentDetailsExpanded(false);
440
730
  setWalletPaymentState({
441
731
  selectedOptionId: option.id,
442
732
  error: null,
@@ -448,6 +738,9 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
448
738
  });
449
739
  };
450
740
  const handleReturnToOptions = () => {
741
+ lastQuoteLoadKeyRef.current = null;
742
+ prepareWalletQuoteReplacement(walletPayment.walletAddress);
743
+ setPaymentDetailsExpanded(false);
451
744
  setWalletPaymentState({
452
745
  selectedOptionId: null,
453
746
  error: null,
@@ -456,32 +749,60 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
456
749
  quoteError: null,
457
750
  });
458
751
  };
752
+ const handleChangeWallet = useCallback(() => {
753
+ isChangingWalletRef.current = true;
754
+ void open({ view: "Connect" });
755
+ }, [open]);
756
+ const confirmDirectWalletPayment = async (txHash) => {
757
+ if (!payment) {
758
+ throw new Error("Missing payment");
759
+ }
760
+ try {
761
+ await confirmPayment(payment.id, { txHash });
762
+ }
763
+ catch (error) {
764
+ const message = messageForWalletError(error, "Failed to confirm wallet payment");
765
+ setWalletPaymentState({
766
+ status: "failed",
767
+ error: message,
768
+ });
769
+ goToView("cryptoIntentWalletPaymentOptions");
770
+ }
771
+ };
459
772
  useEffect(() => {
460
- if (!selectedOption || !payment?.id || !cryptoCurrency) {
773
+ if (!selectedOption || !quoteLoadKey || !cryptoCurrency) {
774
+ if (!selectedOption) {
775
+ lastQuoteLoadKeyRef.current = null;
776
+ }
461
777
  return;
462
778
  }
779
+ if (lastQuoteLoadKeyRef.current === quoteLoadKey) {
780
+ return;
781
+ }
782
+ lastQuoteLoadKeyRef.current = quoteLoadKey;
463
783
  let cancelled = false;
464
- let refreshTimer = null;
465
- const clearRefreshTimer = () => {
466
- if (refreshTimer) {
467
- clearTimeout(refreshTimer);
468
- refreshTimer = null;
469
- }
470
- };
471
784
  const loadQuote = async () => {
472
- clearRefreshTimer();
785
+ const currentPayment = useCheckoutStore.getState().payment;
786
+ if (!currentPayment?.id) {
787
+ return;
788
+ }
473
789
  try {
474
- const preparedContext = await buildContext();
475
- if (hasExpiredAttempt(preparedContext.payment, preparedContext.payment.payment_attempt)) {
476
- throw new Error(PAYMENT_QUOTE_EXPIRED_MESSAGE);
477
- }
478
- const walletAddress = await wallet?.getAddress();
790
+ prepareWalletQuoteReplacement(walletPayment.walletAddress ?? account.address ?? null);
791
+ setWalletPaymentState({
792
+ quoteStatus: "loading",
793
+ quote: null,
794
+ quoteError: null,
795
+ quoteId: null,
796
+ routeId: null,
797
+ });
798
+ const preparedContext = await buildContext(currentPayment);
799
+ const walletAddress = await activeWallet?.getAddress();
479
800
  if (!walletAddress) {
480
801
  throw new Error("Failed to get wallet address");
481
802
  }
482
803
  const ensuredAttempt = await createWalletOptionPaymentAttempt(selectedOption, walletAddress, null);
483
- if (hasExpiredAttempt(preparedContext.payment, ensuredAttempt)) {
484
- throw new Error(PAYMENT_QUOTE_EXPIRED_MESSAGE);
804
+ if (cancelled) {
805
+ return;
485
806
  }
486
807
  const quoteContext = {
487
808
  ...preparedContext,
@@ -489,8 +810,6 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
489
810
  };
490
811
  if (selectedOption.kind === "direct") {
491
812
  const directQuote = buildDirectQuote(selectedOption, quoteContext);
492
- if (cancelled)
493
- return;
494
813
  setWalletPaymentState({
495
814
  quoteStatus: "ready",
496
815
  quote: directQuote,
@@ -498,23 +817,16 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
498
817
  routeId: directQuote.routeId,
499
818
  quoteError: null,
500
819
  });
820
+ configureWalletQuoteRefresh(walletAddress);
501
821
  return;
502
822
  }
503
- if (!cancelled) {
504
- setWalletPaymentState({
505
- quoteStatus: "loading",
506
- quote: null,
507
- quoteError: null,
508
- quoteId: null,
509
- routeId: null,
510
- });
511
- }
512
823
  const quote = await fetchWalletPaymentQuote({
513
824
  option: selectedOption,
514
825
  context: quoteContext,
515
826
  });
516
- if (cancelled)
827
+ if (cancelled) {
517
828
  return;
829
+ }
518
830
  setWalletPaymentState({
519
831
  quoteStatus: "ready",
520
832
  quote,
@@ -522,32 +834,37 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
522
834
  routeId: quote.routeId,
523
835
  quoteError: null,
524
836
  });
525
- const expiryTime = getActiveAttemptExpiryTime(preparedContext.payment, ensuredAttempt);
526
- if (expiryTime && expiryTime > Date.now()) {
527
- refreshTimer = setTimeout(() => {
528
- void loadQuote();
529
- }, Math.min(30_000, Math.max(1_000, expiryTime - Date.now())));
530
- }
837
+ configureWalletQuoteRefresh(walletAddress);
531
838
  }
532
839
  catch (error) {
533
- if (cancelled)
840
+ if (cancelled) {
534
841
  return;
842
+ }
535
843
  const message = error instanceof Error ? error.message : "Failed to load route quote";
536
844
  setWalletPaymentState({
537
845
  quoteStatus: "failed",
538
846
  quote: null,
539
847
  quoteError: message,
540
848
  });
849
+ clearQuoteRefresh({ preserveWalletAddress: true });
541
850
  }
542
851
  };
543
852
  void loadQuote();
544
853
  return () => {
545
854
  cancelled = true;
546
- clearRefreshTimer();
547
855
  };
548
- }, [buildContext, payment?.id, selectedOption?.id, wallet]);
856
+ }, [
857
+ account.address,
858
+ activeWallet,
859
+ buildContext,
860
+ cryptoCurrency,
861
+ goToView,
862
+ quoteLoadKey,
863
+ selectedOption,
864
+ walletPayment.walletAddress,
865
+ ]);
549
866
  const handleSelectOption = async (option) => {
550
- if (!wallet || !payment || !cryptoCurrency) {
867
+ if (!activeWallet || !payment || !cryptoCurrency) {
551
868
  goToView("failed", { reason: "wallet_not_connected" });
552
869
  return;
553
870
  }
@@ -562,25 +879,20 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
562
879
  quoteId: null,
563
880
  routeId: null,
564
881
  });
565
- const walletAddress = await wallet.getAddress();
882
+ const walletAddress = await activeWallet.getAddress();
566
883
  if (!walletAddress) {
567
884
  throw new Error("Failed to get wallet address");
568
885
  }
569
886
  const ensuredAttempt = await createWalletOptionPaymentAttempt(option, walletAddress, option.kind === "direct" ? null : walletPayment.quote);
570
- if (hasExpiredAttempt(payment, ensuredAttempt)) {
571
- throw new Error(PAYMENT_QUOTE_EXPIRED_MESSAGE);
572
- }
573
887
  const preparedContext = {
574
888
  ...(await buildContext(payment)),
575
889
  cryptoPaymentAttempt: ensuredAttempt,
576
890
  };
577
891
  if (option.kind === "direct") {
578
- await executeConnectedWalletPayment(wallet);
579
- const txHash = useCheckoutStore.getState().transfer.transactionHash;
892
+ const txHash = await executeTransfer(activeWallet);
580
893
  if (!txHash) {
581
- throw new Error("Missing transaction hash for direct wallet payment");
894
+ throw new Error("Failed to get transaction hash");
582
895
  }
583
- await confirmPayment(payment.id, { txHash });
584
896
  setWalletPaymentState({
585
897
  status: "submitted",
586
898
  sourceTxHash: txHash,
@@ -588,6 +900,22 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
588
900
  quoteId: null,
589
901
  routeId: null,
590
902
  });
903
+ goToView("paymentStatus");
904
+ void (async () => {
905
+ try {
906
+ await checkChainStatus(activeWallet);
907
+ await confirmDirectWalletPayment(txHash);
908
+ }
909
+ catch (error) {
910
+ const message = messageForWalletError(error, "Failed to confirm wallet payment");
911
+ setWalletPaymentState({
912
+ status: "failed",
913
+ error: message,
914
+ });
915
+ goToView("cryptoIntentWalletPaymentOptions");
916
+ }
917
+ })();
918
+ return;
591
919
  }
592
920
  else {
593
921
  const freshQuote = await fetchWalletPaymentQuote({
@@ -606,7 +934,7 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
606
934
  });
607
935
  const result = await executeWalletPaymentOption({
608
936
  option,
609
- wallet,
937
+ wallet: activeWallet,
610
938
  context: preparedContext,
611
939
  quote: freshQuote,
612
940
  });
@@ -633,48 +961,79 @@ const CryptoIntentWalletPaymentOptionsViewContent = () => {
633
961
  goToView("paymentStatus");
634
962
  }
635
963
  catch (error) {
636
- const message = error instanceof Error
637
- ? error.message
638
- : "Failed to execute wallet payment";
964
+ const message = messageForWalletError(error, "Failed to execute wallet payment");
639
965
  setWalletPaymentState({
640
966
  status: "failed",
641
967
  error: message,
642
968
  });
643
- goToView("failed", { reason: message });
644
969
  }
645
970
  finally {
646
971
  setExecutingId(null);
647
972
  setProcessing(false);
648
973
  }
649
974
  };
650
- return (_jsxs(ModalViewContainer, { ref: modalRef, children: [selectedOption ? (_jsx(Text, { size: "base", weight: "semibold", color: config.theme.font.color.primary, children: "Confirm your payment" })) : null, walletPayment.status === "failed" ? (_jsx(EmptyState, { children: _jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: walletPayment.error ||
651
- "We could not find wallet payment options right now." }) })) : null, walletPayment.status === "loading" ? (_jsx(EmptyState, { children: _jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: "Checking which tokens you can use..." }) })) : null, walletPayment.status === "ready" ||
652
- walletPayment.status === "executing" ? (_jsx(ContentStage, { children: !selectedOption ? (_jsxs(_Fragment, { children: [_jsxs(OptionsHeaderRow, { children: [_jsx(Text, { size: "base", weight: "semibold", color: config.theme.font.color.primary, children: "Choose how you want to pay." }), _jsx(OptionsHeaderLabel, { children: "Your Balance" })] }), _jsx(OptionsContainer, { children: walletPayment.options.map((option) => (_jsx(OptionCard, { onClick: () => handlePickOption(option), role: "button", "aria-pressed": walletPayment.selectedOptionId === option.id, children: _jsxs(OptionHeader, { children: [_jsxs(OptionHeaderLeft, { children: [_jsxs(TokenIconWrap, { children: [_jsx(TokenIcon, { "$token": option.fromTokenName === "ETH" ? "ETH" : "USD", "$iconUrl": option.fromTokenIconUrl, children: !option.fromTokenIconUrl
653
- ? getTokenMonogram(option.fromTokenName, option.fromTokenSymbol)
654
- : null }), _jsx(ChainBadge, { "$iconUrl": option.fromChainIconUrl, children: !option.fromChainIconUrl
655
- ? getTokenMonogram(option.fromChainName)
656
- : 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 ===
657
- "number" ? (_jsxs(Text, { size: "xs", color: config.theme.font.color.tertiary, children: ["~", option.estimatedDurationMinutes, " min"] })) : null] })] }) }, option.id))) }), _jsx(ModalBackButton, { view: "cryptoIntent", disabled: processing })] })) : (_jsxs(ConfirmScreen, { children: [_jsx(ConfirmMeta, { children: _jsxs(ConfirmAmount, { children: [_jsxs(TokenIconWrap, { children: [_jsx(TokenIcon, { "$token": selectedOption.fromTokenName === "ETH" ? "ETH" : "USD", "$iconUrl": selectedOption.fromTokenIconUrl, children: !selectedOption.fromTokenIconUrl
975
+ const handleRetryWalletPayment = () => {
976
+ if (selectedOption) {
977
+ if (walletPayment.sourceTxHash &&
978
+ useCheckoutStore.getState().transfer.chainStatus === "confirmed") {
979
+ setWalletPaymentState({ status: "submitted", error: null });
980
+ goToView("paymentStatus");
981
+ void confirmDirectWalletPayment(walletPayment.sourceTxHash);
982
+ return;
983
+ }
984
+ setWalletPaymentState({ status: "ready", error: null });
985
+ void handleSelectOption(selectedOption);
986
+ return;
987
+ }
988
+ const retry = async () => {
989
+ try {
990
+ await loadWalletPaymentOptions(() => false);
991
+ }
992
+ catch (error) {
993
+ handleWalletPaymentOptionsError(error);
994
+ }
995
+ finally {
996
+ setProcessing(false);
997
+ }
998
+ };
999
+ void retry();
1000
+ };
1001
+ const showWalletPill = account.isConnected &&
1002
+ Boolean(account.address) &&
1003
+ walletPayment.status !== "loading" &&
1004
+ walletPayment.status !== "failed";
1005
+ const walletAddressForPill = walletPayment.walletAddress ?? account.address ?? null;
1006
+ 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
658
1007
  ? getTokenMonogram(selectedOption.fromTokenName, selectedOption.fromTokenSymbol)
659
- : null }), _jsx(ChainBadge, { "$iconUrl": selectedOption.fromChainIconUrl, children: !selectedOption.fromChainIconUrl
660
- ? getTokenMonogram(selectedOption.fromChainName)
661
- : null })] }), _jsxs(ConfirmTextBlock, { children: [_jsx(Text, { size: "base", weight: "semibold", color: config.theme.font.color.primary, children: selectedOption.fromTokenName }), _jsxs(Text, { size: "sm", color: config.theme.font.color.secondary, children: ["On ", selectedOption.fromChainName] })] })] }) }), _jsxs(QuoteBlock, { children: [_jsxs(QuoteRow, { children: [_jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: "Cost" }), _jsx(Text, { size: "sm", weight: "semibold", color: config.theme.font.color.primary, children: formattedCost })] }), confirmationAmount?.amount ? (_jsxs(QuoteRow, { children: [_jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: "You Pay" }), _jsx(Text, { size: "sm", weight: "semibold", color: config.theme.font.color.primary, children: confirmationAmount.amount })] })) : null, walletPayment.quoteStatus === "loading" ? (_jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: "Fetching quote..." })) : null, walletPayment.quoteStatus === "failed" ? (_jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: walletPayment.quoteError ||
662
- "We couldn't fetch a quote right now." })) : null, typeof walletPayment.quote?.estimatedDurationMinutes ===
663
- "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] }), _jsx(ConfirmActions, { children: _jsx(StyledButton, { onClick: () => {
664
- if (selectedOption) {
665
- void handleSelectOption(selectedOption);
666
- }
667
- }, disabled: processing ||
668
- loading.CREATE_PAYMENT_ATTEMPT ||
669
- !selectedOption ||
670
- hasExpiredAttempt(payment, useCheckoutStore.getState().cryptoPaymentAttempt) ||
671
- walletPayment.quoteStatus === "loading" ||
672
- (selectedOption.kind !== "direct" &&
673
- walletPayment.quoteStatus !== "ready"), children: executingId === selectedOption.id
674
- ? "Preparing..."
675
- : walletPayment.quoteStatus === "loading"
676
- ? "Fetching quote..."
677
- : `Pay with ${selectedOption.fromTokenName}` }) })] }, selectedOption.id)) })) : null, selectedOption ? (_jsx(StyledButton, { variant: "secondary", onClick: handleReturnToOptions, disabled: processing, children: "Back" })) : null] }));
1008
+ : 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) => {
1009
+ event.stopPropagation();
1010
+ handleReturnToOptions();
1011
+ }, 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 }) })] })] }), _jsxs(PillDetailRow, { children: [_jsx(PillDetailLabel, { children: "Route" }), _jsx(PillDetailValue, { children: selectedOption.kind === "direct"
1012
+ ? "Direct transfer"
1013
+ : "Routed transfer" })] })] })) : null] })] })) : null, walletPayment.status === "failed" ? (_jsxs(ContentStage, { children: [_jsx(EmptyState, { children: _jsx(Text, { size: "sm", color: config.theme.font.color.secondary, children: walletPayment.error ||
1014
+ "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" }), _jsx(StyledButton, { variant: "secondary", onClick: handleChangeWallet, disabled: processing, children: "Change wallet" })] })) : null, walletPayment.status === "loading" ? (_jsxs(ContentStage, { children: [_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" ||
1015
+ walletPayment.status === "executing" ? (_jsx(ContentStage, { children: hasNoPaymentOptions ? (_jsxs(_Fragment, { children: [_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 && !showWalletPill ? (_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" }), _jsx(StyledButton, { variant: "secondary", onClick: handleChangeWallet, disabled: processing, children: "Change wallet" })] })) : !selectedOption ? (_jsxs(_Fragment, { children: [walletAddressForPill ? (_jsxs(ConnectedWalletRow, { children: [_jsxs(ConnectedWalletIdentity, { children: [_jsx(WalletDot, { "$iconUrl": connectorIcon, "aria-hidden": "true" }), _jsx(ConnectedWalletAddress, { children: formatAddress(walletAddressForPill) })] }), _jsx(WalletSwitchLink, { type: "button", onClick: handleChangeWallet, disabled: processing, "aria-label": "Switch wallet", title: "Switch wallet", children: _jsx(EditIcon, { 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
1016
+ ? getTokenMonogram(option.fromTokenName, option.fromTokenSymbol)
1017
+ : 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 ===
1018
+ "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 ===
1019
+ "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 ||
1020
+ "We couldn't fetch a quote right now." })] })) : null] }), _jsx(StyledButton, { onClick: () => {
1021
+ if (selectedOption) {
1022
+ void handleSelectOption(selectedOption);
1023
+ }
1024
+ }, disabled: processing ||
1025
+ loading.CREATE_PAYMENT_ATTEMPT ||
1026
+ !selectedOption ||
1027
+ walletPayment.quoteStatus === "loading" ||
1028
+ (selectedOption.kind !== "direct" &&
1029
+ walletPayment.quoteStatus !== "ready"), children: executingId === selectedOption.id
1030
+ ? "Preparing..."
1031
+ : walletPayment.quoteStatus === "loading"
1032
+ ? "Fetching quote..."
1033
+ : `Pay with ${selectedOption.fromTokenName}` }), _jsx(StyledButton, { variant: "secondary", onClick: handleReturnToOptions, disabled: processing, children: "Back" })] })) })) : null] }));
1034
+ };
1035
+ const CryptoIntentWalletPaymentOptionsViewContent = () => {
1036
+ return _jsx(CryptoIntentWalletPaymentOptionsAppKitViewContent, {});
678
1037
  };
679
1038
  export { CryptoIntentWalletPaymentOptionsViewContent };
680
1039
  //# sourceMappingURL=wallet-payment-options.js.map