@mintmoney/react 0.2.0-alpha.2 → 0.2.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/dist/css/styles.css +12 -1
  2. package/dist/esm/api/errors.js +89 -0
  3. package/dist/esm/api/errors.js.map +1 -0
  4. package/dist/esm/api/generated.js +825 -65
  5. package/dist/esm/api/generated.js.map +1 -1
  6. package/dist/esm/api/payments.js +26 -2
  7. package/dist/esm/api/payments.js.map +1 -1
  8. package/dist/esm/api/tokens.js +34 -0
  9. package/dist/esm/api/tokens.js.map +1 -0
  10. package/dist/esm/api/types.js.map +1 -1
  11. package/dist/esm/checkout/claimable-funds.js +20 -10
  12. package/dist/esm/checkout/claimable-funds.js.map +1 -1
  13. package/dist/esm/checkout/creation-error-modal.js +2 -2
  14. package/dist/esm/checkout/creation-error-modal.js.map +1 -1
  15. package/dist/esm/checkout/index.js +48 -8
  16. package/dist/esm/checkout/index.js.map +1 -1
  17. package/dist/esm/checkout/modal.js +22 -14
  18. package/dist/esm/checkout/modal.js.map +1 -1
  19. package/dist/esm/checkout/payment-status.js +68 -28
  20. package/dist/esm/checkout/payment-status.js.map +1 -1
  21. package/dist/esm/checkout/provider-status.js +9 -0
  22. package/dist/esm/checkout/provider-status.js.map +1 -0
  23. package/dist/esm/checkout/providers/checkout-wallet.js +140 -44
  24. package/dist/esm/checkout/providers/checkout-wallet.js.map +1 -1
  25. package/dist/esm/checkout/providers/wagmi-config.js +6 -3
  26. package/dist/esm/checkout/providers/wagmi-config.js.map +1 -1
  27. package/dist/esm/checkout/refund-notice.js +16 -0
  28. package/dist/esm/checkout/refund-notice.js.map +1 -0
  29. package/dist/esm/checkout/resume-state.js +147 -0
  30. package/dist/esm/checkout/resume-state.js.map +1 -1
  31. package/dist/esm/checkout/surplus-refund.js +12 -0
  32. package/dist/esm/checkout/surplus-refund.js.map +1 -1
  33. package/dist/esm/checkout/views/amount-header.js +1 -1
  34. package/dist/esm/checkout/views/amount-header.js.map +1 -1
  35. package/dist/esm/checkout/views/claimable-funds.js +22 -13
  36. package/dist/esm/checkout/views/claimable-funds.js.map +1 -1
  37. package/dist/esm/checkout/views/crypto-intent/direct-details.js +218 -890
  38. package/dist/esm/checkout/views/crypto-intent/direct-details.js.map +1 -1
  39. package/dist/esm/checkout/views/crypto-intent/manual-instruction-card.js +235 -0
  40. package/dist/esm/checkout/views/crypto-intent/manual-instruction-card.js.map +1 -0
  41. package/dist/esm/checkout/views/crypto-intent/manual-payment-summary.js +2 -26
  42. package/dist/esm/checkout/views/crypto-intent/manual-payment-summary.js.map +1 -1
  43. package/dist/esm/checkout/views/crypto-intent/manual-refresh.js +19 -0
  44. package/dist/esm/checkout/views/crypto-intent/manual-refresh.js.map +1 -0
  45. package/dist/esm/checkout/views/crypto-intent/manual-refund-preference.js +151 -23
  46. package/dist/esm/checkout/views/crypto-intent/manual-refund-preference.js.map +1 -1
  47. package/dist/esm/checkout/views/crypto-intent/manual-route-picker.js +295 -0
  48. package/dist/esm/checkout/views/crypto-intent/manual-route-picker.js.map +1 -0
  49. package/dist/esm/checkout/views/crypto-intent/manual-sources.js +155 -0
  50. package/dist/esm/checkout/views/crypto-intent/manual-sources.js.map +1 -0
  51. package/dist/esm/checkout/views/crypto-intent/manual-transfer-instructions.js +84 -0
  52. package/dist/esm/checkout/views/crypto-intent/manual-transfer-instructions.js.map +1 -0
  53. package/dist/esm/checkout/views/crypto-intent/payment-route-error.js +10 -0
  54. package/dist/esm/checkout/views/crypto-intent/payment-route-error.js.map +1 -0
  55. package/dist/esm/checkout/views/crypto-intent/processing.js +167 -24
  56. package/dist/esm/checkout/views/crypto-intent/processing.js.map +1 -1
  57. package/dist/esm/checkout/views/crypto-intent/success.js +74 -46
  58. package/dist/esm/checkout/views/crypto-intent/success.js.map +1 -1
  59. package/dist/esm/checkout/views/crypto-intent/wallet-payment-confirmation-amount.js +14 -24
  60. package/dist/esm/checkout/views/crypto-intent/wallet-payment-confirmation-amount.js.map +1 -1
  61. package/dist/esm/checkout/views/crypto-intent/wallet-payment-discovery.js +61 -0
  62. package/dist/esm/checkout/views/crypto-intent/wallet-payment-discovery.js.map +1 -0
  63. package/dist/esm/checkout/views/crypto-intent/wallet-payment-options.js +105 -627
  64. package/dist/esm/checkout/views/crypto-intent/wallet-payment-options.js.map +1 -1
  65. package/dist/esm/checkout/views/crypto-intent/wallet-payment-options.styles.js +506 -0
  66. package/dist/esm/checkout/views/crypto-intent/wallet-payment-options.styles.js.map +1 -0
  67. package/dist/esm/checkout/views/crypto-intent/wallet-select.js +4 -11
  68. package/dist/esm/checkout/views/crypto-intent/wallet-select.js.map +1 -1
  69. package/dist/esm/checkout/views/failed.js +62 -26
  70. package/dist/esm/checkout/views/failed.js.map +1 -1
  71. package/dist/esm/checkout/views/funding-timeline.js +255 -0
  72. package/dist/esm/checkout/views/funding-timeline.js.map +1 -0
  73. package/dist/esm/checkout/views/initial.js +25 -44
  74. package/dist/esm/checkout/views/initial.js.map +1 -1
  75. package/dist/esm/checkout/views/method-select.js +6 -4
  76. package/dist/esm/checkout/views/method-select.js.map +1 -1
  77. package/dist/esm/checkout/views/payment-follower.js +105 -0
  78. package/dist/esm/checkout/views/payment-follower.js.map +1 -0
  79. package/dist/esm/checkout/views/restart.js +8 -2
  80. package/dist/esm/checkout/views/restart.js.map +1 -1
  81. package/dist/esm/components/buttons/index.js +3 -2
  82. package/dist/esm/components/buttons/index.js.map +1 -1
  83. package/dist/esm/components/icons/search.js +5 -0
  84. package/dist/esm/components/icons/search.js.map +1 -0
  85. package/dist/esm/components/loading/index.js +2 -2
  86. package/dist/esm/components/loading/index.js.map +1 -1
  87. package/dist/esm/components/modals/modal-with-views.js +6 -12
  88. package/dist/esm/components/modals/modal-with-views.js.map +1 -1
  89. package/dist/esm/components/modals/modal.js +3 -3
  90. package/dist/esm/components/modals/modal.js.map +1 -1
  91. package/dist/esm/components/modals/transition-view.js +16 -0
  92. package/dist/esm/components/modals/transition-view.js.map +1 -0
  93. package/dist/esm/components/modals/use-modal-with-views.js +17 -19
  94. package/dist/esm/components/modals/use-modal-with-views.js.map +1 -1
  95. package/dist/esm/components/wallet-selector/wallets/wagmi/index.js +21 -2
  96. package/dist/esm/components/wallet-selector/wallets/wagmi/index.js.map +1 -1
  97. package/dist/esm/config.js.map +1 -1
  98. package/dist/esm/integrations/bitcoin-metamask.js +87 -0
  99. package/dist/esm/integrations/bitcoin-metamask.js.map +1 -0
  100. package/dist/esm/integrations/bitcoin-network.js +59 -0
  101. package/dist/esm/integrations/bitcoin-network.js.map +1 -0
  102. package/dist/esm/integrations/bitcoin-psbt.js +4 -0
  103. package/dist/esm/integrations/bitcoin-psbt.js.map +1 -0
  104. package/dist/esm/integrations/bitcoin-source.js +12 -0
  105. package/dist/esm/integrations/bitcoin-source.js.map +1 -0
  106. package/dist/esm/integrations/bitcoin-wallet.js +225 -0
  107. package/dist/esm/integrations/bitcoin-wallet.js.map +1 -0
  108. package/dist/esm/integrations/evm-chain.js +18 -0
  109. package/dist/esm/integrations/evm-chain.js.map +1 -1
  110. package/dist/esm/integrations/guarded-wallet-client.js +19 -0
  111. package/dist/esm/integrations/guarded-wallet-client.js.map +1 -0
  112. package/dist/esm/integrations/lifi.js +85 -38
  113. package/dist/esm/integrations/lifi.js.map +1 -1
  114. package/dist/esm/refund/index.js +216 -225
  115. package/dist/esm/refund/index.js.map +1 -1
  116. package/dist/esm/state/checkout/bitcoin-payment.js +253 -0
  117. package/dist/esm/state/checkout/bitcoin-payment.js.map +1 -0
  118. package/dist/esm/state/checkout/checkout-state.js +3 -9
  119. package/dist/esm/state/checkout/checkout-state.js.map +1 -1
  120. package/dist/esm/state/checkout/funding.js +5 -0
  121. package/dist/esm/state/checkout/funding.js.map +1 -0
  122. package/dist/esm/state/checkout/issuance-conflicts.js +29 -0
  123. package/dist/esm/state/checkout/issuance-conflicts.js.map +1 -0
  124. package/dist/esm/state/checkout/manual-route.js +10 -0
  125. package/dist/esm/state/checkout/manual-route.js.map +1 -0
  126. package/dist/esm/state/checkout/payment-attempt.js +44 -20
  127. package/dist/esm/state/checkout/payment-attempt.js.map +1 -1
  128. package/dist/esm/state/checkout/payment-lifecycle.js +9 -15
  129. package/dist/esm/state/checkout/payment-lifecycle.js.map +1 -1
  130. package/dist/esm/state/checkout/payment-observer.js +147 -0
  131. package/dist/esm/state/checkout/payment-observer.js.map +1 -0
  132. package/dist/esm/state/checkout/payment-phase.js +131 -0
  133. package/dist/esm/state/checkout/payment-phase.js.map +1 -0
  134. package/dist/esm/state/checkout/quote-countdown.js +26 -0
  135. package/dist/esm/state/checkout/quote-countdown.js.map +1 -0
  136. package/dist/esm/state/checkout/quote-lifecycle.js +145 -144
  137. package/dist/esm/state/checkout/quote-lifecycle.js.map +1 -1
  138. package/dist/esm/state/checkout/route-estimate.js +77 -0
  139. package/dist/esm/state/checkout/route-estimate.js.map +1 -0
  140. package/dist/esm/state/checkout/store.js +222 -258
  141. package/dist/esm/state/checkout/store.js.map +1 -1
  142. package/dist/esm/state/checkout/wallet-payment.js +123 -32
  143. package/dist/esm/state/checkout/wallet-payment.js.map +1 -1
  144. package/dist/esm/utils/string.js +2 -0
  145. package/dist/esm/utils/string.js.map +1 -1
  146. package/dist/esm/utils/token-amount.js +88 -0
  147. package/dist/esm/utils/token-amount.js.map +1 -0
  148. package/dist/esm/utils/wallet-errors.js +21 -4
  149. package/dist/esm/utils/wallet-errors.js.map +1 -1
  150. package/dist/types/api/errors.d.ts +37 -0
  151. package/dist/types/api/errors.d.ts.map +1 -0
  152. package/dist/types/api/generated.d.ts +4562 -707
  153. package/dist/types/api/generated.d.ts.map +1 -1
  154. package/dist/types/api/payments.d.ts +28 -1
  155. package/dist/types/api/payments.d.ts.map +1 -1
  156. package/dist/types/api/tokens.d.ts +6 -0
  157. package/dist/types/api/tokens.d.ts.map +1 -0
  158. package/dist/types/api/types.d.ts +28 -2
  159. package/dist/types/api/types.d.ts.map +1 -1
  160. package/dist/types/checkout/claimable-funds.d.ts +15 -2
  161. package/dist/types/checkout/claimable-funds.d.ts.map +1 -1
  162. package/dist/types/checkout/creation-error-modal.d.ts +2 -1
  163. package/dist/types/checkout/creation-error-modal.d.ts.map +1 -1
  164. package/dist/types/checkout/index.d.ts +21 -1
  165. package/dist/types/checkout/index.d.ts.map +1 -1
  166. package/dist/types/checkout/modal.d.ts +4 -1
  167. package/dist/types/checkout/modal.d.ts.map +1 -1
  168. package/dist/types/checkout/payment-status.d.ts +10 -2
  169. package/dist/types/checkout/payment-status.d.ts.map +1 -1
  170. package/dist/types/checkout/provider-status.d.ts +11 -0
  171. package/dist/types/checkout/provider-status.d.ts.map +1 -0
  172. package/dist/types/checkout/providers/checkout-wallet.d.ts +2 -3
  173. package/dist/types/checkout/providers/checkout-wallet.d.ts.map +1 -1
  174. package/dist/types/checkout/providers/wagmi-config.d.ts.map +1 -1
  175. package/dist/types/checkout/refund-notice.d.ts +7 -0
  176. package/dist/types/checkout/refund-notice.d.ts.map +1 -0
  177. package/dist/types/checkout/resume-state.d.ts +41 -0
  178. package/dist/types/checkout/resume-state.d.ts.map +1 -1
  179. package/dist/types/checkout/surplus-refund.d.ts +8 -0
  180. package/dist/types/checkout/surplus-refund.d.ts.map +1 -1
  181. package/dist/types/checkout/views/amount-header.d.ts.map +1 -1
  182. package/dist/types/checkout/views/claimable-funds.d.ts.map +1 -1
  183. package/dist/types/checkout/views/crypto-intent/direct-details.d.ts +3 -13
  184. package/dist/types/checkout/views/crypto-intent/direct-details.d.ts.map +1 -1
  185. package/dist/types/checkout/views/crypto-intent/manual-instruction-card.d.ts +10 -0
  186. package/dist/types/checkout/views/crypto-intent/manual-instruction-card.d.ts.map +1 -0
  187. package/dist/types/checkout/views/crypto-intent/manual-payment-summary.d.ts +4 -11
  188. package/dist/types/checkout/views/crypto-intent/manual-payment-summary.d.ts.map +1 -1
  189. package/dist/types/checkout/views/crypto-intent/manual-refresh.d.ts +4 -0
  190. package/dist/types/checkout/views/crypto-intent/manual-refresh.d.ts.map +1 -0
  191. package/dist/types/checkout/views/crypto-intent/manual-refund-preference.d.ts +14 -10
  192. package/dist/types/checkout/views/crypto-intent/manual-refund-preference.d.ts.map +1 -1
  193. package/dist/types/checkout/views/crypto-intent/manual-route-picker.d.ts +18 -0
  194. package/dist/types/checkout/views/crypto-intent/manual-route-picker.d.ts.map +1 -0
  195. package/dist/types/checkout/views/crypto-intent/manual-sources.d.ts +33 -0
  196. package/dist/types/checkout/views/crypto-intent/manual-sources.d.ts.map +1 -0
  197. package/dist/types/checkout/views/crypto-intent/manual-transfer-instructions.d.ts +18 -0
  198. package/dist/types/checkout/views/crypto-intent/manual-transfer-instructions.d.ts.map +1 -0
  199. package/dist/types/checkout/views/crypto-intent/payment-route-error.d.ts +2 -0
  200. package/dist/types/checkout/views/crypto-intent/payment-route-error.d.ts.map +1 -0
  201. package/dist/types/checkout/views/crypto-intent/processing.d.ts.map +1 -1
  202. package/dist/types/checkout/views/crypto-intent/success.d.ts +2 -1
  203. package/dist/types/checkout/views/crypto-intent/success.d.ts.map +1 -1
  204. package/dist/types/checkout/views/crypto-intent/wallet-payment-confirmation-amount.d.ts +8 -8
  205. package/dist/types/checkout/views/crypto-intent/wallet-payment-confirmation-amount.d.ts.map +1 -1
  206. package/dist/types/checkout/views/crypto-intent/wallet-payment-discovery.d.ts +17 -0
  207. package/dist/types/checkout/views/crypto-intent/wallet-payment-discovery.d.ts.map +1 -0
  208. package/dist/types/checkout/views/crypto-intent/wallet-payment-options.d.ts +2 -1
  209. package/dist/types/checkout/views/crypto-intent/wallet-payment-options.d.ts.map +1 -1
  210. package/dist/types/checkout/views/crypto-intent/wallet-payment-options.styles.d.ts +61 -0
  211. package/dist/types/checkout/views/crypto-intent/wallet-payment-options.styles.d.ts.map +1 -0
  212. package/dist/types/checkout/views/crypto-intent/wallet-select.d.ts +1 -2
  213. package/dist/types/checkout/views/crypto-intent/wallet-select.d.ts.map +1 -1
  214. package/dist/types/checkout/views/failed.d.ts +6 -0
  215. package/dist/types/checkout/views/failed.d.ts.map +1 -1
  216. package/dist/types/checkout/views/funding-timeline.d.ts +49 -0
  217. package/dist/types/checkout/views/funding-timeline.d.ts.map +1 -0
  218. package/dist/types/checkout/views/initial.d.ts +2 -4
  219. package/dist/types/checkout/views/initial.d.ts.map +1 -1
  220. package/dist/types/checkout/views/method-select.d.ts +2 -1
  221. package/dist/types/checkout/views/method-select.d.ts.map +1 -1
  222. package/dist/types/checkout/views/payment-follower.d.ts +31 -0
  223. package/dist/types/checkout/views/payment-follower.d.ts.map +1 -0
  224. package/dist/types/checkout/views/restart.d.ts +1 -1
  225. package/dist/types/checkout/views/restart.d.ts.map +1 -1
  226. package/dist/types/components/buttons/index.d.ts.map +1 -1
  227. package/dist/types/components/icons/search.d.ts +2 -0
  228. package/dist/types/components/icons/search.d.ts.map +1 -0
  229. package/dist/types/components/loading/index.d.ts +6 -1
  230. package/dist/types/components/loading/index.d.ts.map +1 -1
  231. package/dist/types/components/modals/modal-with-views.d.ts +2 -0
  232. package/dist/types/components/modals/modal-with-views.d.ts.map +1 -1
  233. package/dist/types/components/modals/modal.d.ts +2 -1
  234. package/dist/types/components/modals/modal.d.ts.map +1 -1
  235. package/dist/types/components/modals/transition-view.d.ts +2 -0
  236. package/dist/types/components/modals/transition-view.d.ts.map +1 -0
  237. package/dist/types/components/modals/use-modal-with-views.d.ts +2 -1
  238. package/dist/types/components/modals/use-modal-with-views.d.ts.map +1 -1
  239. package/dist/types/components/wallet-selector/domain.d.ts +1 -1
  240. package/dist/types/components/wallet-selector/domain.d.ts.map +1 -1
  241. package/dist/types/components/wallet-selector/wallets/wagmi/index.d.ts +1 -1
  242. package/dist/types/components/wallet-selector/wallets/wagmi/index.d.ts.map +1 -1
  243. package/dist/types/config.d.ts +1 -0
  244. package/dist/types/config.d.ts.map +1 -1
  245. package/dist/types/integrations/bitcoin-metamask.d.ts +11 -0
  246. package/dist/types/integrations/bitcoin-metamask.d.ts.map +1 -0
  247. package/dist/types/integrations/bitcoin-network.d.ts +13 -0
  248. package/dist/types/integrations/bitcoin-network.d.ts.map +1 -0
  249. package/dist/types/integrations/bitcoin-psbt.d.ts +5 -0
  250. package/dist/types/integrations/bitcoin-psbt.d.ts.map +1 -0
  251. package/dist/types/integrations/bitcoin-source.d.ts +12 -0
  252. package/dist/types/integrations/bitcoin-source.d.ts.map +1 -0
  253. package/dist/types/integrations/bitcoin-wallet.d.ts +63 -0
  254. package/dist/types/integrations/bitcoin-wallet.d.ts.map +1 -0
  255. package/dist/types/integrations/evm-chain.d.ts +5 -0
  256. package/dist/types/integrations/evm-chain.d.ts.map +1 -1
  257. package/dist/types/integrations/guarded-wallet-client.d.ts +4 -0
  258. package/dist/types/integrations/guarded-wallet-client.d.ts.map +1 -0
  259. package/dist/types/integrations/lifi.d.ts +22 -0
  260. package/dist/types/integrations/lifi.d.ts.map +1 -1
  261. package/dist/types/refund/index.d.ts +1 -1
  262. package/dist/types/refund/index.d.ts.map +1 -1
  263. package/dist/types/state/checkout/bitcoin-payment.d.ts +28 -0
  264. package/dist/types/state/checkout/bitcoin-payment.d.ts.map +1 -0
  265. package/dist/types/state/checkout/checkout-state.d.ts +42 -10
  266. package/dist/types/state/checkout/checkout-state.d.ts.map +1 -1
  267. package/dist/types/state/checkout/funding.d.ts +6 -0
  268. package/dist/types/state/checkout/funding.d.ts.map +1 -0
  269. package/dist/types/state/checkout/issuance-conflicts.d.ts +22 -0
  270. package/dist/types/state/checkout/issuance-conflicts.d.ts.map +1 -0
  271. package/dist/types/state/checkout/manual-route.d.ts +13 -0
  272. package/dist/types/state/checkout/manual-route.d.ts.map +1 -0
  273. package/dist/types/state/checkout/payment-attempt.d.ts +19 -1
  274. package/dist/types/state/checkout/payment-attempt.d.ts.map +1 -1
  275. package/dist/types/state/checkout/payment-lifecycle.d.ts +6 -8
  276. package/dist/types/state/checkout/payment-lifecycle.d.ts.map +1 -1
  277. package/dist/types/state/checkout/payment-observer.d.ts +41 -0
  278. package/dist/types/state/checkout/payment-observer.d.ts.map +1 -0
  279. package/dist/types/state/checkout/payment-phase.d.ts +116 -0
  280. package/dist/types/state/checkout/payment-phase.d.ts.map +1 -0
  281. package/dist/types/state/checkout/quote-countdown.d.ts +15 -0
  282. package/dist/types/state/checkout/quote-countdown.d.ts.map +1 -0
  283. package/dist/types/state/checkout/quote-lifecycle.d.ts +17 -6
  284. package/dist/types/state/checkout/quote-lifecycle.d.ts.map +1 -1
  285. package/dist/types/state/checkout/route-estimate.d.ts +38 -0
  286. package/dist/types/state/checkout/route-estimate.d.ts.map +1 -0
  287. package/dist/types/state/checkout/store.d.ts +25 -10
  288. package/dist/types/state/checkout/store.d.ts.map +1 -1
  289. package/dist/types/state/checkout/wallet-payment.d.ts +13 -2
  290. package/dist/types/state/checkout/wallet-payment.d.ts.map +1 -1
  291. package/dist/types/utils/string.d.ts +2 -0
  292. package/dist/types/utils/string.d.ts.map +1 -1
  293. package/dist/types/utils/token-amount.d.ts +18 -0
  294. package/dist/types/utils/token-amount.d.ts.map +1 -0
  295. package/dist/types/utils/wallet-errors.d.ts.map +1 -1
  296. package/package.json +3 -1
  297. package/dist/esm/refund/confirmation.js +0 -30
  298. package/dist/esm/refund/confirmation.js.map +0 -1
  299. package/dist/types/refund/confirmation.d.ts +0 -14
  300. package/dist/types/refund/confirmation.d.ts.map +0 -1
