@mintmoney/react 0.1.0-alpha.8 → 0.2.0-alpha.0

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 (340) hide show
  1. package/README.md +13 -88
  2. package/dist/css/styles.css +168 -7
  3. package/dist/docs/customisation.md +67 -0
  4. package/dist/docs/overview.md +19 -0
  5. package/dist/docs/quickstart.md +171 -0
  6. package/dist/esm/api/checkouts.js +13 -12
  7. package/dist/esm/api/checkouts.js.map +1 -1
  8. package/dist/esm/api/generated.js +961 -51
  9. package/dist/esm/api/generated.js.map +1 -1
  10. package/dist/esm/api/index.js +2 -1
  11. package/dist/esm/api/index.js.map +1 -1
  12. package/dist/esm/api/payments.js +74 -11
  13. package/dist/esm/api/payments.js.map +1 -1
  14. package/dist/esm/api/types.js +7 -1
  15. package/dist/esm/api/types.js.map +1 -1
  16. package/dist/esm/checkout/container.js +1 -1
  17. package/dist/esm/checkout/index.js +74 -8
  18. package/dist/esm/checkout/index.js.map +1 -1
  19. package/dist/esm/checkout/launcher.js +6 -0
  20. package/dist/esm/checkout/launcher.js.map +1 -0
  21. package/dist/esm/checkout/modal.js +65 -36
  22. package/dist/esm/checkout/modal.js.map +1 -1
  23. package/dist/esm/checkout/providers/wagmi-config.js +108 -0
  24. package/dist/esm/checkout/providers/wagmi-config.js.map +1 -0
  25. package/dist/esm/checkout/providers/wallet-connect-resume.js +129 -0
  26. package/dist/esm/checkout/providers/wallet-connect-resume.js.map +1 -0
  27. package/dist/esm/checkout/resume-state.js +82 -0
  28. package/dist/esm/checkout/resume-state.js.map +1 -0
  29. package/dist/esm/checkout/surplus-refund.js +38 -0
  30. package/dist/esm/checkout/surplus-refund.js.map +1 -0
  31. package/dist/esm/checkout/views/amount-header.js +82 -0
  32. package/dist/esm/checkout/views/amount-header.js.map +1 -0
  33. package/dist/esm/checkout/views/back.js +2 -2
  34. package/dist/esm/checkout/views/back.js.map +1 -1
  35. package/dist/esm/checkout/views/crypto-intent/direct-details.js +1037 -12
  36. package/dist/esm/checkout/views/crypto-intent/direct-details.js.map +1 -1
  37. package/dist/esm/checkout/views/crypto-intent/manual-payment-summary.js +112 -0
  38. package/dist/esm/checkout/views/crypto-intent/manual-payment-summary.js.map +1 -0
  39. package/dist/esm/checkout/views/crypto-intent/manual-refund-preference.js +69 -0
  40. package/dist/esm/checkout/views/crypto-intent/manual-refund-preference.js.map +1 -0
  41. package/dist/esm/checkout/views/crypto-intent/methods.js +166 -18
  42. package/dist/esm/checkout/views/crypto-intent/methods.js.map +1 -1
  43. package/dist/esm/checkout/views/crypto-intent/processing.js +97 -27
  44. package/dist/esm/checkout/views/crypto-intent/processing.js.map +1 -1
  45. package/dist/esm/checkout/views/crypto-intent/success.js +87 -11
  46. package/dist/esm/checkout/views/crypto-intent/success.js.map +1 -1
  47. package/dist/esm/checkout/views/crypto-intent/test-payment.js +35 -0
  48. package/dist/esm/checkout/views/crypto-intent/test-payment.js.map +1 -0
  49. package/dist/esm/checkout/views/crypto-intent/wallet-payment-confirmation-amount.js +30 -0
  50. package/dist/esm/checkout/views/crypto-intent/wallet-payment-confirmation-amount.js.map +1 -0
  51. package/dist/esm/checkout/views/crypto-intent/wallet-payment-options.js +1207 -0
  52. package/dist/esm/checkout/views/crypto-intent/wallet-payment-options.js.map +1 -0
  53. package/dist/esm/checkout/views/crypto-intent/wallet-select.js +166 -0
  54. package/dist/esm/checkout/views/crypto-intent/wallet-select.js.map +1 -0
  55. package/dist/esm/checkout/views/failed.js +108 -0
  56. package/dist/esm/checkout/views/failed.js.map +1 -0
  57. package/dist/esm/checkout/views/initial.js +62 -12
  58. package/dist/esm/checkout/views/initial.js.map +1 -1
  59. package/dist/esm/checkout/views/method-select.js +22 -4
  60. package/dist/esm/checkout/views/method-select.js.map +1 -1
  61. package/dist/esm/checkout/views/restart.js +12 -0
  62. package/dist/esm/checkout/views/restart.js.map +1 -0
  63. package/dist/esm/components/buttons/async-button.js +16 -0
  64. package/dist/esm/components/buttons/async-button.js.map +1 -0
  65. package/dist/esm/components/buttons/index.js +102 -16
  66. package/dist/esm/components/buttons/index.js.map +1 -1
  67. package/dist/esm/components/buttons/use-async-button.js +44 -0
  68. package/dist/esm/components/buttons/use-async-button.js.map +1 -0
  69. package/dist/esm/components/crypto/currency-selector.js +26 -0
  70. package/dist/esm/components/crypto/currency-selector.js.map +1 -0
  71. package/dist/esm/components/icons/alert.js +20 -0
  72. package/dist/esm/components/icons/alert.js.map +1 -0
  73. package/dist/esm/components/icons/checkMark.js.map +1 -1
  74. package/dist/esm/components/icons/clipboard-add.js +20 -0
  75. package/dist/esm/components/icons/clipboard-add.js.map +1 -0
  76. package/dist/esm/components/icons/clipboard-check.js +20 -0
  77. package/dist/esm/components/icons/clipboard-check.js.map +1 -0
  78. package/dist/esm/components/icons/clock.js +4 -0
  79. package/dist/esm/components/icons/clock.js.map +1 -0
  80. package/dist/esm/components/icons/close.js.map +1 -1
  81. package/dist/esm/components/icons/edit.js +6 -0
  82. package/dist/esm/components/icons/edit.js.map +1 -0
  83. package/dist/esm/components/icons/index.js +9 -0
  84. package/dist/esm/components/icons/index.js.map +1 -1
  85. package/dist/esm/components/icons/link.js +20 -0
  86. package/dist/esm/components/icons/link.js.map +1 -0
  87. package/dist/esm/components/icons/loading.js +26 -0
  88. package/dist/esm/components/icons/loading.js.map +1 -0
  89. package/dist/esm/components/icons/log-out.js +6 -0
  90. package/dist/esm/components/icons/log-out.js.map +1 -0
  91. package/dist/esm/components/icons/send.js +6 -0
  92. package/dist/esm/components/icons/send.js.map +1 -0
  93. package/dist/esm/components/index.js +1 -0
  94. package/dist/esm/components/index.js.map +1 -1
  95. package/dist/esm/components/inputs/index.js +47 -0
  96. package/dist/esm/components/inputs/index.js.map +1 -0
  97. package/dist/esm/components/lists/index.js.map +1 -1
  98. package/dist/esm/components/loading/index.js.map +1 -1
  99. package/dist/esm/components/modals/modal-with-views.js +7 -4
  100. package/dist/esm/components/modals/modal-with-views.js.map +1 -1
  101. package/dist/esm/components/modals/modal.js +3 -3
  102. package/dist/esm/components/modals/modal.js.map +1 -1
  103. package/dist/esm/components/modals/use-modal-with-views.js +11 -3
  104. package/dist/esm/components/modals/use-modal-with-views.js.map +1 -1
  105. package/dist/esm/components/quote-expiry/index.js +2 -0
  106. package/dist/esm/components/quote-expiry/index.js.map +1 -0
  107. package/dist/esm/components/quote-expiry/quote-expiry-countdown.js +35 -0
  108. package/dist/esm/components/quote-expiry/quote-expiry-countdown.js.map +1 -0
  109. package/dist/esm/components/quote-expiry/styles.js +109 -0
  110. package/dist/esm/components/quote-expiry/styles.js.map +1 -0
  111. package/dist/esm/components/quote-expiry/tiers.js +31 -0
  112. package/dist/esm/components/quote-expiry/tiers.js.map +1 -0
  113. package/dist/esm/components/text/index.js +2 -0
  114. package/dist/esm/components/text/index.js.map +1 -1
  115. package/dist/esm/components/wallet-selector/component.js +59 -0
  116. package/dist/esm/components/wallet-selector/component.js.map +1 -0
  117. package/dist/esm/components/wallet-selector/domain.js +2 -0
  118. package/dist/esm/components/wallet-selector/domain.js.map +1 -0
  119. package/dist/esm/components/wallet-selector/helper.js +12 -0
  120. package/dist/esm/components/wallet-selector/helper.js.map +1 -0
  121. package/dist/esm/components/wallet-selector/index.js +5 -0
  122. package/dist/esm/components/wallet-selector/index.js.map +1 -0
  123. package/dist/esm/components/wallet-selector/provider.js +15 -0
  124. package/dist/esm/components/wallet-selector/provider.js.map +1 -0
  125. package/dist/esm/components/wallet-selector/schemas.js +6 -0
  126. package/dist/esm/components/wallet-selector/schemas.js.map +1 -0
  127. package/dist/esm/components/wallet-selector/store.js +134 -0
  128. package/dist/esm/components/wallet-selector/store.js.map +1 -0
  129. package/dist/esm/components/wallet-selector/util/exceptions.js +16 -0
  130. package/dist/esm/components/wallet-selector/util/exceptions.js.map +1 -0
  131. package/dist/esm/components/wallet-selector/wallets/index.js +3 -0
  132. package/dist/esm/components/wallet-selector/wallets/index.js.map +1 -0
  133. package/dist/esm/components/wallet-selector/wallets/wagmi/index.js +218 -0
  134. package/dist/esm/components/wallet-selector/wallets/wagmi/index.js.map +1 -0
  135. package/dist/esm/components/wallet-selector/wallets/wagmi/usdt-abi.json +671 -0
  136. package/dist/esm/config.js +10 -1
  137. package/dist/esm/config.js.map +1 -1
  138. package/dist/esm/context.js +2 -1
  139. package/dist/esm/context.js.map +1 -1
  140. package/dist/esm/index.js +4 -0
  141. package/dist/esm/index.js.map +1 -1
  142. package/dist/esm/integrations/evm-chain.js +22 -0
  143. package/dist/esm/integrations/evm-chain.js.map +1 -0
  144. package/dist/esm/integrations/index.js +3 -0
  145. package/dist/esm/integrations/index.js.map +1 -0
  146. package/dist/esm/integrations/lifi.js +218 -0
  147. package/dist/esm/integrations/lifi.js.map +1 -0
  148. package/dist/esm/integrations/types.js +2 -0
  149. package/dist/esm/integrations/types.js.map +1 -0
  150. package/dist/esm/refund/confirmation.js +30 -0
  151. package/dist/esm/refund/confirmation.js.map +1 -0
  152. package/dist/esm/refund/index.js +599 -0
  153. package/dist/esm/refund/index.js.map +1 -0
  154. package/dist/esm/refund/prepare-guard.js +13 -0
  155. package/dist/esm/refund/prepare-guard.js.map +1 -0
  156. package/dist/esm/state/checkout/payment-attempt.js +46 -0
  157. package/dist/esm/state/checkout/payment-attempt.js.map +1 -0
  158. package/dist/esm/state/checkout/payment-lifecycle.js +66 -0
  159. package/dist/esm/state/checkout/payment-lifecycle.js.map +1 -0
  160. package/dist/esm/state/checkout/store.js +845 -55
  161. package/dist/esm/state/checkout/store.js.map +1 -1
  162. package/dist/esm/state/checkout/wallet-payment-options.js +44 -0
  163. package/dist/esm/state/checkout/wallet-payment-options.js.map +1 -0
  164. package/dist/esm/themes/default.js +48 -0
  165. package/dist/esm/themes/default.js.map +1 -1
  166. package/dist/esm/themes/types.js +1 -1
  167. package/dist/esm/themes/types.js.map +1 -1
  168. package/dist/esm/utils/string.js +35 -0
  169. package/dist/esm/utils/string.js.map +1 -0
  170. package/dist/esm/utils/wallet-errors.js +15 -0
  171. package/dist/esm/utils/wallet-errors.js.map +1 -0
  172. package/dist/types/api/checkouts.d.ts +2 -8
  173. package/dist/types/api/checkouts.d.ts.map +1 -1
  174. package/dist/types/api/generated.d.ts +4625 -269
  175. package/dist/types/api/generated.d.ts.map +1 -1
  176. package/dist/types/api/index.d.ts +2 -0
  177. package/dist/types/api/index.d.ts.map +1 -1
  178. package/dist/types/api/payments.d.ts +53 -5
  179. package/dist/types/api/payments.d.ts.map +1 -1
  180. package/dist/types/api/types.d.ts +24 -7
  181. package/dist/types/api/types.d.ts.map +1 -1
  182. package/dist/types/checkout/index.d.ts +10 -2
  183. package/dist/types/checkout/index.d.ts.map +1 -1
  184. package/dist/types/checkout/launcher.d.ts +6 -0
  185. package/dist/types/checkout/launcher.d.ts.map +1 -0
  186. package/dist/types/checkout/modal.d.ts +4 -2
  187. package/dist/types/checkout/modal.d.ts.map +1 -1
  188. package/dist/types/checkout/providers/wagmi-config.d.ts +18 -0
  189. package/dist/types/checkout/providers/wagmi-config.d.ts.map +1 -0
  190. package/dist/types/checkout/providers/wallet-connect-resume.d.ts +9 -0
  191. package/dist/types/checkout/providers/wallet-connect-resume.d.ts.map +1 -0
  192. package/dist/types/checkout/resume-state.d.ts +13 -0
  193. package/dist/types/checkout/resume-state.d.ts.map +1 -0
  194. package/dist/types/checkout/surplus-refund.d.ts +10 -0
  195. package/dist/types/checkout/surplus-refund.d.ts.map +1 -0
  196. package/dist/types/checkout/views/amount-header.d.ts +10 -0
  197. package/dist/types/checkout/views/amount-header.d.ts.map +1 -0
  198. package/dist/types/checkout/views/back.d.ts +3 -1
  199. package/dist/types/checkout/views/back.d.ts.map +1 -1
  200. package/dist/types/checkout/views/crypto-intent/direct-details.d.ts +12 -1
  201. package/dist/types/checkout/views/crypto-intent/direct-details.d.ts.map +1 -1
  202. package/dist/types/checkout/views/crypto-intent/manual-payment-summary.d.ts +20 -0
  203. package/dist/types/checkout/views/crypto-intent/manual-payment-summary.d.ts.map +1 -0
  204. package/dist/types/checkout/views/crypto-intent/manual-refund-preference.d.ts +16 -0
  205. package/dist/types/checkout/views/crypto-intent/manual-refund-preference.d.ts.map +1 -0
  206. package/dist/types/checkout/views/crypto-intent/methods.d.ts.map +1 -1
  207. package/dist/types/checkout/views/crypto-intent/processing.d.ts +3 -0
  208. package/dist/types/checkout/views/crypto-intent/processing.d.ts.map +1 -1
  209. package/dist/types/checkout/views/crypto-intent/success.d.ts +2 -1
  210. package/dist/types/checkout/views/crypto-intent/success.d.ts.map +1 -1
  211. package/dist/types/checkout/views/crypto-intent/test-payment.d.ts +3 -0
  212. package/dist/types/checkout/views/crypto-intent/test-payment.d.ts.map +1 -0
  213. package/dist/types/checkout/views/crypto-intent/wallet-payment-confirmation-amount.d.ts +13 -0
  214. package/dist/types/checkout/views/crypto-intent/wallet-payment-confirmation-amount.d.ts.map +1 -0
  215. package/dist/types/checkout/views/crypto-intent/wallet-payment-options.d.ts +3 -0
  216. package/dist/types/checkout/views/crypto-intent/wallet-payment-options.d.ts.map +1 -0
  217. package/dist/types/checkout/views/crypto-intent/wallet-select.d.ts +3 -0
  218. package/dist/types/checkout/views/crypto-intent/wallet-select.d.ts.map +1 -0
  219. package/dist/types/checkout/views/failed.d.ts +2 -0
  220. package/dist/types/checkout/views/failed.d.ts.map +1 -0
  221. package/dist/types/checkout/views/initial.d.ts +6 -2
  222. package/dist/types/checkout/views/initial.d.ts.map +1 -1
  223. package/dist/types/checkout/views/method-select.d.ts +2 -0
  224. package/dist/types/checkout/views/method-select.d.ts.map +1 -1
  225. package/dist/types/checkout/views/restart.d.ts +4 -0
  226. package/dist/types/checkout/views/restart.d.ts.map +1 -0
  227. package/dist/types/components/buttons/async-button.d.ts +14 -0
  228. package/dist/types/components/buttons/async-button.d.ts.map +1 -0
  229. package/dist/types/components/buttons/index.d.ts +21 -3
  230. package/dist/types/components/buttons/index.d.ts.map +1 -1
  231. package/dist/types/components/buttons/use-async-button.d.ts +16 -0
  232. package/dist/types/components/buttons/use-async-button.d.ts.map +1 -0
  233. package/dist/types/components/crypto/currency-selector.d.ts +11 -0
  234. package/dist/types/components/crypto/currency-selector.d.ts.map +1 -0
  235. package/dist/types/components/icons/alert.d.ts +7 -0
  236. package/dist/types/components/icons/alert.d.ts.map +1 -0
  237. package/dist/types/components/icons/checkMark.d.ts.map +1 -1
  238. package/dist/types/components/icons/clipboard-add.d.ts +6 -0
  239. package/dist/types/components/icons/clipboard-add.d.ts.map +1 -0
  240. package/dist/types/components/icons/clipboard-check.d.ts +6 -0
  241. package/dist/types/components/icons/clipboard-check.d.ts.map +1 -0
  242. package/dist/types/components/icons/clock.d.ts +6 -0
  243. package/dist/types/components/icons/clock.d.ts.map +1 -0
  244. package/dist/types/components/icons/close.d.ts.map +1 -1
  245. package/dist/types/components/icons/edit.d.ts +6 -0
  246. package/dist/types/components/icons/edit.d.ts.map +1 -0
  247. package/dist/types/components/icons/index.d.ts +9 -0
  248. package/dist/types/components/icons/index.d.ts.map +1 -1
  249. package/dist/types/components/icons/link.d.ts +6 -0
  250. package/dist/types/components/icons/link.d.ts.map +1 -0
  251. package/dist/types/components/icons/loading.d.ts +6 -0
  252. package/dist/types/components/icons/loading.d.ts.map +1 -0
  253. package/dist/types/components/icons/log-out.d.ts +6 -0
  254. package/dist/types/components/icons/log-out.d.ts.map +1 -0
  255. package/dist/types/components/icons/send.d.ts +6 -0
  256. package/dist/types/components/icons/send.d.ts.map +1 -0
  257. package/dist/types/components/index.d.ts +1 -0
  258. package/dist/types/components/index.d.ts.map +1 -1
  259. package/dist/types/components/inputs/index.d.ts +7 -0
  260. package/dist/types/components/inputs/index.d.ts.map +1 -0
  261. package/dist/types/components/lists/index.d.ts.map +1 -1
  262. package/dist/types/components/loading/index.d.ts.map +1 -1
  263. package/dist/types/components/modals/modal-with-views.d.ts +1 -0
  264. package/dist/types/components/modals/modal-with-views.d.ts.map +1 -1
  265. package/dist/types/components/modals/modal.d.ts.map +1 -1
  266. package/dist/types/components/modals/use-modal-with-views.d.ts.map +1 -1
  267. package/dist/types/components/quote-expiry/index.d.ts +2 -0
  268. package/dist/types/components/quote-expiry/index.d.ts.map +1 -0
  269. package/dist/types/components/quote-expiry/quote-expiry-countdown.d.ts +15 -0
  270. package/dist/types/components/quote-expiry/quote-expiry-countdown.d.ts.map +1 -0
  271. package/dist/types/components/quote-expiry/styles.d.ts +22 -0
  272. package/dist/types/components/quote-expiry/styles.d.ts.map +1 -0
  273. package/dist/types/components/quote-expiry/tiers.d.ts +10 -0
  274. package/dist/types/components/quote-expiry/tiers.d.ts.map +1 -0
  275. package/dist/types/components/text/index.d.ts.map +1 -1
  276. package/dist/types/components/wallet-selector/component.d.ts +12 -0
  277. package/dist/types/components/wallet-selector/component.d.ts.map +1 -0
  278. package/dist/types/components/wallet-selector/domain.d.ts +96 -0
  279. package/dist/types/components/wallet-selector/domain.d.ts.map +1 -0
  280. package/dist/types/components/wallet-selector/helper.d.ts +4 -0
  281. package/dist/types/components/wallet-selector/helper.d.ts.map +1 -0
  282. package/dist/types/components/wallet-selector/index.d.ts +7 -0
  283. package/dist/types/components/wallet-selector/index.d.ts.map +1 -0
  284. package/dist/types/components/wallet-selector/provider.d.ts +10 -0
  285. package/dist/types/components/wallet-selector/provider.d.ts.map +1 -0
  286. package/dist/types/components/wallet-selector/schemas.d.ts +4 -0
  287. package/dist/types/components/wallet-selector/schemas.d.ts.map +1 -0
  288. package/dist/types/components/wallet-selector/store.d.ts +33 -0
  289. package/dist/types/components/wallet-selector/store.d.ts.map +1 -0
  290. package/dist/types/components/wallet-selector/util/exceptions.d.ts +7 -0
  291. package/dist/types/components/wallet-selector/util/exceptions.d.ts.map +1 -0
  292. package/dist/types/components/wallet-selector/wallets/index.d.ts +3 -0
  293. package/dist/types/components/wallet-selector/wallets/index.d.ts.map +1 -0
  294. package/dist/types/components/wallet-selector/wallets/wagmi/index.d.ts +519 -0
  295. package/dist/types/components/wallet-selector/wallets/wagmi/index.d.ts.map +1 -0
  296. package/dist/types/config.d.ts +74 -0
  297. package/dist/types/config.d.ts.map +1 -1
  298. package/dist/types/context.d.ts.map +1 -1
  299. package/dist/types/index.d.ts +4 -0
  300. package/dist/types/index.d.ts.map +1 -1
  301. package/dist/types/integrations/evm-chain.d.ts +3 -0
  302. package/dist/types/integrations/evm-chain.d.ts.map +1 -0
  303. package/dist/types/integrations/index.d.ts +3 -0
  304. package/dist/types/integrations/index.d.ts.map +1 -0
  305. package/dist/types/integrations/lifi.d.ts +14 -0
  306. package/dist/types/integrations/lifi.d.ts.map +1 -0
  307. package/dist/types/integrations/types.d.ts +5 -0
  308. package/dist/types/integrations/types.d.ts.map +1 -0
  309. package/dist/types/refund/confirmation.d.ts +14 -0
  310. package/dist/types/refund/confirmation.d.ts.map +1 -0
  311. package/dist/types/refund/index.d.ts +26 -0
  312. package/dist/types/refund/index.d.ts.map +1 -0
  313. package/dist/types/refund/prepare-guard.d.ts +11 -0
  314. package/dist/types/refund/prepare-guard.d.ts.map +1 -0
  315. package/dist/types/state/checkout/payment-attempt.d.ts +9 -0
  316. package/dist/types/state/checkout/payment-attempt.d.ts.map +1 -0
  317. package/dist/types/state/checkout/payment-lifecycle.d.ts +37 -0
  318. package/dist/types/state/checkout/payment-lifecycle.d.ts.map +1 -0
  319. package/dist/types/state/checkout/store.d.ts +88 -40
  320. package/dist/types/state/checkout/store.d.ts.map +1 -1
  321. package/dist/types/state/checkout/wallet-payment-options.d.ts +24 -0
  322. package/dist/types/state/checkout/wallet-payment-options.d.ts.map +1 -0
  323. package/dist/types/themes/default.d.ts +2 -2
  324. package/dist/types/themes/default.d.ts.map +1 -1
  325. package/dist/types/themes/types.d.ts +20 -0
  326. package/dist/types/themes/types.d.ts.map +1 -1
  327. package/dist/types/utils/string.d.ts +24 -0
  328. package/dist/types/utils/string.d.ts.map +1 -0
  329. package/dist/types/utils/wallet-errors.d.ts +2 -0
  330. package/dist/types/utils/wallet-errors.d.ts.map +1 -0
  331. package/package.json +50 -7
  332. package/LICENSE +0 -21
  333. package/dist/esm/checkout/views/card-intent/details.js +0 -12
  334. package/dist/esm/checkout/views/card-intent/details.js.map +0 -1
  335. package/dist/esm/checkout/views/crypto-intent/curreny.js +0 -28
  336. package/dist/esm/checkout/views/crypto-intent/curreny.js.map +0 -1
  337. package/dist/types/checkout/views/card-intent/details.d.ts +0 -3
  338. package/dist/types/checkout/views/card-intent/details.d.ts.map +0 -1
  339. package/dist/types/checkout/views/crypto-intent/curreny.d.ts +0 -3
  340. package/dist/types/checkout/views/crypto-intent/curreny.d.ts.map +0 -1
