thirdweb 5.108.6 → 5.108.7

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 (391) hide show
  1. package/dist/cjs/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  2. package/dist/cjs/react/core/hooks/usePaymentMethods.js +1 -2
  3. package/dist/cjs/react/core/hooks/usePaymentMethods.js.map +1 -1
  4. package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js +1 -1
  5. package/dist/cjs/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
  6. package/dist/cjs/react/web/ui/Bridge/BuyWidget.js +185 -99
  7. package/dist/cjs/react/web/ui/Bridge/BuyWidget.js.map +1 -1
  8. package/dist/cjs/react/web/ui/Bridge/CheckoutWidget.js +210 -56
  9. package/dist/cjs/react/web/ui/Bridge/CheckoutWidget.js.map +1 -1
  10. package/dist/cjs/react/web/ui/Bridge/DirectPayment.js +7 -7
  11. package/dist/cjs/react/web/ui/Bridge/DirectPayment.js.map +1 -1
  12. package/dist/cjs/react/web/ui/Bridge/FundWallet.js +233 -105
  13. package/dist/cjs/react/web/ui/Bridge/FundWallet.js.map +1 -1
  14. package/dist/cjs/react/web/ui/Bridge/QuoteLoader.js +1 -7
  15. package/dist/cjs/react/web/ui/Bridge/QuoteLoader.js.map +1 -1
  16. package/dist/cjs/react/web/ui/Bridge/TransactionPayment.js +16 -12
  17. package/dist/cjs/react/web/ui/Bridge/TransactionPayment.js.map +1 -1
  18. package/dist/cjs/react/web/ui/Bridge/TransactionWidget.js +199 -36
  19. package/dist/cjs/react/web/ui/Bridge/TransactionWidget.js.map +1 -1
  20. package/dist/cjs/react/web/ui/Bridge/bridge-widget/bridge-widget.js +2 -2
  21. package/dist/cjs/react/web/ui/Bridge/bridge-widget/bridge-widget.js.map +1 -1
  22. package/dist/cjs/react/web/ui/Bridge/common/WithHeader.js +4 -5
  23. package/dist/cjs/react/web/ui/Bridge/common/WithHeader.js.map +1 -1
  24. package/dist/cjs/react/web/ui/Bridge/common/active-wallet-details.js +52 -0
  25. package/dist/cjs/react/web/ui/Bridge/common/active-wallet-details.js.map +1 -0
  26. package/dist/cjs/react/web/ui/Bridge/common/decimal-input.js +36 -0
  27. package/dist/cjs/react/web/ui/Bridge/common/decimal-input.js.map +1 -0
  28. package/dist/cjs/react/web/ui/Bridge/common/selected-token-button.js +58 -0
  29. package/dist/cjs/react/web/ui/Bridge/common/selected-token-button.js.map +1 -0
  30. package/dist/cjs/react/web/ui/Bridge/common/token-balance.js +20 -0
  31. package/dist/cjs/react/web/ui/Bridge/common/token-balance.js.map +1 -0
  32. package/dist/cjs/react/web/ui/Bridge/common/token-query.js +34 -0
  33. package/dist/cjs/react/web/ui/Bridge/common/token-query.js.map +1 -0
  34. package/dist/cjs/react/web/ui/Bridge/payment-details/PaymentDetails.js +3 -3
  35. package/dist/cjs/react/web/ui/Bridge/payment-details/PaymentDetails.js.map +1 -1
  36. package/dist/cjs/react/web/ui/Bridge/payment-details/PaymentOverview.js +7 -7
  37. package/dist/cjs/react/web/ui/Bridge/payment-details/PaymentOverview.js.map +1 -1
  38. package/dist/cjs/react/web/ui/Bridge/payment-selection/PaymentSelection.js +1 -4
  39. package/dist/cjs/react/web/ui/Bridge/payment-selection/PaymentSelection.js.map +1 -1
  40. package/dist/cjs/react/web/ui/Bridge/payment-selection/TokenSelection.js.map +1 -1
  41. package/dist/cjs/react/web/ui/Bridge/payment-success/SuccessScreen.js +3 -3
  42. package/dist/cjs/react/web/ui/Bridge/payment-success/SuccessScreen.js.map +1 -1
  43. package/dist/cjs/react/web/ui/Bridge/swap-widget/SwapWidget.js +8 -11
  44. package/dist/cjs/react/web/ui/Bridge/swap-widget/SwapWidget.js.map +1 -1
  45. package/dist/cjs/react/web/ui/Bridge/swap-widget/swap-ui.js +19 -147
  46. package/dist/cjs/react/web/ui/Bridge/swap-widget/swap-ui.js.map +1 -1
  47. package/dist/cjs/react/web/ui/Bridge/types.js +3 -0
  48. package/dist/cjs/react/web/ui/Bridge/types.js.map +1 -0
  49. package/dist/cjs/react/web/ui/ConnectWallet/Details.js +4 -2
  50. package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
  51. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.js +1 -1
  52. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.js.map +1 -1
  53. package/dist/cjs/react/web/ui/ConnectWallet/screens/formatTokenBalance.js.map +1 -1
  54. package/dist/cjs/react/web/ui/TransactionButton/DepositScreen.js +1 -1
  55. package/dist/cjs/react/web/ui/TransactionButton/DepositScreen.js.map +1 -1
  56. package/dist/cjs/react/web/ui/TransactionButton/TransactionModal.js +17 -10
  57. package/dist/cjs/react/web/ui/TransactionButton/TransactionModal.js.map +1 -1
  58. package/dist/cjs/react/web/ui/components/CopyIcon.js +1 -1
  59. package/dist/cjs/react/web/ui/components/CopyIcon.js.map +1 -1
  60. package/dist/cjs/stories/Bridge/CheckoutWidget.stories.js +115 -0
  61. package/dist/cjs/stories/Bridge/CheckoutWidget.stories.js.map +1 -0
  62. package/dist/cjs/stories/Bridge/ErrorBanner.stories.js +7 -111
  63. package/dist/cjs/stories/Bridge/ErrorBanner.stories.js.map +1 -1
  64. package/dist/cjs/stories/Bridge/PaymentDetails.stories.js +27 -306
  65. package/dist/cjs/stories/Bridge/PaymentDetails.stories.js.map +1 -1
  66. package/dist/cjs/stories/Bridge/PaymentSelection.stories.js +21 -128
  67. package/dist/cjs/stories/Bridge/PaymentSelection.stories.js.map +1 -1
  68. package/dist/cjs/stories/Bridge/StepRunner.stories.js +13 -39
  69. package/dist/cjs/stories/Bridge/StepRunner.stories.js.map +1 -1
  70. package/dist/cjs/stories/Bridge/SuccessScreen.stories.js +13 -101
  71. package/dist/cjs/stories/Bridge/SuccessScreen.stories.js.map +1 -1
  72. package/dist/cjs/stories/Bridge/Transaction/TransactionWidget.stories.js +49 -0
  73. package/dist/cjs/stories/Bridge/Transaction/TransactionWidget.stories.js.map +1 -0
  74. package/dist/cjs/stories/Bridge/Transaction/useSendTransactionModal.stories.js +53 -0
  75. package/dist/cjs/stories/Bridge/Transaction/useSendTransactionModal.stories.js.map +1 -0
  76. package/dist/cjs/stories/Bridge/UnsupportedTokenScreen.stories.js +11 -79
  77. package/dist/cjs/stories/Bridge/UnsupportedTokenScreen.stories.js.map +1 -1
  78. package/dist/cjs/stories/Bridge/fixtures.js +21 -62
  79. package/dist/cjs/stories/Bridge/fixtures.js.map +1 -1
  80. package/dist/cjs/stories/BuyWidget.stories.js +44 -8
  81. package/dist/cjs/stories/BuyWidget.stories.js.map +1 -1
  82. package/dist/cjs/stories/utils.js +5 -2
  83. package/dist/cjs/stories/utils.js.map +1 -1
  84. package/dist/cjs/version.js +1 -1
  85. package/dist/cjs/x402/common.js +3 -5
  86. package/dist/cjs/x402/common.js.map +1 -1
  87. package/dist/cjs/x402/facilitator.js +0 -1
  88. package/dist/cjs/x402/facilitator.js.map +1 -1
  89. package/dist/cjs/x402/schemas.js +4 -0
  90. package/dist/cjs/x402/schemas.js.map +1 -1
  91. package/dist/cjs/x402/settle-payment.js +6 -5
  92. package/dist/cjs/x402/settle-payment.js.map +1 -1
  93. package/dist/cjs/x402/sign.js +2 -6
  94. package/dist/cjs/x402/sign.js.map +1 -1
  95. package/dist/cjs/x402/types.js.map +1 -1
  96. package/dist/cjs/x402/verify-payment.js +6 -5
  97. package/dist/cjs/x402/verify-payment.js.map +1 -1
  98. package/dist/esm/react/core/hooks/transaction/useSendTransaction.js.map +1 -1
  99. package/dist/esm/react/core/hooks/usePaymentMethods.js +1 -2
  100. package/dist/esm/react/core/hooks/usePaymentMethods.js.map +1 -1
  101. package/dist/esm/react/web/hooks/transaction/useSendTransaction.js +1 -1
  102. package/dist/esm/react/web/hooks/transaction/useSendTransaction.js.map +1 -1
  103. package/dist/esm/react/web/ui/Bridge/BuyWidget.js +185 -99
  104. package/dist/esm/react/web/ui/Bridge/BuyWidget.js.map +1 -1
  105. package/dist/esm/react/web/ui/Bridge/CheckoutWidget.js +211 -57
  106. package/dist/esm/react/web/ui/Bridge/CheckoutWidget.js.map +1 -1
  107. package/dist/esm/react/web/ui/Bridge/DirectPayment.js +7 -7
  108. package/dist/esm/react/web/ui/Bridge/DirectPayment.js.map +1 -1
  109. package/dist/esm/react/web/ui/Bridge/FundWallet.js +237 -109
  110. package/dist/esm/react/web/ui/Bridge/FundWallet.js.map +1 -1
  111. package/dist/esm/react/web/ui/Bridge/QuoteLoader.js +1 -7
  112. package/dist/esm/react/web/ui/Bridge/QuoteLoader.js.map +1 -1
  113. package/dist/esm/react/web/ui/Bridge/TransactionPayment.js +16 -12
  114. package/dist/esm/react/web/ui/Bridge/TransactionPayment.js.map +1 -1
  115. package/dist/esm/react/web/ui/Bridge/TransactionWidget.js +198 -36
  116. package/dist/esm/react/web/ui/Bridge/TransactionWidget.js.map +1 -1
  117. package/dist/esm/react/web/ui/Bridge/bridge-widget/bridge-widget.js +2 -2
  118. package/dist/esm/react/web/ui/Bridge/bridge-widget/bridge-widget.js.map +1 -1
  119. package/dist/esm/react/web/ui/Bridge/common/WithHeader.js +4 -5
  120. package/dist/esm/react/web/ui/Bridge/common/WithHeader.js.map +1 -1
  121. package/dist/esm/react/web/ui/Bridge/common/active-wallet-details.js +49 -0
  122. package/dist/esm/react/web/ui/Bridge/common/active-wallet-details.js.map +1 -0
  123. package/dist/esm/react/web/ui/Bridge/common/decimal-input.js +33 -0
  124. package/dist/esm/react/web/ui/Bridge/common/decimal-input.js.map +1 -0
  125. package/dist/esm/react/web/ui/Bridge/common/selected-token-button.js +55 -0
  126. package/dist/esm/react/web/ui/Bridge/common/selected-token-button.js.map +1 -0
  127. package/dist/esm/react/web/ui/Bridge/common/token-balance.js +17 -0
  128. package/dist/esm/react/web/ui/Bridge/common/token-balance.js.map +1 -0
  129. package/dist/esm/react/web/ui/Bridge/common/token-query.js +31 -0
  130. package/dist/esm/react/web/ui/Bridge/common/token-query.js.map +1 -0
  131. package/dist/esm/react/web/ui/Bridge/payment-details/PaymentDetails.js +3 -3
  132. package/dist/esm/react/web/ui/Bridge/payment-details/PaymentDetails.js.map +1 -1
  133. package/dist/esm/react/web/ui/Bridge/payment-details/PaymentOverview.js +7 -7
  134. package/dist/esm/react/web/ui/Bridge/payment-details/PaymentOverview.js.map +1 -1
  135. package/dist/esm/react/web/ui/Bridge/payment-selection/PaymentSelection.js +1 -4
  136. package/dist/esm/react/web/ui/Bridge/payment-selection/PaymentSelection.js.map +1 -1
  137. package/dist/esm/react/web/ui/Bridge/payment-selection/TokenSelection.js.map +1 -1
  138. package/dist/esm/react/web/ui/Bridge/payment-success/SuccessScreen.js +3 -3
  139. package/dist/esm/react/web/ui/Bridge/payment-success/SuccessScreen.js.map +1 -1
  140. package/dist/esm/react/web/ui/Bridge/swap-widget/SwapWidget.js +8 -11
  141. package/dist/esm/react/web/ui/Bridge/swap-widget/SwapWidget.js.map +1 -1
  142. package/dist/esm/react/web/ui/Bridge/swap-widget/swap-ui.js +16 -144
  143. package/dist/esm/react/web/ui/Bridge/swap-widget/swap-ui.js.map +1 -1
  144. package/dist/esm/react/web/ui/Bridge/types.js +2 -0
  145. package/dist/esm/react/web/ui/Bridge/types.js.map +1 -0
  146. package/dist/esm/react/web/ui/ConnectWallet/Details.js +4 -2
  147. package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
  148. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.js +1 -1
  149. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.js.map +1 -1
  150. package/dist/esm/react/web/ui/ConnectWallet/screens/formatTokenBalance.js.map +1 -1
  151. package/dist/esm/react/web/ui/TransactionButton/DepositScreen.js +1 -1
  152. package/dist/esm/react/web/ui/TransactionButton/DepositScreen.js.map +1 -1
  153. package/dist/esm/react/web/ui/TransactionButton/TransactionModal.js +17 -10
  154. package/dist/esm/react/web/ui/TransactionButton/TransactionModal.js.map +1 -1
  155. package/dist/esm/react/web/ui/components/CopyIcon.js +1 -1
  156. package/dist/esm/react/web/ui/components/CopyIcon.js.map +1 -1
  157. package/dist/esm/stories/Bridge/CheckoutWidget.stories.js +112 -0
  158. package/dist/esm/stories/Bridge/CheckoutWidget.stories.js.map +1 -0
  159. package/dist/esm/stories/Bridge/ErrorBanner.stories.js +7 -111
  160. package/dist/esm/stories/Bridge/ErrorBanner.stories.js.map +1 -1
  161. package/dist/esm/stories/Bridge/PaymentDetails.stories.js +28 -307
  162. package/dist/esm/stories/Bridge/PaymentDetails.stories.js.map +1 -1
  163. package/dist/esm/stories/Bridge/PaymentSelection.stories.js +22 -129
  164. package/dist/esm/stories/Bridge/PaymentSelection.stories.js.map +1 -1
  165. package/dist/esm/stories/Bridge/StepRunner.stories.js +12 -38
  166. package/dist/esm/stories/Bridge/StepRunner.stories.js.map +1 -1
  167. package/dist/esm/stories/Bridge/SuccessScreen.stories.js +14 -102
  168. package/dist/esm/stories/Bridge/SuccessScreen.stories.js.map +1 -1
  169. package/dist/esm/stories/Bridge/Transaction/TransactionWidget.stories.js +46 -0
  170. package/dist/esm/stories/Bridge/Transaction/TransactionWidget.stories.js.map +1 -0
  171. package/dist/esm/stories/Bridge/Transaction/useSendTransactionModal.stories.js +50 -0
  172. package/dist/esm/stories/Bridge/Transaction/useSendTransactionModal.stories.js.map +1 -0
  173. package/dist/esm/stories/Bridge/UnsupportedTokenScreen.stories.js +12 -80
  174. package/dist/esm/stories/Bridge/UnsupportedTokenScreen.stories.js.map +1 -1
  175. package/dist/esm/stories/Bridge/fixtures.js +15 -56
  176. package/dist/esm/stories/Bridge/fixtures.js.map +1 -1
  177. package/dist/esm/stories/BuyWidget.stories.js +37 -9
  178. package/dist/esm/stories/BuyWidget.stories.js.map +1 -1
  179. package/dist/esm/stories/utils.js +6 -3
  180. package/dist/esm/stories/utils.js.map +1 -1
  181. package/dist/esm/version.js +1 -1
  182. package/dist/esm/x402/common.js +3 -5
  183. package/dist/esm/x402/common.js.map +1 -1
  184. package/dist/esm/x402/facilitator.js +0 -1
  185. package/dist/esm/x402/facilitator.js.map +1 -1
  186. package/dist/esm/x402/schemas.js +5 -1
  187. package/dist/esm/x402/schemas.js.map +1 -1
  188. package/dist/esm/x402/settle-payment.js +6 -5
  189. package/dist/esm/x402/settle-payment.js.map +1 -1
  190. package/dist/esm/x402/sign.js +2 -6
  191. package/dist/esm/x402/sign.js.map +1 -1
  192. package/dist/esm/x402/types.js.map +1 -1
  193. package/dist/esm/x402/verify-payment.js +6 -5
  194. package/dist/esm/x402/verify-payment.js.map +1 -1
  195. package/dist/scripts/bridge-widget.d.ts +3 -3
  196. package/dist/scripts/bridge-widget.js +113 -150
  197. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts +6 -0
  198. package/dist/types/react/core/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  199. package/dist/types/react/core/hooks/usePaymentMethods.d.ts +1 -2
  200. package/dist/types/react/core/hooks/usePaymentMethods.d.ts.map +1 -1
  201. package/dist/types/react/web/hooks/transaction/useSendTransaction.d.ts.map +1 -1
  202. package/dist/types/react/web/ui/Bridge/BuyWidget.d.ts +7 -12
  203. package/dist/types/react/web/ui/Bridge/BuyWidget.d.ts.map +1 -1
  204. package/dist/types/react/web/ui/Bridge/CheckoutWidget.d.ts +5 -8
  205. package/dist/types/react/web/ui/Bridge/CheckoutWidget.d.ts.map +1 -1
  206. package/dist/types/react/web/ui/Bridge/DirectPayment.d.ts +15 -12
  207. package/dist/types/react/web/ui/Bridge/DirectPayment.d.ts.map +1 -1
  208. package/dist/types/react/web/ui/Bridge/FundWallet.d.ts +33 -15
  209. package/dist/types/react/web/ui/Bridge/FundWallet.d.ts.map +1 -1
  210. package/dist/types/react/web/ui/Bridge/QuoteLoader.d.ts +9 -12
  211. package/dist/types/react/web/ui/Bridge/QuoteLoader.d.ts.map +1 -1
  212. package/dist/types/react/web/ui/Bridge/StepRunner.d.ts +7 -7
  213. package/dist/types/react/web/ui/Bridge/StepRunner.d.ts.map +1 -1
  214. package/dist/types/react/web/ui/Bridge/TransactionPayment.d.ts +14 -7
  215. package/dist/types/react/web/ui/Bridge/TransactionPayment.d.ts.map +1 -1
  216. package/dist/types/react/web/ui/Bridge/TransactionWidget.d.ts +3 -5
  217. package/dist/types/react/web/ui/Bridge/TransactionWidget.d.ts.map +1 -1
  218. package/dist/types/react/web/ui/Bridge/UnsupportedTokenScreen.d.ts +4 -3
  219. package/dist/types/react/web/ui/Bridge/UnsupportedTokenScreen.d.ts.map +1 -1
  220. package/dist/types/react/web/ui/Bridge/bridge-widget/bridge-widget.d.ts +3 -3
  221. package/dist/types/react/web/ui/Bridge/bridge-widget/bridge-widget.d.ts.map +1 -1
  222. package/dist/types/react/web/ui/Bridge/common/WithHeader.d.ts +4 -4
  223. package/dist/types/react/web/ui/Bridge/common/WithHeader.d.ts.map +1 -1
  224. package/dist/types/react/web/ui/Bridge/common/active-wallet-details.d.ts +8 -0
  225. package/dist/types/react/web/ui/Bridge/common/active-wallet-details.d.ts.map +1 -0
  226. package/dist/types/react/web/ui/Bridge/common/decimal-input.d.ts +6 -0
  227. package/dist/types/react/web/ui/Bridge/common/decimal-input.d.ts.map +1 -0
  228. package/dist/types/react/web/ui/Bridge/common/selected-token-button.d.ts +13 -0
  229. package/dist/types/react/web/ui/Bridge/common/selected-token-button.d.ts.map +1 -0
  230. package/dist/types/react/web/ui/Bridge/common/token-balance.d.ts +8 -0
  231. package/dist/types/react/web/ui/Bridge/common/token-balance.d.ts.map +1 -0
  232. package/dist/types/react/web/ui/Bridge/common/token-query.d.ts +15 -0
  233. package/dist/types/react/web/ui/Bridge/common/token-query.d.ts.map +1 -0
  234. package/dist/types/react/web/ui/Bridge/payment-details/PaymentDetails.d.ts +13 -11
  235. package/dist/types/react/web/ui/Bridge/payment-details/PaymentDetails.d.ts.map +1 -1
  236. package/dist/types/react/web/ui/Bridge/payment-details/PaymentOverview.d.ts +8 -3
  237. package/dist/types/react/web/ui/Bridge/payment-details/PaymentOverview.d.ts.map +1 -1
  238. package/dist/types/react/web/ui/Bridge/payment-selection/PaymentSelection.d.ts +12 -16
  239. package/dist/types/react/web/ui/Bridge/payment-selection/PaymentSelection.d.ts.map +1 -1
  240. package/dist/types/react/web/ui/Bridge/payment-selection/TokenSelection.d.ts +1 -1
  241. package/dist/types/react/web/ui/Bridge/payment-selection/TokenSelection.d.ts.map +1 -1
  242. package/dist/types/react/web/ui/Bridge/payment-success/SuccessScreen.d.ts +6 -6
  243. package/dist/types/react/web/ui/Bridge/payment-success/SuccessScreen.d.ts.map +1 -1
  244. package/dist/types/react/web/ui/Bridge/swap-widget/swap-ui.d.ts.map +1 -1
  245. package/dist/types/react/web/ui/Bridge/types.d.ts +39 -0
  246. package/dist/types/react/web/ui/Bridge/types.d.ts.map +1 -0
  247. package/dist/types/react/web/ui/ConnectWallet/Details.d.ts.map +1 -1
  248. package/dist/types/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.d.ts.map +1 -1
  249. package/dist/types/react/web/ui/ConnectWallet/screens/formatTokenBalance.d.ts +2 -1
  250. package/dist/types/react/web/ui/ConnectWallet/screens/formatTokenBalance.d.ts.map +1 -1
  251. package/dist/types/react/web/ui/TransactionButton/DepositScreen.d.ts +0 -1
  252. package/dist/types/react/web/ui/TransactionButton/DepositScreen.d.ts.map +1 -1
  253. package/dist/types/react/web/ui/TransactionButton/TransactionModal.d.ts +3 -1
  254. package/dist/types/react/web/ui/TransactionButton/TransactionModal.d.ts.map +1 -1
  255. package/dist/types/react/web/ui/components/CopyIcon.d.ts +1 -0
  256. package/dist/types/react/web/ui/components/CopyIcon.d.ts.map +1 -1
  257. package/dist/types/script-exports/bridge-widget-script.d.ts +3 -3
  258. package/dist/types/script-exports/bridge-widget-script.d.ts.map +1 -1
  259. package/dist/types/stories/Bridge/CheckoutWidget.stories.d.ts +25 -0
  260. package/dist/types/stories/Bridge/CheckoutWidget.stories.d.ts.map +1 -0
  261. package/dist/types/stories/Bridge/ErrorBanner.stories.d.ts +3 -47
  262. package/dist/types/stories/Bridge/ErrorBanner.stories.d.ts.map +1 -1
  263. package/dist/types/stories/Bridge/PaymentDetails.stories.d.ts +3 -56
  264. package/dist/types/stories/Bridge/PaymentDetails.stories.d.ts.map +1 -1
  265. package/dist/types/stories/Bridge/PaymentSelection.stories.d.ts +5 -63
  266. package/dist/types/stories/Bridge/PaymentSelection.stories.d.ts.map +1 -1
  267. package/dist/types/stories/Bridge/StepRunner.stories.d.ts +4 -52
  268. package/dist/types/stories/Bridge/StepRunner.stories.d.ts.map +1 -1
  269. package/dist/types/stories/Bridge/SuccessScreen.stories.d.ts +4 -54
  270. package/dist/types/stories/Bridge/SuccessScreen.stories.d.ts.map +1 -1
  271. package/dist/types/stories/Bridge/Transaction/TransactionWidget.stories.d.ts +11 -0
  272. package/dist/types/stories/Bridge/Transaction/TransactionWidget.stories.d.ts.map +1 -0
  273. package/dist/types/stories/Bridge/Transaction/useSendTransactionModal.stories.d.ts +18 -0
  274. package/dist/types/stories/Bridge/Transaction/useSendTransactionModal.stories.d.ts.map +1 -0
  275. package/dist/types/stories/Bridge/UnsupportedTokenScreen.stories.d.ts +3 -34
  276. package/dist/types/stories/Bridge/UnsupportedTokenScreen.stories.d.ts.map +1 -1
  277. package/dist/types/stories/Bridge/fixtures.d.ts +19 -17
  278. package/dist/types/stories/Bridge/fixtures.d.ts.map +1 -1
  279. package/dist/types/stories/BuyWidget.stories.d.ts +9 -1
  280. package/dist/types/stories/BuyWidget.stories.d.ts.map +1 -1
  281. package/dist/types/stories/utils.d.ts +0 -2
  282. package/dist/types/stories/utils.d.ts.map +1 -1
  283. package/dist/types/version.d.ts +1 -1
  284. package/dist/types/x402/common.d.ts.map +1 -1
  285. package/dist/types/x402/facilitator.d.ts +2 -3
  286. package/dist/types/x402/facilitator.d.ts.map +1 -1
  287. package/dist/types/x402/schemas.d.ts +21 -0
  288. package/dist/types/x402/schemas.d.ts.map +1 -1
  289. package/dist/types/x402/settle-payment.d.ts.map +1 -1
  290. package/dist/types/x402/types.d.ts +5 -4
  291. package/dist/types/x402/types.d.ts.map +1 -1
  292. package/dist/types/x402/verify-payment.d.ts.map +1 -1
  293. package/package.json +1 -1
  294. package/src/react/core/hooks/transaction/useSendTransaction.ts +6 -0
  295. package/src/react/core/hooks/usePaymentMethods.ts +1 -4
  296. package/src/react/web/hooks/transaction/useSendTransaction.tsx +1 -0
  297. package/src/react/web/ui/Bridge/BuyWidget.tsx +355 -160
  298. package/src/react/web/ui/Bridge/CheckoutWidget.tsx +384 -107
  299. package/src/react/web/ui/Bridge/DirectPayment.tsx +34 -26
  300. package/src/react/web/ui/Bridge/FundWallet.tsx +610 -266
  301. package/src/react/web/ui/Bridge/QuoteLoader.tsx +10 -20
  302. package/src/react/web/ui/Bridge/StepRunner.tsx +7 -7
  303. package/src/react/web/ui/Bridge/TransactionPayment.tsx +35 -25
  304. package/src/react/web/ui/Bridge/TransactionWidget.tsx +395 -71
  305. package/src/react/web/ui/Bridge/UnsupportedTokenScreen.tsx +3 -3
  306. package/src/react/web/ui/Bridge/bridge-widget/bridge-widget.tsx +16 -14
  307. package/src/react/web/ui/Bridge/common/WithHeader.tsx +13 -19
  308. package/src/react/web/ui/Bridge/common/active-wallet-details.tsx +103 -0
  309. package/src/react/web/ui/Bridge/common/decimal-input.tsx +61 -0
  310. package/src/react/web/ui/Bridge/common/selected-token-button.tsx +168 -0
  311. package/src/react/web/ui/Bridge/common/token-balance.tsx +23 -0
  312. package/src/react/web/ui/Bridge/common/token-query.ts +49 -0
  313. package/src/react/web/ui/Bridge/payment-details/PaymentDetails.tsx +23 -14
  314. package/src/react/web/ui/Bridge/payment-details/PaymentOverview.tsx +36 -22
  315. package/src/react/web/ui/Bridge/payment-selection/PaymentSelection.tsx +11 -22
  316. package/src/react/web/ui/Bridge/payment-selection/TokenSelection.tsx +1 -1
  317. package/src/react/web/ui/Bridge/payment-success/SuccessScreen.tsx +7 -8
  318. package/src/react/web/ui/Bridge/swap-widget/SwapWidget.tsx +14 -12
  319. package/src/react/web/ui/Bridge/swap-widget/swap-ui.tsx +19 -332
  320. package/src/react/web/ui/Bridge/types.ts +47 -0
  321. package/src/react/web/ui/ConnectWallet/Details.tsx +3 -1
  322. package/src/react/web/ui/ConnectWallet/screens/Buy/swap/WalletRow.tsx +1 -5
  323. package/src/react/web/ui/ConnectWallet/screens/formatTokenBalance.ts +5 -1
  324. package/src/react/web/ui/TransactionButton/DepositScreen.tsx +1 -2
  325. package/src/react/web/ui/TransactionButton/TransactionModal.tsx +44 -27
  326. package/src/react/web/ui/components/CopyIcon.tsx +11 -2
  327. package/src/script-exports/bridge-widget-script.tsx +3 -3
  328. package/src/script-exports/readme.md +1 -8
  329. package/src/stories/Bridge/CheckoutWidget.stories.tsx +147 -0
  330. package/src/stories/Bridge/ErrorBanner.stories.tsx +13 -138
  331. package/src/stories/Bridge/PaymentDetails.stories.tsx +34 -349
  332. package/src/stories/Bridge/PaymentSelection.stories.tsx +28 -156
  333. package/src/stories/Bridge/StepRunner.stories.tsx +18 -65
  334. package/src/stories/Bridge/SuccessScreen.stories.tsx +21 -130
  335. package/src/stories/Bridge/Transaction/TransactionWidget.stories.tsx +63 -0
  336. package/src/stories/Bridge/Transaction/useSendTransactionModal.stories.tsx +68 -0
  337. package/src/stories/Bridge/UnsupportedTokenScreen.stories.tsx +19 -108
  338. package/src/stories/Bridge/fixtures.ts +36 -63
  339. package/src/stories/BuyWidget.stories.tsx +103 -8
  340. package/src/stories/utils.tsx +16 -9
  341. package/src/version.ts +1 -1
  342. package/src/x402/common.ts +2 -5
  343. package/src/x402/facilitator.ts +3 -3
  344. package/src/x402/schemas.ts +10 -0
  345. package/src/x402/settle-payment.ts +7 -6
  346. package/src/x402/sign.ts +3 -8
  347. package/src/x402/types.ts +5 -4
  348. package/src/x402/verify-payment.ts +7 -6
  349. package/dist/cjs/react/core/machines/paymentMachine.js +0 -191
  350. package/dist/cjs/react/core/machines/paymentMachine.js.map +0 -1
  351. package/dist/cjs/react/web/ui/Bridge/BridgeOrchestrator.js +0 -129
  352. package/dist/cjs/react/web/ui/Bridge/BridgeOrchestrator.js.map +0 -1
  353. package/dist/cjs/stories/Bridge/BridgeOrchestrator.stories.js +0 -258
  354. package/dist/cjs/stories/Bridge/BridgeOrchestrator.stories.js.map +0 -1
  355. package/dist/cjs/stories/Bridge/DirectPayment.stories.js +0 -222
  356. package/dist/cjs/stories/Bridge/DirectPayment.stories.js.map +0 -1
  357. package/dist/cjs/stories/Bridge/FundWallet.stories.js +0 -201
  358. package/dist/cjs/stories/Bridge/FundWallet.stories.js.map +0 -1
  359. package/dist/cjs/stories/Bridge/TransactionPayment.stories.js +0 -168
  360. package/dist/cjs/stories/Bridge/TransactionPayment.stories.js.map +0 -1
  361. package/dist/esm/react/core/machines/paymentMachine.js +0 -188
  362. package/dist/esm/react/core/machines/paymentMachine.js.map +0 -1
  363. package/dist/esm/react/web/ui/Bridge/BridgeOrchestrator.js +0 -126
  364. package/dist/esm/react/web/ui/Bridge/BridgeOrchestrator.js.map +0 -1
  365. package/dist/esm/stories/Bridge/BridgeOrchestrator.stories.js +0 -255
  366. package/dist/esm/stories/Bridge/BridgeOrchestrator.stories.js.map +0 -1
  367. package/dist/esm/stories/Bridge/DirectPayment.stories.js +0 -219
  368. package/dist/esm/stories/Bridge/DirectPayment.stories.js.map +0 -1
  369. package/dist/esm/stories/Bridge/FundWallet.stories.js +0 -198
  370. package/dist/esm/stories/Bridge/FundWallet.stories.js.map +0 -1
  371. package/dist/esm/stories/Bridge/TransactionPayment.stories.js +0 -165
  372. package/dist/esm/stories/Bridge/TransactionPayment.stories.js.map +0 -1
  373. package/dist/types/react/core/machines/paymentMachine.d.ts +0 -89
  374. package/dist/types/react/core/machines/paymentMachine.d.ts.map +0 -1
  375. package/dist/types/react/web/ui/Bridge/BridgeOrchestrator.d.ts +0 -99
  376. package/dist/types/react/web/ui/Bridge/BridgeOrchestrator.d.ts.map +0 -1
  377. package/dist/types/stories/Bridge/BridgeOrchestrator.stories.d.ts +0 -97
  378. package/dist/types/stories/Bridge/BridgeOrchestrator.stories.d.ts.map +0 -1
  379. package/dist/types/stories/Bridge/DirectPayment.stories.d.ts +0 -69
  380. package/dist/types/stories/Bridge/DirectPayment.stories.d.ts.map +0 -1
  381. package/dist/types/stories/Bridge/FundWallet.stories.d.ts +0 -67
  382. package/dist/types/stories/Bridge/FundWallet.stories.d.ts.map +0 -1
  383. package/dist/types/stories/Bridge/TransactionPayment.stories.d.ts +0 -60
  384. package/dist/types/stories/Bridge/TransactionPayment.stories.d.ts.map +0 -1
  385. package/src/react/core/machines/paymentMachine.test.ts +0 -519
  386. package/src/react/core/machines/paymentMachine.ts +0 -295
  387. package/src/react/web/ui/Bridge/BridgeOrchestrator.tsx +0 -425
  388. package/src/stories/Bridge/BridgeOrchestrator.stories.tsx +0 -298
  389. package/src/stories/Bridge/DirectPayment.stories.tsx +0 -256
  390. package/src/stories/Bridge/FundWallet.stories.tsx +0 -227
  391. package/src/stories/Bridge/TransactionPayment.stories.tsx +0 -202
