// Web3Auth Libraries
import { Web3AuthConnector } from '@web3auth/web3auth-wagmi-connector'
import { Web3Auth } from '@web3auth/modal'
import { EthereumPrivateKeyProvider } from '@web3auth/ethereum-provider'
import { OpenloginAdapter } from '@web3auth/openlogin-adapter'
import { CHAIN_NAMESPACES, WALLET_ADAPTERS } from '@web3auth/base'
import { Chain } from 'wagmi'
export default function Web3AuthConnectorInstance(chains: Chain[]) {
const dev_clientId =
'BIB3D_my_dev_clientId'
const prod_clientId =
'my_prod_clientId'
// Create Web3Auth Instance
const name = 'my_name'
const chainConfig = {
chainNamespace: CHAIN_NAMESPACES.EIP155,
chainId: '0x' + chains[0].id.toString(16),
rpcTarget: chains[0].rpcUrls.default.http[0],
displayName: chains[0].name,
tickerName: chains[0].nativeCurrency?.name,
ticker: chains[0].nativeCurrency?.symbol,
blockExplorer: chains[0].blockExplorers?.default.url as string
}
const mode = process.env.NEXT_PUBLIC_APP_MODE
const web3AuthInstance = new Web3Auth({
clientId:
mode === 'PROD' || mode === 'STAGING' ? prod_clientId : dev_clientId,
web3AuthNetwork:
mode === 'PROD' || mode === 'STAGING'
? 'sapphire_mainnet'
: 'sapphire_devnet',
chainConfig,
uiConfig: {
defaultLanguage: 'en',
appName: name,
mode: 'light',
loginMethodsOrder: ['twitter', 'google'],
loginGridCol: 2,
logoLight: 'https://my_logo.png',
primaryButton: 'socialLogin'
}
})
const privateKeyProvider = new EthereumPrivateKeyProvider({
config: { chainConfig }
})
const openloginAdapterInstance = new OpenloginAdapter({
privateKeyProvider,
adapterSettings: {
network: 'cyan',
uxMode: 'popup',
whiteLabel: {
appName: 'My Wallet',
defaultLanguage: 'en',
mode: 'light',
logoLight: 'https://my_logo.png'
}
}
})
web3AuthInstance.configureAdapter(openloginAdapterInstance)
return new Web3AuthConnector({
chains: chains as any,
options: {
web3AuthInstance,
modalConfig: {
[WALLET_ADAPTERS.WALLET_CONNECT_V2]: {
label: 'wallet_connect',
showOnModal: false
},
[WALLET_ADAPTERS.OPENLOGIN]: {
label: 'openlogin',
loginMethods: {
apple: {
name: 'apple',
showOnModal: false
},
facebook: {
name: 'facebook',
showOnModal: false
},
reddit: {
name: 'reddit',
showOnModal: false
},
twitch: {
name: 'twitch',
showOnModal: false
},
line: {
name: 'line',
showOnModal: false
},
github: {
name: 'github',
showOnModal: false
},
kakao: {
name: 'kakao',
showOnModal: false
},
linkedin: {
name: 'linkedin',
showOnModal: false
},
weibo: {
name: 'weibo',
showOnModal: false
},
wechat: {
name: 'wechat',
showOnModal: false
},
sms_passwordless: {
name: 'sms_passwordless',
showOnModal: false
}
}
}
}
}
})
}