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.
- package/dist/cjs/adapters/wallet-adapter.js +12 -1
- package/dist/cjs/adapters/wallet-adapter.js.map +1 -1
- package/dist/cjs/client/client.js +19 -1
- package/dist/cjs/client/client.js.map +1 -1
- package/dist/cjs/exports/extensions/common.js +3 -1
- package/dist/cjs/exports/extensions/common.js.map +1 -1
- package/dist/cjs/exports/extensions/erc1155.js +2 -1
- package/dist/cjs/exports/extensions/erc1155.js.map +1 -1
- package/dist/cjs/exports/react.js +7 -2
- package/dist/cjs/exports/react.js.map +1 -1
- package/dist/cjs/exports/utils.js +3 -1
- package/dist/cjs/exports/utils.js.map +1 -1
- package/dist/cjs/exports/wallets/in-app.js.map +1 -1
- package/dist/cjs/exports/wallets.js.map +1 -1
- package/dist/cjs/exports/wallets.native.js.map +1 -1
- package/dist/cjs/react/core/hooks/others/useChainQuery.js +19 -3
- package/dist/cjs/react/core/hooks/others/useChainQuery.js.map +1 -1
- package/dist/cjs/react/core/hooks/transaction/transaction-button-utils.js.map +1 -1
- package/dist/cjs/react/web/ui/AutoConnect/AutoConnect.js +5 -0
- package/dist/cjs/react/web/ui/AutoConnect/AutoConnect.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js +196 -2
- package/dist/cjs/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js +109 -3
- package/dist/cjs/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/DirectPaymentModeScreen.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/DirectPaymentModeScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.js.map +1 -1
- package/dist/cjs/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.js +127 -0
- package/dist/cjs/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.js.map +1 -0
- package/dist/cjs/react/web/ui/prebuilt/thirdweb/ClaimButton/index.js +70 -3
- package/dist/cjs/react/web/ui/prebuilt/thirdweb/ClaimButton/index.js.map +1 -1
- package/dist/cjs/react/web/wallets/shared/ConnectWalletSocialOptions.js +19 -7
- package/dist/cjs/react/web/wallets/shared/ConnectWalletSocialOptions.js.map +1 -1
- package/dist/cjs/storage/download.js +44 -4
- package/dist/cjs/storage/download.js.map +1 -1
- package/dist/cjs/utils/contract/parse-abi-params.js +87 -0
- package/dist/cjs/utils/contract/parse-abi-params.js.map +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/create-wallet.js +73 -0
- package/dist/cjs/wallets/create-wallet.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/wallet/index.js +2 -3
- package/dist/cjs/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/ecosystem.js +29 -3
- package/dist/cjs/wallets/in-app/web/ecosystem.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/in-app.js +100 -5
- package/dist/cjs/wallets/in-app/web/in-app.js.map +1 -1
- package/dist/cjs/wallets/smart/smart-wallet.js +71 -5
- package/dist/cjs/wallets/smart/smart-wallet.js.map +1 -1
- package/dist/esm/adapters/wallet-adapter.js +12 -1
- package/dist/esm/adapters/wallet-adapter.js.map +1 -1
- package/dist/esm/client/client.js +19 -1
- package/dist/esm/client/client.js.map +1 -1
- package/dist/esm/exports/extensions/common.js +1 -0
- package/dist/esm/exports/extensions/common.js.map +1 -1
- package/dist/esm/exports/extensions/erc1155.js +1 -1
- package/dist/esm/exports/extensions/erc1155.js.map +1 -1
- package/dist/esm/exports/react.js +3 -0
- package/dist/esm/exports/react.js.map +1 -1
- package/dist/esm/exports/utils.js +1 -0
- package/dist/esm/exports/utils.js.map +1 -1
- package/dist/esm/exports/wallets/in-app.js.map +1 -1
- package/dist/esm/exports/wallets.js.map +1 -1
- package/dist/esm/exports/wallets.native.js.map +1 -1
- package/dist/esm/react/core/hooks/others/useChainQuery.js +19 -3
- package/dist/esm/react/core/hooks/others/useChainQuery.js.map +1 -1
- package/dist/esm/react/core/hooks/transaction/transaction-button-utils.js.map +1 -1
- package/dist/esm/react/web/ui/AutoConnect/AutoConnect.js +5 -0
- package/dist/esm/react/web/ui/AutoConnect/AutoConnect.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js +196 -2
- package/dist/esm/react/web/ui/ConnectWallet/ConnectButton.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js +109 -3
- package/dist/esm/react/web/ui/ConnectWallet/Modal/ConnectEmbed.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/DirectPaymentModeScreen.js +2 -2
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/DirectPaymentModeScreen.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.js +2 -2
- package/dist/esm/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.js.map +1 -1
- package/dist/esm/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.js +124 -0
- package/dist/esm/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.js.map +1 -0
- package/dist/esm/react/web/ui/prebuilt/thirdweb/ClaimButton/index.js +69 -3
- package/dist/esm/react/web/ui/prebuilt/thirdweb/ClaimButton/index.js.map +1 -1
- package/dist/esm/react/web/wallets/shared/ConnectWalletSocialOptions.js +19 -7
- package/dist/esm/react/web/wallets/shared/ConnectWalletSocialOptions.js.map +1 -1
- package/dist/esm/storage/download.js +44 -4
- package/dist/esm/storage/download.js.map +1 -1
- package/dist/esm/utils/contract/parse-abi-params.js +84 -0
- package/dist/esm/utils/contract/parse-abi-params.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/create-wallet.js +73 -0
- package/dist/esm/wallets/create-wallet.js.map +1 -1
- package/dist/esm/wallets/in-app/core/wallet/index.js +2 -3
- package/dist/esm/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/esm/wallets/in-app/web/ecosystem.js +29 -3
- package/dist/esm/wallets/in-app/web/ecosystem.js.map +1 -1
- package/dist/esm/wallets/in-app/web/in-app.js +100 -5
- package/dist/esm/wallets/in-app/web/in-app.js.map +1 -1
- package/dist/esm/wallets/smart/smart-wallet.js +71 -5
- package/dist/esm/wallets/smart/smart-wallet.js.map +1 -1
- package/dist/types/adapters/wallet-adapter.d.ts +12 -1
- package/dist/types/adapters/wallet-adapter.d.ts.map +1 -1
- package/dist/types/client/client.d.ts +19 -1
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/exports/extensions/common.d.ts +1 -0
- package/dist/types/exports/extensions/common.d.ts.map +1 -1
- package/dist/types/exports/extensions/erc1155.d.ts +1 -1
- package/dist/types/exports/extensions/erc1155.d.ts.map +1 -1
- package/dist/types/exports/react.d.ts +2 -0
- package/dist/types/exports/react.d.ts.map +1 -1
- package/dist/types/exports/utils.d.ts +2 -0
- package/dist/types/exports/utils.d.ts.map +1 -1
- package/dist/types/exports/wallets/in-app.d.ts +1 -0
- package/dist/types/exports/wallets/in-app.d.ts.map +1 -1
- package/dist/types/exports/wallets.d.ts +4 -2
- package/dist/types/exports/wallets.d.ts.map +1 -1
- package/dist/types/exports/wallets.native.d.ts +3 -2
- package/dist/types/exports/wallets.native.d.ts.map +1 -1
- package/dist/types/react/core/hooks/others/useChainQuery.d.ts +21 -4
- package/dist/types/react/core/hooks/others/useChainQuery.d.ts.map +1 -1
- package/dist/types/react/core/hooks/transaction/transaction-button-utils.d.ts +1 -0
- package/dist/types/react/core/hooks/transaction/transaction-button-utils.d.ts.map +1 -1
- package/dist/types/react/web/ui/AutoConnect/AutoConnect.d.ts +5 -0
- package/dist/types/react/web/ui/AutoConnect/AutoConnect.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/ConnectButton.d.ts +196 -2
- package/dist/types/react/web/ui/ConnectWallet/ConnectButton.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/Modal/ConnectEmbed.d.ts +109 -3
- package/dist/types/react/web/ui/ConnectWallet/Modal/ConnectEmbed.d.ts.map +1 -1
- package/dist/types/react/web/ui/PayEmbed.d.ts +1 -1
- package/dist/types/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.d.ts +63 -0
- package/dist/types/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.d.ts.map +1 -0
- package/dist/types/react/web/ui/prebuilt/thirdweb/ClaimButton/index.d.ts +21 -0
- package/dist/types/react/web/ui/prebuilt/thirdweb/ClaimButton/index.d.ts.map +1 -1
- package/dist/types/react/web/wallets/shared/ConnectWalletSocialOptions.d.ts.map +1 -1
- package/dist/types/storage/download.d.ts +43 -3
- package/dist/types/storage/download.d.ts.map +1 -1
- package/dist/types/utils/contract/parse-abi-params.d.ts +29 -0
- package/dist/types/utils/contract/parse-abi-params.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/create-wallet.d.ts +73 -0
- package/dist/types/wallets/create-wallet.d.ts.map +1 -1
- package/dist/types/wallets/ecosystem/types.d.ts +5 -4
- package/dist/types/wallets/ecosystem/types.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/wallet/index.d.ts.map +1 -1
- package/dist/types/wallets/in-app/web/ecosystem.d.ts +29 -3
- package/dist/types/wallets/in-app/web/ecosystem.d.ts.map +1 -1
- package/dist/types/wallets/in-app/web/in-app.d.ts +100 -5
- package/dist/types/wallets/in-app/web/in-app.d.ts.map +1 -1
- package/dist/types/wallets/smart/smart-wallet.d.ts +71 -5
- package/dist/types/wallets/smart/smart-wallet.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/adapters/wallet-adapter.ts +12 -1
- package/src/client/client.ts +19 -1
- package/src/exports/extensions/common.ts +5 -0
- package/src/exports/extensions/erc1155.ts +1 -0
- package/src/exports/react.ts +7 -0
- package/src/exports/utils.ts +3 -0
- package/src/exports/wallets/in-app.ts +6 -0
- package/src/exports/wallets.native.ts +8 -1
- package/src/exports/wallets.ts +13 -1
- package/src/react/core/hooks/others/useChainQuery.ts +24 -4
- package/src/react/core/hooks/transaction/transaction-button-utils.ts +1 -0
- package/src/react/web/ui/AutoConnect/AutoConnect.tsx +5 -0
- package/src/react/web/ui/ConnectWallet/ConnectButton.tsx +196 -2
- package/src/react/web/ui/ConnectWallet/Modal/ConnectEmbed.tsx +109 -3
- package/src/react/web/ui/ConnectWallet/screens/Buy/DirectPaymentModeScreen.tsx +2 -2
- package/src/react/web/ui/ConnectWallet/screens/Buy/TransactionModeScreen.tsx +2 -2
- package/src/react/web/ui/PayEmbed.tsx +1 -1
- package/src/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/BuyDirectListingButton.test.tsx +27 -0
- package/src/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/index.tsx +200 -0
- package/src/react/web/ui/prebuilt/thirdweb/ClaimButton/index.tsx +78 -5
- package/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx +19 -8
- package/src/storage/download.ts +47 -4
- package/src/utils/contract/parse-abi-params.test.ts +160 -0
- package/src/utils/contract/parse-abi-params.ts +90 -0
- package/src/version.ts +1 -1
- package/src/wallets/create-wallet.ts +73 -0
- package/src/wallets/ecosystem/types.ts +9 -5
- package/src/wallets/in-app/core/wallet/index.ts +2 -3
- package/src/wallets/in-app/web/ecosystem.ts +29 -3
- package/src/wallets/in-app/web/in-app.ts +100 -5
- 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
|
37
|
-
*
|
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
|
-
*
|
43
|
+
* An inline wallet connection component that allows to:
|
44
44
|
*
|
45
|
-
*
|
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 {
|
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 } =
|
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 {
|
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 } =
|
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,
|
package/src/react/web/ui/prebuilt/thirdweb/BuyDirectListingButton/BuyDirectListingButton.test.tsx
ADDED
@@ -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
|
+
}
|