@@ -1,43 +1,62 @@
1
1
  /** biome-ignore-all lint/a11y/useSemanticElements: FIXME */
2
2
  "use client";
3
- import { useRef, useState } from "react";
3
+ import { ArrowDownIcon } from "@radix-ui/react-icons";
4
+ import { useState } from "react";
4
5
  import type { TokenWithPrices } from "../../../../bridge/types/Token.js";
5
6
  import type { ThirdwebClient } from "../../../../client/client.js";
6
- import { type Address, getAddress } from "../../../../utils/address.js";
7
- import { numberToPlainString } from "../../../../utils/formatNumber.js";
7
+ import { NATIVE_TOKEN_ADDRESS } from "../../../../constants/addresses.js";
8
+ import {
9
+ getFiatSymbol,
10
+ type SupportedFiatCurrency,
11
+ } from "../../../../pay/convert/type.js";
12
+ import {
13
+ type Address,
14
+ checksumAddress,
15
+ getAddress,
16
+ isAddress,
17
+ shortenAddress,
18
+ } from "../../../../utils/address.js";
8
19
  import { useCustomTheme } from "../../../core/design-system/CustomThemeProvider.js";
9
20
  import {
10
21
  fontSize,
11
22
  iconSize,
12
23
  radius,
13
24
  spacing,
25
+ type Theme,
14
26
  } from "../../../core/design-system/index.js";