@@ -1,7 +1,15 @@
1
+ import { waitForTransactionReceipt } from "@wagmi/core";
1
2
  import { create } from "zustand";
2
3
  import { immer } from "zustand/middleware/immer";
3
- import { getCheckoutById, getCheckoutCryptoCurrencies, } from "../../api/checkouts.js";
4
- import { createPayment, createPaymentAttempt, getPaymentById, } from "../../api/payments.js";
4
+ import { getCheckoutCryptoCurrencies } from "../../api/checkouts.js";
5
+ import { createPaymentAttempt, createTestPaymentAttempt, getPaymentById, getRequiredSettlementConfig, } from "../../api/payments.js";
6
+ import { PaymentStatus, } from "../../api/types.js";
7
+ import { WagmiWalletInterface } from "../../components/wallet-selector/wallets/wagmi/index.js";
8
+ import { resolveEvmChainId, switchEvmWalletChain, } from "../../integrations/evm-chain.js";
9
+ import { buildWalletPaymentAttemptPayload } from "./payment-attempt.js";
10
+ import { canCreateFreshAttempt, getAttemptExpiry, getAttemptQuoteTiming, isAttemptStale, } from "./payment-lifecycle.js";
11
+ const PAYMENT_NO_LONGER_PAYABLE_MESSAGE = "This payment is no longer payable.";
12
+ const STALE_REPLACEMENT_QUOTE_MESSAGE = "The refreshed quote expired before it could be used. Please try again.";
5
13
  export var ACTIONS;
