Skip to content
Open
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
16 changes: 11 additions & 5 deletions dapp/src/components/ConnectWalletModal/ConnectWalletButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React, {
import { time } from "#/constants"
import {
useAppDispatch,
useConnector,
useIsEmbed,
useModal,
usePostHogIdentity,
Expand Down Expand Up @@ -125,6 +126,7 @@ export default function ConnectWalletButton({
onDisconnect,
status: connectionStatus,
} = useWallet()
const connectedConnector = useConnector()
const { signMessageStatus, resetMessageStatus, signMessageAndCreateSession } =
useSignMessageAndCreateSession()
const { type, setConnectionAlert, resetConnectionAlert } =
Expand Down Expand Up @@ -178,19 +180,19 @@ export default function ConnectWalletButton({

if (!btcAddress) return

await handleSignMessageAndCreateSession(connector, btcAddress)
await handleSignMessageAndCreateSession(connectedConnector, btcAddress)
handleIdentification(btcAddress, {
connector: connectedConnector.id,
})
},
[connector, handleSignMessageAndCreateSession, handleIdentification],
[handleSignMessageAndCreateSession, handleIdentification],
)

const handleConnection = useCallback(() => {
onConnect(connector, {
isReconnecting,
onSuccess: () => {
logPromiseFailure(onSuccessConnection(connector))
onSuccess: (walletConnector) => {
logPromiseFailure(onSuccessConnection(walletConnector))
},
onError: (error: OrangeKitError) => {
const errorData = orangeKit.parseOrangeKitConnectionError(error)
Expand Down Expand Up @@ -335,8 +337,12 @@ export default function ConnectWalletButton({
size="lg"
variant="outline"
onClick={() =>
connectedConnector &&
logPromiseFailure(
handleSignMessageAndCreateSession(connector, address),
handleSignMessageAndCreateSession(
connectedConnector,
address,
),
)
}
>
Expand Down
10 changes: 5 additions & 5 deletions dapp/src/utils/logPromiseFailure.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* If the promise fails, log the underlying error but maintain the failed
* promise.
* Fire-and-forget helper: if the promise rejects, log it and do not rethrow.
*
* Does nothing to successful promises.
* Rethrowing inside `.catch()` would leave a second rejected promise that no
* caller awaits, which surfaces as an unhandled rejection in runtimes that
* enforce it.
*/
export default function logPromiseFailure<T>(promise: Promise<T>) {
promise.catch((error) => {
void promise.catch((error: unknown) => {
console.error(error)
throw error
})
}