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

fix(wallet): prevent panel from closing after a HW connection error #11090

Merged
merged 1 commit into from
Nov 15, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const openWalletApps = createAction('openWalletApps')
export const expandRestoreWallet = createAction('expandRestoreWallet')
export const expandWalletAccounts = createAction('expandWalletAccounts')
export const navigateTo = createAction<string>('navigateTo')
export const navigateToMain = createAction('navigateToMain')
export const setPanelSwapQuote = createAction<SwapResponse>('setPanelSwapQuote')
export const setPanelSwapError = createAction<SwapErrorResponse | undefined>('setPanelSwapError')
export const fetchPanelSwapQuote = createAction<SwapParamsPayloadType>('fetchPanelSwapQuote')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ async function getPendingSignMessageRequest () {
return null
}

handler.on(PanelActions.navigateToMain.getType(), async (store: Store) => {
const apiProxy = getWalletPanelApiProxy()

await store.dispatch(PanelActions.navigateTo('main'))
await store.dispatch(PanelActions.setHardwareWalletInteractionError(undefined))
apiProxy.panelHandler.setCloseOnDeactivate(true)
apiProxy.panelHandler.showUI()
})

async function navigateToConnectHardwareWallet (store: Store) {
const apiProxy = getWalletPanelApiProxy()

await store.dispatch(PanelActions.navigateTo('connectHardwareWallet'))
await store.dispatch(PanelActions.setHardwareWalletInteractionError(undefined))
apiProxy.panelHandler.setCloseOnDeactivate(false)
}

handler.on(WalletActions.initialize.getType(), async (store) => {
const state = getPanelState(store)
// Sanity check we only initialize once
Expand Down Expand Up @@ -153,28 +170,25 @@ handler.on(PanelActions.approveHardwareTransaction.getType(), async (store: Stor
}

const apiProxy = getWalletPanelApiProxy()
apiProxy.panelHandler.setCloseOnDeactivate(false)
await navigateToConnectHardwareWallet(store)

if (hardwareAccount.hardware.vendor === LEDGER_HARDWARE_VENDOR) {
await store.dispatch(PanelActions.navigateTo('connectHardwareWallet'))
await store.dispatch(PanelActions.setHardwareWalletInteractionError(undefined))

const { success, error, deviceError } = await signLedgerTransaction(apiProxy, hardwareAccount.hardware.path, txInfo)
if (!success) {
if (deviceError) {
if (deviceError === 'transactionRejected') {
await store.dispatch(WalletActions.rejectTransaction(txInfo))
await store.dispatch(PanelActions.navigateTo('main'))
await store.dispatch(PanelActions.navigateToMain())
} else {
await store.dispatch(PanelActions.setHardwareWalletInteractionError(deviceError))
}
} else if (error) {
// TODO: handle non-device errors
console.log(error)
await store.dispatch(PanelActions.navigateToMain())
}
} else {
await store.dispatch(PanelActions.navigateTo('main'))
await store.dispatch(PanelActions.setHardwareWalletInteractionError(undefined))
await store.dispatch(PanelActions.navigateToMain())
refreshTransactionHistory(txInfo.fromAddress)
}
} else if (hardwareAccount.hardware.vendor === TREZOR_HARDWARE_VENDOR) {
Expand All @@ -185,10 +199,9 @@ handler.on(PanelActions.approveHardwareTransaction.getType(), async (store: Stor
} else {
refreshTransactionHistory(txInfo.fromAddress)
}
}

apiProxy.panelHandler.setCloseOnDeactivate(true)
apiProxy.panelHandler.showUI()
await store.dispatch(PanelActions.navigateToMain())
}
})

handler.on(PanelActions.connectToSite.getType(), async (store: Store, payload: AccountPayloadType) => {
Expand Down
2 changes: 1 addition & 1 deletion components/brave_wallet_ui/panel/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ function Container (props: Props) {
const onCancelConnectHardwareWallet = () => {
// Navigating to main panel view will unmount ConnectHardwareWalletPanel
// and therefore forfeit connecting to the hardware wallet.
props.walletPanelActions.navigateTo('main')
props.walletPanelActions.navigateToMain()
}

const removeSitePermission = (origin: string, address: string) => {
Expand Down