saepenatus
Version:
Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, mul
50 lines (39 loc) • 1.35 kB
text/typescript
import type { WalletInit, APIKey } from '@web3-onboard/common'
function portis(options: APIKey): WalletInit {
const { apiKey } = options
return () => {
return {
label: 'Portis',
getIcon: async () => (await import('./icon.js')).default,
getInterface: async ({ chains }) => {
const { default: Portis } = await import('@portis/web3')
const { createEIP1193Provider } = await import('@web3-onboard/common')
const instance = new Portis(apiKey, {
nodeUrl: chains[0].rpcUrl,
chainId: chains[0].id
})
const portisProvider = instance.provider
const provider = createEIP1193Provider(portisProvider, {
eth_requestAccounts: portisProvider.enable,
eth_selectAccounts: null,
wallet_switchEthereumChain: async ({ params }) => {
const chain = chains.find(({ id }) => id === params[0].chainId)
if (!chain) throw new Error('chain must be set before switching')
instance.changeNetwork({
nodeUrl: chain.rpcUrl,
chainId: chain.id
})
//@ts-ignore
provider.emit('chainChanged', chain.id)
return null
}
})
return {
provider,
instance
}
}
}
}
}
export default portis