15
- import { useActiveAccount } from "../../../core/hooks/wallets/useActiveAccount.js";
27
+ import { useEnsName } from "../../../core/utils/wallet.js";
16
28
  import { ConnectButton } from "../ConnectWallet/ConnectButton.js";
17
- import { OutlineWalletIcon } from "../ConnectWallet/icons/OutlineWalletIcon.js";
29
+ import { DetailsModal } from "../ConnectWallet/Details.js";
30
+ import { WalletDotIcon } from "../ConnectWallet/icons/WalletDotIcon.js";
31
+ import connectLocaleEn from "../ConnectWallet/locale/en.js";
18
32
  import { PoweredByThirdweb } from "../ConnectWallet/PoweredByTW.js";
19
- import { WalletRow } from "../ConnectWallet/screens/Buy/swap/WalletRow.js";
20
- import { formatCurrencyAmount } from "../ConnectWallet/screens/formatTokenBalance.js";
33
+ import { formatTokenAmount } from "../ConnectWallet/screens/formatTokenBalance.js";
21
34
  import { Container } from "../components/basic.js";
22
35
  import { Button } from "../components/buttons.js";
23
- import { Input } from "../components/formElements.js";
36
+ import { CopyIcon } from "../components/CopyIcon.js";
37
+ import { Modal } from "../components/Modal.js";
38
+ import { Skeleton } from "../components/Skeleton.js";
24
39
  import { Spacer } from "../components/Spacer.js";