6
14
  (function (ACTIONS) {
7
15
  ACTIONS["GET_CHECKOUT_CONFIG"] = "GET_CHECKOUT_CONFIG";
@@ -9,27 +17,432 @@ export var ACTIONS;
9
17
  ACTIONS["CREATE_PAYMENT"] = "CREATE_PAYMENT";
10
18
  ACTIONS["GET_PAYMENT"] = "GET_PAYMENT";
11
19
  ACTIONS["CREATE_PAYMENT_ATTEMPT"] = "CREATE_PAYMENT_ATTEMPT";
20
+ ACTIONS["CREATE_TEST_PAYMENT_ATTEMPT"] = "CREATE_TEST_PAYMENT_ATTEMPT";
21
+ ACTIONS["EXECUTE_TRANSFER"] = "EXECUTE_TRANSFER";
22
+ ACTIONS["POLL_PAYMENT"] = "POLL_PAYMENT";
23
+ ACTIONS["CHECK_CHAIN_STATUS"] = "CHECK_CHAIN_STATUS";
12
24
  })(ACTIONS || (ACTIONS = {}));
25
+ const initialWalletPaymentState = () => ({
26
+ status: "idle",
27
+ options: [],
28
+ walletAddress: null,
29
+ selectedOptionId: null,
30
+ quoteId: null,
31
+ routeId: null,
32
+ sourceTxHash: null,
33
+ destinationTxHash: null,
34
+ quoteStatus: "idle",
35
+ quote: null,
36
+ quoteError: null,
37
+ error: null,
38
+ });
13
39
  const initialActionState = (initialValue) => Object.values(ACTIONS).reduce((acc, action) => {
14
40
  acc[action] = initialValue;
15
41
  return acc;
16
42
  }, {});