@@ -2,15 +2,20 @@ import { waitForTransactionReceipt } from "@wagmi/core";
2
2
  import { create } from "zustand";
3
3
  import { immer } from "zustand/middleware/immer";
4
4
  import { getCheckoutCryptoCurrencies } from "../../api/checkouts.js";
5
- import { createPaymentAttempt, createTestPaymentAttempt, getPaymentById, getRequiredSettlementConfig, } from "../../api/payments.js";
5
+ import { CheckoutRequestError, describeRequestFailure, getCryptoPayConflictCode, withConflictCopy, } from "../../api/errors.js";
6
+ import { createPaymentAttempt, createTestPaymentAttempt, estimateCryptoPay, getPaymentById, getRequiredSettlementConfig, } from "../../api/payments.js";
6
7
  import { PaymentStatus, } from "../../api/types.js";
7
8
  import { WagmiWalletInterface } from "../../components/wallet-selector/wallets/wagmi/index.js";
9
+ import { BITCOIN_CHAIN } from "../../integrations/bitcoin-source.js";
8
10
  import { resolveEvmChainId, switchEvmWalletChain, } from "../../integrations/evm-chain.js";
11
+ import { assertNoUncertainBitcoinSend, getUncertainBitcoinSend, isReturnedBitcoinRoute, observeBitcoinRecovery, retryBitcoinBroadcast, } from "./bitcoin-payment.js";
9
12
  import { ACTIONS, createInitialCheckoutState, } from "./checkout-state.js";
