-
Notifications
You must be signed in to change notification settings - Fork 242
/
ConnectButtonProps.ts
712 lines (664 loc) · 20.7 KB
/
ConnectButtonProps.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
import type { Chain } from "../../../../chains/types.js";
import type { ThirdwebClient } from "../../../../client/client.js";
import type { Wallet } from "../../../../wallets/interfaces/wallet.js";
import type { SmartWalletOptions } from "../../../../wallets/smart/types.js";
import type { AppMetadata } from "../../../../wallets/types.js";
import type { SiweAuthOptions } from "../../../core/hooks/auth/useSiweAuth.js";
import type { Theme } from "../design-system/index.js";
import type { LocaleId } from "../types.js";
import type { NetworkSelectorProps } from "./NetworkSelector.js";
import type { SupportedTokens } from "./defaultTokens.js";
import type { WelcomeScreen } from "./screens/types.js";
export type PayUIOptions = {
/**
* Prefill the Buy Token amount, chain and/or token.
* You can also disable the edits for the prefilled values using `allowEdits` - By default all are editable
*
* For example, if you want to allow changing the amount, but disable changing the token and chain,
* you can set `allowEdits` to `{ amount: true, token: false, chain: false }`
*
* If no `token` object is not specified, native token will be prefilled by default
*/
prefillBuy?: {
chain: Chain;
token?: {
name: string;
symbol: string;
address: string;
icon?: string;
};
amount?: string;
allowEdits?: {
amount: boolean;
token: boolean;
chain: boolean;
};
};
/**
* Configure options for buying tokens using other token ( aka Swap )
*
* By default, the "Crypto" option is enabled. You can disable it by setting `buyWithCrypto` to `false`
*
* You can prefill the source token and chain using `prefillSource`
* You can also disable the edits for the prefilled values by setting `prefillSource.allowEdits` - By default all are editable
*
* For example, if you want to allow selecting chain and but disable selecting token, you can set `allowEdits` to `{ token: false, chain: true }`
*/
buyWithCrypto?:
| false
| {
prefillSource?: {
chain: Chain;
token?: {
name: string;
symbol: string;
address: string;
icon?: string;
};
allowEdits?: {
token: boolean;
chain: boolean;
};
};
};
/**
* By default "Credit card" option is enabled. you can disable it by setting `buyWithFiat` to `false`
*
* You can also enable the test mode for the on-ramp provider to test on-ramp without using real credit card.
*/
buyWithFiat?:
| {
testMode?: boolean;
}
| false;
};
/**
* Options for configuring the `ConnectButton`'s Connect Button
* @connectWallet
*/
export type ConnectButton_connectButtonOptions = {
/**
* Set a custom label for the button. The default is `"Connect"`
* @example
* ```tsx
* <ConnectButton button={{
* label: "Sign in"
* }} />
* ```
*/
label?: string;
/**
* CSS class to apply to the button element
*
* For some CSS properties, you may need to use the `!important` to override the default styles
*
* ```tsx
* <ConnectButton button={{
* className="my-custom-class"
* }} />
* ```
*/
className?: string;
/**
* CSS styles to apply to the connectButton element
*/
style?: React.CSSProperties;
};
/**
* Options for configuring the `ConnectButton`'s Details Modal
* @connectWallet
*/
export type ConnectButton_detailsModalOptions = {
/**
* Show a "Request Testnet funds" link in `ConnectButton` Details Modal when user is connected to a testnet.
*
* By default it is `false`, If you want to show the "Request Testnet funds" link when user is connected to a testnet, set this prop to `true`
* @example
* ```tsx
* <ConnectButton showTestnetFaucet={true} />
* ```
*/
showTestnetFaucet?: boolean;
/**
* customize the Network selector shown in the `ConnectButton` Details Modal
*/
networkSelector?: NetworkSelectorProps;
/**
* Hide the "Switch to Personal wallet" option in the Connect Wallet details modal which is shown when wallet is connected to either Smart Wallet or Safe.
*
* By default it is `false`
* @example
* ```tsx
* <ConnectButton detailsModal={{
* hideSwitchToPersonalWallet: true
* }}
* />
* ```
*/
hideSwitchToPersonalWallet?: boolean;
/**
* Hide the "Disconnect Wallet" button in the `ConnectButton` Details Modal.
*
* By default it is `false`
* @example
* ```tsx
* <ConnectButton detailsModal={{
* hideDisconnect: true
* }} />
* ```
*/
hideDisconnect?: boolean;
/**
* Render custom UI at the bottom of the `ConnectButton` Details Modal
* @param props - props passed to the footer component which includes a function to close the modal
* @example
* ```tsx
* <ConnectButton
* detailsModal={{
* footer(props) {
* const { close } = props;
* return <div> ... </div>
* }
* }}
* />
* ```
*/
footer?: (props: { close: () => void }) => JSX.Element;
/**
* Configure options for thirdweb Pay.
*
* thirdweb Pay allows users to buy tokens using crypto or fiat currency.
*/
payOptions?: PayUIOptions;
};
/**
* Options for configuring the `ConnectButton`'s Details Button
* @connectWallet
*/
export type ConnectButton_detailsButtonOptions = {
/**
* CSS class to apply to the details button element
*/
className?: string;
/**
* CSS styles to apply to the details button element
*/
style?: React.CSSProperties;
/**
* Render a custom button to display connected wallet details instead of the default one
*
* ```tsx
* <ConnectButton
* detailsButton={{
* render() {
* return <button> .... </button>
* }
* }}
* />
* ```
*/
render?: () => JSX.Element;
/**
* Display the balance of a token instead of the native token in `ConnectButton` details button.
* @example
* ```tsx
* <ConnectButton detailsButton={{
* balanceToken:{
* // show USDC balance when connected to Ethereum mainnet
* 1: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
* }
* })
* />
* ```
*/
displayBalanceToken?: Record<number, string>;
};
/**
* Options for configuring the `ConnectButton`'s Connect Modal
* @connectWallet
*/
export type ConnectButton_connectModalOptions = {
/**
* Title to show in `ConnectButton`'s Modal
*
* The default is `"Connect"`
*/
title?: string;
/**
* Replace the default thirdweb icon next to Modal title with your own icon
*
* Set to empty string (`""`) to hide the icon
* @example
* ```tsx
* <ConnectButton modal={{
* titleIconUrl: "https://your-icon-url.png"
* }} />
* ```
*/
titleIcon?: string;
/**
* Set the size of the connect modal on desktop - `"compact"` or `"wide"`
*
* Modal size is always `compact` on mobile
*
* By default it is `"wide"` for desktop.
*/
size?: "compact" | "wide";
/**
* URL of the "terms of service" page
*
* If provided, Modal will show a Terms of Service message at the bottom with below link
* @example
* ```tsx
* <ConnectButton connectModal={{
* termsOfServiceUrl: "https://your-terms-of-service-url.com"
* }} />
* ```
*/
termsOfServiceUrl?: string;
/**
* URL of the "privacy policy" page
*
* If provided, Modal will show a Privacy Policy message at the bottom with below link
* @example
* ```tsx
* <ConnectButton connectModal={{
* privacyPolicyUrl="https://your-privacy-policy-url.com"
* }} />
* ```
*/
privacyPolicyUrl?: string;
/**
* Customize the welcome screen. This prop is only applicable when modalSize prop is set to "wide". On "wide" Modal size, a welcome screen is shown on the right side of the modal.
*
* This screen can be customized in two ways
*
* #### 1. Customize Metadata and Image
* ```tsx
* const welcomeScreen = {
* title: "your title",
* subtitle: "your subtitle",
* img: {
* src: "https://your-image-url.png",
* width: 300,
* height: 50,
* },
* }
*
* <ConnectButton connectModal={{
* welcomeScreen: welcomeScreen,
* }} />
* ```
*
* #### 2. Render Custom Component
*
* ```tsx
* <ConnectButton
* connectModal={{
* welcomeScreen: () => <YourCustomComponent />
* }}
* />
* ```
*/
welcomeScreen?: WelcomeScreen;
/**
* By default `ConnectButton`'s Modal shows "Powered by Thirdweb" branding at the bottom of the Modal.
*
* If you want to hide the branding, set this prop to `false`
* @example
* ```tsx
* <ConnectButton connectModal={{
* showThirdwebBranding: false
* }} />
*```
*/
showThirdwebBranding?: boolean;
};
/**
* Props for the [`ConnectButton`](https://portal.thirdweb.com/references/typescript/v5/ConnectButton) component
* @connectWallet
*/
export type ConnectButtonProps = {
/**
* A client is the entry point to the thirdweb SDK.
* It is required for all other actions.
* You can create a client using the `createThirdwebClient` function. Refer to the [Creating a Client](https://portal.thirdweb.com/typescript/v5/client) documentation for more information.
*
* You must provide a `clientId` or `secretKey` in order to initialize a client. Pass `clientId` if you want for client-side usage and `secretKey` for server-side usage.
*
* ```tsx
* import { createThirdwebClient } from "thirdweb";
*
* const client = createThirdwebClient({
* clientId: "<your_client_id>",
* })
* ```
*/
client: ThirdwebClient;
/**
* By default - ConnectButton UI uses the `en-US` locale for english language users.
*
* You can customize the language used in the ConnectButton UI by setting the `locale` prop.
*
* Refer to the [`LocaleId`](https://portal.thirdweb.com/references/typescript/v5/LocaleId) type for supported locales.
*/
locale?: LocaleId;
/**
* Array of supported wallets. If not provided, default wallets will be used.
* @example
* ```tsx
* import { AutoConnect } from "thirdweb/react";
* import { createWallet, inAppWallet } from "thirdweb/wallets";
*
* const wallets = [
* inAppWallet(),
* createWallet("io.metamask"),
* createWallet("com.coinbase.wallet"),
* createWallet("me.rainbow"),
* ];
*
* function Example() {
* return (
* <ConnectButton
* client={client}
* wallets={wallets}
* />
* )
* }
* ```
*
* If no wallets are specified. The component will show All the EIP-6963 compliant installed wallet extensions, as well as below default wallets:
*
* ```tsx
* const defaultWallets = [
* inAppWallet(),
* createWallet("io.metamask"),
* createWallet("com.coinbase.wallet"),
* createWallet("me.rainbow"),
* createWallet("io.zerion.wallet"),
* ]
* ```
*
* The `ConnectButton` also shows a "All wallets" button at the end of wallet list which allows user to connect to any of the 350+ wallets
*/
wallets?: Wallet[];
/**
* When the user has connected their wallet to your site, this configuration determines whether or not you want to automatically connect to the last connected wallet when user visits your site again in the future.
*
* By default it is set to `{ timeout: 15000 }` meaning that autoConnect is enabled and if the autoConnection does not succeed within 15 seconds, it will be cancelled.
*
* If you want to disable autoConnect, set this prop to `false`.
*
* If you want to customize the timeout, you can assign an object with a `timeout` key to this prop.
* ```tsx
* <ConnectButton client={client} autoConnect={{ timeout: 10000 }} />
* ```
*/
autoConnect?:
| {
timeout: number;
}
| boolean;
/**
* Metadata of the app that will be passed to connected wallet. Setting this is highly recommended.
*
* Some wallets display this information to the user when they connect to your app.
* @example
* ```ts
* {
* name: "My App",
* url: "https://my-app.com",
* description: "some description about your app",
* logoUrl: "https://path/to/my-app/logo.svg",
* };
* ```
*/
appMetadata?: AppMetadata;
/**
* The [`Chain`](https://portal.thirdweb.com/references/typescript/v5/Chain) object of the blockchain you want the wallet to connect to
*
* If a `chain` is not specified, Wallet will be connected to whatever is the default set in the wallet.
*
* If a `chain` is specified, Wallet will be prompted to switch to given chain after connection if it is not already connected to it.
* This ensures that the wallet is connected to the correct blockchain before interacting with your app.
*
* The `ConnectButton` also shows a "Switch Network" button until the wallet is connected to the specified chain. Clicking on the "Switch Network" button triggers the wallet to switch to the specified chain.
*
* You can create a `Chain` object using the [`defineChain`](https://portal.thirdweb.com/references/typescript/v5/defineChain) function.
* At minimum, you need to pass the `id` of the blockchain to `defineChain` function to create a `Chain` object.
* @example
* ```tsx
* import { polygon } from "thirdweb/wallets";
*
* function Example() {
* return <div> <ConnectButton chain={polygon} /> </div>
* }
* ```
*/
chain?: Chain;
/**
* Array of chains that your app supports.
*
* This is only relevant if your app is a multi-chain app and works across multiple blockchains.
* If your app only works on a single blockchain, you should only specify the `chain` prop.
*
* Given list of chains will used in various ways:
* - They will be displayed in the network selector in the `ConnectButton`'s details modal post connection
* - They will be sent to wallet at the time of connection if the wallet supports requesting multiple chains ( example: WalletConnect ) so that users can switch between the chains post connection easily
*
* ```tsx
* <ConnectButton chains={[ethereum, polygon, optimism]} />
* ```
*
* You can create a `Chain` object using the [`defineChain`](https://portal.thirdweb.com/references/typescript/v5/defineChain) function.
* At minimum, you need to pass the `id` of the blockchain to `defineChain` function to create a `Chain` object.
*
* ```tsx
* import { defineChain } from "thirdweb/react";
*
* const polygon = defineChain({
* id: 137,
* });
* ```
*/
chains?: Chain[];
/**
* Set the theme for the `ConnectButton` component. By default it is set to `"dark"`
*
* theme can be set to either `"dark"`, `"light"` or a custom theme object.
* You can also import [`lightTheme`](https://portal.thirdweb.com/references/typescript/v5/lightTheme)
* or [`darkTheme`](https://portal.thirdweb.com/references/typescript/v5/darkTheme)
* functions from `thirdweb/react` to use the default themes as base and overrides parts of it.
* @example
* ```ts
* import { lightTheme } from "thirdweb/react";
*
* const customTheme = lightTheme({
* colors: {
* modalBg: 'red'
* }
* })
*
* function Example() {
* return <ConnectButton theme={customTheme} />
* }
* ```
*/
theme?: "dark" | "light" | Theme;
/**
* Configurations for the button element that is shown when wallet is not connected
* @example
* ```tsx
* <ConnectButton
* connectButton={{
* connectButton: {
* label: "Connect",
* className: "my-custom-class",
* style: {
* borderRadius: "10px",
* },
* },
* }}
* />;
* ```
*/
connectButton?: ConnectButton_connectButtonOptions;
/**
* Configuration for the "Switch Network" button.
* This button is rendered when the wallet is connected, but it is not connected to the `chain` prop provided in `ConnectButton` component
* @example
* ```tsx
* <ConnectButton
* switchButton={{
* label: "Wrong Network",
* className: "my-custom-class",
* style: {
* backgroundColor: "red",
* },
* }}
* />;
* ```
*/
switchButton?: {
/**
* Set a custom label for the "Switch Network" button
*/
label?: string;
/**
* CSS styles to apply to the switch button element
*/
style?: React.CSSProperties;
/**
* CSS class to apply to the switch button element
*/
className?: string;
};
signInButton?: {
/**
* Set a custom label for the sign-in button
*/
label?: string;
/**
* CSS styles to apply to the sign-in button element
*/
style?: React.CSSProperties;
/**
* CSS class to apply to the sign-in button element
*/
className?: string;
};
/**
* Configurations for the `ConnectButton`'s Modal that is shown for connecting a wallet
* Refer to the [`ConnectButton_connectModalOptions`](https://portal.thirdweb.com/references/typescript/v5/ConnectButton_connectModalOptions) type for more details
* @example
* ```tsx
* <ConnectButton connectModal={{ size: "compact" }} />
*/
connectModal?: ConnectButton_connectModalOptions;
/**
* Configurations for the Details Button that is shown when wallet is connected
* Refer to the [`ConnectButton_detailsButtonOptions`](https://portal.thirdweb.com/references/typescript/v5/ConnectButton_detailsButtonOptions) type for more details
* @example
* ```tsx
* <ConnectButton
* detailsButton={{
* className: "my-custom-class",
* style: { borderRadius: "10px" },
* }}
* />;
* ```
*/
detailsButton?: ConnectButton_detailsButtonOptions;
/**
* Configurations for the Details Modal that is shown when wallet is connected and user clicks on the details button to see the connected wallet details
* Refer to the [`ConnectButton_detailsModalOptions`](https://portal.thirdweb.com/references/typescript/v5/ConnectButton_detailsModalOptions) type for more details
*/
detailsModal?: ConnectButton_detailsModalOptions;
/**
* Customize the tokens shown in the "Send Funds" screen in Details Modal for various networks.
*
* By default, The "Send Funds" screen shows a few popular tokens for default chains and the native token. For other chains it only shows the native token.
* @example
*
* supportedTokens prop allows you to customize this list as shown below which shows "Dai Stablecoin" when users wallet is connected to the "Base" mainnet.
*
* ```tsx
* import { ConnectButton } from 'thirdweb/react';
*
* function Example() {
* return (
* <ConnectButton
* supportedTokens={{
* // when connected to "Base" mainnet - show balance of DAI stablecoin
* 84532: [
* {
* address: '0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb', // token contract address
* name: 'Dai Stablecoin',
* symbol: 'DAI',
* icon: 'https://assets.coingecko.com/coins/images/9956/small/Badge_Dai.png?1687143508',
* },
* ],
* }}
* />
* );
* }
* ```
*/
supportedTokens?: SupportedTokens;
/**
* Callback to be called on successful connection of wallet - including auto connect.
* The callback is called with the connected wallet
*
* ```tsx
* <ConnectButton
* onConnect={(wallet) => {
* console.log("connected to", wallet)
* }}
* />
* ```
*/
onConnect?: (wallet: Wallet) => void;
/**
* Configure options for WalletConnect
*
* By default WalletConnect uses the thirdweb's default project id.
* Setting your own project id is recommended.
*
* You can create a project id by signing up on [walletconnect.com](https://walletconnect.com/)
*/
walletConnect?: {
projectId?: string;
};
/**
* Enable Account abstraction for all wallets. This will connect to the users's smart account based on the connected personal wallet and the given options.
*
* This allows to sponsor gas fees for your user's transaction using the thirdweb account abstraction infrastructure.
*
* ```tsx
* <ConnectButton
* accountAbstraction={{
* factoryAddress: "0x123...",
* chain: sepolia,
* gasless: true;
* }}
* />
*/
accountAbstraction?: SmartWalletOptions;
/**
* Wallets to show as recommended in the `ConnectButton`'s Modal
*/
recommendedWallets?: Wallet[];
/**
* By default, ConnectButton modal shows a "All Wallets" button that shows a list of 350+ wallets.
*
* You can disable this button by setting `showAllWallets` prop to `false`
*/
showAllWallets?: boolean;
/**
* Enable SIWE (Sign in with Ethererum) by passing an object of type `SiweAuthOptions` to
* enforce the users to sign a message after connecting their wallet to authenticate themselves.
*
* Refer to the [`SiweAuthOptions`](https://portal.thirdweb.com/references/typescript/v5/SiweAuthOptions) for more details
*/
auth?: SiweAuthOptions;
};