mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-28 03:08:30 +00:00
eslint fixes for DiscoveryReducer
This commit is contained in:
parent
bcb404e321
commit
130b852977
@ -12,7 +12,6 @@ import type { Action, TrezorDevice } from 'flowtype';
|
|||||||
import type {
|
import type {
|
||||||
DiscoveryStartAction,
|
DiscoveryStartAction,
|
||||||
DiscoveryWaitingAction,
|
DiscoveryWaitingAction,
|
||||||
DiscoveryStopAction,
|
|
||||||
DiscoveryCompleteAction,
|
DiscoveryCompleteAction,
|
||||||
} from 'actions/DiscoveryActions';
|
} from 'actions/DiscoveryActions';
|
||||||
|
|
||||||
@ -40,8 +39,8 @@ const findIndex = (state: State, network: string, deviceState: string): number =
|
|||||||
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 hdKey: HDKey = new HDKey();
|
const hdKey: HDKey = new HDKey();
|
||||||
hdKey.publicKey = new Buffer(action.publicKey, 'hex');
|
hdKey.publicKey = Buffer.from(action.publicKey, 'hex');
|
||||||
hdKey.chainCode = new Buffer(action.chainCode, 'hex');
|
hdKey.chainCode = Buffer.from(action.chainCode, 'hex');
|
||||||
const instance: Discovery = {
|
const instance: Discovery = {
|
||||||
network: action.network,
|
network: action.network,
|
||||||
publicKey: action.publicKey,
|
publicKey: action.publicKey,
|
||||||
@ -90,16 +89,17 @@ const clear = (state: State, devices: Array<TrezorDevice>): State => {
|
|||||||
return newState;
|
return newState;
|
||||||
};
|
};
|
||||||
|
|
||||||
const stop = (state: State, action: DiscoveryStopAction): State => {
|
const stop = (state: State, device: TrezorDevice): State => {
|
||||||
const newState: State = [...state];
|
const affectedProcesses = state.filter(d => d.deviceState === device.state && !d.completed);
|
||||||
return newState.map((d: Discovery) => {
|
const otherProcesses = state.filter(d => affectedProcesses.indexOf(d) === -1);
|
||||||
if (d.deviceState === action.device.state && !d.completed) {
|
const changedProcesses = affectedProcesses.map(d => ({
|
||||||
d.interrupted = true;
|
...d,
|
||||||
d.waitingForDevice = false;
|
interrupted: true,
|
||||||
d.waitingForBlockchain = false;
|
waitingForDevice: false,
|
||||||
}
|
waitingForBlockchain: false,
|
||||||
return d;
|
}));
|
||||||
});
|
|
||||||
|
return otherProcesses.concat(changedProcesses);
|
||||||
};
|
};
|
||||||
|
|
||||||
const waitingForDevice = (state: State, action: DiscoveryWaitingAction): State => {
|
const waitingForDevice = (state: State, action: DiscoveryWaitingAction): State => {
|
||||||
@ -163,7 +163,7 @@ export default function discovery(state: State = initialState, action: Action):
|
|||||||
case ACCOUNT.CREATE:
|
case ACCOUNT.CREATE:
|
||||||
return accountCreate(state, action.payload);
|
return accountCreate(state, action.payload);
|
||||||
case DISCOVERY.STOP:
|
case DISCOVERY.STOP:
|
||||||
return stop(state, action);
|
return stop(state, action.device);
|
||||||
case DISCOVERY.COMPLETE:
|
case DISCOVERY.COMPLETE:
|
||||||
return complete(state, action);
|
return complete(state, action);
|
||||||
case DISCOVERY.WAITING_FOR_DEVICE:
|
case DISCOVERY.WAITING_FOR_DEVICE:
|
||||||
@ -173,8 +173,8 @@ export default function discovery(state: State = initialState, action: Action):
|
|||||||
case DISCOVERY.FROM_STORAGE:
|
case DISCOVERY.FROM_STORAGE:
|
||||||
return action.payload.map((d) => {
|
return action.payload.map((d) => {
|
||||||
const hdKey: HDKey = new HDKey();
|
const hdKey: HDKey = new HDKey();
|
||||||
hdKey.publicKey = new Buffer(d.publicKey, 'hex');
|
hdKey.publicKey = Buffer.from(d.publicKey, 'hex');
|
||||||
hdKey.chainCode = new Buffer(d.chainCode, 'hex');
|
hdKey.chainCode = Buffer.from(d.chainCode, 'hex');
|
||||||
return {
|
return {
|
||||||
...d,
|
...d,
|
||||||
hdKey,
|
hdKey,
|
||||||
|
Loading…
Reference in New Issue
Block a user