10
- import { buildWalletPaymentAttemptPayload } from "./payment-attempt.js";
11
- import { canCreateFreshAttempt, isAttemptStale, isPaymentPollingTerminal, } from "./payment-lifecycle.js";
12
- import { createQuoteLifecycle } from "./quote-lifecycle.js";
13
- const PAYMENT_NO_LONGER_PAYABLE_MESSAGE = "This payment is no longer payable.";
13
+ import { createIssuanceConflictRecovery } from "./issuance-conflicts.js";
14
+ import { buildManualRoutePayload, buildWalletEstimatePayload, buildWalletPaymentAttemptPayload, } from "./payment-attempt.js";
15
+ import { canCreateFreshAttempt, isAttemptStale, PAYMENT_NO_LONGER_PAYABLE_MESSAGE, } from "./payment-lifecycle.js";
16
+ import { createPaymentObserver } from "./payment-observer.js";
17
+ import { createQuoteLifecycle, } from "./quote-lifecycle.js";
18
+ import { buildDirectWalletQuote, buildWalletQuoteTarget, priceBitcoinWalletEstimate, priceEstimate, } from "./route-estimate.js";
14
19
  export { ACTIONS } from "./checkout-state.js";
15
20
  export const useCheckoutStore = create()(immer(() => createInitialCheckoutState()));
