thirdweb 5.41.0 → 5.42.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 (180) hide show
  1. package/dist/cjs/adapters/wallet-adapter.js +12 -1
  2. package/dist/cjs/adapters/wallet-adapter.js.map +1 -1
  3. package/dist/cjs/client/client.js +19 -1
  4. package/dist/cjs/client/client.js.map +1 -1
  5. package/dist/cjs/exports/extensions/common.js +3 -1
  6. package/dist/cjs/exports/extensions/common.js.map +1 -1
  7. package/dist/cjs/exports/extensions/erc1155.js +2 -1
  8. package/dist/cjs/exports/extensions/erc1155.js.map +1 -1
  9. package/dist/cjs/exports/react.js +7 -2
  10. package/dist/cjs/exports/react.js.map +1 -1
  11. package/dist/cjs/exports/utils.js +3 -1
  12. package/dist/cjs/exports/utils.js.map +1 -1
  13. package/dist/cjs/exports/wallets/in-app.js.map +1 -1
  14. package/dist/cjs/exports/wallets.js.map +1 -1
  15. package/dist/cjs/exports/wallets.native.js.map +1 -1
  16. package/dist/cjs/react/core/hooks/others/useChainQuery.js +19 -3
  17. package/dist/cjs/react/core/hooks/others/useChainQuery.js.map +1 -1
  18. package/dist/cjs/react/core/hooks/transaction/transaction-button-utils.js.map +1 -1
  19. package/dist/cjs/react/web/ui/AutoConnect/AutoConnect.js +5 -0
  20. package/dist/cjs/react/web/ui/AutoConnect/AutoConnect.js.map +1 -1
  21. package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js +196 -2
  22. package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
  23. package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js +109 -3
  24. package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js.map +1 -1
  25. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/DirectPaymentModeScreen.js +1 -1
  26. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/DirectPaymentModeScreen.js.map +1 -1
  27. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.js +1 -1
  28. package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.js.map +1 -1
  29. package/dist/cjs/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.js +127 -0
  30. package/dist/cjs/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.js.map +1 -0
  31. package/dist/cjs/react/web/ui/prebuilt/thirdweb/ClaimButton/index.js +70 -3
  32. package/dist/cjs/react/web/ui/prebuilt/thirdweb/ClaimButton/index.js.map +1 -1
  33. package/dist/cjs/react/web/wallets/shared/ConnectWalletSocialOptions.js +19 -7
  34. package/dist/cjs/react/web/wallets/shared/ConnectWalletSocialOptions.js.map +1 -1
  35. package/dist/cjs/storage/download.js +44 -4
  36. package/dist/cjs/storage/download.js.map +1 -1
  37. package/dist/cjs/utils/contract/parse-abi-params.js +87 -0
  38. package/dist/cjs/utils/contract/parse-abi-params.js.map +1 -0
  39. package/dist/cjs/version.js +1 -1
  40. package/dist/cjs/wallets/create-wallet.js +73 -0
  41. package/dist/cjs/wallets/create-wallet.js.map +1 -1
  42. package/dist/cjs/wallets/in-app/core/wallet/index.js +2 -3
  43. package/dist/cjs/wallets/in-app/core/wallet/index.js.map +1 -1
  44. package/dist/cjs/wallets/in-app/web/ecosystem.js +29 -3
  45. package/dist/cjs/wallets/in-app/web/ecosystem.js.map +1 -1
  46. package/dist/cjs/wallets/in-app/web/in-app.js +100 -5
  47. package/dist/cjs/wallets/in-app/web/in-app.js.map +1 -1
  48. package/dist/cjs/wallets/smart/smart-wallet.js +71 -5
  49. package/dist/cjs/wallets/smart/smart-wallet.js.map +1 -1
  50. package/dist/esm/adapters/wallet-adapter.js +12 -1
  51. package/dist/esm/adapters/wallet-adapter.js.map +1 -1
  52. package/dist/esm/client/client.js +19 -1
  53. package/dist/esm/client/client.js.map +1 -1
  54. package/dist/esm/exports/extensions/common.js +1 -0
  55. package/dist/esm/exports/extensions/common.js.map +1 -1
  56. package/dist/esm/exports/extensions/erc1155.js +1 -1
  57. package/dist/esm/exports/extensions/erc1155.js.map +1 -1
  58. package/dist/esm/exports/react.js +3 -0
  59. package/dist/esm/exports/react.js.map +1 -1
  60. package/dist/esm/exports/utils.js +1 -0
  61. package/dist/esm/exports/utils.js.map +1 -1
  62. package/dist/esm/exports/wallets/in-app.js.map +1 -1
  63. package/dist/esm/exports/wallets.js.map +1 -1
  64. package/dist/esm/exports/wallets.native.js.map +1 -1
  65. package/dist/esm/react/core/hooks/others/useChainQuery.js +19 -3
  66. package/dist/esm/react/core/hooks/others/useChainQuery.js.map +1 -1
  67. package/dist/esm/react/core/hooks/transaction/transaction-button-utils.js.map +1 -1
  68. package/dist/esm/react/web/ui/AutoConnect/AutoConnect.js +5 -0
  69. package/dist/esm/react/web/ui/AutoConnect/AutoConnect.js.map +1 -1
  70. package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js +196 -2
  71. package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
  72. package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js +109 -3
  73. package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js.map +1 -1
  74. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/DirectPaymentModeScreen.js +2 -2
  75. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/DirectPaymentModeScreen.js.map +1 -1
  76. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.js +2 -2
  77. package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.js.map +1 -1
  78. package/dist/esm/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.js +124 -0
  79. package/dist/esm/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.js.map +1 -0
  80. package/dist/esm/react/web/ui/prebuilt/thirdweb/ClaimButton/index.js +69 -3
  81. package/dist/esm/react/web/ui/prebuilt/thirdweb/ClaimButton/index.js.map +1 -1
  82. package/dist/esm/react/web/wallets/shared/ConnectWalletSocialOptions.js +19 -7
  83. package/dist/esm/react/web/wallets/shared/ConnectWalletSocialOptions.js.map +1 -1
  84. package/dist/esm/storage/download.js +44 -4
  85. package/dist/esm/storage/download.js.map +1 -1
  86. package/dist/esm/utils/contract/parse-abi-params.js +84 -0
  87. package/dist/esm/utils/contract/parse-abi-params.js.map +1 -0
  88. package/dist/esm/version.js +1 -1
  89. package/dist/esm/wallets/create-wallet.js +73 -0
  90. package/dist/esm/wallets/create-wallet.js.map +1 -1
  91. package/dist/esm/wallets/in-app/core/wallet/index.js +2 -3
  92. package/dist/esm/wallets/in-app/core/wallet/index.js.map +1 -1
  93. package/dist/esm/wallets/in-app/web/ecosystem.js +29 -3
  94. package/dist/esm/wallets/in-app/web/ecosystem.js.map +1 -1
  95. package/dist/esm/wallets/in-app/web/in-app.js +100 -5
  96. package/dist/esm/wallets/in-app/web/in-app.js.map +1 -1
  97. package/dist/esm/wallets/smart/smart-wallet.js +71 -5
  98. package/dist/esm/wallets/smart/smart-wallet.js.map +1 -1
  99. package/dist/types/adapters/wallet-adapter.d.ts +12 -1
  100. package/dist/types/adapters/wallet-adapter.d.ts.map +1 -1
  101. package/dist/types/client/client.d.ts +19 -1
  102. package/dist/types/client/client.d.ts.map +1 -1
  103. package/dist/types/exports/extensions/common.d.ts +1 -0
  104. package/dist/types/exports/extensions/common.d.ts.map +1 -1
  105. package/dist/types/exports/extensions/erc1155.d.ts +1 -1
  106. package/dist/types/exports/extensions/erc1155.d.ts.map +1 -1
  107. package/dist/types/exports/react.d.ts +2 -0
  108. package/dist/types/exports/react.d.ts.map +1 -1
  109. package/dist/types/exports/utils.d.ts +2 -0
  110. package/dist/types/exports/utils.d.ts.map +1 -1
  111. package/dist/types/exports/wallets/in-app.d.ts +1 -0
  112. package/dist/types/exports/wallets/in-app.d.ts.map +1 -1
  113. package/dist/types/exports/wallets.d.ts +4 -2
  114. package/dist/types/exports/wallets.d.ts.map +1 -1
  115. package/dist/types/exports/wallets.native.d.ts +3 -2
  116. package/dist/types/exports/wallets.native.d.ts.map +1 -1
  117. package/dist/types/react/core/hooks/others/useChainQuery.d.ts +21 -4
  118. package/dist/types/react/core/hooks/others/useChainQuery.d.ts.map +1 -1
  119. package/dist/types/react/core/hooks/transaction/transaction-button-utils.d.ts +1 -0
  120. package/dist/types/react/core/hooks/transaction/transaction-button-utils.d.ts.map +1 -1
  121. package/dist/types/react/web/ui/AutoConnect/AutoConnect.d.ts +5 -0
  122. package/dist/types/react/web/ui/AutoConnect/AutoConnect.d.ts.map +1 -1
  123. package/dist/types/react/web/ui/ConnectWallet/ConnectButton.d.ts +196 -2
  124. package/dist/types/react/web/ui/ConnectWallet/ConnectButton.d.ts.map +1 -1
  125. package/dist/types/react/web/ui/ConnectWallet/Modal/ConnectEmbed.d.ts +109 -3
  126. package/dist/types/react/web/ui/ConnectWallet/Modal/ConnectEmbed.d.ts.map +1 -1
  127. package/dist/types/react/web/ui/PayEmbed.d.ts +1 -1
  128. package/dist/types/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.d.ts +63 -0
  129. package/dist/types/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.d.ts.map +1 -0
  130. package/dist/types/react/web/ui/prebuilt/thirdweb/ClaimButton/index.d.ts +21 -0
  131. package/dist/types/react/web/ui/prebuilt/thirdweb/ClaimButton/index.d.ts.map +1 -1
  132. package/dist/types/react/web/wallets/shared/ConnectWalletSocialOptions.d.ts.map +1 -1
  133. package/dist/types/storage/download.d.ts +43 -3
  134. package/dist/types/storage/download.d.ts.map +1 -1
  135. package/dist/types/utils/contract/parse-abi-params.d.ts +29 -0
  136. package/dist/types/utils/contract/parse-abi-params.d.ts.map +1 -0
  137. package/dist/types/version.d.ts +1 -1
  138. package/dist/types/wallets/create-wallet.d.ts +73 -0
  139. package/dist/types/wallets/create-wallet.d.ts.map +1 -1
  140. package/dist/types/wallets/ecosystem/types.d.ts +5 -4
  141. package/dist/types/wallets/ecosystem/types.d.ts.map +1 -1
  142. package/dist/types/wallets/in-app/core/wallet/index.d.ts.map +1 -1
  143. package/dist/types/wallets/in-app/web/ecosystem.d.ts +29 -3
  144. package/dist/types/wallets/in-app/web/ecosystem.d.ts.map +1 -1
  145. package/dist/types/wallets/in-app/web/in-app.d.ts +100 -5
  146. package/dist/types/wallets/in-app/web/in-app.d.ts.map +1 -1
  147. package/dist/types/wallets/smart/smart-wallet.d.ts +71 -5
  148. package/dist/types/wallets/smart/smart-wallet.d.ts.map +1 -1
  149. package/package.json +1 -1
  150. package/src/adapters/wallet-adapter.ts +12 -1
  151. package/src/client/client.ts +19 -1
  152. package/src/exports/extensions/common.ts +5 -0
  153. package/src/exports/extensions/erc1155.ts +1 -0
  154. package/src/exports/react.ts +7 -0
  155. package/src/exports/utils.ts +3 -0
  156. package/src/exports/wallets/in-app.ts +6 -0
  157. package/src/exports/wallets.native.ts +8 -1
  158. package/src/exports/wallets.ts +13 -1
  159. package/src/react/core/hooks/others/useChainQuery.ts +24 -4
  160. package/src/react/core/hooks/transaction/transaction-button-utils.ts +1 -0
  161. package/src/react/web/ui/AutoConnect/AutoConnect.tsx +5 -0
  162. package/src/react/web/ui/ConnectWallet/ConnectButton.tsx +196 -2
  163. package/src/react/web/ui/ConnectWallet/Modal/ConnectEmbed.tsx +109 -3
  164. package/src/react/web/ui/ConnectWallet/screens/Buy/DirectPaymentModeScreen.tsx +2 -2
  165. package/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx +2 -2
  166. package/src/react/web/ui/PayEmbed.tsx +1 -1
  167. package/src/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/BuyDirectListingButton.test.tsx +27 -0
  168. package/src/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.tsx +200 -0
  169. package/src/react/web/ui/prebuilt/thirdweb/ClaimButton/index.tsx +78 -5
  170. package/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx +19 -8
  171. package/src/storage/download.ts +47 -4
  172. package/src/utils/contract/parse-abi-params.test.ts +160 -0
  173. package/src/utils/contract/parse-abi-params.ts +90 -0
  174. package/src/version.ts +1 -1
  175. package/src/wallets/create-wallet.ts +73 -0
  176. package/src/wallets/ecosystem/types.ts +9 -5
  177. package/src/wallets/in-app/core/wallet/index.ts +2 -3
  178. package/src/wallets/in-app/web/ecosystem.ts +29 -3
  179. package/src/wallets/in-app/web/in-app.ts +100 -5
  180. package/src/wallets/smart/smart-wallet.ts +71 -5
