Skip to content

Commit

Permalink
Merge pull request #13232 from brave/fix-confirm-hardware-wallet-tran…
Browse files Browse the repository at this point in the history
…saction

fix(wallet): Confirm Hardware Wallet Transaction
  • Loading branch information
Douglashdaniel committed May 2, 2022
1 parent c1e8f2b commit f999c85
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
3 changes: 2 additions & 1 deletion components/brave_wallet_ui/constants/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export interface PanelState {
switchChainRequest: BraveWallet.SwitchChainRequest
hardwareWalletCode?: HardwareWalletResponseCodeType
suggestedToken?: BraveWallet.BlockchainToken
selectedTransaction: BraveWallet.TransactionInfo | undefined
}

export interface PageState {
Expand Down Expand Up @@ -374,7 +375,7 @@ interface BaseTransactionParams {
coin: BraveWallet.CoinType
}

interface BaseEthTransactionParams extends BaseTransactionParams{
interface BaseEthTransactionParams extends BaseTransactionParams {
gas?: string

// Legacy gas pricing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ export const setHardwareWalletInteractionError = createAction<HardwareWalletResp
export const cancelConnectHardwareWallet = createAction<BraveWallet.TransactionInfo>('cancelConnectHardwareWallet')
export const addSuggestToken = createAction<BraveWallet.AddSuggestTokenRequest>('addSuggestToken')
export const addSuggestTokenProcessed = createAction<AddSuggestTokenProcessedPayload>('addSuggestTokenProcessed')
export const setSelectedTransaction = createAction<BraveWallet.TransactionInfo | undefined>('setSelectedTransaction')
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,13 @@ handler.on(PanelActions.approveHardwareTransaction.getType(), async (store: Stor
const hardwareAccount: HardwareInfo = found.hardware
await navigateToConnectHardwareWallet(store)
const apiProxy = getWalletPanelApiProxy()
await store.dispatch(PanelActions.navigateToMain())
const coin = getCoinFromTxDataUnion(txInfo.txDataUnion)
if (hardwareAccount.vendor === BraveWallet.LEDGER_HARDWARE_VENDOR) {
const { success, error, code } = await signLedgerTransaction(apiProxy, hardwareAccount.path, txInfo)
if (success) {
refreshTransactionHistory(coin, txInfo.fromAddress)
await store.dispatch(PanelActions.setSelectedTransaction(txInfo))
await store.dispatch(PanelActions.navigateTo('transactionDetails'))
return
}

Expand All @@ -245,7 +246,8 @@ handler.on(PanelActions.approveHardwareTransaction.getType(), async (store: Stor
const { success, error, deviceError } = await signTrezorTransaction(apiProxy, hardwareAccount.path, txInfo)
if (success) {
refreshTransactionHistory(coin, txInfo.fromAddress)
await store.dispatch(PanelActions.navigateToMain())
await store.dispatch(PanelActions.setSelectedTransaction(txInfo))
await store.dispatch(PanelActions.navigateTo('transactionDetails'))
return
}

Expand Down
9 changes: 4 additions & 5 deletions components/brave_wallet_ui/panel/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ function Container (props: Props) {
signMessageData,
switchChainRequest,
suggestedToken,
publicEncryptionKeyData
publicEncryptionKeyData,
selectedTransaction
} = props.panel

// TODO(petemill): If initial data or UI takes a noticeable amount of time to arrive
Expand All @@ -136,7 +137,6 @@ function Container (props: Props) {
// that loading indicator ASAP.
const [selectedAccounts, setSelectedAccounts] = React.useState<WalletAccountType[]>([])
const [filteredAppsList, setFilteredAppsList] = React.useState<AppsListType[]>(AppsList)
const [selectedTransaction, setSelectedTransaction] = React.useState<BraveWallet.TransactionInfo | undefined>()
const [showSelectAsset, setShowSelectAsset] = React.useState<boolean>(false)
const [buyAmount, setBuyAmount] = React.useState('')

Expand Down Expand Up @@ -478,9 +478,8 @@ function Container (props: Props) {
props.walletPanelActions.approveHardwareTransaction(selectedPendingTransaction)
} else {
props.walletActions.approveTransaction(selectedPendingTransaction)
onSelectTransaction(selectedPendingTransaction)
}

onSelectTransaction(selectedPendingTransaction)
}

const onOpenSettings = () => {
Expand Down Expand Up @@ -547,7 +546,7 @@ function Container (props: Props) {
}

const onSelectTransaction = (transaction: BraveWallet.TransactionInfo) => {
setSelectedTransaction(transaction)
props.walletPanelActions.setSelectedTransaction(transaction)
props.walletPanelActions.navigateTo('transactionDetails')
}

Expand Down
14 changes: 11 additions & 3 deletions components/brave_wallet_ui/panel/reducers/panel_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ const defaultState: PanelState = {
decimals: 18,
coin: BraveWallet.CoinType.ETH,
data: {
ethData: {
ethData: {
isEip1559: true
}
}
}
},
swapQuote: undefined,
Expand All @@ -62,7 +62,8 @@ const defaultState: PanelState = {
chainId: ''
},
hardwareWalletCode: undefined,
suggestedToken: undefined
suggestedToken: undefined,
selectedTransaction: undefined
}

const reducer = createReducer<PanelState>({}, defaultState)
Expand Down Expand Up @@ -135,4 +136,11 @@ reducer.on(PanelActions.addSuggestToken, (state: any, payload: BraveWallet.AddSu
}
})

reducer.on(PanelActions.setSelectedTransaction, (state: PanelState, payload: BraveWallet.TransactionInfo | undefined): PanelState => {
return {
...state,
selectedTransaction: payload
}
})

export default reducer

0 comments on commit f999c85

Please sign in to comment.