Skip to content
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
28 changes: 17 additions & 11 deletions packages/chain-adapters/src/utils/ledgerAppGate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,23 @@ export const verifyLedgerAppOpen = async (chainId: ChainId | KnownChainIds, wall
const args: LedgerOpenAppEventArgs = { chainId, reject }
emitter.emit('LedgerOpenApp', args)

// prompt user to open app on device
wallet.openApp(appName)

intervalId = setInterval(async () => {
if (!(await isAppOpen())) return

// emit event to trigger modal close
emitter.emit('LedgerAppOpened')
clearInterval(intervalId)
resolve()
}, 1000)
// start polling for app open status after openApp completes to avoid concurrent USB requests
const startPolling = () => {
intervalId = setInterval(async () => {
if (!(await isAppOpen())) return

// emit event to trigger modal close
emitter.emit('LedgerAppOpened')
clearInterval(intervalId)
resolve()
}, 1000)
}

// prompt user to open app on device, then start polling
// Promise.resolve normalizes both promise and non-promise return values
Promise.resolve(wallet.openApp(appName))
.then(() => startPolling())
.catch(() => startPolling())
})
} catch {
clearInterval(intervalId)
Expand Down
7 changes: 6 additions & 1 deletion src/context/AppProvider/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
emitter.off('LedgerOpenApp', handleLedgerOpenApp)
emitter.off('LedgerAppOpened', handleLedgerAppOpened)
}
})
// Empty deps array intentional - event listeners are global via EventEmitter.
// They should register once on AppProvider mount and remain stable throughout app lifecycle.
// The handlers capture closeModal/openModal but these are stable functions from ModalProvider.
// Re-registering listeners on every render was causing the Ledger app gate flakiness (issue #11492).
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

// track anonymous portfolio
useMixpanelPortfolioTracking()
Expand Down