@@ -33,18 +33,212 @@ import { SignatureScreen } from "./screens/SignatureScreen.js";
33
33
  const TW_CONNECT_WALLET = "tw-connect-wallet";
34
34
 
35
35
  /**
36
- * A component that allows the user to connect their wallet.
37
- * It renders a button which when clicked opens a modal to allow users to connect to wallets specified in `wallets` prop.
36
+ * A fully featured wallet connection component that allows to:
37
+ *
38
+ * - Connect to 350+ external wallets
39
+ * - Connect with email, phone, passkey or socials
40
+ * - Convert any wallet to a ERC4337 smart wallet for gasless transactions
41
+ * - Sign in with ethereum (Auth)
42
+ *
43
+ * Once connected, the component allows to:
44
+ *
45
+ * - Reolve ENS names and avatars
46
+ * - Manage multipple connected wallets
47
+ * - Send and receive native tokens and ERC20 tokens
48
+ * - View ERC20 tokens and NFTs
49
+ * - Onramp, bridge and swap tokens
50
+ * - Switch chains
51
+ * - Connect to another app with WalletConnect
52
+ *
38
53
  * @example
54
+ *
55
+ * ## Default setup
56
+ *
39
57
  * ```tsx
58
+ * import { createThirdwebClient } from "thirdweb";
59
+ * import { ConnectButton } from "thirdweb/react";
60
+ *
61
+ * const client = createThirdwebClient({ clientId: "YOUR_CLIENT_ID" });
62
+ *
40
63
  * <ConnectButton
41
64
  * client={client}
42
65
  * />
43
66
  * ```
67
+ *
68
+ * [View all available config options](https://portal.thirdweb.com/references/typescript/v5/ConnectButtonProps)
69
+ *
70
+ * ## Customization options
71
+ *
72
+ * ### Customizing wallet options
73
+ *
74
+ * ```tsx
75
+ * <ConnectButton
76
+ * client={client}
77
+ * wallets={[
78
+ * createWallet("io.metamask"),
79
+ * createWallet("com.coinbase.wallet"),
80
+ * createWallet("me.rainbow"),
81
+ * ]}
82
+ * />
83
+ * ```
84
+ *
85
+ * [View all available wallets](https://portal.thirdweb.com/typescript/v5/supported-wallets)
86
+ *
87
+ * ### Customizing the default chain to connect to
88
+ *
89
+ * ```tsx
90
+ * import { base } from "thirdweb/chains";
91
+ *
92
+ * <ConnectButton
93
+ * client={client}
94
+ * chain={base}
95
+ * />
96
+ * ```
97
+ *
98
+ * ### Enabling sign in with ethereum (Auth)
99
+ *
100
+ * ```tsx
101
+ * <ConnectButton
102
+ * client={client}
103
+ * auth={{
104
+ * isLoggedIn: async (address) => {
105
+ * console.log("checking if logged in!", { address });
106
+ * return await isLoggedIn();
107
+ * },
108
+ * doLogin: async (params) => {
109
+ * console.log("logging in!");
110
+ * await login(params);
111
+ * },
112
+ * getLoginPayload: async ({ address }) =>
113
+ * generatePayload({ address }),
114
+ * doLogout: async () => {
115
+ * console.log("logging out!");
116
+ * await logout();
117
+ * },
118
+ * }}
119
+ * />;
120
+ * ```
121
+ *
122
+ * ### Customizing the theme
123
+ *
124
+ * ```tsx
125
+ * <ConnectButton
126
+ * client={client}
127
+ * theme="light"
128
+ * />
129
+ * ```
130
+ *
131
+ * For more granular control, you can also pass a custom theme object:
132
+ *
133
+ * ```tsx
134
+ * <ConnectButton
135
+ * client={client}
136
+ * theme={lightTheme({
137
+ * colors: {
138
+ * modalBg: "red",
139
+ * },
140
+ * })}
141
+ * />
142
+ * ```
143
+ *
144
+ * [View all available themes properties](https://portal.thirdweb.com/references/typescript/v5/Theme)
145
+ *
146
+ * ### Changing the display language
147
+ *
148
+ * ```tsx
149
+ * <ConnectEmbed
150
+ * client={client}
151
+ * locale="ja_JP"
152
+ * />
153
+ * ```
154
+ *
155
+ * [View all available locales](https://portal.thirdweb.com/references/typescript/v5/LocaleId)
156
+ *
157
+ * ### Customizing the connect button UI
158
+ *
159
+ * ```tsx
160
+ * <ConnectButton
161
+ * client={client}
162
+ * connectButton={{
163
+ * label: "Sign in to MyApp",
164
+ * }}
165
+ * />
166
+ * ```
167
+ *
168
+ * ### Customizing the modal UI
169
+ *
170
+ * ```tsx
171
+ * <ConnectButton
172
+ * client={client}
173
+ * connectModal={{
174
+ * title: "Sign in to MyApp",
175
+ * titleIcon: https://example.com/logo.png,
176
+ * size: "compact",
177
+ * }}
178
+ * />
179
+ * ```
180
+ *
181
+ * ### Customizing details button UI (after connecting)
182
+ *
183
+ * ```tsx
184
+ * <ConnectButton
185
+ * client={client}
186
+ * detailsButton={{
187
+ * displayBalanceToken: {
188
+ * [sepolia.id]: "0x...", // token address to display balance for
189
+ * [ethereum.id]: "0x...", // token address to display balance for
190
+ * },
191
+ * }}
192
+ * />
193
+ * ```
194
+ *
195
+ * [View all available auth helper functions](https://portal.thirdweb.com/references/typescript/v5/createAuth)
196
+ *
197
+ * ### Customizing the Auth sign in button (after connecting, but before authenticating)
198
+ *
199
+ * ```tsx
200
+ * <ConnectButton
201
+ * client={client}
202
+ * auth={{ ... }}
203
+ * signInButton: {
204
+ * label: "Authenticate with MyApp",
205
+ * },
206
+ * }}
207
+ * />;
208
+ * ```
209
+ *
210
+ * ### Customizing supported Tokens and NFTs
211
+ *
212
+ * These tokens and NFTs will be shown in the modal when the user clicks "View Assets", as well as the send token screen.
213
+ *
214
+ * ```tsx
215
+ * <ConnectButton
216
+ * client={client}
217
+ * supportedTokens={{
218
+ * [ethereum.id]: [
219
+ * {
220
+ * address: "0x...",
221
+ * name: "MyToken",
222
+ * symbol: "MT",
223
+ * icon: "https://example.com/icon.png",
224
+ * },
225
+ * ],
226
+ * }}
227
+ * supportedNFTs={{
228
+ * [ethereum.id]: [
229
+ * "0x...", // nft contract address
230
+ * ],
231
+ * }}
232
+ * />
233
+ * ```
234
+ *
44
235
  * @param props
45
236
  * Props for the `ConnectButton` component
46
237
  *
47
238
  * Refer to [ConnectButtonProps](https://portal.thirdweb.com/references/typescript/v5/ConnectButtonProps) to see the available props.
239
+ *
240
+ * @returns A JSX element that renders the <ConnectButton> component.
241
+ *
48
242
  * @component
49
243
  */
