From e0f5cbf7098ced808393d1efa6cc497a1881063a Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Fri, 11 May 2018 16:45:10 +0200 Subject: [PATCH] sendform address label + forget_sigle device (remove accounts) bugfix --- src/js/actions/SendFormActions.js | 11 +++++++---- src/js/reducers/AccountsReducer.js | 9 +++++---- src/js/reducers/TrezorConnectReducer.js | 9 +++++++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/js/actions/SendFormActions.js b/src/js/actions/SendFormActions.js index 987d44b7..5fecb4c1 100644 --- a/src/js/actions/SendFormActions.js +++ b/src/js/actions/SendFormActions.js @@ -17,7 +17,7 @@ import BigNumber from 'bignumber.js'; import { initialState } from '../reducers/SendFormReducer'; import { findAccount } from '../reducers/AccountsReducer'; import { findToken } from '../reducers/TokensReducer'; -import { findSelectedDevice } from '../reducers/TrezorConnectReducer'; +import { findSelectedDevice, findDevice } from '../reducers/TrezorConnectReducer'; import type { Dispatch, @@ -269,10 +269,13 @@ export const validation = (): ThunkAction => { // corner-case: when same derivation path is used on different networks const currentNetworkAccount = savedAccounts.find(a => a.network === accountState.network); if (currentNetworkAccount) { - infos.address = `TREZOR Address #${ (currentNetworkAccount.index + 1) }`; + const device: ?TrezorDevice = findDevice(getState().connect, currentNetworkAccount.deviceID, currentNetworkAccount.deviceState); + if (!device) return; + infos.address = `${ device.instanceLabel } Account #${ (currentNetworkAccount.index + 1) }`; } else { - // TODO: load coins from config - warnings.address = `Looks like it's TREZOR address in Account #${ (savedAccounts[0].index + 1) } of ${ savedAccounts[0].network.toUpperCase() } network`; + const device: ?TrezorDevice = findDevice(getState().connect, savedAccounts[0].deviceID, savedAccounts[0].deviceState); + if (!device) return; + warnings.address = `Looks like it's ${ device.instanceLabel } Account #${ (savedAccounts[0].index + 1) } address of ${ savedAccounts[0].network.toUpperCase() } network`; } } } diff --git a/src/js/reducers/AccountsReducer.js b/src/js/reducers/AccountsReducer.js index 9238fc9f..5b60c6ec 100644 --- a/src/js/reducers/AccountsReducer.js +++ b/src/js/reducers/AccountsReducer.js @@ -35,12 +35,12 @@ const createAccount = (state: State, action: AccountCreateAction): State => { // TODO check with device_id // check if account was created before - const exist: ?Account = state.find((account: Account) => account.address === action.address && account.network === action.network && action.device.features && account.deviceID === action.device.features.device_id); + const exist: ?Account = state.find(account => account.address === action.address && account.network === action.network && action.device.features && account.deviceID === action.device.features.device_id); if (exist) { return state; } - const address: Account = { + const account: Account = { loaded: false, network: action.network, deviceID: action.device.features ? action.device.features.device_id : '0', @@ -53,12 +53,13 @@ const createAccount = (state: State, action: AccountCreateAction): State => { } const newState: State = [ ...state ]; - newState.push(address); + newState.push(account); return newState; } const removeAccounts = (state: State, device: TrezorDevice): State => { - return state.filter(account => device.features && account.deviceID !== device.features.device_id); + //return state.filter(account => device.features && account.deviceID !== device.features.device_id); + return state.filter(account => account.deviceState !== device.state); } // const forgetAccounts = (state: State, action: any): State => { diff --git a/src/js/reducers/TrezorConnectReducer.js b/src/js/reducers/TrezorConnectReducer.js index 23d1878c..0be85da7 100644 --- a/src/js/reducers/TrezorConnectReducer.js +++ b/src/js/reducers/TrezorConnectReducer.js @@ -55,6 +55,15 @@ export const findSelectedDevice = (state: State): ?TrezorDevice => { }); } +export const findDevice = (state: State, deviceId: string, deviceState: string): ?TrezorDevice => { + return state.devices.find(d => { + if (d.features && d.features.device_id === deviceId && d.state === deviceState){ + return true; + } + return false; + }); +} + export const isSavedDevice = (state: State, device: any): ?Array => {