17
43
  export const useCheckoutStore = create()(immer((_set, _get) => ({
18
- amount: null,
19
44
  checkoutId: null,
20
45
  selectedMethod: null,
21
46
  selectedCurrency: null,
47
+ retrySession: false,
22
48
  methods: null,
23
- cryptoCurrencies: null,
49
+ cryptoCurrency: null,
24
50
  checkout: null,
25
51
  payment: null,
26
52
  cryptoPaymentAttempt: null,
27
53
  loading: initialActionState(false),
28
54
  error: initialActionState(null),
55
+ processing: false,
56
+ transfer: {
57
+ status: "idle",
58
+ error: null,
59
+ transactionHash: null,
60
+ chainStatus: "pending",
61
+ },
62
+ polling: {
63
+ isPolling: false,
64
+ pollCount: 0,
65
+ lastPollTime: null,
66
+ },
67
+ quote: {
68
+ status: "idle",
69
+ error: null,
70
+ expiresAt: null,
71
+ remainingMs: null,
72
+ totalDurationMs: null,
73
+ },
74
+ walletPayment: initialWalletPaymentState(),
29
75
  })));
30
- const set = useCheckoutStore.setState;
76
+ const set = (fn) => {
77
+ useCheckoutStore.setState(fn);
78
+ };
31
79
  const get = () => useCheckoutStore.getState();
