-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
defaultConfig.ts
116 lines (107 loc) · 3.04 KB
/
defaultConfig.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
import '@web3modal/polyfills'
import type { CreateConfigParameters, CreateConnectorFn, Config } from '@wagmi/core'
import { createConfig } from '@wagmi/core'
import { coinbaseWallet, walletConnect, injected } from '@wagmi/connectors'
import { authConnector } from '../connectors/AuthConnector.js'
import { getTransport } from './helpers.js'
import type { SocialProvider } from '@web3modal/scaffold-utils'
export type ConfigOptions = Partial<CreateConfigParameters> & {
chains: CreateConfigParameters['chains']
projectId: string
enableEIP6963?: boolean
enableCoinbase?: boolean
auth?: {
email?: boolean
socials?: SocialProvider[]
showWallets?: boolean
walletFeatures?: boolean
}
enableInjected?: boolean
enableWalletConnect?: boolean
metadata: {
name: string
description: string
url: string
icons: string[]
}
coinbasePreference?: 'all' | 'smartWalletOnly' | 'eoaOnly'
}
export function defaultConfig({
projectId,
chains,
metadata,
enableCoinbase,
enableInjected,
auth = {},
enableWalletConnect,
enableEIP6963,
...wagmiConfig
}: ConfigOptions): Config {
const connectors: CreateConnectorFn[] = wagmiConfig?.connectors ?? []
const transportsArr = chains.map(chain => [chain.id, getTransport({ chain, projectId })])
const transports = Object.fromEntries(transportsArr)
const defaultAuth = {
email: true,
showWallets: true,
walletFeatures: true,
socials: [
'google',
'x',
'discord',
'farcaster',
'github',
'apple',
'facebook'
] as SocialProvider[]
}
// Enabled by default
if (enableWalletConnect !== false) {
connectors.push(walletConnect({ projectId, metadata, showQrModal: false }))
}
// Enabled by default
if (enableInjected !== false) {
connectors.push(injected({ shimDisconnect: true }))
}
// Enabled by default
if (enableCoinbase !== false) {
connectors.push(
coinbaseWallet({
version: '4',
appName: metadata?.name ?? 'Unknown',
appLogoUrl: metadata?.icons[0] ?? 'Unknown',
/**
* Determines which wallet options to display in Coinbase Wallet SDK.
* @property preference
* - `all`: Show both smart wallet and EOA options.
* - `smartWalletOnly`: Show only smart wallet options.
* - `eoaOnly`: Show only EOA options.
* @see https://www.smartwallet.dev/sdk/v3-to-v4-changes#parameters
*/
preference: wagmiConfig.coinbasePreference || 'all'
})
)
}
const mergedAuth = {
...defaultAuth,
...auth
}
if (mergedAuth.email || mergedAuth.socials?.length) {
connectors.push(
authConnector({
chains: [...chains],
options: { projectId },
socials: mergedAuth.socials,
email: mergedAuth.email,
showWallets: mergedAuth.showWallets,
walletFeatures: mergedAuth.walletFeatures
})
)
}
return createConfig({
chains,
multiInjectedProviderDiscovery: enableEIP6963 !== false,
transports,
...wagmiConfig,
connectors
})
}