50
244
  export function ConnectButton(props: ConnectButtonProps) {
@@ -40,21 +40,127 @@ import { ConnectModalContent } from "./ConnectModalContent.js";
40
40
  import { useSetupScreen } from "./screen.js";
41
41
 
42
42
  /**
43
- * A component that allows the user to connect their wallet.
43
+ * An inline wallet connection component that allows to:
44
44
  *
45
- * it renders the same UI as the [`ConnectButton`](https://portal.thirdweb.com/react/v4/components/ConnectButton) component's modal - but directly on the page instead of being in a modal.
45
+ * - Connect to 350+ external wallets
46
+ * - Connect with email, phone, passkey or socials
47
+ * - Convert any wallet to a ERC4337 smart wallet for gasless transactions
48
+ * - Sign in with ethereum (Auth)
49
+ *
50
+ * It renders the same UI as the [`ConnectButton`](https://portal.thirdweb.com/react/v5/ConnectButton) component's modal - but directly inline in the page instead of being in a modal.
51
+ *
52
+ * Once connected, the component does not render any UI. It only renders UI if wallet is not connected.
46
53
  *
47
- * It only renders UI if wallet is not connected
48
54
  * @example
55
+ *
56
+ * ## Default setup
57
+ *
49
58
  * ```tsx
59
+ * import { createThirdwebClient } from "thirdweb";
60
+ * import { ConnectEmbed } from "thirdweb/react";
61
+ *
62
+ * const client = createThirdwebClient({ clientId: "YOUR_CLIENT_ID" });
63
+ *
50
64
  * <ConnectEmbed
51
65
  * client={client}
52
66
  * />
53
67
  * ```
68
+ *
69
+ * [View all available config options](https://portal.thirdweb.com/references/typescript/v5/ConnectEmbedProps)
70
+ *
71
+ * ## Customization options
72
+ *
73
+ * ### Customizing wallet options
74
+ *
75
+ * ```tsx
76
+ * <ConnectEmbed
77
+ * client={client}
78
+ * wallets={[
79
+ * createWallet("io.metamask"),
80
+ * createWallet("com.coinbase.wallet"),
81
+ * createWallet("me.rainbow"),
82
+ * ]}
83
+ * />
84
+ * ```
85
+ *
86
+ * [View all available wallets](https://portal.thirdweb.com/typescript/v5/supported-wallets)
87
+ *
88
+ * ### Customizing the default chain to connect to
89
+ *
90
+ * ```tsx
91
+ * import { base } from "thirdweb/chains";
92
+ *
93
+ * <ConnectEmbed
94
+ * client={client}
95
+ * chain={base}
96
+ * />
97
+ * ```
98
+ *
99
+ * ### Enabling sign in with ethereum (Auth)
100
+ *
101
+ * ```tsx
102
+ * <ConnectEmbed
103
+ * client={client}
104
+ * auth={{
105
+ * isLoggedIn: async (address) => {
106
+ * console.log("checking if logged in!", { address });
107
+ * return await isLoggedIn();
108
+ * },
109
+ * doLogin: async (params) => {
110
+ * console.log("logging in!");
111
+ * await login(params);
112
+ * },
113
+ * getLoginPayload: async ({ address }) =>
114
+ * generatePayload({ address }),
115
+ * doLogout: async () => {
116
+ * console.log("logging out!");
117
+ * await logout();
118
+ * },
119
+ * }}
120
+ * />;
121
+ * ```
122
+ *
123
+ * ### Customizing the theme
124
+ *
125
+ * ```tsx
126
+ * <ConnectEmbed
127
+ * client={client}
128
+ * theme="light"
129
+ * />
130
+ * ```
131
+ *
132
+ * For more granular control, you can also pass a custom theme object:
133
+ *
134
+ * ```tsx
135
+ * <ConnectEmbed
136
+ * client={client}
137
+ * theme={lightTheme({
138
+ * colors: {
139
+ * modalBg: "red",
140
+ * },
141
+ * })}
142
+ * />
143
+ * ```
144
+ *
145
+ * [View all available themes properties](https://portal.thirdweb.com/references/typescript/v5/Theme)
146
+ *
147
+ * ### Changing the display language
148
+ *
149
+ * ```tsx
150
+ * <ConnectEmbed
151
+ * client={client}
152
+ * locale="ja_JP"
153
+ * />
154
+ * ```
155
+ *
156
+ * [View all available locales](https://portal.thirdweb.com/references/typescript/v5/LocaleId)
157
+ *
54
158
  * @param props -
55
159
  * The props for the `ConnectEmbed` component.
56
160
  *
57
161
  * Refer to the [`ConnectEmbedProps`](https://portal.thirdweb.com/references/typescript/v5/ConnectEmbedProps) type for more details
162
+ *
163
+ * @returns A JSX element that renders the <ConnectEmbed> component.
58
164
  * @component
59
165
  */
60
166
  export function ConnectEmbed(props: ConnectEmbedProps) {
@@ -11,7 +11,7 @@ import type { Account } from "../../../../../../wallets/interfaces/wallet.js";
11
11
  import { useCustomTheme } from "../../../../../core/design-system/CustomThemeProvider.js";
12
12
  import { iconSize, spacing } from "../../../../../core/design-system/index.js";
13
13
  import type { PayUIOptions } from "../../../../../core/hooks/connection/ConnectButtonProps.js";
14
- import { useChainQuery } from "../../../../../core/hooks/others/useChainQuery.js";
14
+ import { useChainMetadata } from "../../../../../core/hooks/others/useChainQuery.js";
15
15
  import { useActiveWallet } from "../../../../../core/hooks/wallets/useActiveWallet.js";
16
16
  import type { TokenInfo } from "../../../../../core/utils/defaultTokens.js";
17
17
  import { useEnsName } from "../../../../../core/utils/wallet.js";
@@ -52,7 +52,7 @@ export function DirectPaymentModeScreen(props: {
52
52
  const activeWallet = useActiveWallet();
53
53
  const metadata = payUiOptions.metadata;
54
54
  const paymentInfo = payUiOptions.paymentInfo;
55
- const { data: chainData } = useChainQuery(paymentInfo.chain);
55
+ const { data: chainData } = useChainMetadata(paymentInfo.chain);
56
56
  const { data: sellerEns } = useEnsName({
57
57
  client,
58
58
  address: paymentInfo.sellerAddress,
@@ -7,7 +7,7 @@ import type { Account } from "../../../../../../wallets/interfaces/wallet.js";
7
7
  import { useCustomTheme } from "../../../../../core/design-system/CustomThemeProvider.js";
8
8
  import { iconSize, spacing } from "../../../../../core/design-system/index.js";
9
9
  import type { PayUIOptions } from "../../../../../core/hooks/connection/ConnectButtonProps.js";
10
- import { useChainQuery } from "../../../../../core/hooks/others/useChainQuery.js";
10
+ import { useChainMetadata } from "../../../../../core/hooks/others/useChainQuery.js";
11
11
  import { useActiveWallet } from "../../../../../core/hooks/wallets/useActiveWallet.js";
12
12
  import { hasSponsoredTransactionsEnabled } from "../../../../../core/utils/wallet.js";
13
13
  import { LoadingScreen } from "../../../../wallets/shared/LoadingScreen.js";
@@ -44,7 +44,7 @@ export function TransactionModeScreen(props: {
44
44
  supportedDestinations,
45
45
  onContinue,
46
46
  } = props;
47
- const { data: chainData } = useChainQuery(payUiOptions.transaction.chain);
47
+ const { data: chainData } = useChainMetadata(payUiOptions.transaction.chain);
48
48
  const metadata = payUiOptions.metadata;
49
49
  const { data: transactionCostAndData } = useTransactionCostAndData({
50
50
  transaction: payUiOptions.transaction,
@@ -29,7 +29,7 @@ import type { LocaleId } from "./types.js";
29
29
  export type PayEmbedProps = {
30
30
  /**
31
31
  * Override the default tokens shown in PayEmbed uI
32
- *
32
+ * @component
33
33
  * By default, PayEmbed shows a few popular tokens for Pay supported chains
34
34
  * @example
35
35
  *
@@ -0,0 +1,27 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { render, screen } from "~test/react-render.js";
3
+ import { TEST_CLIENT } from "~test/test-clients.js";
4
+ import { sepolia } from "../../../../../../chains/chain-definitions/sepolia.js";
5
+ import { BuyDirectListingButton } from "./index.js";
6
+
7
+ const client = TEST_CLIENT;
8
+
9
+ // marketplace v3 on sepolia
10
+ const marketplaceAddress = "0xe0eFD6fb388405b67b3E9FaFc02649c70E749f03";
11
+
12
+ describe.runIf(process.env.TW_SECRET_KEY)("BuyDirectListingButton", () => {
13
+ it("should render", () => {
14
+ render(
15
+ <BuyDirectListingButton
16
+ client={client}
17
+ chain={sepolia}
18
+ contractAddress={marketplaceAddress}
19
+ listingId={1n}
20
+ >
21
+ Buy NFT
22
+ </BuyDirectListingButton>,
23
+ );
24
+ expect(screen.queryByText("Buy NFT")).toBeInTheDocument();
25
+ expect(screen.getByRole("button")).toBeInTheDocument();
26
+ });
27
+ });
@@ -0,0 +1,200 @@
1
+ "use client";
2
+
3
+ import { useCallback } from "react";
4
+ import type { Chain } from "../../../../../../chains/types.js";
5
+ import type { ThirdwebClient } from "../../../../../../client/client.js";
6
+ import { getContract } from "../../../../../../contract/contract.js";
7
+ import { getListing } from "../../../../../../extensions/marketplace/direct-listings/read/getListing.js";
8
+ import type { BaseTransactionOptions } from "../../../../../../transaction/types.js";
9
+ import { useReadContract } from "../../../../../core/hooks/contract/useReadContract.js";
10
+ import type { TransactionButtonProps } from "../../../../../core/hooks/transaction/transaction-button-utils.js";
11
+ import { useSendAndConfirmTransaction } from "../../../../../core/hooks/transaction/useSendAndConfirmTransaction.js";
12
+ import { useActiveAccount } from "../../../../../core/hooks/wallets/useActiveAccount.js";
13
+ import { TransactionButton } from "../../../TransactionButton/index.js";
14
+
15
+ export type BuyDirectListingButtonProps = Omit<
16
+ TransactionButtonProps,
17
+ "transaction"
18
+ > & {
19
+ /**
20
+ * The contract address of the Marketplace v3 contract.
21
+ */
22
+ contractAddress: string;
23
+
24
+ /**
25
+ * The chain which the Drop contract is deployed on
26
+ */
27
+ chain: Chain;
28
+
29
+ /**
30
+ * thirdweb Client
31
+ */
32
+ client: ThirdwebClient;
33
+
34
+ /**
35
+ * ID of the marketplace's DirectListing
36
+ */
37
+ listingId: bigint;
38
+
39
+ /**
40
+ * Qty to buy (optional)
41
+ *
42
+ * - For ERC721 listing: the `quantity` is always hard-coded to 1n - passing this props doesn't do anything
43
+ *
44
+ * - For ERC1155 listing: the `quantity` defaults to the quantity of the listing if not specified.
45
+ *
46
+ * The component will also throw an error if you pass a `quantity` and it's greater than the listing's quantity
47
+ */
48
+ quantity?: bigint;
49
+ };
50
+
51
+ /**
52
+ * This button is used with thirdweb Marketplace v3 contract, for buying NFT(s) from a listing.
53
+ *
54
+ * Under the hood, it prepares a transaction using the [`buyFromListing` extension](https://portal.thirdweb.com/references/typescript/v5/marketplace/buyFromListing)
55
+ * and then pass it to a <TransactionButton />
56
+ *
57
+ * Since it uses the TransactionButton, it can take in any props that can be passed
58
+ * to the [`TransactionButton`](https://portal.thirdweb.com/references/typescript/v5/TransactionButton)
59
+ *
60
+ *
61
+ * @param props
62
+ * @returns <TransactionButton />
63
+ *
64
+ * @example
65
+ * ```tsx
66
+ * import { BuyDirectListingButton } from "thirdweb/react";
67
+ *
68
+ * <BuyDirectListingButton
69
+ * contractAddress="0x..." // contract address of the marketplace v3
70
+ * chain={...} // the chain which the marketplace contract is deployed on
71
+ * client={...} // thirdweb client
72
+ * listingId={100n} // the listingId or the item you want to buy
73
+ * quantity={1n} // optional - see the docs to learn more
74
+ * >
75
+ * Buy NFT
76
+ * </BuyDirectListingButton>
77
+ * ```
78
+ *
79
+ * @component
80
+ */
81
+ export function BuyDirectListingButton(props: BuyDirectListingButtonProps) {
82
+ const {
83
+ contractAddress,
84
+ listingId,
85
+ children,
86
+ chain,
87
+ client,
88
+ quantity,
89
+ payModal,
90
+ } = props;
91
+ const defaultPayModalMetadata = payModal ? payModal.metadata : undefined;
92
+ const account = useActiveAccount();
93
+ const contract = getContract({
94
+ address: contractAddress,
95
+ client,
96
+ chain,
97
+ });
98
+
99
+ const { data: payMetadata } = useReadContract(getPayMetadata, {
100
+ contract,
101
+ listingId,
102
+ queryOptions: {
103
+ enabled: !defaultPayModalMetadata,
104
+ },
105
+ });
106
+
107
+ const { mutateAsync } = useSendAndConfirmTransaction();
108
+
109
+ const prepareBuyTransaction = useCallback(async () => {
110
+ if (!account) {
111
+ throw new Error("No account detected");
112
+ }
113
+ const [listing, { getApprovalForTransaction }, { buyFromListing }] =
114
+ await Promise.all([
115
+ getListing({
116
+ contract,
117
+ listingId,
118
+ }),
119
+ import(
120
+ "../../../../../../extensions/erc20/write/getApprovalForTransaction.js"
121
+ ),
122
+ import(
123
+ "../../../../../../extensions/marketplace/direct-listings/write/buyFromListing.js"
124
+ ),
125
+ ]);
126
+ if (!listing) {
127
+ throw new Error(`Could not retrieve listing with ID: ${listingId}`);
128
+ }
129
+
130
+ let _quantity = 1n;
131
+ // For ERC721 the quantity should always be 1n. We throw an error if user passes a different props
132
+ if (listing.asset.type === "ERC721") {
133
+ if (typeof quantity === "bigint" && (quantity !== 1n || quantity < 0n)) {
134
+ throw new Error(
135
+ "Invalid quantity. This is an ERC721 listing & quantity is always `1n`",
136
+ );
137
+ }
138
+ } else if (listing.asset.type === "ERC1155") {
139
+ if (typeof quantity === "bigint") {
140
+ if (quantity > listing.quantity) {
141
+ throw new Error(
142
+ `quantity exceeds available amount. Available: ${listing.quantity.toString()}`,
143
+ );
144
+ }
145
+ if (quantity < 0n) {
146
+ throw new Error("Invalid quantity. Should be at least 1n");
147
+ }
148
+ _quantity = quantity;
149
+ }
150
+ _quantity = listing.quantity;
151
+ }
152
+
153
+ const buyTx = buyFromListing({
154
+ contract,
155
+ listingId,
156
+ quantity: _quantity,
157
+ recipient: account?.address || "",
158
+ });
159
+
160
+ const approveTx = await getApprovalForTransaction({
161
+ transaction: buyTx,
162
+ account,
163
+ });
164
+
165
+ if (approveTx) {
166
+ await mutateAsync(approveTx);
167
+ }
168
+
169
+ return buyTx;
170
+ }, [account, contract, quantity, listingId, mutateAsync]);
171
+
172
+ return (
173
+ <TransactionButton
174
+ payModal={{
175
+ metadata: defaultPayModalMetadata || payMetadata,
176
+ ...payModal,
177
+ }}
178
+ transaction={() => prepareBuyTransaction()}
179
+ {...props}
180
+ >
181
+ {children}
182
+ </TransactionButton>
183
+ );
184
+ }
185
+
186
+ /**
187
+ * @internal
188
+ */
189
+ async function getPayMetadata(
190
+ options: BaseTransactionOptions<{ listingId: bigint }>,
191
+ ): Promise<{ name?: string; image?: string }> {
192
+ const listing = await getListing(options);
193
+ if (!listing) {
194
+ return { name: undefined, image: undefined };
195
+ }
196
+ return {
197
+ name: listing.asset?.metadata?.name,
198
+ image: listing.asset?.metadata?.image,
199
+ };
200
+ }