32
- // Actions: Directly expose the function
80
+ // Quote refresh is mode-agnostic from a view's perspective: the store remembers
81
+ // how to rebuild (wallet route vs manual address) while views only read
82
+ // `quote.status`. A one-shot timer refreshes the live quote at expiry, while a
83
+ // lightweight interval updates the visible countdown.
84
+ let refreshMode = "none";
85
+ let quoteExpiryTimer = null;
86
+ let quoteCountdownInterval = null;
87
+ // True only while refreshQuote() is rebuilding the attempt. This is the
88
+ // re-entrancy guard (not quote.status): intermediate snapshots emitted during
89
+ // the rebuild are ignored, and refreshQuote settles the final state itself when
90
+ // it returns — so a freshly created attempt can never leave the UI stuck on the
91
+ // "refreshing" spinner, and a stale rebuild can never tight-loop.
92
+ let isRefreshing = false;
93
+ const clearQuoteExpiryTimer = () => {
94
+ if (quoteExpiryTimer) {
95
+ clearTimeout(quoteExpiryTimer);
96
+ quoteExpiryTimer = null;
97
+ }
98
+ if (quoteCountdownInterval) {
99
+ clearInterval(quoteCountdownInterval);
100
+ quoteCountdownInterval = null;
101
+ }
102
+ };
103
+ const clearQuoteAutoRefreshTimer = () => {
104
+ if (quoteExpiryTimer) {
105
+ clearTimeout(quoteExpiryTimer);
106
+ quoteExpiryTimer = null;
107
+ }
108
+ };
109
+ const getPreservedRefreshingQuoteState = () => {
110
+ const currentQuote = get().quote;
111
+ if (currentQuote.remainingMs === null) {
112
+ return { status: "refreshing", error: null, ...clearQuoteTiming() };
113
+ }
114
+ return {
115
+ status: "refreshing",
116
+ error: null,
117
+ expiresAt: currentQuote.expiresAt,
118
+ remainingMs: currentQuote.expiresAt !== null
119
+ ? Math.max(0, currentQuote.expiresAt - Date.now())
120
+ : currentQuote.remainingMs,
121
+ totalDurationMs: currentQuote.totalDurationMs,
122
+ };
123
+ };
124
+ const getCurrentCheckoutAttempt = (state = get()) => {
125
+ return state.cryptoPaymentAttempt ?? state.payment?.payment_attempt ?? null;
126
+ };
127
+ const normalizeWalletAddress = (value) => value?.trim().toLowerCase() || null;
128
+ const attemptMatchesSource = (attempt, source) => {
129
+ const attemptSource = attempt?.routing?.source;
130
+ return (attemptSource?.token?.toLowerCase() === source.token.toLowerCase() &&
131
+ attemptSource?.chain?.toLowerCase() === source.chain.toLowerCase());
132
+ };
133
+ const getReusableCurrentAttemptForSource = (source) => {
134
+ const attempt = getCurrentCheckoutAttempt();
135
+ if (!attempt || isAttemptStale(attempt))
136
+ return null;
137
+ if (!attemptMatchesSource(attempt, source))
138
+ return null;
139
+ return normalizeWalletAddress(attempt.refund_to) ===
140
+ normalizeWalletAddress(source.sendingAddress)
141
+ ? attempt
142
+ : null;
143
+ };
144
+ const reuseCurrentAttempt = (attempt) => {
145
+ set((state) => {
146
+ state.cryptoPaymentAttempt = attempt;
147
+ state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = null;
148
+ state.loading[ACTIONS.CREATE_PAYMENT_ATTEMPT] = false;
149
+ });
150
+ syncQuote(get().payment, attempt);
151
+ return attempt;
152
+ };
153
+ const withFreshAttempt = (payment, attempt) => {
154
+ if (!payment) {
155
+ return payment;
156
+ }
157
+ return {
158
+ ...payment,
159
+ payment_attempt: attempt,
160
+ };
161
+ };
162
+ const getPaymentSnapshotAfterAttempt = async (paymentId, attempt, fallbackPayment) => {
163
+ try {
164
+ return await getPaymentById(paymentId);
165
+ }
166
+ catch {
167
+ return withFreshAttempt(get().payment ?? fallbackPayment, attempt);
168
+ }
169
+ };
170
+ const buildDirectWalletQuote = (option, attempt) => {
171
+ const amount = String(attempt.amount_formatted);
172
+ return {
173
+ quoteId: option.quoteId,
174
+ routeId: option.routeId,
175
+ toolName: "Direct transfer",
176
+ fromAmount: amount,
177
+ fromAmountDisplay: amount,
178
+ toAmount: amount,
179
+ toAmountDisplay: amount,
180
+ estimatedDurationMinutes: 1,
181
+ };
182
+ };
183
+ const setQuote = (update, walletUpdate) => {
184
+ set((state) => {
185
+ Object.assign(state.quote, update);
186
+ if (walletUpdate) {
187
+ Object.assign(state.walletPayment, walletUpdate);
188
+ }
189
+ });
190
+ };
191
+ const clearQuoteTiming = () => ({
192
+ expiresAt: null,
193
+ remainingMs: null,
194
+ totalDurationMs: null,
195
+ });
196
+ const refreshQuoteCountdown = (expiresAt) => {
197
+ if (expiresAt === null)
198
+ return;
199
+ setQuote({
200
+ remainingMs: Math.max(0, expiresAt - Date.now()),
201
+ });
202
+ };
203
+ const getWalletQuoteLoadingState = () => ({
204
+ quoteStatus: "loading",
205
+ quote: null,
206
+ quoteError: null,
207
+ quoteId: null,
208
+ routeId: null,
209
+ });
210
+ const getWalletQuoteReadyState = (quote) => ({
211
+ quoteStatus: "ready",
212
+ quote,
213
+ quoteId: quote.quoteId,
214
+ routeId: quote.routeId,
215
+ quoteError: null,
216
+ });
217
+ const getWalletQuoteFailedState = (message) => ({
218
+ quoteStatus: "failed",
219
+ quote: null,
220
+ quoteError: message,
221
+ });
222
+ const getWalletAttemptRefreshContext = () => {
223
+ const state = get();
224
+ const payment = state.payment;
225
+ const checkout = state.checkout;
226
+ const settlementCurrency = state.cryptoCurrency;
227
+ const selectedOption = state.walletPayment.options.find((option) => option.id === state.walletPayment.selectedOptionId);
228
+ const walletAddress = state.walletPayment.walletAddress;
229
+ if (!payment || !checkout || !settlementCurrency) {
230
+ throw new Error("Wallet payment context is not ready");
231
+ }
232
+ if (!selectedOption || !walletAddress) {
233
+ throw new Error("Missing wallet payment selection for quote refresh");
234
+ }
235
+ return {
236
+ payment,
237
+ checkout,
238
+ settlementCurrency,
239
+ selectedOption,
240
+ walletAddress,
241
+ };
242
+ };
243
+ const resolveRefreshedWalletQuote = async ({ selectedOption, checkout, payment, settlementCurrency, walletAddress, attempt, }) => {
244
+ if (selectedOption.kind === "direct") {
245
+ return buildDirectWalletQuote(selectedOption, attempt);
246
+ }
247
+ // Keep routed-quote loading behind a dynamic import so the checkout store
248
+ // does not eagerly pull the LI.FI integration path into manual-only flows.
249
+ const { fetchWalletPaymentQuote } = await import("../../integrations/index.js");
250
+ return fetchWalletPaymentQuote({
251
+ option: selectedOption,
252
+ context: {
253
+ checkout,
254
+ payment: get().payment ?? payment,
255
+ settlementCurrency,
256
+ walletAddress,
257
+ cryptoPaymentAttempt: attempt,
258
+ },
259
+ });
260
+ };
261
+ const refreshWalletPaymentAttempt = async () => {
262
+ const context = getWalletAttemptRefreshContext();
263
+ const attempt = await createWalletOptionPaymentAttempt(context.selectedOption, context.walletAddress, null);
264
+ const quote = await resolveRefreshedWalletQuote({
265
+ ...context,
266
+ attempt,
267
+ });
268
+ // Only the wallet-quote payload is set here; refreshQuote settles quote.status
269
+ // (ready + expiry timer) from the freshly created attempt once the rebuild ends.
270
+ setWalletPaymentState(getWalletQuoteReadyState(quote));
271
+ };
272
+ /**
273
+ * Settle the displayed quote state from the active attempt and arm a single
274
+ * expiry timer for a live quote. It never triggers a refresh — the caller
275
+ * decides what to do with a "stale" result — so it is safe to reuse mid-refresh
276
+ * without recursion.
277
+ */
278
+ const settleQuoteFromAttempt = (payment, attempt) => {
279
+ clearQuoteExpiryTimer();
280
+ if (refreshMode === "none" || !attempt || !canCreateFreshAttempt(payment)) {
281
+ setQuote({ status: "idle", error: null, ...clearQuoteTiming() });
282
+ return "idle";
283
+ }
284
+ if (isAttemptStale(attempt)) {
285
+ return "stale";
286
+ }
287
+ const timing = getAttemptQuoteTiming(attempt);
288
+ setQuote({ status: "ready", error: null, ...timing });
289
+ // One-shot timer: when the live quote crosses its window we refresh
290
+ // so the payer always sees a payable amount instead of an expiry dead-end.
291
+ const expiresAt = timing.expiresAt ?? getAttemptExpiry(attempt);
292
+ if (expiresAt !== null) {
293
+ quoteExpiryTimer = setTimeout(() => {
294
+ void refreshQuote();
295
+ }, Math.max(0, expiresAt - Date.now()));
296
+ quoteCountdownInterval = setInterval(() => {
297
+ refreshQuoteCountdown(expiresAt);
298
+ }, 1000);
299
+ }
300
+ return "ready";
301
+ };
302
+ /**
303
+ * Fetch a fresh payable amount for the active flow. Driven both by the silent
304
+ * expiry timer and by the payer's explicit "Try again" — a stale or missing
305
+ * quote is always recoverable, never terminal.
306
+ */
307
+ export const refreshQuote = async () => {
308
+ if (refreshMode === "none" || isRefreshing)
309
+ return;
310
+ if (refreshMode === "wallet" && !get().walletPayment.selectedOptionId) {
311
+ // Wallet refresh needs a chosen option to know which quote to rebuild, so
312
+ // skip ticks that land before the payer picked one (or after returning to
313
+ // the option list).
314
+ setQuote({ status: "idle", error: null, ...clearQuoteTiming() });
315
+ return;
316
+ }
317
+ if (!canCreateFreshAttempt(get().payment)) {
318
+ setQuote({
319
+ status: "failed",
320
+ error: PAYMENT_NO_LONGER_PAYABLE_MESSAGE,
321
+ ...clearQuoteTiming(),
322
+ });
323
+ return;
324
+ }
325
+ // Never refresh out from under an in-flight payment: the execution already
326
+ // captured the quote it is paying, so swapping the attempt would churn the UI
327
+ // and orphan an extra attempt. The view tears down the refresh context when it
328
+ // leaves the pay screen.
329
+ if (get().processing)
330
+ return;
331
+ isRefreshing = true;
332
+ clearQuoteExpiryTimer();
333
+ setQuote(getPreservedRefreshingQuoteState(), refreshMode === "wallet" ? getWalletQuoteLoadingState() : undefined);
334
+ try {
335
+ if (refreshMode === "wallet") {
336
+ await refreshWalletPaymentAttempt();
337
+ }
338
+ else {
339
+ // The replacement attempt must keep the refund recipient the payer bound
340
+ // to the expiring attempt: refund_to exists precisely for the expiry case,
341
+ // and an automatic refresh gives the payer no chance to re-enter it.
342
+ const currentAttempt = get().cryptoPaymentAttempt;
343
+ await createManualDirectPaymentAttempt("", 1, currentAttempt?.refund_to ?? null, {
344
+ ...(currentAttempt?.payment_provider === "relay"
345
+ ? {
346
+ mode: "relay_deposit",
347
+ source: {
348
+ asset: currentAttempt.routing.source.token,
349
+ chain: currentAttempt.routing.source.chain,
350
+ },
351
+ }
352
+ : {}),
353
+ });
354
+ }
355
+ }
356
+ catch (error) {
357
+ isRefreshing = false;
358
+ const message = error instanceof Error
359
+ ? error.message
360
+ : "Failed to refresh payment quote";
361
+ setQuote({ status: "failed", error: message, ...clearQuoteTiming() }, refreshMode === "wallet" ? getWalletQuoteFailedState(message) : undefined);
362
+ return;
363
+ }
364
+ isRefreshing = false;
365
+ if (settleQuoteFromAttempt(get().payment, get().cryptoPaymentAttempt) ===
366
+ "stale") {
367
+ setQuote({
368
+ status: "failed",
369
+ error: STALE_REPLACEMENT_QUOTE_MESSAGE,
370
+ ...clearQuoteTiming(),
371
+ });
372
+ }
373
+ };
374
+ /**
375
+ * Re-sync the quote lifecycle whenever the payment snapshot or active attempt
376
+ * changes. A fresh attempt arms the expiry refresh timer; a stale or missing
377
+ * one triggers an immediate refresh. This is the only entrypoint used
378
+ * after loading a payment, creating an attempt, or configuring a refresh mode.
379
+ */
380
+ export const syncQuote = (payment, attempt) => {
381
+ // A refresh in flight settles the final state itself; ignore the intermediate
382
+ // snapshot it emits while rebuilding the attempt.
383
+ if (isRefreshing)
384
+ return;
385
+ if (settleQuoteFromAttempt(payment, attempt ?? null) === "stale") {
386
+ void refreshQuote();
387
+ }
388
+ };
389
+ export const configureWalletQuoteRefresh = (walletAddress) => {
390
+ // Wallet refresh replaces a stale attempt by creating a fresh crypto payment
391
+ // attempt and reloading the wallet quote for the selected route.
392
+ refreshMode = "wallet";
393
+ set((state) => {
394
+ state.quote.error = null;
395
+ state.walletPayment.walletAddress = walletAddress;
396
+ });
397
+ syncQuote(get().payment, get().cryptoPaymentAttempt);
398
+ };
399
+ export const prepareWalletQuoteReplacement = (walletAddress = null) => {
400
+ // A payer-triggered wallet quote replacement is already fetching a new
401
+ // attempt/route, so pause only the automatic expiry refresh. Keep the
402
+ // countdown visible until the replacement quote is ready or fails.
403
+ refreshMode = "wallet";
404
+ clearQuoteAutoRefreshTimer();
405
+ set((state) => {
406
+ state.quote.error = null;
407
+ state.walletPayment.walletAddress =
408
+ walletAddress ?? state.walletPayment.walletAddress;
409
+ });
410
+ };
411
+ export const configureManualQuoteRefresh = () => {
412
+ // Manual refresh reuses the same lifecycle but only needs a fresh direct/relay
413
+ // address — no wallet quote metadata.
414
+ refreshMode = "manual";
415
+ set((state) => {
416
+ state.quote.error = null;
417
+ });
418
+ syncQuote(get().payment, get().cryptoPaymentAttempt);
419
+ };
420
+ export const clearQuoteRefresh = (options = {}) => {
421
+ // Drop the refresh mode before returning to method selection or closing the
422
+ // checkout so future expiry events do not reuse stale wallet/manual context.
423
+ refreshMode = "none";
424
+ isRefreshing = false;
425
+ clearQuoteExpiryTimer();
426
+ set((state) => {
427
+ state.quote = { status: "idle", error: null, ...clearQuoteTiming() };
428
+ if (!options.preserveWalletAddress) {
429
+ state.walletPayment.walletAddress = null;
430
+ }
431
+ });
432
+ };
433
+ const updatePaymentSnapshot = (payment, attempt, extra) => {
434
+ set((state) => {
435
+ state.payment = payment;
436
+ state.cryptoPaymentAttempt =
437
+ attempt !== undefined ? attempt : (payment?.payment_attempt ?? null);
438
+ if (extra) {
439
+ extra(state);
440
+ }
441
+ });
442
+ // Hydrate the current attempt from the payment snapshot so retry can resume
443
+ // the existing quote context and refresh it instead of restarting selection.
444
+ syncQuote(payment, get().cryptoPaymentAttempt);
445
+ };
33
446
  export const clearErrors = () => {
34
447
  set((state) => {
35
448
  Object.values(ACTIONS).forEach((action) => {
@@ -37,13 +450,13 @@ export const clearErrors = () => {
37
450
  });
38
451
  });
39
452
  };
40
- export const initialiseStore = async (checkoutId, amount) => {
41
- set((state) => {
42
- state.checkoutId = checkoutId;
43
- state.amount = amount;
44
- });
453
+ export const initialiseStore = async (payment) => {
454
+ resetCheckoutStore();
455
+ updatePaymentSnapshot(payment);
45
456
  try {
46
- await getCheckoutConfig(checkoutId);
457
+ const refreshedPayment = await getPaymentById(payment.id);
458
+ updatePaymentSnapshot(refreshedPayment);
459
+ hydrateCheckoutFromPayment(refreshedPayment);
47
460
  }
48
461
  catch (err) {
49
462
  set((state) => {
@@ -51,61 +464,166 @@ export const initialiseStore = async (checkoutId, amount) => {
51
464
  });
52
465
  }
53
466
  };
54
- export const createCheckoutPayment = async () => {
55
- const checkoutId = useCheckoutStore.getState().checkoutId;
56
- const amount = useCheckoutStore.getState().amount;
57
- if (!checkoutId || !amount) {
58
- console.error(`checkoutId and amount are required to make a payment.`);
59
- set((state) => {
60
- state.error[ACTIONS.CREATE_PAYMENT] = "Failed to create payment";
61
- state.loading[ACTIONS.CREATE_PAYMENT] = false;
467
+ export const createWalletOptionPaymentAttempt = async (
468
+ // "direct" is a routing classification: the payer sends the settlement
469
+ // asset on the settlement chain. It is not tied to manual vs wallet UX.
470
+ option, sendingAddress, quote) => {
471
+ const payment = useCheckoutStore.getState().payment;
472
+ const paymentId = payment?.id;
473
+ if (!paymentId) {
474
+ throw Error("Cannot create payment attempt without payment object.");
475
+ }
476
+ if (!canCreateFreshAttempt(payment)) {
477
+ throw Error(PAYMENT_NO_LONGER_PAYABLE_MESSAGE);
478
+ }
479
+ if (option.kind === "direct") {
480
+ const reusableAttempt = getReusableCurrentAttemptForSource({
481
+ token: option.fromToken,
482
+ chain: option.fromChain,
483
+ sendingAddress,
62
484
  });
63
- return;
485
+ if (reusableAttempt) {
486
+ return reuseCurrentAttempt(reusableAttempt);
487
+ }
64
488
  }
65
489
  try {
66
490
  set((state) => {
67
- state.error[ACTIONS.CREATE_PAYMENT] = null;
68
- state.loading[ACTIONS.CREATE_PAYMENT] = true;
491
+ state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = null;
492
+ state.loading[ACTIONS.CREATE_PAYMENT_ATTEMPT] = true;
69
493
  });
70
- const payment = await createPayment({ checkoutId, amount });
71
- set((state) => {
72
- state.payment = payment;
73
- state.error[ACTIONS.CREATE_PAYMENT] = null;
74
- state.loading[ACTIONS.CREATE_PAYMENT] = false;
494
+ const attemptPayload = buildWalletPaymentAttemptPayload({
495
+ option,
496
+ sendingAddress,
497
+ quote,
498
+ requiredConfirmations: 1,
499
+ });
500
+ const attempt = await createPaymentAttempt(paymentId, attemptPayload, 1);
501
+ const refreshedPayment = await getPaymentSnapshotAfterAttempt(paymentId, attempt, payment);
502
+ updatePaymentSnapshot(refreshedPayment, attempt, (state) => {
503
+ state.retrySession = false;
504
+ state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = null;
505
+ state.loading[ACTIONS.CREATE_PAYMENT_ATTEMPT] = false;
75
506
  });
507
+ return attempt;
76
508
  }
77
509
  catch (err) {
510
+ const error = err;
78
511
  set((state) => {
79
- state.error[ACTIONS.CREATE_PAYMENT] = "Failed to create payment";
80
- state.loading[ACTIONS.CREATE_PAYMENT] = false;
512
+ state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = error.message;
513
+ state.loading[ACTIONS.CREATE_PAYMENT_ATTEMPT] = false;
81
514
  });
515
+ throw error;
82
516
  }
83
517
  };
84
- export const createCheckoutCryptoPaymentAttempt = async (currency) => {
85
- const paymentId = useCheckoutStore.getState().payment?.id;
518
+ export const createManualDirectPaymentAttempt = async (sendingAddress = "", confirmations = 1, refundTo, options = {}) => {
519
+ const payment = useCheckoutStore.getState().payment;
520
+ const paymentId = payment?.id;
86
521
  if (!paymentId) {
87
522
  throw Error("Cannot create payment attempt without payment object.");
88
523
  }
524
+ if (!canCreateFreshAttempt(payment)) {
525
+ throw Error(PAYMENT_NO_LONGER_PAYABLE_MESSAGE);
526
+ }
527
+ const settlementConfig = getRequiredSettlementConfig(payment);
528
+ const source = options.source ?? {
529
+ asset: settlementConfig.asset,
530
+ chain: settlementConfig.chain,
531
+ };
532
+ const normalizedSendingAddress = sendingAddress.trim();
533
+ const effectiveRefundTo = refundTo?.trim() || normalizedSendingAddress || null;
534
+ const routingType = source.chain !== settlementConfig.chain
535
+ ? "bridge"
536
+ : source.asset !== settlementConfig.asset
537
+ ? "swap"
538
+ : "direct";
539
+ const attemptPayload = {
540
+ mode: options.mode,
541
+ ...(normalizedSendingAddress
542
+ ? { sendingAddress: normalizedSendingAddress }
543
+ : {}),
544
+ refund_to: effectiveRefundTo,
545
+ required_confirmations: confirmations,
546
+ source: options.mode === "relay_deposit"
547
+ ? {
548
+ token: source.asset,
549
+ chain: source.chain,
550
+ }
551
+ : undefined,
552
+ routing: {
553
+ type: routingType,
554
+ source: {
555
+ token: source.asset,
556
+ chain: source.chain,
557
+ },
558
+ },
559
+ };
560
+ const attempt = await createPaymentAttempt(paymentId, attemptPayload);
561
+ const refreshedPayment = await getPaymentSnapshotAfterAttempt(paymentId, attempt, payment);
562
+ updatePaymentSnapshot(refreshedPayment, attempt, (state) => {
563
+ state.retrySession = false;
564
+ });
565
+ return attempt;
566
+ };
567
+ export const createSuccessfulTestPaymentAttempt = async () => {
568
+ const paymentId = useCheckoutStore.getState().payment?.id;
569
+ if (!paymentId) {
570
+ throw Error("Cannot create test payment attempt without payment object.");
571
+ }
89
572
  try {
90
573
  set((state) => {
91
- state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = null;
92
- state.loading[ACTIONS.CREATE_PAYMENT_ATTEMPT] = true;
574
+ state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = null;
575
+ state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = true;
93
576
  });
94
- const attempt = await createPaymentAttempt(paymentId, currency);
577
+ const currentPayment = useCheckoutStore.getState().payment;
578
+ if (!currentPayment) {
579
+ throw Error("Cannot create test payment attempt without payment object.");
580
+ }
581
+ const attempt = await createTestPaymentAttempt(paymentId, "0xsuccess", currentPayment);
95
582
  const payment = await getPaymentById(paymentId);
583
+ updatePaymentSnapshot(payment, attempt, (state) => {
584
+ state.retrySession = false;
585
+ state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = null;
586
+ state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = false;
587
+ });
588
+ }
589
+ catch (err) {
590
+ const error = err;
96
591
  set((state) => {
97
- state.payment = payment;
98
- state.cryptoPaymentAttempt = attempt;
99
- state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = null;
100
- state.loading[ACTIONS.CREATE_PAYMENT_ATTEMPT] = false;
592
+ state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = error.message;
593
+ state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = false;
594
+ });
595
+ throw error;
596
+ }
597
+ };
598
+ export const createFailedTestPaymentAttempt = async () => {
599
+ const paymentId = useCheckoutStore.getState().payment?.id;
600
+ if (!paymentId) {
601
+ throw Error("Cannot create test payment attempt without payment object.");
602
+ }
603
+ try {
604
+ set((state) => {
605
+ state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = null;
606
+ state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = true;
607
+ });
608
+ const currentPayment = useCheckoutStore.getState().payment;
609
+ if (!currentPayment) {
610
+ throw Error("Cannot create test payment attempt without payment object.");
611
+ }
612
+ const attempt = await createTestPaymentAttempt(paymentId, "0xfail", currentPayment);
613
+ const payment = await getPaymentById(paymentId);
614
+ updatePaymentSnapshot(payment, attempt, (state) => {
615
+ state.retrySession = false;
616
+ state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = null;
617
+ state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = false;
101
618
  });
102
619
  }
103
620
  catch (err) {
104
621
  const error = err;
105
622
  set((state) => {
106
- state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = error.message;
107
- state.loading[ACTIONS.CREATE_PAYMENT_ATTEMPT] = false;
623
+ state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = error.message;
624
+ state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = false;
108
625
  });
626
+ throw error;
109
627
  }
110
628
  };
111
629
  export function getAvailableCheckoutMethods(checkout) {
@@ -116,27 +634,20 @@ export function getAvailableCheckoutMethods(checkout) {
116
634
  intentName: "cryptoIntent",
117
635
  });
118
636
  }
119
- if (checkout.checkout_config.card?.enabled) {
120
- methods.push({
121
- name: "Pay by Card",
122
- intentName: "cardIntent",
123
- });
124
- }
125
637
  return methods;
126
638
  }
127
- export const getCheckoutConfig = async (checkoutId) => {
639
+ export const hydrateCheckoutFromPayment = (payment) => {
128
640
  const ACTION = ACTIONS.GET_CHECKOUT_CONFIG;
129
641
  set((state) => {
130
642
  state.loading[ACTION] = true;
131
643
  state.error[ACTION] = null;
132
644
  });
133
645
  try {
134
- const resp = await getCheckoutById(checkoutId);
135
- if (resp) {
646
+ if (payment.checkout) {
136
647
  set((state) => {
137
- state.checkout = resp;
138
- state.methods = getAvailableCheckoutMethods(resp);
139
- state.cryptoCurrencies = getCheckoutCryptoCurrencies(resp);
648
+ state.checkout = payment.checkout;
649
+ state.methods = getAvailableCheckoutMethods(payment.checkout);
650
+ state.cryptoCurrency = getCheckoutCryptoCurrencies(payment.checkout);
140
651
  state.loading[ACTION] = false;
141
652
  state.error[ACTION] = null;
142
653
  });
@@ -172,11 +683,12 @@ export const getPayment = async () => {
172
683
  try {
173
684
  const resp = await getPaymentById(payment.id);
174
685
  if (resp) {
686
+ updatePaymentSnapshot(resp);
175
687
  set((state) => {
176
- state.payment = resp;
177
688
  state.loading[ACTION] = false;
178
689
  state.error[ACTION] = null;
179
690
  });
691
+ hydrateCheckoutFromPayment(resp);
180
692
  return resp;
181
693
  }
182
694
  else {
@@ -195,26 +707,304 @@ export const getPayment = async () => {
195
707
  return null;
196
708
  }
197
709
  };
710
+ export const executeTransfer = async (wallet) => {
711
+ const ACTION = ACTIONS.EXECUTE_TRANSFER;
712
+ const state = get();
713
+ if (!state.cryptoPaymentAttempt) {
714
+ throw new Error("Missing required data for payment execution");
715
+ }
716
+ set((state) => {
717
+ state.loading[ACTION] = true;
718
+ state.error[ACTION] = null;
719
+ state.transfer.status = "pending";
720
+ state.transfer.error = null;
721
+ state.transfer.transactionHash = null;
722
+ state.transfer.chainStatus = "pending";
723
+ });
724
+ try {
725
+ const settlementChainHex = state.cryptoPaymentAttempt.settlement_config.chain_hex;
726
+ const targetChainId = resolveEvmChainId(settlementChainHex);
727
+ if (targetChainId && wallet.switchChain) {
728
+ await wallet.switchChain(targetChainId);
729
+ }
730
+ else {
731
+ await switchEvmWalletChain(settlementChainHex);
732
+ }
733
+ const address = await wallet.getAddress();
734
+ if (!address) {
735
+ throw new Error("Failed to get wallet address");
736
+ }
737
+ const transfer = {
738
+ sendingAddress: address,
739
+ destinationAddress: state.cryptoPaymentAttempt.destination_address,
740
+ amount: state.cryptoPaymentAttempt.amount,
741
+ evm: {
742
+ implementationAddress: state.cryptoPaymentAttempt.settlement_token_address,
743
+ assetName: state.cryptoPaymentAttempt.settlement_config.asset_name,
744
+ },
745
+ };
746
+ const txHash = await wallet.executeTransfer(transfer);
747
+ if (!txHash) {
748
+ throw new Error("Failed to get transaction hash");
749
+ }
750
+ set((state) => {
751
+ state.transfer.status = "success";
752
+ state.transfer.transactionHash = txHash;
753
+ state.loading[ACTION] = false;
754
+ state.error[ACTION] = null;
755
+ });
756
+ return txHash;
757
+ }
758
+ catch (error) {
759
+ const errorMessage = error instanceof Error ? error.message : "Failed to execute transfer";
760
+ set((state) => {
761
+ state.transfer.status = "failed";
762
+ state.transfer.error = errorMessage;
763
+ state.loading[ACTION] = false;
764
+ state.error[ACTION] = errorMessage;
765
+ });
766
+ throw error instanceof Error ? error : new Error(errorMessage);
767
+ }
768
+ };
769
+ export const checkChainStatus = async (wallet) => {
770
+ const ACTION = ACTIONS.CHECK_CHAIN_STATUS;
771
+ const state = get();
772
+ if (state.transfer.status !== "success" || !state.transfer.transactionHash) {
773
+ return;
774
+ }
775
+ // Check if the wallet is a WagmiWalletInterface
776
+ if (!(wallet instanceof WagmiWalletInterface)) {
777
+ const error = new Error("Wallet does not support chain status checks");
778
+ console.error(error.message);
779
+ set((state) => {
780
+ state.transfer.status = "failed";
781
+ state.transfer.error = error.message;
782
+ state.transfer.chainStatus = "failed";
783
+ state.error[ACTION] = error.message;
784
+ });
785
+ throw error;
786
+ }
787
+ set((state) => {
788
+ state.loading[ACTION] = true;
789
+ state.error[ACTION] = null;
790
+ });
791
+ try {
792
+ const receipt = await waitForTransactionReceipt(wallet.wagmiConfig, {
793
+ hash: state.transfer.transactionHash,
794
+ confirmations: 1,
795
+ });
796
+ if (receipt.status === "reverted") {
797
+ throw new Error("Transaction reverted before confirmation");
798
+ }
799
+ set((state) => {
800
+ state.transfer.chainStatus = "confirmed";
801
+ state.loading[ACTION] = false;
802
+ state.error[ACTION] = null;
803
+ });
804
+ }
805
+ catch (error) {
806
+ console.error("Error checking transaction status:", error);
807
+ const errorMessage = error instanceof Error ? error.message : "Failed to check chain status";
808
+ set((state) => {
809
+ state.transfer.status = "failed";
810
+ state.transfer.error = errorMessage;
811
+ state.transfer.chainStatus = "failed";
812
+ state.loading[ACTION] = false;
813
+ state.error[ACTION] = errorMessage;
814
+ });
815
+ throw error instanceof Error ? error : new Error(errorMessage);
816
+ }
817
+ };
818
+ export const resetTransfer = () => {
819
+ set((state) => {
820
+ state.transfer = {
821
+ status: "idle",
822
+ error: null,
823
+ transactionHash: null,
824
+ chainStatus: "pending",
825
+ };
826
+ });
827
+ };
828
+ export const startPaymentPolling = (onPaymentStatusChange, confirmationStatus = PaymentStatus.PAID) => {
829
+ const ACTION = ACTIONS.POLL_PAYMENT;
830
+ const POLL_INTERVAL = 5000;
831
+ let pollInterval = null;
832
+ const pollPaymentStatus = async () => {
833
+ const state = get();
834
+ if (!state.polling.isPolling)
835
+ return;
836
+ set((state) => {
837
+ state.polling.pollCount++;
838
+ state.polling.lastPollTime = Date.now();
839
+ });
840
+ try {
841
+ const updatedPayment = await getPayment();
842
+ if (!updatedPayment) {
843
+ return;
844
+ }
845
+ const successStatuses = confirmationStatus === PaymentStatus.PAID
846
+ ? [PaymentStatus.PAID]
847
+ : [confirmationStatus, PaymentStatus.PAID];
848
+ if (successStatuses.includes(updatedPayment.status) ||
849
+ updatedPayment.status === PaymentStatus.FAILED) {
850
+ onPaymentStatusChange(updatedPayment.status);
851
+ stopPaymentPolling();
852
+ }
853
+ }
854
+ catch (error) {
855
+ console.error(`[Payment Poll] Error fetching payment status (poll #${state.polling.pollCount}):`, error);
856
+ }
857
+ };
858
+ const stopPolling = () => {
859
+ if (pollInterval) {
860
+ clearInterval(pollInterval);
861
+ pollInterval = null;
862
+ }
863
+ set((state) => {
864
+ state.polling.isPolling = false;
865
+ });
866
+ };
867
+ set((state) => {
868
+ state.polling.isPolling = true;
869
+ state.polling.pollCount = 0;
870
+ state.polling.lastPollTime = null;
871
+ state.loading[ACTION] = true;
872
+ state.error[ACTION] = null;
873
+ });
874
+ // Start polling immediately
875
+ void pollPaymentStatus();
876
+ // Set up interval for subsequent polls
877
+ pollInterval = setInterval(pollPaymentStatus, POLL_INTERVAL);
878
+ return {
879
+ stop: stopPolling,
880
+ };
881
+ };
882
+ export const stopPaymentPolling = () => {
883
+ set((state) => {
884
+ state.polling.isPolling = false;
885
+ state.polling.pollCount = 0;
886
+ state.polling.lastPollTime = null;
887
+ state.loading[ACTIONS.POLL_PAYMENT] = false;
888
+ });
889
+ };
198
890
  export const resetCheckoutStore = () => {
891
+ refreshMode = "none";
892
+ isRefreshing = false;
893
+ clearQuoteExpiryTimer();
199
894
  set((state) => {
200
895
  Object.assign(state, {
201
896
  amount: null,
202
897
  checkoutId: null,
203
898
  selectedMethod: null,
204
899
  selectedCurrency: null,
900
+ retrySession: false,
205
901
  methods: null,
206
- cryptoCurrencies: null,
902
+ cryptoCurrency: null,
207
903
  checkout: null,
208
904
  payment: null,
209
905
  cryptoPaymentAttempt: null,
906
+ quote: {
907
+ status: "idle",
908
+ error: null,
909
+ expiresAt: null,
910
+ remainingMs: null,
911
+ totalDurationMs: null,
912
+ },
210
913
  loading: initialActionState(false),
211
914
  error: initialActionState(null),
915
+ transfer: {
916
+ status: "idle",
917
+ error: null,
918
+ transactionHash: null,
919
+ chainStatus: "pending",
920
+ },
921
+ polling: {
922
+ isPolling: false,
923
+ pollCount: 0,
924
+ lastPollTime: null,
925
+ },
926
+ walletPayment: initialWalletPaymentState(),
212
927
  });
213
928
  });
214
929
  };
930
+ export const resetCheckoutSessionForRetry = () => {
931
+ refreshMode = "none";
932
+ isRefreshing = false;
933
+ clearQuoteExpiryTimer();
934
+ set((state) => {
935
+ // Retry keeps the same payment intent but discards all attempt-scoped UI
936
+ // state so the payer can choose a fresh route. The payment object itself is
937
+ // preserved elsewhere in the store; this reset only clears execution state
938
+ // that was tied to the previous attempt.
939
+ state.selectedMethod = null;
940
+ state.selectedCurrency = null;
941
+ state.retrySession = true;
942
+ state.cryptoPaymentAttempt = null;
943
+ state.processing = false;
944
+ state.transfer = {
945
+ status: "idle",
946
+ error: null,
947
+ transactionHash: null,
948
+ chainStatus: "pending",
949
+ };
950
+ state.polling = {
951
+ isPolling: false,
952
+ pollCount: 0,
953
+ lastPollTime: null,
954
+ };
955
+ state.walletPayment = initialWalletPaymentState();
956
+ state.quote = {
957
+ status: "idle",
958
+ error: null,
959
+ expiresAt: null,
960
+ remainingMs: null,
961
+ totalDurationMs: null,
962
+ };
963
+ state.error[ACTIONS.CREATE_PAYMENT_ATTEMPT] = null;
964
+ state.error[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = null;
965
+ state.error[ACTIONS.EXECUTE_TRANSFER] = null;
966
+ state.error[ACTIONS.POLL_PAYMENT] = null;
967
+ state.error[ACTIONS.CHECK_CHAIN_STATUS] = null;
968
+ state.loading[ACTIONS.CREATE_PAYMENT_ATTEMPT] = false;
969
+ state.loading[ACTIONS.CREATE_TEST_PAYMENT_ATTEMPT] = false;
970
+ state.loading[ACTIONS.EXECUTE_TRANSFER] = false;
971
+ state.loading[ACTIONS.POLL_PAYMENT] = false;
972
+ state.loading[ACTIONS.CHECK_CHAIN_STATUS] = false;
973
+ });
974
+ };
215
975
  export const setCheckoutMethod = (method) => {
216
976
  set((state) => {
217
977
  state.selectedMethod = method;
218
978
  });
219
979
  };
980
+ export const setProcessing = (processing) => {
981
+ set((state) => {
982
+ state.processing = processing;
983
+ });
984
+ };
985
+ export const getProcessing = () => {
986
+ return get().processing;
987
+ };
988
+ export const setSelectedCurrency = (currency) => {
989
+ set((state) => {
990
+ state.selectedCurrency = currency;
991
+ });
992
+ };
993
+ export const isTestMode = () => {
994
+ const state = get();
995
+ if (state.checkout?.is_live !== undefined) {
996
+ return !state.checkout.is_live;
997
+ }
998
+ return false;
999
+ };
1000
+ export const setWalletPaymentState = (update) => {
1001
+ set((state) => {
1002
+ Object.assign(state.walletPayment, update);
1003
+ });
1004
+ };
1005
+ export const resetWalletPaymentState = () => {
1006
+ set((state) => {
1007
+ state.walletPayment = initialWalletPaymentState();
1008
+ });
1009
+ };
220
1010
  //# sourceMappingURL=store.js.map