Skip to content

Commit

Permalink
Merge pull request #53 from oasisprotocol/ml/request-accounts-after-s…
Browse files Browse the repository at this point in the history
…witching-network

Auto request accounts after switching network
  • Loading branch information
lubej authored Mar 20, 2024
2 parents f0bfd1c + 3362397 commit 7b995bf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
23 changes: 12 additions & 11 deletions frontend/src/components/ConnectWallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,29 @@ export const ConnectWallet: FC<Props> = ({ mobileSticky }) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

const handleSwitchNetwork = async () => {
const handleConnectWallet = async () => {
setIsLoading(true)
try {
await switchNetwork()
setIsUnknownNetwork(false)
await connectWallet()
} catch (ex) {
setAppError(ex as Error)
if (ex instanceof UnknownNetworkError) {
setIsUnknownNetwork(true)
} else {
setAppError(ex as Error)
}
} finally {
setIsLoading(false)
}
}

const handleConnectWallet = async () => {
const handleSwitchNetwork = async () => {
setIsLoading(true)
try {
await connectWallet()
await switchNetwork()
setIsUnknownNetwork(false)
handleConnectWallet()
} catch (ex) {
if (ex instanceof UnknownNetworkError) {
setIsUnknownNetwork(true)
} else {
setAppError(ex as Error)
}
setAppError(ex as Error)
} finally {
setIsLoading(false)
}
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/providers/Web3Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ export const Web3ContextProvider: FC<PropsWithChildren> = ({ children }) => {

const _chainChanged = useCallback(() => {
// TODO: Integrate seamlessly, so that page reload is not needed
window.location.reload()
}, [])

if (state.isConnected) {
window.location.reload()
}
}, [state.isConnected])

const _connect = useCallback(() => _connectionChanged(true), [])
const _disconnect = useCallback(() => _connectionChanged(false), [])
Expand Down

0 comments on commit 7b995bf

Please sign in to comment.