mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 09:18:09 +00:00
eslint ./src/actions 2
This commit is contained in:
parent
ef235e6ab8
commit
b36b9667e4
@ -9,10 +9,7 @@ import type {
|
|||||||
ThunkAction, AsyncAction, PromiseAction, Action, GetState, Dispatch, TrezorDevice,
|
ThunkAction, AsyncAction, PromiseAction, Action, GetState, Dispatch, TrezorDevice,
|
||||||
} from 'flowtype';
|
} from 'flowtype';
|
||||||
import type { Discovery, State } from 'reducers/DiscoveryReducer';
|
import type { Discovery, State } from 'reducers/DiscoveryReducer';
|
||||||
import * as AccountsActions from './AccountsActions';
|
|
||||||
import * as BlockchainActions from './BlockchainActions';
|
import * as BlockchainActions from './BlockchainActions';
|
||||||
import { setBalance as setTokenBalance } from './TokenActions';
|
|
||||||
|
|
||||||
|
|
||||||
export type DiscoveryStartAction = {
|
export type DiscoveryStartAction = {
|
||||||
type: typeof DISCOVERY.START,
|
type: typeof DISCOVERY.START,
|
||||||
@ -65,7 +62,7 @@ export const start = (device: TrezorDevice, network: string, ignoreCompleted?: b
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const discovery: State = getState().discovery;
|
const { discovery } = getState();
|
||||||
const discoveryProcess: ?Discovery = discovery.find(d => d.deviceState === device.state && d.network === network);
|
const discoveryProcess: ?Discovery = discovery.find(d => d.deviceState === device.state && d.network === network);
|
||||||
|
|
||||||
if (!selected.connected && (!discoveryProcess || !discoveryProcess.completed)) {
|
if (!selected.connected && (!discoveryProcess || !discoveryProcess.completed)) {
|
||||||
@ -88,7 +85,7 @@ export const start = (device: TrezorDevice, network: string, ignoreCompleted?: b
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!discoveryProcess) {
|
if (!discoveryProcess) {
|
||||||
dispatch(begin(device, network))
|
dispatch(begin(device, network));
|
||||||
} else if (discoveryProcess.completed && !ignoreCompleted) {
|
} else if (discoveryProcess.completed && !ignoreCompleted) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: DISCOVERY.COMPLETE,
|
type: DISCOVERY.COMPLETE,
|
||||||
@ -172,9 +169,8 @@ const begin = (device: TrezorDevice, network: string): AsyncAction => async (dis
|
|||||||
dispatch(start(device, network));
|
dispatch(start(device, network));
|
||||||
};
|
};
|
||||||
|
|
||||||
const discoverAccount = (device: TrezorDevice, discoveryProcess: Discovery): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
const discoverAccount = (device: TrezorDevice, discoveryProcess: Discovery): AsyncAction => async (dispatch: Dispatch): Promise<void> => {
|
||||||
const { completed } = discoveryProcess;
|
const { completed } = discoveryProcess;
|
||||||
discoveryProcess.completed = false;
|
|
||||||
|
|
||||||
const derivedKey = discoveryProcess.hdKey.derive(`m/${discoveryProcess.accountIndex}`);
|
const derivedKey = discoveryProcess.hdKey.derive(`m/${discoveryProcess.accountIndex}`);
|
||||||
const path = discoveryProcess.basePath.concat(discoveryProcess.accountIndex);
|
const path = discoveryProcess.basePath.concat(discoveryProcess.accountIndex);
|
||||||
@ -183,7 +179,6 @@ const discoverAccount = (device: TrezorDevice, discoveryProcess: Discovery): Asy
|
|||||||
const { network } = discoveryProcess;
|
const { network } = discoveryProcess;
|
||||||
|
|
||||||
// TODO: check if address was created before
|
// TODO: check if address was created before
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const account = await dispatch(BlockchainActions.discoverAccount(device, ethAddress, network));
|
const account = await dispatch(BlockchainActions.discoverAccount(device, ethAddress, network));
|
||||||
if (discoveryProcess.interrupted) return;
|
if (discoveryProcess.interrupted) return;
|
||||||
@ -191,7 +186,6 @@ const discoverAccount = (device: TrezorDevice, discoveryProcess: Discovery): Asy
|
|||||||
// const accountIsEmpty = account.transactions <= 0 && account.nonce <= 0 && account.balance === '0';
|
// const accountIsEmpty = account.transactions <= 0 && account.nonce <= 0 && account.balance === '0';
|
||||||
const accountIsEmpty = account.nonce <= 0 && account.balance === '0';
|
const accountIsEmpty = account.nonce <= 0 && account.balance === '0';
|
||||||
if (!accountIsEmpty || (accountIsEmpty && completed) || (accountIsEmpty && discoveryProcess.accountIndex === 0)) {
|
if (!accountIsEmpty || (accountIsEmpty && completed) || (accountIsEmpty && discoveryProcess.accountIndex === 0)) {
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: ACCOUNT.CREATE,
|
type: ACCOUNT.CREATE,
|
||||||
payload: {
|
payload: {
|
||||||
@ -205,22 +199,20 @@ const discoverAccount = (device: TrezorDevice, discoveryProcess: Discovery): Asy
|
|||||||
balance: account.balance,
|
balance: account.balance,
|
||||||
nonce: account.nonce,
|
nonce: account.nonce,
|
||||||
block: account.block,
|
block: account.block,
|
||||||
transactions: account.transactions
|
transactions: account.transactions,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (accountIsEmpty) {
|
if (accountIsEmpty) {
|
||||||
dispatch(finish(device, discoveryProcess));
|
dispatch(finish(device, discoveryProcess));
|
||||||
} else {
|
} else if (!completed) {
|
||||||
if (!completed) { dispatch( discoverAccount(device, discoveryProcess) ); }
|
dispatch(discoverAccount(device, discoveryProcess));
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: DISCOVERY.STOP,
|
type: DISCOVERY.STOP,
|
||||||
device
|
device,
|
||||||
});
|
});
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
@ -243,7 +235,7 @@ const discoverAccount = (device: TrezorDevice, discoveryProcess: Discovery): Asy
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const finish = (device: TrezorDevice, discoveryProcess: Discovery): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
const finish = (device: TrezorDevice, discoveryProcess: Discovery): AsyncAction => async (dispatch: Dispatch): Promise<void> => {
|
||||||
await TrezorConnect.getFeatures({
|
await TrezorConnect.getFeatures({
|
||||||
device: {
|
device: {
|
||||||
path: device.path,
|
path: device.path,
|
||||||
@ -263,13 +255,12 @@ const finish = (device: TrezorDevice, discoveryProcess: Discovery): AsyncAction
|
|||||||
device,
|
device,
|
||||||
network: discoveryProcess.network,
|
network: discoveryProcess.network,
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
}
|
export const reconnect = (network: string): PromiseAction<void> => async (dispatch: Dispatch): Promise<void> => {
|
||||||
|
|
||||||
export const reconnect = (network: string): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
|
||||||
await dispatch(BlockchainActions.subscribe(network));
|
await dispatch(BlockchainActions.subscribe(network));
|
||||||
dispatch(restore());
|
dispatch(restore());
|
||||||
}
|
};
|
||||||
|
|
||||||
export const restore = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
export const restore = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
||||||
const selected = getState().wallet.selectedDevice;
|
const selected = getState().wallet.selectedDevice;
|
||||||
|
@ -25,7 +25,7 @@ export const onPinSubmit = (value: string): Action => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const onPassphraseSubmit = (passphrase: string): AsyncAction => async (dispatch: Dispatch): Promise<void> => {
|
export const onPassphraseSubmit = (passphrase: string): AsyncAction => async (dispatch: Dispatch): Promise<void> => {
|
||||||
const resp = await TrezorConnect.uiResponse({
|
await TrezorConnect.uiResponse({
|
||||||
type: UI.RECEIVE_PASSPHRASE,
|
type: UI.RECEIVE_PASSPHRASE,
|
||||||
payload: {
|
payload: {
|
||||||
value: passphrase,
|
value: passphrase,
|
||||||
|
Loading…
Reference in New Issue
Block a user