mirror of
https://github.com/trezor/trezor-wallet
synced 2025-02-15 17:42:03 +00:00
fix flow
This commit is contained in:
parent
27f35b097d
commit
bb4a3268f7
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import * as ACCOUNT from 'actions/constants/account';
|
import * as ACCOUNT from 'actions/constants/account';
|
||||||
import * as NOTIFICATION from 'actions/constants/notification';
|
import * as NOTIFICATION from 'actions/constants/notification';
|
||||||
import type { Action, TrezorDevice, Network } from 'flowtype';
|
import type { Action, AsyncAction, TrezorDevice, Network, Dispatch, GetState } from 'flowtype';
|
||||||
import type { Account, State } from 'reducers/AccountsReducer';
|
import type { Account, State } from 'reducers/AccountsReducer';
|
||||||
import * as BlockchainActions from 'actions/ethereum/BlockchainActions';
|
import * as BlockchainActions from 'actions/ethereum/BlockchainActions';
|
||||||
import * as LocalStorageActions from 'actions/LocalStorageActions';
|
import * as LocalStorageActions from 'actions/LocalStorageActions';
|
||||||
@ -27,13 +27,17 @@ export const update = (account: Account): Action => ({
|
|||||||
export const importAddress = (
|
export const importAddress = (
|
||||||
address: string,
|
address: string,
|
||||||
network: Network,
|
network: Network,
|
||||||
device: TrezorDevice
|
device: ?TrezorDevice
|
||||||
): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||||
if (!device) return;
|
if (!device) return;
|
||||||
|
|
||||||
let payload;
|
let payload;
|
||||||
const index = getState().accounts.filter(
|
const index = getState().accounts.filter(
|
||||||
a => a.imported === true && a.network === network.shortcut && a.deviceState === device.state
|
a =>
|
||||||
|
a.imported === true &&
|
||||||
|
a.network === network.shortcut &&
|
||||||
|
device &&
|
||||||
|
a.deviceState === device.state
|
||||||
).length;
|
).length;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -58,9 +62,22 @@ export const importAddress = (
|
|||||||
transactions: account.transactions,
|
transactions: account.transactions,
|
||||||
empty,
|
empty,
|
||||||
|
|
||||||
networkType: network.type,
|
networkType: 'ethereum',
|
||||||
nonce: account.nonce,
|
nonce: account.nonce,
|
||||||
};
|
};
|
||||||
|
dispatch({
|
||||||
|
type: ACCOUNT.CREATE,
|
||||||
|
payload,
|
||||||
|
});
|
||||||
|
dispatch(LocalStorageActions.setImportedAccount(payload));
|
||||||
|
dispatch({
|
||||||
|
type: NOTIFICATION.ADD,
|
||||||
|
payload: {
|
||||||
|
type: 'success',
|
||||||
|
title: 'The account has been successfully imported',
|
||||||
|
cancelable: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
} else if (network.type === 'ripple') {
|
} else if (network.type === 'ripple') {
|
||||||
const response = await TrezorConnect.rippleGetAccountInfo({
|
const response = await TrezorConnect.rippleGetAccountInfo({
|
||||||
account: {
|
account: {
|
||||||
@ -93,24 +110,24 @@ export const importAddress = (
|
|||||||
transactions: account.transactions,
|
transactions: account.transactions,
|
||||||
empty,
|
empty,
|
||||||
|
|
||||||
networkType: network.type,
|
networkType: 'ripple',
|
||||||
sequence: account.sequence,
|
sequence: account.sequence,
|
||||||
reserve: toDecimalAmount(account.reserve, network.decimals),
|
reserve: toDecimalAmount(account.reserve, network.decimals),
|
||||||
};
|
};
|
||||||
|
dispatch({
|
||||||
|
type: ACCOUNT.CREATE,
|
||||||
|
payload,
|
||||||
|
});
|
||||||
|
dispatch(LocalStorageActions.setImportedAccount(payload));
|
||||||
|
dispatch({
|
||||||
|
type: NOTIFICATION.ADD,
|
||||||
|
payload: {
|
||||||
|
type: 'success',
|
||||||
|
title: 'The account has been successfully imported',
|
||||||
|
cancelable: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
dispatch({
|
|
||||||
type: ACCOUNT.CREATE,
|
|
||||||
payload,
|
|
||||||
});
|
|
||||||
dispatch(LocalStorageActions.setImportedAccount(payload));
|
|
||||||
dispatch({
|
|
||||||
type: NOTIFICATION.ADD,
|
|
||||||
payload: {
|
|
||||||
type: 'success',
|
|
||||||
title: 'The account has been successfully imported',
|
|
||||||
cancelable: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: NOTIFICATION.ADD,
|
type: NOTIFICATION.ADD,
|
||||||
|
@ -385,7 +385,7 @@ export const addAccount = (): ThunkAction => (dispatch: Dispatch, getState: GetS
|
|||||||
|
|
||||||
export const addImportedAccounts = (): ThunkAction => (dispatch: Dispatch): void => {
|
export const addImportedAccounts = (): ThunkAction => (dispatch: Dispatch): void => {
|
||||||
// get imported accounts from local storage
|
// get imported accounts from local storage
|
||||||
const importedAccounts = dispatch(LocalStorageActions.getImportedAccounts());
|
const importedAccounts = LocalStorageActions.getImportedAccounts();
|
||||||
if (importedAccounts) {
|
if (importedAccounts) {
|
||||||
// create each account
|
// create each account
|
||||||
importedAccounts.forEach(account => {
|
importedAccounts.forEach(account => {
|
||||||
|
@ -323,8 +323,8 @@ export const setLocalCurrency = (): ThunkAction => (
|
|||||||
storageUtils.set(TYPE, KEY_LOCAL_CURRENCY, JSON.stringify(localCurrency));
|
storageUtils.set(TYPE, KEY_LOCAL_CURRENCY, JSON.stringify(localCurrency));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const setImportedAccount = (account: Account): ThunkAction => (dispatch: Dispatch): void => {
|
export const setImportedAccount = (account: Account): ThunkAction => (): void => {
|
||||||
const prevImportedAccounts: ?Array<Account> = dispatch(getImportedAccounts());
|
const prevImportedAccounts: ?Array<Account> = getImportedAccounts();
|
||||||
let importedAccounts = [account];
|
let importedAccounts = [account];
|
||||||
if (prevImportedAccounts) {
|
if (prevImportedAccounts) {
|
||||||
importedAccounts = importedAccounts.concat(prevImportedAccounts);
|
importedAccounts = importedAccounts.concat(prevImportedAccounts);
|
||||||
@ -332,18 +332,18 @@ export const setImportedAccount = (account: Account): ThunkAction => (dispatch:
|
|||||||
storageUtils.set(TYPE, KEY_IMPORTED_ACCOUNTS, JSON.stringify(importedAccounts));
|
storageUtils.set(TYPE, KEY_IMPORTED_ACCOUNTS, JSON.stringify(importedAccounts));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getImportedAccounts = (): ThunkAction => (): ?Array<Account> => {
|
export const getImportedAccounts = (): ?Array<Account> => {
|
||||||
const importedAccounts: ?string = storageUtils.get(TYPE, KEY_IMPORTED_ACCOUNTS);
|
const importedAccounts: ?string = storageUtils.get(TYPE, KEY_IMPORTED_ACCOUNTS);
|
||||||
if (importedAccounts) {
|
if (importedAccounts) {
|
||||||
return JSON.parse(importedAccounts);
|
return JSON.parse(importedAccounts);
|
||||||
}
|
}
|
||||||
return importedAccounts;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const removeImportedAccounts = (device: TrezorDevice): ThunkAction => (
|
export const removeImportedAccounts = (device: TrezorDevice): ThunkAction => (
|
||||||
dispatch: Dispatch
|
dispatch: Dispatch
|
||||||
): void => {
|
): void => {
|
||||||
const importedAccounts: ?Array<Account> = dispatch(getImportedAccounts());
|
const importedAccounts: ?Array<Account> = getImportedAccounts();
|
||||||
if (!importedAccounts) return;
|
if (!importedAccounts) return;
|
||||||
|
|
||||||
const deviceId = device.features ? device.features.device_id : null;
|
const deviceId = device.features ? device.features.device_id : null;
|
||||||
|
@ -78,7 +78,7 @@ const createAccount = (state: State, account: Account): State => {
|
|||||||
|
|
||||||
// sort the accounts array so the imported accounts always come before discovered accounts
|
// sort the accounts array so the imported accounts always come before discovered accounts
|
||||||
if (account.imported) {
|
if (account.imported) {
|
||||||
newState.sort((a, b) => b.imported - a.imported || a.index - b.index);
|
newState.sort((a, b) => Number(b.imported) - Number(a.imported) || a.index - b.index);
|
||||||
}
|
}
|
||||||
return newState;
|
return newState;
|
||||||
};
|
};
|
||||||
|
@ -5,12 +5,12 @@ import { bindActionCreators } from 'redux';
|
|||||||
import * as AccountsAction from 'actions/AccountsActions';
|
import * as AccountsAction from 'actions/AccountsActions';
|
||||||
|
|
||||||
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
|
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
|
||||||
import type { Device, State, Dispatch } from 'flowtype';
|
import type { TrezorDevice, Config, State, Dispatch } from 'flowtype';
|
||||||
import ImportView from './index';
|
import ImportView from './index';
|
||||||
|
|
||||||
export type StateProps = {
|
export type StateProps = {
|
||||||
transport: $ElementType<$ElementType<State, 'connect'>, 'transport'>,
|
device: ?TrezorDevice,
|
||||||
device: ?Device,
|
config: Config,
|
||||||
children?: React.Node,
|
children?: React.Node,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ const Import = (props: Props) => {
|
|||||||
<StyledSelect
|
<StyledSelect
|
||||||
value={selectedNetwork}
|
value={selectedNetwork}
|
||||||
options={networks
|
options={networks
|
||||||
.sort((a, b) => a.shortcut > b.shortcut)
|
.sort((a, b) => a.shortcut.localeCompare(b.shortcut))
|
||||||
.map(net => ({
|
.map(net => ({
|
||||||
label: net.shortcut,
|
label: net.shortcut,
|
||||||
value: net,
|
value: net,
|
||||||
|
Loading…
Reference in New Issue
Block a user