Skip to content

Commit

Permalink
Trigger connection action for embed dApp
Browse files Browse the repository at this point in the history
The connection request should run right away when the user opens the modal window.
  • Loading branch information
kkosiorowska committed Sep 27, 2024
1 parent dd38e20 commit b09fbeb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion dapp/src/components/ConnectWalletModal/ConnectWalletButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useState } from "react"
import React, { useCallback, useEffect, useRef, useState } from "react"
import { CONNECTION_ERRORS, ONE_SEC_IN_MILLISECONDS } from "#/constants"
import {
useAppDispatch,
Expand Down Expand Up @@ -68,6 +68,7 @@ export default function ConnectWalletButton({
useWalletConnectionError()
const { closeModal } = useModal()
const dispatch = useAppDispatch()
const isMounted = useRef(false)

const [isLoading, setIsLoading] = useState<boolean>(false)

Expand Down Expand Up @@ -163,6 +164,13 @@ export default function ConnectWalletButton({
handleConnection()
}

useEffect(() => {
if (!isMounted.current && isEmbed && isSelected) {
isMounted.current = true
handleConnection()
}
}, [handleConnection, isEmbed, isSelected])

return (
<Card
key={connector.id}
Expand Down

0 comments on commit b09fbeb

Please sign in to comment.