16
21
  const set = (fn) => {
@@ -40,59 +45,103 @@ const quoteLifecycle = createQuoteLifecycle({
40
45
  get,
41
46
  set,
42
47
  captureOpening: captureCheckoutOpening,
43
- createWalletAttempt: (...args) => createWalletOptionPaymentAttempt(...args),
48
+ priceWalletRoute: (...args) => priceWalletRoute(...args),
44
49
  createManualAttempt: (...args) => createManualDirectPaymentAttempt(...args),
45
50
  });
46
- export const { refreshQuote, syncQuote, configureWalletQuoteRefresh, configureManualQuoteRefresh, prepareWalletQuoteReplacement, clearQuoteRefresh, loadWalletPaymentQuote, setWalletPaymentOptions, resetWalletPaymentState, setWalletPaymentQuote, } = quoteLifecycle;
51
+ export const { refreshQuote, syncQuote, configureManualQuoteRefresh, prepareWalletQuoteReplacement, clearQuoteRefresh, loadWalletPaymentQuote, setWalletPaymentOptions, resetWalletPaymentState, beginBitcoinWalletPreparation, setWalletPaymentQuote, } = quoteLifecycle;
47
52
  const getCurrentCheckoutAttempt = (state = get()) => {
48
53
  return state.cryptoPaymentAttempt ?? state.payment?.payment_attempt ?? null;
49
54
  };
50
- const normalizeWalletAddress = (value) => value?.trim().toLowerCase() || null;
51
- const attemptMatchesSource = (attempt, source) => {
52
- const attemptSource = attempt?.routing?.source;
53
- return (attemptSource?.token?.toLowerCase() === source.token.toLowerCase() &&
54
- attemptSource?.chain?.toLowerCase() === source.chain.toLowerCase());
55
- };
56
- const getReusableCurrentAttemptForSource = (source) => {
57
- const attempt = getCurrentCheckoutAttempt();
58
- if (!attempt || isAttemptStale(attempt))
59
- return null;
60
- if (attempt.quote_request_id !== source.quoteRequestId)
61
- return null;
62
- if (!attemptMatchesSource(attempt, source))
63
- return null;
64
- return normalizeWalletAddress(attempt.refund_to) ===
65
- normalizeWalletAddress(source.sendingAddress)
66
- ? attempt
67
- : null;
68
- };
69
- const reuseCurrentAttempt = (attempt) => {
70
- set((state) => {
71
- state.cryptoPaymentAttempt = attempt;
72
- state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = null;
73
- state.loading[ACTIONS.CREATE_PAYMENT_ATTEMPT] = false;
74
- });
75
- syncQuote(get().payment, attempt);
76
- return attempt;
77
- };
55
+ /**
56
+ * A payment is issued once its only attempt exists (QCT D1). From then on its
57
+ * terms, including the refund recipient, are fixed.
58
+ */
59
+ export const isCheckoutIssued = (state = get()) => Boolean(getCurrentCheckoutAttempt(state));
60
+ /** The refund recipient frozen at issuance, or null before issuance. */
61
+ export const getFrozenRefundRecipient = (state = get()) => getCurrentCheckoutAttempt(state)?.refund_to ?? null;
62
+ /** Routes are priced against an issued payment's frozen asset, else the checkout's. */
63
+ const getRouteSettlement = (payment, state = get()) => getCurrentCheckoutAttempt(state)?.settlement_config ??
64
+ getRequiredSettlementConfig(payment);
78
65
  const withFreshAttempt = (payment, attempt) => {
79
66
  if (!payment) {
80
67
  return payment;
81
68
  }
82
69
  return {
83
70
  ...payment,
71
+ // Public-key calls receive the public attempt shape the payment read uses.
84
72
  payment_attempt: attempt,
85
73
  };
86
74
  };
87
- const getPaymentSnapshotAfterAttempt = async (paymentId, attempt, fallbackPayment) => {
75
+ // A read that has already observed newer instructions takes precedence over
76
+ // the issuing response. Matching timestamps cannot order two different quotes.
77
+ const reconcileIssuedAttempt = (issued, observed) => {
78
+ if (!observed)
79
+ return issued;
80
+ const issuedAt = Date.parse(issued.updated_at);
81
+ const observedAt = Date.parse(observed.updated_at);
82
+ const differentQuote = observed.attempt_id !== issued.attempt_id ||
83
+ (Boolean(observed.quote_request_id) &&
84
+ observed.quote_request_id !== issued.quote_request_id);
85
+ return observedAt > issuedAt || (differentQuote && !(observedAt < issuedAt))
86
+ ? observed
87
+ : issued;
88
+ };
89
+ const changedQuoteError = (message = "The payment quote changed. Try again for a fresh quote.") => new CheckoutRequestError(message, "PAYMENT_QUOTE_CHANGED");
90
+ export const assertWalletAttemptCurrent = (attempt) => {
91
+ const { payment } = get();
92
+ if (!payment || !canCreateFreshAttempt(payment)) {
93
+ throw new Error(PAYMENT_NO_LONGER_PAYABLE_MESSAGE);
94
+ }
95
+ assertNoUncertainBitcoinSend(payment.id);
96
+ if (isAttemptStale(attempt) ||
97
+ reconcileIssuedAttempt(attempt, getCurrentCheckoutAttempt()) !== attempt) {
98
+ quoteLifecycle.clearWalletQuoteRequestId(attempt.quote_request_id ?? "");
99
+ throw changedQuoteError();
100
+ }
101
+ };
102
+ const getPaymentSnapshotAfterAttempt = async (paymentId, fallbackPayment) => {
103
+ const beforeRead = get().payment;
88
104
  try {
89
- return await getPaymentById(paymentId);
105
+ const read = await getPaymentById(paymentId);
106
+ const current = get().payment;
107
+ if (current?.id !== paymentId || current === beforeRead)
108
+ return read;
109
+ const snapshot = current.status === "pending" && read.status !== "pending"
110
+ ? read
111
+ : current;
112
+ const attempt = current.payment_attempt
113
+ ? reconcileIssuedAttempt(current.payment_attempt, read.payment_attempt)
114
+ : read.payment_attempt;
115
+ return attempt
116
+ ? { ...snapshot, payment_attempt: attempt }
117
+ : snapshot;
90
118
  }
91
119
  catch {
92
- return withFreshAttempt(fallbackPayment, attempt);
120
+ const current = get().payment;
121
+ return current?.id === paymentId ? current : fallbackPayment;
93
122
  }
94
123
  };
95
- const updatePaymentSnapshot = (payment, attempt, extra) => {
124
+ const updatePaymentSnapshot = (payment, attempt, extra, syncQuoteWithSnapshot = true, verifiedRefund) => {
125
+ if (payment) {
126
+ const { walletPayment, cryptoPaymentAttempt } = get();
127
+ const submission = walletPayment.submission;
128
+ const returnedQuote = payment.payment_attempt?.quote_request_id;
129
+ const retireWallet = isReturnedBitcoinRoute(payment) &&
130
+ Boolean(returnedQuote) &&
131
+ returnedQuote === cryptoPaymentAttempt?.quote_request_id &&
132
+ walletPayment.status === "submitted" &&
133
+ (!submission || submission.kind === "bitcoin");
134
+ const resolvedQuote = observeBitcoinRecovery(payment, retireWallet && submission?.kind === "bitcoin"
135
+ ? submission.quoteId
136
+ : undefined, verifiedRefund);
137
+ if (walletPayment.status === "submitted" &&
138
+ (resolvedQuote
139
+ ? !submission ||
140
+ (submission.kind === "bitcoin" &&
141
+ submission.quoteId === resolvedQuote)
142
+ : retireWallet && !getUncertainBitcoinSend(payment)))
143
+ resetWalletPaymentState();
144
+ }
96
145
  set((state) => {
97
146
  state.payment = payment;
98
147
  state.cryptoPaymentAttempt =
@@ -103,8 +152,16 @@ const updatePaymentSnapshot = (payment, attempt, extra) => {
103
152
  });
104
153
  // Hydrate the current attempt from the payment snapshot so retry can resume
105
154
  // the existing quote context and refresh it instead of restarting selection.
106
- syncQuote(payment, get().cryptoPaymentAttempt);
155
+ if (syncQuoteWithSnapshot)
156
+ syncQuote(payment, get().cryptoPaymentAttempt);
107
157
  };
158
+ export const { followPayment } = createPaymentObserver({
159
+ get,
160
+ captureOpening: captureCheckoutOpening,
161
+ updatePaymentSnapshot: (payment, attempt, syncQuote, verifiedRefund) => updatePaymentSnapshot(payment, attempt, undefined, syncQuote, verifiedRefund),
162
+ hydrateCheckout: (payment) => hydrateCheckoutFromPayment(payment),
163
+ });
164
+ const recoverFromIssuanceConflict = createIssuanceConflictRecovery((payment) => updatePaymentSnapshot(payment));
108
165
  export const clearErrors = () => {
109
166
  set((state) => {
110
167
  Object.values(ACTIONS).forEach((action) => {
@@ -121,6 +178,11 @@ export const initialiseStore = async (payment) => {
121
178
  return;
122
179
  updatePaymentSnapshot(refreshedPayment);
123
180
  hydrateCheckoutFromPayment(refreshedPayment);
181
+ // Pending payments use their submission to resume the status view, which
182
+ // retries while polling. A settled payment might never start polling.
183
+ if (refreshedPayment.status !== PaymentStatus.PENDING) {
184
+ void retryBitcoinBroadcast(payment.id);
185
+ }
124
186
  }
125
187
  catch (err) {
126
188
  if (!canUpdate())
@@ -130,33 +192,33 @@ export const initialiseStore = async (payment) => {
130
192
  });
131
193
  }
132
194
  };
133
- export const createWalletOptionPaymentAttempt = async (
134
- // "direct" is a routing classification: the payer sends the settlement
135
- // asset on the settlement chain. It is not tied to manual vs wallet UX.
136
- option, sendingAddress, quote, ownsWallet) => {
137
- const canUpdate = captureCheckoutOpening(ownsWallet);
195
+ /**
196
+ * The checks every issuing call shares: the opening (and the caller's own
197
+ * lifetime) still owns the request, and the payment still takes instructions.
198
+ */
199
+ const beginIssuance = (owns) => {
200
+ const canUpdate = captureCheckoutOpening(owns);
138
201
  if (!canUpdate())
139
202
  throw new Error("Checkout is no longer active");
140
- const payment = useCheckoutStore.getState().payment;
141
- const paymentId = payment?.id;
142
- if (!paymentId) {
203
+ const payment = get().payment;
204
+ if (!payment?.id) {
143
205
  throw Error("Cannot create payment attempt without payment object.");
144
206
  }
145
207
  if (!canCreateFreshAttempt(payment)) {
146
208
  throw Error(PAYMENT_NO_LONGER_PAYABLE_MESSAGE);
147
209
  }
210
+ assertNoUncertainBitcoinSend(payment.id);
211
+ return { canUpdate, payment, paymentId: payment.id };
212
+ };
213
+ export const createWalletOptionPaymentAttempt = async (
214
+ // "direct" is a routing classification: the payer sends the settlement
215
+ // asset on the settlement chain. It is not tied to manual vs wallet UX.
216
+ option, sendingAddress, quote, ownsWallet) => {
217
+ const { canUpdate, payment, paymentId } = beginIssuance(ownsWallet);
148
218
  const quoteRequestId = quoteLifecycle.getWalletQuoteRequestId();
149
- if (option.kind === "direct") {
150
- const reusableAttempt = getReusableCurrentAttemptForSource({
151
- token: option.fromToken,
152
- chain: option.fromChain,
153
- sendingAddress,
154
- quoteRequestId,
155
- });
156
- if (reusableAttempt) {
157
- return reuseCurrentAttempt(reusableAttempt);
158
- }
159
- }
219
+ // The refund recipient is frozen at issuance: the first wallet Pay names the
220
+ // connected wallet, and later calls never send it (QCT D1, D7).
221
+ const refundTo = isCheckoutIssued() ? null : sendingAddress;
160
222
  try {
161
223
  set((state) => {
162
224
  state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = null;
@@ -168,132 +230,140 @@ option, sendingAddress, quote, ownsWallet) => {
168
230
  quote,
169
231
  requiredConfirmations: 1,
170
232
  quoteRequestId,
233
+ refundTo,
171
234
  });
172
235
  const attempt = await createPaymentAttempt(paymentId, attemptPayload, 1);
173
236
  if (!canUpdate())
174
237
  return attempt;
175
238
  if (attempt.quote_request_id !== quoteRequestId) {
176
- throw new Error("Could not get a fresh payment quote. Please try again.");
239
+ throw changedQuoteError("Could not get a fresh payment quote. Please try again.");
177
240
  }
178
- const refreshedPayment = await getPaymentSnapshotAfterAttempt(paymentId, attempt, payment);
241
+ const refreshedPayment = await getPaymentSnapshotAfterAttempt(paymentId, payment);
179
242
  if (!canUpdate())
180
243
  return attempt;
181
- updatePaymentSnapshot(refreshedPayment, attempt, (state) => {
244
+ const currentAttempt = reconcileIssuedAttempt(attempt, refreshedPayment.payment_attempt);
245
+ updatePaymentSnapshot(withFreshAttempt(refreshedPayment, currentAttempt), currentAttempt, (state) => {
182
246
  state.retrySession = false;
183
247
  state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = null;
184
248
  state.loading[ACTIONS.CREATE_PAYMENT_ATTEMPT] = false;
185
249
  });
250
+ if (currentAttempt !== attempt)
251
+ throw changedQuoteError();
186
252
  return attempt;
187
253
  }
188
254
  catch (err) {
189
255
  if (!canUpdate())
190
256
  throw err;
191
- const error = err;
257
+ if (getCryptoPayConflictCode(err) === "PAYMENT_QUOTE_CHANGED") {
258
+ quoteLifecycle.clearWalletQuoteRequestId(quoteRequestId);
259
+ }
260
+ const error = await recoverFromIssuanceConflict(err, paymentId, canUpdate, [
261
+ "REFUND_RECIPIENT_FIXED",
262
+ ]);
263
+ if (!canUpdate())
264
+ throw error;
192
265
  set((state) => {
193
- state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = error.message;
266
+ state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = describeRequestFailure(error, "Failed to create payment attempt");
194
267
  state.loading[ACTIONS.CREATE_PAYMENT_ATTEMPT] = false;
195
268
  });
196
269
  throw error;
197
270
  }
198
271
  };
199
272
  export const createManualDirectPaymentAttempt = async (sendingAddress = "", confirmations = 1, refundTo, options = {}, ownsQuote) => {
200
- const canUpdate = captureCheckoutOpening(ownsQuote);
201
- if (!canUpdate())
202
- throw new Error("Checkout is no longer active");
203
- const payment = useCheckoutStore.getState().payment;
204
- const paymentId = payment?.id;
205
- if (!paymentId) {
206
- throw Error("Cannot create payment attempt without payment object.");
207
- }
208
- if (!canCreateFreshAttempt(payment)) {
209
- throw Error(PAYMENT_NO_LONGER_PAYABLE_MESSAGE);
210
- }
211
- const settlementConfig = getRequiredSettlementConfig(payment);
273
+ const { canUpdate, payment, paymentId } = beginIssuance(ownsQuote);
274
+ const settlementConfig = getRouteSettlement(payment);
212
275
  const source = options.source ?? {
213
276
  asset: settlementConfig.asset,
214
277
  chain: settlementConfig.chain,
215
278
  };
216
279
  const normalizedSendingAddress = sendingAddress.trim();
217
- const effectiveRefundTo = refundTo?.trim() || normalizedSendingAddress || null;
218
- const routingType = source.chain !== settlementConfig.chain
219
- ? "bridge"
220
- : source.asset !== settlementConfig.asset
221
- ? "swap"
222
- : "direct";
280
+ // The refund recipient is frozen at issuance: only the first issuing call
281
+ // names it (the manual refund field, else the checkout fallback). Later
282
+ // reveals and refreshes never send it (QCT D1, D7).
283
+ const refundRecipient = isCheckoutIssued()
284
+ ? {}
285
+ : { refund_to: refundTo?.trim() || normalizedSendingAddress || null };
223
286
  const attemptPayload = {
224
- mode: options.mode,
287
+ ...buildManualRoutePayload(source, settlementConfig, options.mode),
225
288
  ...(normalizedSendingAddress
226
289
  ? { sendingAddress: normalizedSendingAddress }
227
290
  : {}),
228
- refund_to: effectiveRefundTo,
291
+ ...refundRecipient,
229
292
  required_confirmations: confirmations,
230
- source: options.mode === "relay_deposit"
231
- ? {
232
- token: source.asset,
233
- chain: source.chain,
234
- }
235
- : undefined,
236
- routing: {
237
- type: routingType,
238
- source: {
239
- token: source.asset,
240
- chain: source.chain,
241
- },
242
- },
243
293
  };
244
- const attempt = await createPaymentAttempt(paymentId, attemptPayload);
294
+ let attempt;
295
+ try {
296
+ attempt = await createPaymentAttempt(paymentId, attemptPayload);
297
+ }
298
+ catch (err) {
299
+ if (!canUpdate())
300
+ throw err;
301
+ // Revealed instructions refresh through this call, so a closed payment is
302
+ // read again: it may hold the payer's funds rather than need a new link.
303
+ throw await recoverFromIssuanceConflict(err, paymentId, canUpdate, [
304
+ "REFUND_RECIPIENT_FIXED",
305
+ "PAYMENT_REQUIRES_NEW_LINK",
306
+ ]);
307
+ }
245
308
  if (!canUpdate())
246
309
  return attempt;
247
- const refreshedPayment = await getPaymentSnapshotAfterAttempt(paymentId, attempt, payment);
310
+ const refreshedPayment = await getPaymentSnapshotAfterAttempt(paymentId, payment);
248
311
  if (!canUpdate())
249
312
  return attempt;
250
- updatePaymentSnapshot(refreshedPayment, attempt, (state) => {
313
+ const currentAttempt = reconcileIssuedAttempt(attempt, refreshedPayment.payment_attempt);
314
+ updatePaymentSnapshot(withFreshAttempt(refreshedPayment, currentAttempt), currentAttempt, (state) => {
251
315
  state.retrySession = false;
252
316
  });
253
317
  return attempt;
254
318
  };
255
- export const createSuccessfulTestPaymentAttempt = async () => {
256
- const canUpdate = captureCheckoutOpening();
257
- const paymentId = useCheckoutStore.getState().payment?.id;
258
- if (!paymentId) {
259
- throw Error("Cannot create test payment attempt without payment object.");
319
+ /** Prices a selected wallet route without issuing payment instructions. */
320
+ export const priceWalletRoute = async (option, walletAddress, ownsQuote) => {
321
+ const canUpdate = captureCheckoutOpening(ownsQuote);
322
+ if (!canUpdate())
323
+ throw new Error("Checkout is no longer active");
324
+ const payment = get().payment;
325
+ if (!payment) {
326
+ throw new Error("Cannot price a route without payment object.");
260
327
  }
328
+ let estimate;
261
329
  try {
262
- set((state) => {
263
- state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = null;
264
- state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = true;
265
- });
266
- const currentPayment = useCheckoutStore.getState().payment;
267
- if (!currentPayment) {
268
- throw Error("Cannot create test payment attempt without payment object.");
269
- }
270
- const attempt = await createTestPaymentAttempt(paymentId, "0xsuccess", currentPayment);
271
- if (!canUpdate())
272
- return;
273
- const payment = await getPaymentById(paymentId);
274
- if (!canUpdate())
275
- return;
276
- updatePaymentSnapshot(payment, attempt, (state) => {
277
- state.retrySession = false;
278
- state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = null;
279
- state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = false;
280
- });
330
+ estimate = await estimateCryptoPay(payment.id, buildWalletEstimatePayload({ option, sendingAddress: walletAddress }));
281
331
  }
282
332
  catch (err) {
283
- if (!canUpdate())
284
- return;
285
- const error = err;
286
- set((state) => {
287
- state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = error.message;
288
- state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = false;
289
- });
290
- throw error;
333
+ throw withConflictCopy(err);
334
+ }
335
+ assertNoUncertainBitcoinSend(payment.id);
336
+ if (option.fromChain === BITCOIN_CHAIN) {
337
+ return priceBitcoinWalletEstimate(estimate);
291
338
  }
339
+ const attempt = getCurrentCheckoutAttempt();
340
+ const priced = await priceEstimate(estimate, getRouteSettlement(payment), attempt);
341
+ if (option.kind === "direct") {
342
+ return {
343
+ quote: { kind: "quoted", quote: buildDirectWalletQuote(option, priced) },
344
+ expiresAt: priced.expiresAt,
345
+ };
346
+ }
347
+ // Keep routed-quote loading behind a dynamic import so the checkout store
348
+ // does not eagerly pull the LI.FI integration path into manual-only flows.
349
+ const { fetchWalletRouteQuote } = await import("../../integrations/index.js");
350
+ const quote = await fetchWalletRouteQuote({
351
+ option,
352
+ walletAddress,
353
+ target: buildWalletQuoteTarget({
354
+ priced,
355
+ attempt: getCurrentCheckoutAttempt(),
356
+ settlement: getRouteSettlement(payment),
357
+ walletAddress,
358
+ }),
359
+ });
360
+ return { quote: { kind: "quoted", quote }, expiresAt: priced.expiresAt };
292
361
  };
293
- export const createFailedTestPaymentAttempt = async () => {
362
+ // A test payment settles or fails through the transaction hash it reports.
363
+ const createSimulatedTestPaymentAttempt = async (txHash) => {
294
364
  const canUpdate = captureCheckoutOpening();
295
- const paymentId = useCheckoutStore.getState().payment?.id;
296
- if (!paymentId) {
365
+ const payment = get().payment;
366
+ if (!payment?.id) {
297
367
  throw Error("Cannot create test payment attempt without payment object.");
298
368
  }
299
369
  try {
@@ -301,17 +371,13 @@ export const createFailedTestPaymentAttempt = async () => {
301
371
  state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = null;
302
372
  state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = true;
303
373
  });
304
- const currentPayment = useCheckoutStore.getState().payment;
305
- if (!currentPayment) {
306
- throw Error("Cannot create test payment attempt without payment object.");
307
- }
308
- const attempt = await createTestPaymentAttempt(paymentId, "0xfail", currentPayment);
374
+ const attempt = await createTestPaymentAttempt(payment.id, txHash, payment);
309
375
  if (!canUpdate())
310
376
  return;
311
- const payment = await getPaymentById(paymentId);
377
+ const refreshedPayment = await getPaymentById(payment.id);
312
378
  if (!canUpdate())
313
379
  return;
314
- updatePaymentSnapshot(payment, attempt, (state) => {
380
+ updatePaymentSnapshot(refreshedPayment, attempt, (state) => {
315
381
  state.retrySession = false;
316
382
  state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = null;
317
383
  state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = false;
@@ -328,6 +394,8 @@ export const createFailedTestPaymentAttempt = async () => {
328
394
  throw error;
329
395
  }
330
396
  };
397
+ export const createSuccessfulTestPaymentAttempt = () => createSimulatedTestPaymentAttempt("0xsuccess");
398
+ export const createFailedTestPaymentAttempt = () => createSimulatedTestPaymentAttempt("0xfail");
331
399
  export function getAvailableCheckoutMethods(checkout) {
332
400
  const methods = [];
333
401
  if (checkout.checkout_config.crypto?.enabled) {
@@ -368,53 +436,7 @@ export const hydrateCheckoutFromPayment = (payment) => {
368
436
  });
369
437
  }
370
438
  };
371
- export const getPayment = async () => {
372
- const canUpdate = captureCheckoutOpening();
373
- const ACTION = ACTIONS.GET_PAYMENT;
374
- set((state) => {
375
- state.loading[ACTION] = true;
376
- state.error[ACTION] = null;
377
- });
378
- const payment = get().payment;
379
- if (!payment) {
380
- set((state) => {
381
- state.loading[ACTION] = false;
382
- state.error[ACTION] = "No payment found";
383
- });
384
- return null;
385
- }
386
- try {
387
- const resp = await getPaymentById(payment.id);
388
- if (!canUpdate())
389
- return null;
390
- if (resp) {
391
- updatePaymentSnapshot(resp);
392
- set((state) => {
393
- state.loading[ACTION] = false;
394
- state.error[ACTION] = null;
395
- });
396
- hydrateCheckoutFromPayment(resp);
397
- return resp;
398
- }
399
- else {
400
- set((state) => {
401
- state.loading[ACTION] = false;
402
- state.error[ACTION] = "Failed to load payment";
403
- });
404
- return null;
405
- }
406
- }
407
- catch (error) {
408
- if (!canUpdate())
409
- return null;
410
- set((state) => {
411
- state.loading[ACTION] = false;
412
- state.error[ACTION] = "Failed to load payment";
413
- });
414
- return null;
415
- }
416
- };
417
- export const executeTransfer = async (wallet, ownsWallet) => {
439
+ export const executeTransfer = async (wallet, ownsWallet, beforeSign) => {
418
440
  const canExecute = captureCheckoutOpening(ownsWallet);
419
441
  if (!canExecute())
420
442
  throw new Error("Checkout is no longer active");
@@ -432,6 +454,7 @@ export const executeTransfer = async (wallet, ownsWallet) => {
432
454
  state.transfer.chainStatus = "pending";
433
455
  });
434
456
  try {
457
+ beforeSign?.();
435
458
  const settlementChainHex = state.cryptoPaymentAttempt.settlement_config.chain_hex;
436
459
  const targetChainId = resolveEvmChainId(settlementChainHex);
437
460
  if (targetChainId && wallet.switchChain) {
@@ -447,7 +470,8 @@ export const executeTransfer = async (wallet, ownsWallet) => {
447
470
  const transfer = {
448
471
  sendingAddress: address,
449
472
  destinationAddress: state.cryptoPaymentAttempt.destination_address,
450
- amount: state.cryptoPaymentAttempt.amount,
473
+ amount: state.cryptoPaymentAttempt.amount_to_pay ??
474
+ state.cryptoPaymentAttempt.amount,
451
475
  evm: {
452
476
  implementationAddress: state.cryptoPaymentAttempt.settlement_token_address,
453
477
  assetName: state.cryptoPaymentAttempt.settlement_config.asset_name,
@@ -456,7 +480,8 @@ export const executeTransfer = async (wallet, ownsWallet) => {
456
480
  if (!canExecute()) {
457
481
  throw new Error("Wallet connection changed. Connect again before paying.");
458
482
  }
459
- const txHash = await wallet.executeTransfer(transfer);
483
+ beforeSign?.();
484
+ const txHash = await wallet.executeTransfer(transfer, beforeSign);
460
485
  if (!canExecute())
461
486
  return txHash;
462
487
  if (!txHash) {
@@ -483,6 +508,11 @@ export const executeTransfer = async (wallet, ownsWallet) => {
483
508
  throw error instanceof Error ? error : new Error(errorMessage);
484
509
  }
485
510
  };
511
+ export class TransferRevertedError extends Error {
512
+ constructor() {
513
+ super("Transaction reverted before confirmation");
514
+ }
515
+ }
486
516
  export const checkChainStatus = async (wallet, submitted) => {
487
517
  const ACTION = ACTIONS.CHECK_CHAIN_STATUS;
488
518
  const state = get();
@@ -516,7 +546,7 @@ export const checkChainStatus = async (wallet, submitted) => {
516
546
  confirmations: 1,
517
547
  });
518
548
  if (receipt.status === "reverted") {
519
- throw new Error("Transaction reverted before confirmation");
549
+ throw new TransferRevertedError();
520
550
  }
521
551
  if (canUpdate())
522
552
  set((state) => {
@@ -549,70 +579,6 @@ export const resetTransfer = () => {
549
579
  };
550
580
  });
551
581
  };
552
- export const startPaymentPolling = (onPaymentStatusChange, confirmationStatus = PaymentStatus.PAID) => {
553
- const ACTION = ACTIONS.POLL_PAYMENT;
554
- const POLL_INTERVAL = 5000;
555
- let pollInterval = null;
556
- let stopped = false;
557
- const canUpdate = captureCheckoutOpening(() => !stopped);
558
- const pollPaymentStatus = async () => {
559
- if (!canUpdate()) {
560
- stopPolling();
561
- return;
562
- }
563
- const state = get();
564
- if (!state.polling.isPolling)
565
- return;
566
- set((state) => {
567
- state.polling.pollCount++;
568
- state.polling.lastPollTime = Date.now();
569
- });
570
- try {
571
- const updatedPayment = await getPayment();
572
- if (!canUpdate() || !updatedPayment) {
573
- return;
574
- }
575
- if (isPaymentPollingTerminal(updatedPayment.status, confirmationStatus)) {
576
- onPaymentStatusChange(updatedPayment.status);
577
- stopPolling();
578
- }
579
- }
580
- catch (error) {
581
- console.error(`[Payment Poll] Error fetching payment status (poll #${state.polling.pollCount}):`, error);
582
- }
583
- };
584
- const stopPolling = () => {
585
- const owned = canUpdate();
586
- stopped = true;
587
- if (pollInterval) {
588
- clearInterval(pollInterval);
589
- pollInterval = null;
590
- }
591
- if (owned)
592
- stopPaymentPolling();
593
- };
594
- set((state) => {
595
- state.polling.isPolling = true;
596
- state.polling.pollCount = 0;
597
- state.polling.lastPollTime = null;
598
- state.loading[ACTION] = true;
599
- state.error[ACTION] = null;
600
- });
601
- // Set up interval for subsequent polls
602
- pollInterval = setInterval(pollPaymentStatus, POLL_INTERVAL);
603
- void pollPaymentStatus();
604
- return {
605
- stop: stopPolling,
606
- };
607
- };
608
- export const stopPaymentPolling = () => {
609
- set((state) => {
610
- state.polling.isPolling = false;
611
- state.polling.pollCount = 0;
612
- state.polling.lastPollTime = null;
613
- state.loading[ACTIONS.POLL_PAYMENT] = false;
614
- });
615
- };
616
582
  export const resetCheckoutStore = (payment = null) => {
617
583
  checkoutOpening += 1;
618
584
  quoteLifecycle.dispose();
@@ -635,7 +601,6 @@ export const resetCheckoutSessionForRetry = () => {
635
601
  cryptoPaymentAttempt: initial.cryptoPaymentAttempt,
636
602
  processing: initial.processing,
637
603
  transfer: initial.transfer,
638
- polling: initial.polling,
639
604
  walletPayment: initial.walletPayment,
640
605
  quote: initial.quote,
641
606
  });
@@ -643,7 +608,6 @@ export const resetCheckoutSessionForRetry = () => {
643
608
  ACTIONS.CREATE_PAYMENT_ATTEMPT,
644
609
  ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT,
645
610
  ACTIONS.EXECUTE_TRANSFER,
646
- ACTIONS.POLL_PAYMENT,
647
611
  ACTIONS.CHECK_CHAIN_STATUS,
648
612
  ]) {
649
613
  state.error[action] = initial.error[action];