Skip to content

Commit

Permalink
Merge pull request #11329 from brave/pr11301_uplift_to_1.33.x
Browse files Browse the repository at this point in the history
(uplift to 1.33.x) Retry signMessage for ConnectHardwareView (#11301)
  • Loading branch information
kjozwiak authored Dec 1, 2021
2 parents c629fd4 + eea8a87 commit 8247e14
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class BraveBubbleDialogDelegateView : public views::BubbleDialogDelegateView {
return;
content::WebContents* active =
browser->tab_strip_model()->GetActiveWebContents();
if (!active) {
return;
}
auto* tab_helper =
brave_wallet::BraveWalletTabHelper::FromWebContents(active);
if (tab_helper)
Expand Down
7 changes: 7 additions & 0 deletions components/brave_wallet_ui/common/async/hardware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ export function dialogErrorFromLedgerErrorCode (code: string | number): Hardware
return 'openEthereumApp'
}

export function dialogErrorFromTrezorErrorCode (code: TrezorErrorsCodes): HardwareWalletResponseCodeType {
if (code === TrezorErrorsCodes.CommandInProgress) {
return 'deviceBusy'
}
return 'openEthereumApp'
}

export async function signTrezorTransaction (apiProxy: WalletApiProxy, path: string, txInfo: BraveWallet.TransactionInfo): Promise<SignHardwareTransactionType> {
const chainId = await apiProxy.ethJsonRpcController.getChainId()
const nonce = await apiProxy.ethTxController.getNonceForHardwareTransaction(txInfo.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default class LedgerBridgeKeyring extends EventEmitter {
}
return { success: true, payload: signature }
} catch (e) {
return { success: false, error: e.message, code: e.id }
return { success: false, error: e.message, code: e.statusCode || e.id || e.name }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at http://mozilla.org/MPL/2.0/.

import {
TransactionInfo,
SignMessageRequest,
Expand Down Expand Up @@ -39,7 +38,8 @@ import {
signLedgerTransaction,
signMessageWithHardwareKeyring,
cancelHardwareOperation,
dialogErrorFromLedgerErrorCode
dialogErrorFromLedgerErrorCode,
dialogErrorFromTrezorErrorCode
} from '../../common/async/hardware'

import { fetchSwapQuoteFactory } from '../../common/async/handlers'
Expand All @@ -48,7 +48,6 @@ import { getLocale } from '../../../common/locale'

import getWalletPanelApiProxy from '../wallet_panel_api_proxy'
import { TrezorErrorsCodes } from '../../common/trezor/trezor-messages'
import { LedgerErrorsCodes } from '../../common/ledgerjs/eth_ledger_bridge_keyring'

const handler = new AsyncActionHandler()

Expand Down Expand Up @@ -343,16 +342,21 @@ handler.on(PanelActions.signMessageHardware.getType(), async (store, messageData
await navigateToConnectHardwareWallet(store)
const info = hardwareAccount.hardware
const signed = await signMessageWithHardwareKeyring(apiProxy, info.vendor, info.path, messageData.message)
if (!signed.success &&
(signed.code === TrezorErrorsCodes.CommandInProgress ||
signed.code === LedgerErrorsCodes.TransportLocked)) {
// do nothing as the operation is already in progress
return
if (!signed.success) {
if (signed.code) {
const deviceError = (info.vendor === TREZOR_HARDWARE_VENDOR)
? dialogErrorFromTrezorErrorCode(signed.code as TrezorErrorsCodes) : dialogErrorFromLedgerErrorCode(signed.code)
if (deviceError !== 'transactionRejected') {
await store.dispatch(PanelActions.setHardwareWalletInteractionError(deviceError))
return
}
}
}
const payload: SignMessageHardwareProcessedPayload =
signed.success ? { success: signed.success, id: messageData.id, signature: signed.payload }
: { success: signed.success, id: messageData.id, error: signed.error }
store.dispatch(PanelActions.signMessageHardwareProcessed(payload))
await store.dispatch(PanelActions.navigateToMain())
apiProxy.panelHandler.closeUI()
})

Expand Down
13 changes: 11 additions & 2 deletions components/brave_wallet_ui/panel/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ function Container (props: Props) {
const onQueueNextTransction = () => {
props.walletActions.queueNextTransaction()
}

const onConfirmTransaction = () => {
if (!selectedPendingTransaction) {
return
Expand All @@ -425,7 +426,15 @@ function Container (props: Props) {
props.walletActions.approveTransaction(selectedPendingTransaction)
}
}

const retryHardwareOperation = () => {
// signMessageData by default initialized as [{ id: -1, address: '', message: '' }]
if (signMessageData && signMessageData.length && signMessageData[0].id !== -1) {
onSignData()
}
if (selectedPendingTransaction) {
onConfirmTransaction()
}
}
const onOpenSettings = () => {
props.walletPanelActions.openWalletSettings()
}
Expand Down Expand Up @@ -492,7 +501,7 @@ function Container (props: Props) {
onCancel={onCancelConnectHardwareWallet}
walletName={selectedAccount.name}
hardwareWalletCode={props.panel.hardwareWalletCode}
retryCallable={onConfirmTransaction}
retryCallable={retryHardwareOperation}
/>
</StyledExtensionWrapper>
</PanelWrapper>
Expand Down
2 changes: 1 addition & 1 deletion components/resources/wallet_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
<message name="IDS_BRAVE_WALLET_CONNECT_HARDWARE_PANEL_DISCONNECTED" desc="Connect Hardware panel disconnected status"><ph name="DEVICE_NAME"><ex>Ledger</ex>$1</ph> disconnected</message>
<message name="IDS_BRAVE_WALLET_CONNECT_HARDWARE_PANEL_INSTRUCTIONS" desc="Connect Hardware panel instructions button">Instructions</message>
<message name="IDS_BRAVE_WALLET_CONNECT_HARDWARE_PANEL_CONNECT" desc="Connect Hardware panel title">Connect your <ph name="DEVICE_NAME"><ex>Ledger</ex>$1</ph></message>
<message name="IDS_BRAVE_WALLET_CONNECT_HARDWARE_PANEL_CONFIRMATION" desc="Connect Hardware panel confirmation description">Hardware wallet requires transaction confirmation. <ph name="DEVICE_NAME"><ex>Ledger</ex>$1</ph></message>
<message name="IDS_BRAVE_WALLET_CONNECT_HARDWARE_PANEL_CONFIRMATION" desc="Connect Hardware panel confirmation description">Hardware wallet requires confirmation on device. <ph name="DEVICE_NAME"><ex>Ledger</ex>$1</ph></message>
<message name="IDS_BRAVE_WALLET_CONNECT_HARDWARE_PANEL_OPEN_APP" desc="Connect Hardware panel open app text">Hardware wallet requires Ethereum App opened on <ph name="DEVICE_NAME"><ex>Ledger</ex>$1</ph></message>
<message name="IDS_BRAVE_WALLET_TRANSACTION_SENT" desc="Transaction sent label">sent</message>
<message name="IDS_BRAVE_WALLET_TRANSACTION_RECEIVED" desc="Transaction received label">received</message>
Expand Down

0 comments on commit 8247e14

Please sign in to comment.