25
40
  import { Text } from "../components/text.js";
41
+ import { useIsMobile } from "../hooks/useisMobile.js";
26
42
  import type { PayEmbedConnectOptions } from "../PayEmbed.js";
27
- import type { UIOptions } from "./BridgeOrchestrator.js";
28
- import { TokenAndChain } from "./common/TokenAndChain.js";
43
+ import { ActiveWalletDetails } from "./common/active-wallet-details.js";
44
+ import { DecimalInput } from "./common/decimal-input.js";
45
+ import { SelectedTokenButton } from "./common/selected-token-button.js";
46
+ import { useTokenBalance } from "./common/token-balance.js";
47
+ import { useTokenQuery } from "./common/token-query.js";
48
+ // import { TokenAndChain } from "./common/TokenAndChain.js";
29
49
  import { WithHeader } from "./common/WithHeader.js";
50
+ import { useActiveWalletInfo } from "./swap-widget/hooks.js";
51
+ import { SelectToken } from "./swap-widget/select-token-ui.js";
52
+ import type { ActiveWalletInfo } from "./swap-widget/types.js";
53
+ import { useBridgeChains } from "./swap-widget/use-bridge-chains.js";
30
54
 
31
- export interface FundWalletProps {
32
- /**
33
- * UI configuration and mode
34
- */
35
- uiOptions: Extract<UIOptions, { mode: "fund_wallet" }>;
36
-
55
+ type FundWalletProps = {
37
56
  /**
38
57
  * The receiver address, defaults to the connected wallet address
39
58
  */
40
- receiverAddress?: Address;
59
+ receiverAddress: Address | undefined;
41
60
  /**
42
61
  * ThirdwebClient for price fetching
43
62
  */
@@ -55,315 +74,640 @@ export interface FundWalletProps {
55
74
  /**
56
75
  * Quick buy amounts
57
76
  */
58
- presetOptions?: [number, number, number];
77
+ presetOptions: [number, number, number];
59
78
 
60
79
  /**
61
80
  * Connect options for wallet connection
62
81
  */
63
- connectOptions?: PayEmbedConnectOptions;
82
+ connectOptions: PayEmbedConnectOptions | undefined;
64
83
 
65
84
  /**
66
85
  * Whether to show thirdweb branding in the widget.
67
- * @default true
68
86
  */
69
- showThirdwebBranding?: boolean;
70
- }
87
+ showThirdwebBranding: boolean;
71
88
 
72
- export function FundWallet({
73
- client,
74
- receiverAddress,
75
- uiOptions,
76
- onContinue,
77
- presetOptions = [5, 10, 20],
78
- connectOptions,
79
- showThirdwebBranding = true,
80
- }: FundWalletProps) {
81
- const [amount, setAmount] = useState(uiOptions.initialAmount ?? "");
82
- const theme = useCustomTheme();
83
- const account = useActiveAccount();
84
- const receiver = receiverAddress ?? account?.address;
85
- const handleAmountChange = (inputValue: string) => {
86
- let processedValue = inputValue;
89
+ initialSelection: {
90
+ tokenAddress: string | undefined;
91
+ chainId: number | undefined;
92
+ amount: string | undefined;
93
+ };
94
+
95
+ /**
96
+ * The currency to use for the payment.
97
+ */
98
+ currency: SupportedFiatCurrency;
87
99
 
88
- // Replace comma with period if it exists
89
- processedValue = processedValue.replace(",", ".");
100
+ /**
101
+ * Override label to display on the button
102
+ */
103
+ buttonLabel: string | undefined;
104
+
105
+ theme: "light" | "dark" | Theme;
90
106
 
91
- if (processedValue.startsWith(".")) {
92
- processedValue = `0${processedValue}`;
107
+ onDisconnect: (() => void) | undefined;
108
+
109
+ /**
110
+ * The metadata to display in the widget.
111
+ */
112
+ metadata: {
113
+ title: string | undefined;
114
+ description: string | undefined;
115
+ image: string | undefined;
116
+ };
117
+ };
118
+
119
+ type SelectedToken =
120
+ | {
121
+ chainId: number;
122
+ tokenAddress: string;
93
123
  }
124
+ | undefined;
94
125
 
95
- const numValue = Number(processedValue);
96
- if (Number.isNaN(numValue)) {
97
- return;
126
+ type AmountSelection =
127
+ | {
128
+ type: "usd";
129
+ value: string;
98
130
  }
131
+ | {
132
+ type: "token";
133
+ value: string;
134
+ };
135
+
136
+ export function FundWallet(props: FundWalletProps) {
137
+ const [amountSelection, setAmountSelection] = useState<AmountSelection>({
138
+ type: "token",
139
+ value: props.initialSelection.amount ?? "",
140
+ });
141
+ const theme = useCustomTheme();
142
+ const activeWalletInfo = useActiveWalletInfo();
143
+ const receiver =
144
+ props.receiverAddress ?? activeWalletInfo?.activeAccount?.address;
145
+
146
+ const [detailsModalOpen, setDetailsModalOpen] = useState(false);
147
+ const [isTokenSelectionOpen, setIsTokenSelectionOpen] = useState(false);
99
148
 
100
- if (processedValue.startsWith("0") && !processedValue.startsWith("0.")) {
101
- setAmount(processedValue.slice(1));
102
- } else {
103
- setAmount(processedValue);
149
+ const isReceiverDifferentFromActiveWallet =
150
+ props.receiverAddress &&
151
+ isAddress(props.receiverAddress) &&
152
+ (activeWalletInfo?.activeAccount?.address
153
+ ? checksumAddress(props.receiverAddress) !==
154
+ checksumAddress(activeWalletInfo?.activeAccount?.address)
155
+ : true);
156
+
157
+ const [selectedToken, setSelectedToken] = useState<SelectedToken>(() => {
158
+ if (!props.initialSelection.chainId) {
159
+ return undefined;
104
160
  }
105
- };
106
161
 
107
- const getAmountFontSize = () => {
108
- const length = amount.length;
109
- if (length > 12) return fontSize.md;
110
- if (length > 8) return fontSize.lg;
111
- return fontSize.xl;
112
- };
162
+ return {
163
+ chainId: props.initialSelection.chainId,
164
+ tokenAddress: props.initialSelection.tokenAddress || NATIVE_TOKEN_ADDRESS,
165
+ };
166
+ });
113
167
 
114
- const isValidAmount = amount && Number(amount) > 0;
168
+ const tokenQuery = useTokenQuery({
169
+ tokenAddress: selectedToken?.tokenAddress,
170
+ chainId: selectedToken?.chainId,
171
+ client: props.client,
172
+ });
115
173
 
116
- const inputRef = useRef<HTMLInputElement>(null);
174
+ const destinationToken =
175
+ tokenQuery.data?.type === "success" ? tokenQuery.data.token : undefined;
117
176
 
118
- const focusInput = () => {
119
- inputRef.current?.focus();
120
- };
177
+ const tokenBalanceQuery = useTokenBalance({
178
+ chainId: selectedToken?.chainId,
179
+ tokenAddress: selectedToken?.tokenAddress,
180
+ client: props.client,
181
+ walletAddress: activeWalletInfo?.activeAccount?.address,
182
+ });
121
183
 
122
- const handleQuickAmount = (usdAmount: number) => {
123
- const price =
124
- uiOptions.destinationToken.prices[uiOptions.currency || "USD"] || 0;
125
- if (price === 0) {
126
- return;
127
- }
128
- // Convert USD amount to token amount using token price
129
- const tokenAmount = usdAmount / price;
130
- // Format to reasonable decimal places (up to 6 decimals, remove trailing zeros)
131
- const formattedAmount = numberToPlainString(
132
- Number.parseFloat(tokenAmount.toFixed(6)),
133
- );
134
- setAmount(formattedAmount);
135
- };
184
+ const actionLabel = isReceiverDifferentFromActiveWallet ? "Pay" : "Buy";
185
+ const isMobile = useIsMobile();
136
186
 
137
187
  return (
138
188
  <WithHeader
139
- client={client}
140
- defaultTitle={`Buy ${uiOptions.destinationToken.symbol}`}
141
- uiOptions={uiOptions}
189
+ client={props.client}
190
+ title={props.metadata.title}
191
+ description={props.metadata.description}
192
+ image={props.metadata.image}
142
193
  >
194
+ {detailsModalOpen && (
195
+ <DetailsModal
196
+ client={props.client}
197
+ locale={connectLocaleEn}
198
+ detailsModal={{
199
+ hideBuyFunds: true,
200
+ }}
201
+ theme={props.theme}
202
+ closeModal={() => {
203
+ setDetailsModalOpen(false);
204
+ }}
205
+ onDisconnect={() => {
206
+ props.onDisconnect?.();
207
+ }}
208
+ chains={[]}
209
+ connectOptions={props.connectOptions}
210
+ />
211
+ )}
212
+
213
+ <Modal
214
+ hide={false}
215
+ className="tw-modal__buy-widget"
216
+ size={isMobile ? "compact" : "wide"}
217
+ title="Select Token"
218
+ open={isTokenSelectionOpen}
219
+ crossContainerStyles={{
220
+ right: spacing.md,
221
+ top: spacing["md+"],
222
+ transform: "none",
223
+ }}
224
+ setOpen={(v) => setIsTokenSelectionOpen(v)}
225
+ >
226
+ <SelectToken
227
+ activeWalletInfo={activeWalletInfo}
228
+ onClose={() => setIsTokenSelectionOpen(false)}
229
+ client={props.client}
230
+ selectedToken={selectedToken}
231
+ setSelectedToken={(token) => {
232
+ setSelectedToken(token);
233
+ setIsTokenSelectionOpen(false);
234
+ }}
235
+ />
236
+ </Modal>
237
+
143
238
  <Container flex="column">
144
239
  {/* Token Info */}
145
- <Container
146
- center="both"
147
- flex="row"
148
- gap="3xs"
149
- p="md"
150
- style={{
151
- backgroundColor: theme.colors.tertiaryBg,
152
- border: `1px solid ${theme.colors.borderColor}`,
153
- borderRadius: radius.lg,
154
- flexWrap: "nowrap",
155
- }}
156
- >
157
- <TokenAndChain
158
- client={client}
159
- size="xl"
160
- token={uiOptions.destinationToken}
161
- />
162
- {/* Amount Input */}
163
- <Container
164
- center="x"
165
- expand
166
- flex="column"
167
- gap="3xs"
168
- style={{
169
- alignItems: "flex-end",
170
- justifyContent: "flex-end",
171
- }}
172
- >
173
- <div
174
- onClick={focusInput}
175
- onKeyDown={(e: React.KeyboardEvent<HTMLDivElement>) => {
176
- if (e.key === "Enter" || e.key === " ") {
177
- e.preventDefault();
178
- focusInput();
240
+ <TokenSection
241
+ title={actionLabel}
242
+ presetOptions={props.presetOptions}
243
+ amountSelection={amountSelection}
244
+ setAmount={setAmountSelection}
245
+ activeWalletInfo={activeWalletInfo}
246
+ selectedToken={
247
+ selectedToken
248
+ ? {
249
+ data:
250
+ tokenQuery.data?.type === "success"
251
+ ? tokenQuery.data.token
252
+ : undefined,
253
+ isFetching: tokenQuery.isFetching,
179
254
  }
180
- }}
181
- role="button"
182
- style={{ cursor: "text" }}
183
- tabIndex={0}
184
- >
185
- <Container
186
- center="y"
187
- flex="row"
188
- gap="xs"
189
- style={{
190
- flexWrap: "nowrap",
191
- justifyContent: "flex-end",
192
- }}
193
- >
194
- <Input
195
- data-placeholder={amount === ""}
196
- inputMode="decimal"
197
- onChange={(e) => {
198
- handleAmountChange(e.target.value);
199
- }}
200
- onClick={(e) => {
201
- // put cursor at the end of the input
202
- if (amount === "") {
203
- e.currentTarget.setSelectionRange(
204
- e.currentTarget.value.length,
205
- e.currentTarget.value.length,
206
- );
207
- }
208
- }}
209
- pattern="^[0-9]*[.,]?[0-9]*$"
210
- placeholder="0"
211
- ref={inputRef}
212
- style={{
213
- border: "none",
214
- boxShadow: "none",
215
- fontSize: getAmountFontSize(),
216
- fontWeight: 600,
217
- padding: "0",
218
- textAlign: "right",
219
- }}
220
- type="text"
221
- value={amount || "0"}
222
- variant="transparent"
223
- />
224
- </Container>
225
- </div>
226
-
227
- {/* Fiat Value */}
228
- <Container
229
- center="both"
230
- flex="row"
231
- style={{ flexWrap: "nowrap", height: fontSize.lg }}
232
- >
233
- <Text
234
- color="secondaryText"
235
- size="md"
236
- style={{ textWrap: "nowrap" }}
237
- >
238
- ≈{" "}
239
- {formatCurrencyAmount(
240
- uiOptions.currency || "USD",
241
- Number(amount) *
242
- (uiOptions.destinationToken.prices[
243
- uiOptions.currency || "USD"
244
- ] || 0),
245
- )}
246
- </Text>
247
- </Container>
248
- </Container>
249
- </Container>
255
+ : undefined
256
+ }
257
+ balance={{
258
+ data: tokenBalanceQuery.data?.value,
259
+ isFetching: tokenBalanceQuery.isFetching,
260
+ }}
261
+ client={props.client}
262
+ isConnected={!!activeWalletInfo}
263
+ onSelectToken={() => {
264
+ setIsTokenSelectionOpen(true);
265
+ }}
266
+ onWalletClick={() => {
267
+ setDetailsModalOpen(true);
268
+ }}
269
+ currency={props.currency}
270
+ />
250
271
 
251
- {/* Quick Amount Buttons */}
252
- {presetOptions && (
272
+ {receiver && isReceiverDifferentFromActiveWallet && (
253
273
  <>
254
- <Spacer y="sm" />
255
- <Container
256
- center="x"
257
- flex="row"
258
- gap="sm"
259
- style={{
260
- justifyContent: "space-evenly",
261
- }}
262
- >
263
- {presetOptions?.map((amount) => (
264
- <Button
265
- key={amount}
266
- onClick={() => handleQuickAmount(Number(amount))}
267
- style={{
268
- backgroundColor: theme.colors.tertiaryBg,
269
- flex: 1,
270
- fontSize: fontSize.sm,
271
- borderRadius: radius.lg,
272
- padding: `${spacing.sm} ${spacing.md}`,
273
- }}
274
- variant="outline"
275
- >
276
- ${amount}
277
- </Button>
278
- ))}
279
- </Container>
274
+ <ArrowSection />
275
+ <ReceiverWalletSection address={receiver} client={props.client} />
280
276
  </>
281
277
  )}
282
-
283
- <Spacer y="sm" />
284
-
285
- <Container
286
- center="y"
287
- color="secondaryText"
288
- flex="row"
289
- gap="sm"
290
- px="md"
291
- py="sm"
292
- style={{
293
- backgroundColor: theme.colors.tertiaryBg,
294
- border: `1px solid ${theme.colors.borderColor}`,
295
- borderRadius: radius.lg,
296
- }}
297
- >
298
- {receiver ? (
299
- <WalletRow
300
- address={receiver}
301
- client={client}
302
- iconSize="md"
303
- textSize="sm"
304
- />
305
- ) : (
306
- <>
307
- <OutlineWalletIcon size={iconSize.md} />
308
- <Text
309
- color="secondaryText"
310
- size="sm"
311
- style={{
312
- flex: 1,
313
- }}
314
- >
315
- No Wallet Connected
316
- </Text>
317
- </>
318
- )}
319
- </Container>
320
278
  </Container>
321
279
 
322
- <Spacer y="lg" />
280
+ <Spacer y="md" />
323
281
 
324
282
  {/* Continue Button */}
325
- {receiver ? (
283
+ {activeWalletInfo ? (
326
284
  <Button
327
- disabled={!isValidAmount}
285
+ disabled={!receiver}
328
286
  fullWidth
329
287
  onClick={() => {
330
- if (isValidAmount) {
331
- onContinue(
332
- amount,
333
- uiOptions.destinationToken,
334
- getAddress(receiver),
335
- );
288
+ if (!receiver || !destinationToken) {
289
+ return;
336
290
  }
291
+
292
+ const fiatPricePerToken = destinationToken.prices[props.currency];
293
+ const { tokenValue } = getAmounts(
294
+ amountSelection,
295
+ fiatPricePerToken,
296
+ );
297
+
298
+ if (!tokenValue) {
299
+ return;
300
+ }
301
+
302
+ props.onContinue(
303
+ String(tokenValue),
304
+ destinationToken,
305
+ getAddress(receiver),
306
+ );
337
307
  }}
338
308
  style={{
339
309
  fontSize: fontSize.md,
340
- borderRadius: radius.lg,
310
+ borderRadius: radius.full,
341
311
  }}
342
312
  variant="primary"
343
313
  >
344
- {uiOptions.buttonLabel ||
345
- `Buy ${amount} ${uiOptions.destinationToken.symbol}`}
314
+ {props.buttonLabel || actionLabel}
346
315
  </Button>
347
316
  ) : (
348
317
  <ConnectButton
349
- client={client}
318
+ client={props.client}
350
319
  connectButton={{
351
- label:
352
- uiOptions.buttonLabel ||
353
- `Buy ${amount} ${uiOptions.destinationToken.symbol}`,
320
+ label: props.buttonLabel || actionLabel,
321
+ style: {
322
+ width: "100%",
323
+ borderRadius: radius.full,
324
+ },
354
325
  }}
355
326
  theme={theme}
356
- {...connectOptions}
327
+ {...props.connectOptions}
357
328
  />
358
329
  )}
359
330
 
360
- {showThirdwebBranding ? (
331
+ {props.showThirdwebBranding ? (
361
332
  <div>
362
333
  <Spacer y="md" />
363
334
  <PoweredByThirdweb link="https://playground.thirdweb.com/payments/fund-wallet" />
364
335
  </div>
365
- ) : null}
336
+ ) : (
337
+ <Spacer y="xxs" />
338
+ )}
366
339
  <Spacer y="md" />
367
340
  </WithHeader>
368
341
  );
369
342
  }
343
+
344
+ function getAmounts(
345
+ amountSelection: AmountSelection,
346
+ fiatPricePerToken: number | undefined,
347
+ ) {
348
+ const fiatValue =
349
+ amountSelection.type === "usd"
350
+ ? amountSelection.value
351
+ : fiatPricePerToken
352
+ ? fiatPricePerToken * Number(amountSelection.value)
353
+ : undefined;
354
+
355
+ const tokenValue =
356
+ amountSelection.type === "token"
357
+ ? amountSelection.value
358
+ : fiatPricePerToken
359
+ ? Number(amountSelection.value) / fiatPricePerToken
360
+ : undefined;
361
+
362
+ return {
363
+ fiatValue,
364
+ tokenValue,
365
+ };
366
+ }
367
+
368
+ function TokenSection(props: {
369
+ amountSelection: AmountSelection;
370
+ setAmount: (amountSelection: AmountSelection) => void;
371
+ activeWalletInfo: ActiveWalletInfo | undefined;
372
+ selectedToken:
373
+ | {
374
+ data: TokenWithPrices | undefined;
375
+ isFetching: boolean;
376
+ }
377
+ | undefined;
378
+ currency: SupportedFiatCurrency;
379
+ onSelectToken: () => void;
380
+ client: ThirdwebClient;
381
+ title: string;
382
+ isConnected: boolean;
383
+ balance: {
384
+ data: bigint | undefined;
385
+ isFetching: boolean;
386
+ };
387
+ onWalletClick: () => void;
388
+ presetOptions: [number, number, number];
389
+ }) {
390
+ const theme = useCustomTheme();
391
+ const chainQuery = useBridgeChains(props.client);
392
+ const chain = chainQuery.data?.find(
393
+ (chain) => chain.chainId === props.selectedToken?.data?.chainId,
394
+ );
395
+
396
+ const fiatPricePerToken = props.selectedToken?.data?.prices[props.currency];
397
+
398
+ const { fiatValue, tokenValue } = getAmounts(
399
+ props.amountSelection,
400
+ fiatPricePerToken,
401
+ );
402
+
403
+ return (
404
+ <SectionContainer
405
+ header={
406
+ <div
407
+ style={{
408
+ display: "flex",
409
+ justifyContent: "space-between",
410
+ alignItems: "center",
411
+ }}
412
+ >
413
+ <Container flex="row" center="y" gap="3xs" color="secondaryText">
414
+ <Text
415
+ size="xs"
416
+ color="primaryText"
417
+ style={{
418
+ letterSpacing: "0.07em",
419
+ textTransform: "uppercase",
420
+ }}
421
+ >
422
+ {props.title}
423
+ </Text>
424
+ </Container>
425
+ {props.activeWalletInfo && (
426
+ <ActiveWalletDetails
427
+ activeWalletInfo={props.activeWalletInfo}
428
+ client={props.client}
429
+ onClick={props.onWalletClick}
430
+ />
431
+ )}
432
+ </div>
433
+ }
434
+ >
435
+ {/* select token */}
436
+ <SelectedTokenButton
437
+ selectedToken={props.selectedToken}
438
+ client={props.client}
439
+ onSelectToken={props.onSelectToken}
440
+ chain={chain}
441
+ />
442
+
443
+ <Container px="md" py="md">
444
+ {/* token value input */}
445
+ <DecimalInput
446
+ value={tokenValue ? String(tokenValue) : ""}
447
+ setValue={(value) => {
448
+ props.setAmount({
449
+ type: "token",
450
+ value,
451
+ });
452
+ }}
453
+ style={{
454
+ border: "none",
455
+ boxShadow: "none",
456
+ fontSize: fontSize.xl,
457
+ fontWeight: 500,
458
+ paddingInline: 0,
459
+ paddingBlock: 0,
460
+ letterSpacing: "-0.025em",
461
+ }}
462
+ />
463
+
464
+ <Spacer y="xs" />
465
+
466
+ {/* fiat value input */}
467
+ <div
468
+ style={{
469
+ display: "flex",
470
+ alignItems: "center",
471
+ gap: "2px",
472
+ }}
473
+ >
474
+ <Text
475
+ size="md"
476
+ color="secondaryText"
477
+ style={{
478
+ flexShrink: 0,
479
+ }}
480
+ >
481
+ {getFiatSymbol(props.currency)}
482
+ </Text>
483
+
484
+ {props.selectedToken?.isFetching ? (
485
+ <Skeleton
486
+ width="120px"
487
+ height="20px"
488
+ style={{
489
+ transform: "translateX(4px)",
490
+ }}
491
+ />
492
+ ) : (
493
+ <DecimalInput
494
+ value={String(fiatValue || 0)}
495
+ setValue={(value) => {
496
+ props.setAmount({
497
+ type: "usd",
498
+ value,
499
+ });
500
+ }}
501
+ style={{
502
+ border: "none",
503
+ boxShadow: "none",
504
+ fontSize: fontSize.md,
505
+ fontWeight: 400,
506
+ color: theme.colors.secondaryText,
507
+ paddingInline: 0,
508
+ height: "20px",
509
+ paddingBlock: 0,
510
+ }}
511
+ />
512
+ )}
513
+ </div>
514
+
515
+ <Spacer y="md" />
516
+
517
+ {/* suggested amounts */}
518
+ <Container flex="row" gap="xxs">
519
+ {props.presetOptions.map((amount) => (
520
+ <Button
521
+ disabled={!props.selectedToken?.data}
522
+ key={amount}
523
+ onClick={() =>
524
+ props.setAmount({
525
+ type: "usd",
526
+ value: String(amount),
527
+ })
528
+ }
529
+ style={{
530
+ backgroundColor: "transparent",
531
+ color: theme.colors.secondaryText,
532
+ fontSize: fontSize.xs,
533
+ fontWeight: 400,
534
+ borderRadius: radius.full,
535
+ gap: "0.5px",
536
+ padding: `${spacing.xxs} ${spacing.sm}`,
537
+ }}
538
+ variant="outline"
539
+ >
540
+ <span>{getFiatSymbol(props.currency)}</span>
541
+ <span>{amount}</span>
542
+ </Button>
543
+ ))}
544
+ </Container>
545
+ </Container>
546
+
547
+ {/* balance */}
548
+ {props.isConnected && props.selectedToken && (
549
+ <Container
550
+ px="md"
551
+ py="md"
552
+ style={{
553
+ borderTop: `1px dashed ${theme.colors.borderColor}`,
554
+ justifyContent: "start",
555
+ }}
556
+ >
557
+ <div
558
+ style={{
559
+ display: "flex",
560
+ justifyContent: "space-between",
561
+ alignItems: "center",
562
+ gap: "3px",
563
+ }}
564
+ >
565
+ <Text size="xs" color="secondaryText">
566
+ Current Balance
567
+ </Text>
568
+ {props.balance.data === undefined ||
569
+ props.selectedToken.data === undefined ? (
570
+ <Skeleton height={fontSize.xs} width="100px" />
571
+ ) : (
572
+ <Text size="xs" color="primaryText">
573
+ {formatTokenAmount(
574
+ props.balance.data,
575
+ props.selectedToken.data.decimals,
576
+ 5,
577
+ )}{" "}
578
+ {props.selectedToken.data.symbol}
579
+ </Text>
580
+ )}
581
+ </div>
582
+ </Container>
583
+ )}
584
+ </SectionContainer>
585
+ );
586
+ }
587
+
588
+ function ReceiverWalletSection(props: {
589
+ address: string;
590
+ client: ThirdwebClient;
591
+ }) {
592
+ const ensNameQuery = useEnsName({
593
+ address: props.address,
594
+ client: props.client,
595
+ });
596
+
597
+ return (
598
+ <SectionContainer
599
+ header={
600
+ <Text
601
+ size="xs"
602
+ color="primaryText"
603
+ style={{
604
+ letterSpacing: "0.07em",
605
+ textTransform: "uppercase",
606
+ }}
607
+ >
608
+ To
609
+ </Text>
610
+ }
611
+ >
612
+ <Container
613
+ px="md"
614
+ py="md"
615
+ flex="row"
616
+ center="y"
617
+ gap="xs"
618
+ color="secondaryText"
619
+ >
620
+ <WalletDotIcon size={iconSize.xs} color="secondaryText" />
621
+ <Text size="sm" color="primaryText">
622
+ {ensNameQuery.data || shortenAddress(props.address)}
623
+ </Text>
624
+ <CopyIcon text={props.address} tip="Copy address" iconSize={14} />
625
+ </Container>
626
+ </SectionContainer>
627
+ );
628
+ }
629
+
630
+ function SectionContainer(props: {
631
+ children: React.ReactNode;
632
+ header: React.ReactNode;
633
+ }) {
634
+ const theme = useCustomTheme();
635
+ return (
636
+ <Container
637
+ style={{
638
+ borderRadius: radius.xl,
639
+ borderWidth: 1,
640
+ borderStyle: "solid",
641
+ position: "relative",
642
+ overflow: "hidden",
643
+ }}
644
+ borderColor="borderColor"
645
+ >
646
+ {/* make the background semi-transparent */}
647
+ <Container
648
+ bg="tertiaryBg"
649
+ style={{
650
+ position: "absolute",
651
+ inset: 0,
652
+ opacity: 0.5,
653
+ zIndex: 0,
654
+ }}
655
+ />
656
+
657
+ {/* header */}
658
+ <Container
659
+ style={{
660
+ position: "relative",
661
+ zIndex: 1,
662
+ }}
663
+ >
664
+ <Container px="md" py="sm" relative>
665
+ {props.header}
666
+ </Container>
667
+ </Container>
668
+
669
+ {/* content */}
670
+ <Container
671
+ bg="tertiaryBg"
672
+ style={{
673
+ position: "relative",
674
+ overflow: "hidden",
675
+ borderRadius: radius.xl,
676
+ borderTop: `1px solid ${theme.colors.borderColor}`,
677
+ }}
678
+ >
679
+ {props.children}
680
+ </Container>
681
+ </Container>
682
+ );
683
+ }
684
+
685
+ function ArrowSection() {
686
+ return (
687
+ <div
688
+ style={{
689
+ display: "flex",
690
+ justifyContent: "center",
691
+ marginBlock: `-13px`,
692
+ zIndex: 2,
693
+ position: "relative",
694
+ }}
695
+ >
696
+ <Container
697
+ p="xs"
698
+ center="both"
699
+ flex="row"
700
+ color="primaryText"
701
+ bg="modalBg"
702
+ borderColor="borderColor"
703
+ style={{
704
+ borderRadius: radius.full,
705
+ borderWidth: 1,
706
+ borderStyle: "solid",
707
+ }}
708
+ >
709
+ <ArrowDownIcon width={iconSize["sm+"]} height={iconSize["sm+"]} />
710
+ </Container>
711
+ </div>
712
+ );
713
+ }