Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ledger Live fix connection errors #797

Merged
merged 5 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions dapp/src/components/ConnectWalletModal/ConnectWalletButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ export default function ConnectWalletButton({
const [isLoading, setIsLoading] = useState<boolean>(false)

const hasConnectionError = connectionError || connectionStatus === "error"
const hasSignMessageStatus = signMessageStatus === "error"
const showStatuses = isSelected && !hasConnectionError
const showRetryButton = address && hasSignMessageStatus
const hasSignMessageErrorStatus = signMessageStatus === "error"
const shouldShowStatuses = isSelected && !hasConnectionError
const shouldShowRetryButton = address && hasSignMessageErrorStatus

const onSuccessSignMessage = useCallback(() => {
closeModal()
Expand Down Expand Up @@ -156,7 +156,7 @@ export default function ConnectWalletButton({

const handleButtonClick = () => {
// Do not trigger action again when wallet connection is in progress
if (showStatuses) return
if (shouldShowStatuses) return

if (!isReconnecting) onDisconnect()
resetConnectionError()
Expand Down Expand Up @@ -225,7 +225,7 @@ export default function ConnectWalletButton({
</CardHeader>

<AnimatePresence initial={false}>
{showStatuses && (
{shouldShowStatuses && (
<CardBody
as={motion.div}
variants={collapseVariants}
Expand Down Expand Up @@ -256,7 +256,7 @@ export default function ConnectWalletButton({
status={signMessageStatus}
label="Sign message"
/>
{showRetryButton && (
{shouldShowRetryButton && (
<Button
mt={4}
size="lg"
Expand Down
20 changes: 18 additions & 2 deletions dapp/src/components/ConnectWalletModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React, { useEffect, useState } from "react"
import { ModalBody, ModalHeader, ModalCloseButton } from "@chakra-ui/react"
import { useConnectors, useIsEmbed, useWalletConnectionError } from "#/hooks"
import {
useConnectors,
useIsEmbed,
useIsSignedMessage,
useWallet,
useWalletConnectionError,
} from "#/hooks"
import { OrangeKitConnector, BaseModalProps, OnSuccessCallback } from "#/types"
import withBaseModal from "../ModalRoot/withBaseModal"
import ConnectWalletButton from "./ConnectWalletButton"
Expand All @@ -15,6 +21,7 @@ export function ConnectWalletModalBase({
isReconnecting?: boolean
} & BaseModalProps) {
const { isEmbed } = useIsEmbed()
const { onDisconnect } = useWallet()
const connectors = useConnectors()
const enabledConnectors = connectors.map((connector) => ({
...connector,
Expand All @@ -23,6 +30,7 @@ export function ConnectWalletModalBase({

const [selectedConnectorId, setSelectedConnectorId] = useState<string>()
const { connectionError, resetConnectionError } = useWalletConnectionError()
const isSignedMessage = useIsSignedMessage()

const handleButtonOnClick = (connector: OrangeKitConnector) => {
setSelectedConnectorId(connector.id)
Expand All @@ -37,7 +45,15 @@ export function ConnectWalletModalBase({
return (
<>
{withCloseButton && (
<ModalCloseButton onClick={() => resetConnectionError()} />
<ModalCloseButton
onClick={() => {
resetConnectionError()

if (!isSignedMessage) {
onDisconnect()
}
}}
/>
)}
<ModalHeader>{`Select your ${isEmbed ? "account" : "wallet"}`}</ModalHeader>

Expand Down
6 changes: 5 additions & 1 deletion dapp/src/hooks/useWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ export function useWallet(): UseWalletReturn {

useEffect(() => {
const fetchBitcoinAddress = async () => {
if (connector) {
if (
connector &&
typeof connector.getAccounts === "function" &&
typeof connector.getBitcoinAddress === "function"
) {
const btcAddress = await connector.getBitcoinAddress()
const accounts = await connector.getAccounts()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { BitcoinNetwork } from "@acre-btc/sdk"
import { beforeAll, vi, expect, describe, it } from "vitest"
import {
Expand Down
Loading