wallet-connect-web-examples/wallets/react-wallet-auth/src/hooks/useInitialization.ts
Gancho Radkov 6aabae1762
feat: auth wallet multi address (#93)
* feat: updates auth wallet to be multi address compatible

* chore: updates `auth` to v2.0.0

* chore: updates `react-dapp-auth` to auth latest

* chore: updates `vue-dapp-auth` to auth latest
2022-12-16 13:43:40 +02:00

28 lines
772 B
TypeScript

import SettingsStore from '@/store/SettingsStore'
import { createOrRestoreEIP155Wallet } from '@/utils/EIP155WalletUtil'
import { createAuthClient } from '@/utils/WalletConnectUtil'
import { useCallback, useEffect, useState } from 'react'
export default function useInitialization() {
const [initialized, setInitialized] = useState(false)
const onInitialize = useCallback(async () => {
try {
const { eip155Addresses } = createOrRestoreEIP155Wallet()
SettingsStore.setEIP155Address(eip155Addresses[0])
await createAuthClient()
setInitialized(true)
} catch (err: unknown) {
alert(err)
}
}, [])
useEffect(() => {
if (!initialized) {
onInitialize()
}
}, [initialized, onInitialize])
return initialized
}