mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-13 20:08:56 +00:00
sendform address label + forget_sigle device (remove accounts) bugfix
This commit is contained in:
parent
ec97e078b7
commit
e0f5cbf709
@ -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`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 => {
|
||||
|
@ -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<TrezorDevice> => {
|
||||
|
Loading…
Reference in New Issue
Block a user