1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-28 03:08:30 +00:00

DiscoveryReducer: hdkey only in ehereum network type

This commit is contained in:
Szymon Lesisz 2018-11-26 10:17:20 +01:00
parent 7956b4a5fb
commit c9eb911756

View File

@ -34,34 +34,41 @@ export type Discovery = {
export type State = Array<Discovery>; export type State = Array<Discovery>;
const initialState: State = []; const initialState: State = [];
const defaultDiscovery: Discovery = {
network: '',
deviceState: '',
basePath: [],
accountIndex: 0,
interrupted: false,
completed: false,
waitingForDevice: false,
waitingForBlockchain: false,
publicKey: '',
chainCode: '',
hdKey: null,
};
const findIndex = (state: State, network: string, deviceState: string): number => state.findIndex(d => d.network === network && d.deviceState === deviceState); const findIndex = (state: State, network: string, deviceState: string): number => state.findIndex(d => d.network === network && d.deviceState === deviceState);
const start = (state: State, action: DiscoveryStartAction): State => { const start = (state: State, action: DiscoveryStartAction): State => {
const deviceState: string = action.device.state || '0'; const deviceState: string = action.device.state || '0';
const instance: Discovery = {
...defaultDiscovery,
network: action.network.shortcut,
deviceState,
};
let hdKey: ?HDKey; if (action.networkType === 'ethereum') {
if (action.network.type === 'ethereum') { const hdKey = new HDKey();
hdKey = new HDKey();
hdKey.publicKey = Buffer.from(action.publicKey, 'hex'); hdKey.publicKey = Buffer.from(action.publicKey, 'hex');
hdKey.chainCode = Buffer.from(action.chainCode, 'hex'); hdKey.chainCode = Buffer.from(action.chainCode, 'hex');
instance.hdKey = hdKey;
instance.publicKey = action.publicKey;
instance.chainCode = action.chainCode;
} }
const instance: Discovery = {
network: action.network.shortcut,
basePath: action.basePath,
deviceState,
accountIndex: 0,
interrupted: false,
completed: false,
waitingForDevice: false,
waitingForBlockchain: false,
publicKey: action.publicKey,
chainCode: action.chainCode,
hdKey,
};
const newState: State = [...state]; const newState: State = [...state];
const index: number = findIndex(state, action.network.shortcut, deviceState); const index: number = findIndex(state, action.network.shortcut, deviceState);
if (index >= 0) { if (index >= 0) {
@ -112,18 +119,10 @@ const stop = (state: State, device: TrezorDevice): State => {
const waitingForDevice = (state: State, action: DiscoveryWaitingAction): State => { const waitingForDevice = (state: State, action: DiscoveryWaitingAction): State => {
const deviceState: string = action.device.state || '0'; const deviceState: string = action.device.state || '0';
const instance: Discovery = { const instance: Discovery = {
...defaultDiscovery,
network: action.network, network: action.network,
deviceState, deviceState,
basePath: [],
accountIndex: 0,
interrupted: false,
completed: false,
waitingForDevice: true, waitingForDevice: true,
waitingForBlockchain: false,
publicKey: '',
chainCode: '',
hdKey: null,
}; };
const index: number = findIndex(state, action.network, deviceState); const index: number = findIndex(state, action.network, deviceState);
@ -140,18 +139,10 @@ const waitingForDevice = (state: State, action: DiscoveryWaitingAction): State =
const waitingForBlockchain = (state: State, action: DiscoveryWaitingAction): State => { const waitingForBlockchain = (state: State, action: DiscoveryWaitingAction): State => {
const deviceState: string = action.device.state || '0'; const deviceState: string = action.device.state || '0';
const instance: Discovery = { const instance: Discovery = {
...defaultDiscovery,
network: action.network, network: action.network,
deviceState, deviceState,
basePath: [],
accountIndex: 0,
interrupted: false,
completed: false,
waitingForDevice: false,
waitingForBlockchain: true, waitingForBlockchain: true,
publicKey: '',
chainCode: '',
hdKey: null,
}; };
const index: number = findIndex(state, action.network, deviceState); const index: number = findIndex(state, action.network, deviceState);