mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 09:18:09 +00:00
fixed flowtypes
This commit is contained in:
parent
15505ff263
commit
eb0a40c417
@ -6,7 +6,7 @@ import * as ACCOUNT from './constants/account';
|
||||
import { initialState } from '../reducers/AbstractAccountReducer';
|
||||
import { findSelectedDevice } from '../reducers/TrezorConnectReducer';
|
||||
|
||||
import type { AsyncAction, Action, GetState, Dispatch, TrezorDevice } from '../flowtype';
|
||||
import type { AsyncAction, ThunkAction, Action, GetState, Dispatch, TrezorDevice } from '../flowtype';
|
||||
import type { State } from '../reducers/AbstractAccountReducer';
|
||||
import type { Coin } from '../reducers/LocalStorageReducer';
|
||||
|
||||
@ -17,7 +17,7 @@ export type AbstractAccountAction = {
|
||||
type: typeof ACCOUNT.DISPOSE,
|
||||
};
|
||||
|
||||
export const init = (): AsyncAction => {
|
||||
export const init = (): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
|
||||
const { location } = getState().router;
|
||||
@ -48,7 +48,7 @@ export const init = (): AsyncAction => {
|
||||
}
|
||||
}
|
||||
|
||||
export const update = (): AsyncAction => {
|
||||
export const update = (): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
const {
|
||||
abstractAccount,
|
||||
|
@ -14,7 +14,7 @@ import EthereumjsUtil from 'ethereumjs-util';
|
||||
import { getNonceAsync, getBalanceAsync, getTokenBalanceAsync } from './Web3Actions';
|
||||
import { setBalance as setTokenBalance } from './TokenActions';
|
||||
|
||||
import type { AsyncAction, Action, GetState, Dispatch, TrezorDevice } from '../flowtype';
|
||||
import type { ThunkAction, AsyncAction, Action, GetState, Dispatch, TrezorDevice } from '../flowtype';
|
||||
import type { Discovery, State } from '../reducers/DiscoveryReducer';
|
||||
|
||||
export type DiscoveryAction = {
|
||||
@ -51,7 +51,7 @@ export type DiscoveryCompleteAction = {
|
||||
network: string
|
||||
}
|
||||
|
||||
export const start = (device: TrezorDevice, network: string, ignoreCompleted?: boolean): AsyncAction => {
|
||||
export const start = (device: TrezorDevice, network: string, ignoreCompleted?: boolean): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
|
||||
const selected = findSelectedDevice(getState().connect);
|
||||
@ -321,7 +321,7 @@ const discoverAddress = (device: TrezorDevice, discoveryProcess: Discovery): Asy
|
||||
}
|
||||
}
|
||||
|
||||
export const restore = (): AsyncAction => {
|
||||
export const restore = (): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
const selected = findSelectedDevice(getState().connect);
|
||||
|
||||
@ -338,7 +338,7 @@ export const restore = (): AsyncAction => {
|
||||
// there is no discovery process but it should be
|
||||
// this is possible race condition when "network" was changed in url but device was not authenticated yet
|
||||
// try to start discovery after CONNECT.AUTH_DEVICE action
|
||||
export const check = (): AsyncAction => {
|
||||
export const check = (): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
const selected = findSelectedDevice(getState().connect);
|
||||
if (!selected) return;
|
||||
|
@ -9,7 +9,7 @@ import * as STORAGE from './constants/localStorage';
|
||||
import * as PENDING from '../actions/constants/pendingTx';
|
||||
import { JSONRequest, httpRequest } from '../utils/networkUtils';
|
||||
|
||||
import type { AsyncAction, GetState, Dispatch } from '../flowtype';
|
||||
import type { ThunkAction, AsyncAction, GetState, Dispatch } from '../flowtype';
|
||||
import type { Config, Coin, TokensCollection } from '../reducers/LocalStorageReducer';
|
||||
|
||||
export type StorageAction = {
|
||||
@ -25,7 +25,7 @@ export type StorageAction = {
|
||||
error: string,
|
||||
};
|
||||
|
||||
export const loadData = (): AsyncAction => {
|
||||
export const loadData = (): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
|
||||
// check if local storage is available
|
||||
@ -151,8 +151,8 @@ export function loadTokensFromJSON(): AsyncAction {
|
||||
}
|
||||
|
||||
|
||||
export const save = (key: string, value: string): AsyncAction => {
|
||||
return (dispatch: Dispatch, getState: GetState) => {
|
||||
export const save = (key: string, value: string): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
if (typeof window.localStorage !== 'undefined') {
|
||||
try {
|
||||
window.localStorage.setItem(key, value);
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
import * as LOG from './constants/log';
|
||||
|
||||
import type { AsyncAction, GetState, Dispatch } from '../flowtype';
|
||||
import type { ThunkAction, GetState, Dispatch } from '../flowtype';
|
||||
|
||||
export type LogAction = {
|
||||
type: typeof LOG.OPEN,
|
||||
@ -11,15 +11,19 @@ export type LogAction = {
|
||||
type: typeof LOG.CLOSE,
|
||||
};
|
||||
|
||||
export const toggle = (): AsyncAction => {
|
||||
export const toggle = (): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
|
||||
if (!getState().log.opened) {
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: getState().log.opened ? LOG.CLOSE : LOG.OPEN
|
||||
type: LOG.CLOSE
|
||||
});
|
||||
} else {
|
||||
dispatch({
|
||||
type: LOG.OPEN
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,13 +5,14 @@ import TrezorConnect, { UI, UI_EVENT } from 'trezor-connect';
|
||||
import * as MODAL from './constants/modal';
|
||||
import * as CONNECT from './constants/TrezorConnect';
|
||||
|
||||
import type { AsyncAction, Action, GetState, Dispatch, TrezorDevice } from '../flowtype';
|
||||
import type { ThunkAction, AsyncAction, Action, GetState, Dispatch, TrezorDevice } from '../flowtype';
|
||||
import type { State } from '../reducers/ModalReducer';
|
||||
|
||||
export type ModalAction = {
|
||||
type: typeof MODAL.CLOSE
|
||||
} | {
|
||||
type: typeof MODAL.REMEMBER,
|
||||
device: any
|
||||
device: TrezorDevice
|
||||
};
|
||||
|
||||
export const onPinSubmit = (value: string): Action => {
|
||||
@ -71,7 +72,7 @@ export const onCancel = (): Action => {
|
||||
}
|
||||
}
|
||||
|
||||
export const onDuplicateDevice = (device: TrezorDevice): AsyncAction => {
|
||||
export const onDuplicateDevice = (device: TrezorDevice): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
|
||||
dispatch( onCancel() );
|
||||
@ -83,6 +84,29 @@ export const onDuplicateDevice = (device: TrezorDevice): AsyncAction => {
|
||||
}
|
||||
}
|
||||
|
||||
export const onRememberRequest = (prevState: State): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
const state: State = getState().modal;
|
||||
// handle case where forget modal is already opened
|
||||
// TODO: 2 modals at once (two devices disconnected in the same time)
|
||||
if (prevState.opened && prevState.windowType === CONNECT.REMEMBER_REQUEST) {
|
||||
// forget current (new)
|
||||
if (state.opened) {
|
||||
dispatch({
|
||||
type: CONNECT.FORGET,
|
||||
device: state.device
|
||||
});
|
||||
}
|
||||
|
||||
// forget previous (old)
|
||||
dispatch({
|
||||
type: CONNECT.FORGET,
|
||||
device: prevState.device
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
onPinSubmit,
|
||||
onPassphraseSubmit,
|
||||
|
@ -39,12 +39,14 @@ export const clear = (currentParams: RouterLocationState, requestedParams: Route
|
||||
if (currentParams.device !== requestedParams.device || currentParams.deviceInstance !== requestedParams.deviceInstance) {
|
||||
const entries = getState().notifications.filter(entry => typeof entry.devicePath === 'string');
|
||||
entries.forEach(entry => {
|
||||
if (typeof entry.devicePath === 'string') {
|
||||
dispatch({
|
||||
type: NOTIFICATION.CLOSE,
|
||||
payload: {
|
||||
devicePath: entry.devicePath
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import { initialState } from '../reducers/ReceiveReducer';
|
||||
import type { State } from '../reducers/ReceiveReducer';
|
||||
import { findSelectedDevice } from '../reducers/TrezorConnectReducer';
|
||||
|
||||
import type { TrezorDevice, AsyncAction, Action, GetState, Dispatch } from '../flowtype';
|
||||
import type { TrezorDevice, ThunkAction, AsyncAction, Action, GetState, Dispatch } from '../flowtype';
|
||||
|
||||
export type ReceiveAction = {
|
||||
type: typeof RECEIVE.INIT,
|
||||
@ -25,7 +25,7 @@ export type ReceiveAction = {
|
||||
type: typeof RECEIVE.SHOW_UNVERIFIED_ADDRESS
|
||||
}
|
||||
|
||||
export const init = (): AsyncAction => {
|
||||
export const init = (): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
|
||||
const state: State = {
|
||||
@ -40,7 +40,7 @@ export const init = (): AsyncAction => {
|
||||
}
|
||||
|
||||
|
||||
export const update = (): AsyncAction => {
|
||||
export const update = (): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
const {
|
||||
abstractAccount,
|
||||
|
@ -23,6 +23,7 @@ import type {
|
||||
Dispatch,
|
||||
GetState,
|
||||
Action,
|
||||
ThunkAction,
|
||||
AsyncAction,
|
||||
RouterLocationState,
|
||||
TrezorDevice
|
||||
@ -160,7 +161,7 @@ export const getFeeLevels = (symbol: string, gasPrice: BigNumber | string, gasLi
|
||||
|
||||
|
||||
// initialize component
|
||||
export const init = (): AsyncAction => {
|
||||
export const init = (): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
|
||||
const accountState: AccountState = getState().abstractAccount;
|
||||
@ -210,7 +211,7 @@ export const init = (): AsyncAction => {
|
||||
}
|
||||
}
|
||||
|
||||
export const update = (): AsyncAction => {
|
||||
export const update = (): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
const {
|
||||
abstractAccount,
|
||||
@ -237,7 +238,7 @@ export const toggleAdvanced = (address: string): Action => {
|
||||
}
|
||||
}
|
||||
|
||||
export const validation = (): AsyncAction => {
|
||||
export const validation = (): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
|
||||
const accountState: AccountState = getState().abstractAccount;
|
||||
@ -368,7 +369,7 @@ export const validation = (): AsyncAction => {
|
||||
}
|
||||
|
||||
|
||||
export const onAddressChange = (address: string): AsyncAction => {
|
||||
export const onAddressChange = (address: string): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
|
||||
const currentState: State = getState().sendForm;
|
||||
@ -390,7 +391,7 @@ export const onAddressChange = (address: string): AsyncAction => {
|
||||
}
|
||||
}
|
||||
|
||||
export const onAmountChange = (amount: string): AsyncAction => {
|
||||
export const onAmountChange = (amount: string): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
|
||||
const accountState: AccountState = getState().abstractAccount;
|
||||
@ -417,7 +418,7 @@ export const onAmountChange = (amount: string): AsyncAction => {
|
||||
}
|
||||
}
|
||||
|
||||
export const onCurrencyChange = (currency: any): AsyncAction => {
|
||||
export const onCurrencyChange = (currency: any): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
const accountState: AccountState = getState().abstractAccount;
|
||||
const currentState: State = getState().sendForm;
|
||||
@ -478,7 +479,7 @@ export const onCurrencyChange = (currency: any): AsyncAction => {
|
||||
|
||||
|
||||
|
||||
export const onSetMax = (): AsyncAction => {
|
||||
export const onSetMax = (): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
const accountState: AccountState = getState().abstractAccount;
|
||||
const currentState: State = getState().sendForm;
|
||||
@ -523,7 +524,7 @@ export const onSetMax = (): AsyncAction => {
|
||||
}
|
||||
}
|
||||
|
||||
export const onFeeLevelChange = (feeLevel: FeeLevel): AsyncAction => {
|
||||
export const onFeeLevelChange = (feeLevel: FeeLevel): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
const accountState: AccountState = getState().abstractAccount;
|
||||
const currentState: State = getState().sendForm;
|
||||
@ -576,7 +577,7 @@ export const onFeeLevelChange = (feeLevel: FeeLevel): AsyncAction => {
|
||||
}
|
||||
}
|
||||
|
||||
export const updateFeeLevels = (): AsyncAction => {
|
||||
export const updateFeeLevels = (): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
const accountState: AccountState = getState().abstractAccount;
|
||||
const currentState: State = getState().sendForm;
|
||||
@ -617,7 +618,7 @@ export const updateFeeLevels = (): AsyncAction => {
|
||||
}
|
||||
}
|
||||
|
||||
export const onGasPriceChange = (gasPrice: string): AsyncAction => {
|
||||
export const onGasPriceChange = (gasPrice: string): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
const accountState: AccountState = getState().abstractAccount;
|
||||
const currentState: State = getState().sendForm;
|
||||
@ -665,7 +666,7 @@ export const onGasPriceChange = (gasPrice: string): AsyncAction => {
|
||||
}
|
||||
}
|
||||
|
||||
export const onGasLimitChange = (gasLimit: string): AsyncAction => {
|
||||
export const onGasLimitChange = (gasLimit: string): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
const accountState: AccountState = getState().abstractAccount;
|
||||
const currentState: State = getState().sendForm;
|
||||
@ -713,7 +714,7 @@ export const onGasLimitChange = (gasLimit: string): AsyncAction => {
|
||||
}
|
||||
}
|
||||
|
||||
export const onDataChange = (data: string): AsyncAction => {
|
||||
export const onDataChange = (data: string): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
const currentState: State = getState().sendForm;
|
||||
const touched = { ...currentState.touched };
|
||||
|
@ -10,7 +10,7 @@ import { getTokenInfoAsync, getTokenBalanceAsync } from './Web3Actions';
|
||||
import { initialState } from '../reducers/SummaryReducer';
|
||||
import { findSelectedDevice } from '../reducers/TrezorConnectReducer';
|
||||
|
||||
import type { AsyncAction, Action, GetState, Dispatch } from '../flowtype';
|
||||
import type { ThunkAction, AsyncAction, Action, GetState, Dispatch } from '../flowtype';
|
||||
import type { State } from '../reducers/SummaryReducer';
|
||||
import type { Token } from '../reducers/TokensReducer';
|
||||
|
||||
@ -23,7 +23,7 @@ export type SummaryAction = {
|
||||
type: typeof SUMMARY.DETAILS_TOGGLE
|
||||
}
|
||||
|
||||
export const init = (): AsyncAction => {
|
||||
export const init = (): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
|
||||
const state: State = {
|
||||
@ -38,7 +38,7 @@ export const init = (): AsyncAction => {
|
||||
}
|
||||
|
||||
|
||||
export const update = (): AsyncAction => {
|
||||
export const update = (): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
const {
|
||||
abstractAccount,
|
||||
|
@ -4,7 +4,7 @@
|
||||
import * as TOKEN from './constants/token';
|
||||
import { getTokenInfoAsync, getTokenBalanceAsync } from './Web3Actions';
|
||||
|
||||
import type { GetState, AsyncAction, Action } from '../flowtype';
|
||||
import type { GetState, AsyncAction, Action, Dispatch } from '../flowtype';
|
||||
import type { State, Token } from '../reducers/TokensReducer';
|
||||
import type { Account } from '../reducers/AccountsReducer';
|
||||
import type { NetworkToken } from '../reducers/LocalStorageReducer';
|
||||
|
@ -30,6 +30,7 @@ import type {
|
||||
Dispatch,
|
||||
GetState,
|
||||
Action,
|
||||
ThunkAction,
|
||||
AsyncAction,
|
||||
TrezorDevice,
|
||||
RouterLocationState
|
||||
@ -87,6 +88,9 @@ export type TrezorConnectAction = {
|
||||
} | {
|
||||
type: typeof CONNECT.STOP_ACQUIRING,
|
||||
device: TrezorDevice
|
||||
} | {
|
||||
type: typeof CONNECT.ACQUIRED,
|
||||
device: TrezorDevice
|
||||
};
|
||||
|
||||
|
||||
@ -141,7 +145,7 @@ export const init = (): AsyncAction => {
|
||||
|
||||
// called after backend was initialized
|
||||
// set listeners for connect/disconnect
|
||||
export const postInit = (): AsyncAction => {
|
||||
export const postInit = (): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
|
||||
const handleDeviceConnect = (device: Device) => {
|
||||
@ -162,8 +166,8 @@ export const postInit = (): AsyncAction => {
|
||||
if (initialPathname) {
|
||||
dispatch({
|
||||
type: WALLET.SET_INITIAL_URL,
|
||||
pathname: null,
|
||||
params: null
|
||||
// pathname: null,
|
||||
// params: null
|
||||
});
|
||||
}
|
||||
|
||||
@ -199,7 +203,7 @@ const sortDevices = (devices: Array<TrezorDevice>): Array<TrezorDevice> => {
|
||||
});
|
||||
}
|
||||
|
||||
export const initConnectedDevice = (device: any): AsyncAction => {
|
||||
export const initConnectedDevice = (device: any): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
|
||||
const selected = findSelectedDevice(getState().connect);
|
||||
@ -218,12 +222,12 @@ export const initConnectedDevice = (device: any): AsyncAction => {
|
||||
// after device_connect event
|
||||
// or after acquiring device
|
||||
// device type could be local TrezorDevice or Device (from trezor-connect device_connect event)
|
||||
export const onSelectDevice = (device: TrezorDevice | Device): AsyncAction => {
|
||||
export const onSelectDevice = (device: TrezorDevice | Device): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
// || device.isUsedElsewhere
|
||||
|
||||
// switch to initial url and reset this value
|
||||
|
||||
console.warn("ON SELECT DEV d", device);
|
||||
|
||||
if (!device.features) {
|
||||
dispatch( push(`/device/${ device.path }/acquire`) );
|
||||
@ -354,7 +358,7 @@ export const deviceDisconnect = (device: Device): AsyncAction => {
|
||||
if (instances.length > 0) {
|
||||
dispatch({
|
||||
type: CONNECT.REMEMBER_REQUEST,
|
||||
device,
|
||||
device: instances[0],
|
||||
instances,
|
||||
});
|
||||
}
|
||||
@ -367,7 +371,7 @@ export const deviceDisconnect = (device: Device): AsyncAction => {
|
||||
}
|
||||
}
|
||||
|
||||
export const coinChanged = (network: ?string): AsyncAction => {
|
||||
export const coinChanged = (network: ?string): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
const selected: ?TrezorDevice = findSelectedDevice(getState().connect);
|
||||
if (!selected) return;
|
||||
@ -415,7 +419,10 @@ export function acquire(): AsyncAction {
|
||||
}
|
||||
});
|
||||
|
||||
const selected2 = findSelectedDevice(getState().connect);
|
||||
const selected2: ?TrezorDevice = findSelectedDevice(getState().connect);
|
||||
if (!selected2) return;
|
||||
const s: TrezorDevice = selected2;
|
||||
|
||||
dispatch({
|
||||
type: CONNECT.STOP_ACQUIRING,
|
||||
device: selected2
|
||||
@ -423,12 +430,11 @@ export function acquire(): AsyncAction {
|
||||
|
||||
if (response && response.success) {
|
||||
dispatch({
|
||||
type: DEVICE.ACQUIRED,
|
||||
device: null
|
||||
})
|
||||
type: CONNECT.ACQUIRED,
|
||||
device: selected2
|
||||
});
|
||||
} else {
|
||||
// TODO: handle invalid pin?
|
||||
console.log("-error ack", response)
|
||||
|
||||
dispatch({
|
||||
type: NOTIFICATION.ADD,
|
||||
@ -451,7 +457,7 @@ export function acquire(): AsyncAction {
|
||||
}
|
||||
}
|
||||
|
||||
export const forgetDevice = (device: any): AsyncAction => {
|
||||
export const forgetDevice = (device: TrezorDevice): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
// find accounts associated with this device
|
||||
// const accounts: Array<any> = getState().accounts.find(a => a.deviceState === device.state);
|
||||
@ -463,10 +469,12 @@ export const forgetDevice = (device: any): AsyncAction => {
|
||||
}
|
||||
}
|
||||
|
||||
export const gotoDeviceSettings = (device: any): AsyncAction => {
|
||||
export const gotoDeviceSettings = (device: TrezorDevice): ThunkAction => {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
if (device.features) {
|
||||
dispatch( push(`/device/${ device.features.device_id }/settings`) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// called from Aside - device menu (forget single instance)
|
||||
@ -495,7 +503,7 @@ export const onDuplicateDevice = (): AsyncAction => {
|
||||
}
|
||||
|
||||
|
||||
export function addAddress(): AsyncAction {
|
||||
export function addAddress(): ThunkAction {
|
||||
return (dispatch: Dispatch, getState: GetState): void => {
|
||||
const selected = findSelectedDevice(getState().connect);
|
||||
if (!selected) return;
|
||||
|
@ -4,26 +4,27 @@
|
||||
//regExp1 : string = '(.*)'
|
||||
//regExp2 : '$1' = '$1'
|
||||
|
||||
export const READY: 'trezorconnect__ready' = 'trezorconnect__ready';
|
||||
export const INITIALIZATION_ERROR: 'trezorconnect__init_error' = 'trezorconnect__init_error';
|
||||
export const SELECT_DEVICE: 'trezorconnect__select_device' = 'trezorconnect__select_device';
|
||||
export const READY: 'connect__ready' = 'connect__ready';
|
||||
export const INITIALIZATION_ERROR: 'connect__init_error' = 'connect__init_error';
|
||||
export const SELECT_DEVICE: 'connect__select_device' = 'connect__select_device';
|
||||
|
||||
|
||||
export const DEVICE_FROM_STORAGE: 'trezorconnect__device_from_storage' = 'trezorconnect__device_from_storage';
|
||||
export const AUTH_DEVICE: 'trezorconnect__auth_device' = 'trezorconnect__auth_device';
|
||||
export const COIN_CHANGED: 'trezorconnect__coin_changed' = 'trezorconnect__coin_changed';
|
||||
export const DEVICE_FROM_STORAGE: 'connect__device_from_storage' = 'connect__device_from_storage';
|
||||
export const AUTH_DEVICE: 'connect__auth_device' = 'connect__auth_device';
|
||||
export const COIN_CHANGED: 'connect__coin_changed' = 'connect__coin_changed';
|
||||
|
||||
export const REMEMBER_REQUEST: 'trezorconnect__remember_request' = 'trezorconnect__remember_request';
|
||||
export const FORGET_REQUEST: 'trezorconnect__forget_request' = 'trezorconnect__forget_request';
|
||||
export const FORGET: 'trezorconnect__forget' = 'trezorconnect__forget';
|
||||
export const FORGET_SINGLE: 'trezorconnect__forget_single' = 'trezorconnect__forget_single';
|
||||
export const DISCONNECT_REQUEST: 'trezorconnect__disconnect_request' = 'trezorconnect__disconnect_request';
|
||||
export const REMEMBER: 'trezorconnect__remember' = 'trezorconnect__remember';
|
||||
export const REMEMBER_REQUEST: 'connect__remember_request' = 'connect__remember_request';
|
||||
export const FORGET_REQUEST: 'connect__forget_request' = 'connect__forget_request';
|
||||
export const FORGET: 'connect__forget' = 'connect__forget';
|
||||
export const FORGET_SINGLE: 'connect__forget_single' = 'connect__forget_single';
|
||||
export const DISCONNECT_REQUEST: 'connect__disconnect_request' = 'connect__disconnect_request';
|
||||
export const REMEMBER: 'connect__remember' = 'connect__remember';
|
||||
|
||||
export const START_ACQUIRING: 'trezorconnect__start_acquiring' = 'trezorconnect__start_acquiring';
|
||||
export const STOP_ACQUIRING: 'trezorconnect__stop_acquiring' = 'trezorconnect__stop_acquiring';
|
||||
export const START_ACQUIRING: 'connect__start_acquiring' = 'connect__start_acquiring';
|
||||
export const STOP_ACQUIRING: 'connect__stop_acquiring' = 'connect__stop_acquiring';
|
||||
export const ACQUIRED: 'connect__device_acquired' = 'connect__device_acquired';
|
||||
|
||||
export const TRY_TO_DUPLICATE: 'trezorconnect__try_to_duplicate' = 'trezorconnect__try_to_duplicate';
|
||||
export const DUPLICATE: 'trezorconnect__duplicate' = 'trezorconnect__duplicate';
|
||||
export const TRY_TO_DUPLICATE: 'connect__try_to_duplicate' = 'connect__try_to_duplicate';
|
||||
export const DUPLICATE: 'connect__duplicate' = 'connect__duplicate';
|
||||
|
||||
export const DEVICE_STATE_EXCEPTION: 'trezorconnect__device_state_exception' = 'trezorconnect__device_state_exception';
|
||||
export const DEVICE_STATE_EXCEPTION: 'connect__device_state_exception' = 'connect__device_state_exception';
|
@ -2,5 +2,5 @@
|
||||
'use strict';
|
||||
|
||||
export const ON_BEFORE_UNLOAD: 'wallet__on_before_unload' = 'wallet__on_before_unload';
|
||||
export const TOGGLE_DEVICE_DROPDOWN: 'wallet_toggle_dropdown' = 'wallet_toggle_dropdown';
|
||||
export const SET_INITIAL_URL: 'wallet_set_initial_url' = 'wallet_set_initial_url';
|
||||
export const TOGGLE_DEVICE_DROPDOWN: 'wallet__toggle_dropdown' = 'wallet__toggle_dropdown';
|
||||
export const SET_INITIAL_URL: 'wallet__set_initial_url' = 'wallet__set_initial_url';
|
@ -60,7 +60,7 @@ export default (props: Props) => {
|
||||
body = <BrowserNotSupported />;
|
||||
} else if (connectError || bridgeRoute) {
|
||||
css += ' install-bridge';
|
||||
body = <InstallBridge browserState={ props.connect.browserState } />;
|
||||
body = <InstallBridge browserState={ browserState } />;
|
||||
} else if (props.wallet.ready && devices.length < 1) {
|
||||
css += ' connect-device';
|
||||
body = <ConnectDevice transport={ transport } />;
|
||||
|
@ -10,24 +10,26 @@ import LandingPage from './LandingPage';
|
||||
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
|
||||
import type { State, Dispatch } from '../../flowtype';
|
||||
|
||||
export type Props = {
|
||||
localStorage: any,
|
||||
modal: any,
|
||||
web3: any,
|
||||
wallet: any,
|
||||
connect: any,
|
||||
router: any
|
||||
export type StateProps = {
|
||||
localStorage: $ElementType<State, 'localStorage'>,
|
||||
modal: $ElementType<State, 'modal'>,
|
||||
web3: $ElementType<State, 'web3'>,
|
||||
wallet: $ElementType<State, 'wallet'>,
|
||||
connect: $ElementType<State, 'connect'>,
|
||||
router: $ElementType<State, 'router'>
|
||||
}
|
||||
|
||||
type DispatchProps = {
|
||||
foo: () => string
|
||||
|
||||
}
|
||||
|
||||
type OwnProps = {
|
||||
|
||||
}
|
||||
|
||||
const mapStateToProps: MapStateToProps<State, OwnProps, Props> = (state: State): Props => {
|
||||
export type Props = StateProps & DispatchProps;
|
||||
|
||||
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: State): StateProps => {
|
||||
return {
|
||||
localStorage: state.localStorage,
|
||||
modal: state.modal,
|
||||
@ -38,10 +40,10 @@ const mapStateToProps: MapStateToProps<State, OwnProps, Props> = (state: State):
|
||||
};
|
||||
}
|
||||
|
||||
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (dispatch: Dispatch) => {
|
||||
const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps> = (dispatch: Dispatch): DispatchProps => {
|
||||
return {
|
||||
foo: ():string => { return "A"; }
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, null)(LandingPage);
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(LandingPage);
|
@ -5,6 +5,8 @@ import React from 'react';
|
||||
import type { Props } from './index';
|
||||
|
||||
const InvalidPin = (props: Props) => {
|
||||
if (!props.modal.opened) return null;
|
||||
|
||||
const { device } = props.modal;
|
||||
return (
|
||||
<div className="pin">
|
||||
|
@ -28,12 +28,15 @@ export default class PinModal extends Component<Props, State> {
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
|
||||
const device = props.modal.opened ? props.modal.device : null;
|
||||
if (!device) return;
|
||||
|
||||
// check if this device is already known
|
||||
// const isSavedDevice = props.devices.find(d => d.path === props.modal.device.path && d.remember);
|
||||
const selected = findSelectedDevice(props.connect);
|
||||
let deviceLabel = props.modal.device.label;
|
||||
let deviceLabel =device.label;
|
||||
let singleInput = false;
|
||||
if (selected && selected.path === props.modal.device.path) {
|
||||
if (selected && selected.path === device.path) {
|
||||
deviceLabel = selected.instanceLabel;
|
||||
singleInput = selected.remember;
|
||||
}
|
||||
@ -209,6 +212,8 @@ export default class PinModal extends Component<Props, State> {
|
||||
|
||||
render(): any {
|
||||
|
||||
if (!this.props.modal.opened) return null;
|
||||
|
||||
const {
|
||||
device,
|
||||
} = this.props.modal;
|
||||
|
@ -104,6 +104,9 @@ export default class Pin extends Component<Props, State> {
|
||||
}
|
||||
|
||||
render(): any {
|
||||
|
||||
if (!this.props.modal.opened) return null;
|
||||
|
||||
const { onPinSubmit } = this.props.modalActions;
|
||||
const { device } = this.props.modal;
|
||||
const { pin } = this.state;
|
||||
|
@ -33,8 +33,9 @@ export default class RememberDevice extends Component<Props, State> {
|
||||
// TODO: possible race condition,
|
||||
// device could be already connected but it didn't emit Device.CONNECT event yet
|
||||
window.clearInterval(this.state.ticker);
|
||||
const { device } = this.props.modal;
|
||||
this.props.modalActions.onForgetDevice(device);
|
||||
if (this.props.modal.opened) {
|
||||
this.props.modalActions.onForgetDevice(this.props.modal.device);
|
||||
}
|
||||
} else {
|
||||
this.setState({
|
||||
countdown: this.state.countdown - 1
|
||||
@ -61,6 +62,7 @@ export default class RememberDevice extends Component<Props, State> {
|
||||
}
|
||||
|
||||
render(): any {
|
||||
if (!this.props.modal.opened) return null;
|
||||
const { device, instances } = this.props.modal;
|
||||
const { onForgetDevice, onRememberDevice } = this.props.modalActions;
|
||||
|
||||
|
@ -62,6 +62,9 @@ const Fade = ({ children, ...props }) => (
|
||||
|
||||
class Modal extends Component<Props> {
|
||||
render() {
|
||||
|
||||
if (!this.props.modal.opened) return null;
|
||||
|
||||
const { opened, windowType } = this.props.modal;
|
||||
|
||||
let component = null;
|
||||
|
@ -3,10 +3,11 @@
|
||||
|
||||
import type {
|
||||
Store as ReduxStore,
|
||||
Dispatch as ReduxDispatch,
|
||||
ReduxDispatch,
|
||||
MiddlewareAPI as ReduxMiddlewareAPI,
|
||||
Middleware as ReduxMiddleware,
|
||||
ThunkAction as ReduxThunkAction,
|
||||
AsyncAction as ReduxAsyncAction,
|
||||
ThunkDispatch as ReduxThunkDispatch,
|
||||
PlainDispatch as ReduxPlainDispatch
|
||||
} from 'redux';
|
||||
@ -90,6 +91,10 @@ type TransportEventAction = {
|
||||
type UiEventAction = {
|
||||
type: UiMessageType,
|
||||
payload: any,
|
||||
// payload: {
|
||||
// device: Device;
|
||||
// code?: string;
|
||||
// },
|
||||
}
|
||||
|
||||
// TODO: join this message with uiMessage
|
||||
@ -134,6 +139,8 @@ export type MiddlewareDispatch = ReduxPlainDispatch<Action>;
|
||||
export type MiddlewareAPI = ReduxMiddlewareAPI<State, Action>;
|
||||
export type Middleware = ReduxMiddleware<State, Action>;
|
||||
|
||||
export type ThunkAction = ReduxThunkAction<State, Action>;
|
||||
export type AsyncAction = ReduxAsyncAction<State, Action>;
|
||||
|
||||
export type Store = ReduxStore<State, Action>;
|
||||
export type GetState = () => State;
|
||||
export type AsyncAction = ReduxThunkAction<State, Action>;
|
||||
|
11
src/js/flowtype/react-router-redux.js
vendored
11
src/js/flowtype/react-router-redux.js
vendored
@ -20,7 +20,6 @@ declare module "react-router-redux" {
|
||||
|
||||
declare export type RouterAction = {
|
||||
type: typeof LOCATION_CHANGE,
|
||||
// type: "@@router/LOCATION_CHANGE",
|
||||
payload: Location;
|
||||
}
|
||||
|
||||
@ -28,11 +27,11 @@ declare module "react-router-redux" {
|
||||
location: Location; // should be ?Location
|
||||
}
|
||||
|
||||
declare export function push(a: string): void;
|
||||
declare export function replace(a: string): void;
|
||||
declare export function go(a: string): void;
|
||||
declare export function goBack(): void;
|
||||
declare export function goForward(): void;
|
||||
declare export function push(a: string): RouterAction;
|
||||
declare export function replace(a: string): RouterAction;
|
||||
declare export function go(a: string): RouterAction;
|
||||
declare export function goBack(): RouterAction;
|
||||
declare export function goForward(): RouterAction;
|
||||
|
||||
//declare export function routerReducer<S, A>(state?: S, action: A): S;
|
||||
declare export function routerReducer(state?: State, action: any): State;
|
||||
|
@ -1,74 +0,0 @@
|
||||
// flow-typed signature: cca4916b0213065533df8335c3285a4a
|
||||
// flow-typed version: cab04034e7/redux_v3.x.x/flow_>=v0.55.x
|
||||
|
||||
declare module 'redux' {
|
||||
|
||||
/*
|
||||
|
||||
S = State
|
||||
A = Action
|
||||
D = Dispatch
|
||||
|
||||
*/
|
||||
|
||||
declare export type DispatchAPI<A> = (action: A) => A;
|
||||
// declare export type Dispatch<A: { type: $Subtype<string> }> = DispatchAPI<A>;
|
||||
/* NEW: Dispatch is now a combination of these different dispatch types */
|
||||
declare export type Dispatch<S, A> = PlainDispatch<A> & ThunkDispatch<S, A>;
|
||||
|
||||
// declare export type ThunkAction<S, A> = (dispatch: Dispatch<S, A>, getState: () => S) => Promise<void> | void;
|
||||
//declare export type ThunkAction<S, A> = (dispatch: PlainDispatch<A> | ThunkDispatch<S, A>, getState: () => S) => Promise<void> | void;
|
||||
declare export type ThunkAction<S, A> = (dispatch: ThunkDispatch<S, A>, getState: () => S) => Promise<void> | void;
|
||||
//declare export type ThunkDispatch<S, A> = (action: ThunkAction<S, A>) => void;
|
||||
declare export type ThunkDispatch<S, A> = (action: PlainDispatch<A> | ThunkDispatch<S, A>) => void;
|
||||
|
||||
declare export type PlainDispatch<A: {type: $Subtype<string>}> = DispatchAPI<A>;
|
||||
|
||||
// declare export type ThunkAction<S, D> = (dispatch: D, getState: () => S) => Promise<void> | void;
|
||||
// declare type ThunkDispatch<S, D> = (action: ThunkAction<S, D & ThunkDispatch<S, D>>) => void;
|
||||
|
||||
declare export type MiddlewareAPI<S, A> = {
|
||||
dispatch: ThunkDispatch<S, A>;
|
||||
// dispatch: (action: PlainDispatch<A> | ThunkDispatch<S, A>) => void;
|
||||
getState(): S;
|
||||
};
|
||||
|
||||
declare export type Middleware<S, A> =
|
||||
(api: MiddlewareAPI<S, A>) =>
|
||||
(next: PlainDispatch<A>) => PlainDispatch<A>;
|
||||
|
||||
declare export type Store<S, A, D = Dispatch<S, A>> = {
|
||||
// rewrite MiddlewareAPI members in order to get nicer error messages (intersections produce long messages)
|
||||
dispatch: D;
|
||||
getState(): S;
|
||||
subscribe(listener: () => void): () => void;
|
||||
replaceReducer(nextReducer: Reducer<S, A>): void
|
||||
};
|
||||
|
||||
declare export type Reducer<S, A> = (state: S | void, action: A) => S;
|
||||
|
||||
declare export type CombinedReducer<S, A> = (state: $Shape<S> & {} | void, action: A) => S;
|
||||
|
||||
declare export type StoreCreator<S, A, D = Dispatch<S, A>> = {
|
||||
(reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
|
||||
(reducer: Reducer<S, A>, preloadedState: S, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
|
||||
};
|
||||
|
||||
declare export type StoreEnhancer<S, A, D = Dispatch<S, A>> = (next: StoreCreator<S, A, D>) => StoreCreator<S, A, D>;
|
||||
|
||||
declare export function createStore<S, A, D>(reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
|
||||
declare export function createStore<S, A, D>(reducer: Reducer<S, A>, preloadedState?: S, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
|
||||
|
||||
declare export function applyMiddleware<S, A, D>(...middlewares: Array<Middleware<S, A>>): StoreEnhancer<S, A, D>;
|
||||
|
||||
declare export type ActionCreator<A, B> = (...args: Array<B>) => A;
|
||||
declare export type ActionCreators<K, A> = { [key: K]: ActionCreator<A, any> };
|
||||
|
||||
declare export function bindActionCreators<A, C: ActionCreator<A, any>, D: DispatchAPI<A>>(actionCreator: C, dispatch: D): C;
|
||||
declare export function bindActionCreators<A, K, C: ActionCreators<K, A>, D: DispatchAPI<A>>(actionCreators: C, dispatch: D): C;
|
||||
|
||||
declare export function combineReducers<O: Object, A>(reducers: O): CombinedReducer<$ObjMap<O, <S>(r: Reducer<S, any>) => S>, A>;
|
||||
|
||||
declare export var compose: $Compose;
|
||||
}
|
||||
|
@ -1,6 +1,3 @@
|
||||
// flow-typed signature: cca4916b0213065533df8335c3285a4a
|
||||
// flow-typed version: cab04034e7/redux_v3.x.x/flow_>=v0.55.x
|
||||
|
||||
declare module 'redux' {
|
||||
|
||||
/*
|
||||
@ -12,24 +9,34 @@ declare module 'redux' {
|
||||
*/
|
||||
|
||||
declare export type DispatchAPI<A> = (action: A) => A;
|
||||
// declare export type Dispatch<A: { type: $Subtype<string> }> = DispatchAPI<A>;
|
||||
// old Dispatch needs to stay as it is, because also "react-redux" is using this type
|
||||
declare export type Dispatch<A: { type: $Subtype<string> }> = DispatchAPI<A>;
|
||||
|
||||
declare export type ThunkAction<S, A> = (dispatch: ReduxDispatch<S, A>, getState: () => S) => void;
|
||||
declare export type AsyncAction<S, A> = (dispatch: ReduxDispatch<S, A>, getState: () => S) => Promise<void>;
|
||||
|
||||
declare export type ThunkAction<S, A> = (dispatch: Dispatch<S, A>, getState: () => S) => Promise<void> | void;
|
||||
declare export type ThunkDispatch<S, A> = (action: ThunkAction<S, A>) => void;
|
||||
|
||||
declare export type AsyncDispatch<S, A> = (action: AsyncAction<S, A>) => Promise<void>;
|
||||
declare export type PlainDispatch<A: {type: $Subtype<string>}> = DispatchAPI<A>;
|
||||
/* NEW: Dispatch is now a combination of these different dispatch types */
|
||||
declare export type Dispatch<S, A> = PlainDispatch<A> & ThunkDispatch<S, A>;
|
||||
|
||||
// declare export type ThunkAction<S, D> = (dispatch: D, getState: () => S) => Promise<void> | void;
|
||||
// declare type ThunkDispatch<S, D> = (action: ThunkAction<S, D & ThunkDispatch<S, D>>) => void;
|
||||
declare export type ReduxDispatch<S, A> = PlainDispatch<A> & ThunkDispatch<S, A> & AsyncDispatch<S ,A>;
|
||||
|
||||
declare export type MiddlewareAPI<S, A> = {
|
||||
dispatch: Dispatch<S, A>;
|
||||
// dispatch: Dispatch<S, A>;
|
||||
// dispatch: (action: A | ThunkAction<S, A>) => A | void;
|
||||
// dispatch: PlainDispatch<A> | () => A;
|
||||
// dispatch: ( A | ThunkAction<S, A> | void ) => void;
|
||||
dispatch: ReduxDispatch<S, A>;
|
||||
// dispatch: Dispatch<S, A>;
|
||||
// dispatch: D;
|
||||
getState(): S;
|
||||
};
|
||||
|
||||
declare export type Store<S, A, D = Dispatch<S, A>> = {
|
||||
declare export type Middleware<S, A> =
|
||||
(api: MiddlewareAPI<S, A>) =>
|
||||
(next: PlainDispatch<A>) => PlainDispatch<A>;
|
||||
|
||||
declare export type Store<S, A, D = ReduxDispatch<S, A>> = {
|
||||
// rewrite MiddlewareAPI members in order to get nicer error messages (intersections produce long messages)
|
||||
dispatch: D;
|
||||
getState(): S;
|
||||
@ -41,32 +48,28 @@ declare module 'redux' {
|
||||
|
||||
declare export type CombinedReducer<S, A> = (state: $Shape<S> & {} | void, action: A) => S;
|
||||
|
||||
declare export type Middleware<S, A> =
|
||||
(api: MiddlewareAPI<S, A>) =>
|
||||
(next: PlainDispatch<A>) => PlainDispatch<A>;
|
||||
|
||||
declare export type StoreCreator<S, A, D = Dispatch<S, A>> = {
|
||||
declare export type StoreCreator<S, A, D = ReduxDispatch<S, A>> = {
|
||||
(reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
|
||||
(reducer: Reducer<S, A>, preloadedState: S, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
|
||||
};
|
||||
|
||||
declare export type StoreEnhancer<S, A, D = Dispatch<S, A>> = (next: StoreCreator<S, A, D>) => StoreCreator<S, A, D>;
|
||||
declare export type StoreEnhancer<S, A, D = ReduxDispatch<S, A>> = (next: StoreCreator<S, A, D>) => StoreCreator<S, A, D>;
|
||||
|
||||
declare export function createStore<S, A, D>(reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
|
||||
declare export function createStore<S, A, D>(reducer: Reducer<S, A>, preloadedState?: S, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
|
||||
|
||||
declare export function applyMiddleware<S, A, D>(...middlewares: Array<Middleware<S, A>>): StoreEnhancer<S, A, D>;
|
||||
|
||||
declare export type ActionCreator<A, B> = (...args: Array<B>) => A;
|
||||
// declare export type ActionCreator<A, B> = (...args: Array<B>) => A;
|
||||
declare export type ActionCreator<A, B> = (...args: Array<B>) => any;
|
||||
declare export type ActionCreators<K, A> = { [key: K]: ActionCreator<A, any> };
|
||||
|
||||
declare export function bindActionCreators<A, C: ActionCreator<A, any>, D: DispatchAPI<A>>(actionCreator: C, dispatch: D): C;
|
||||
declare export function bindActionCreators<A, K, C: ActionCreators<K, A>, D: DispatchAPI<A>>(actionCreators: C, dispatch: D): C;
|
||||
declare export function bindActionCreators<A, C: ActionCreator<A, any>, D: ReduxDispatch<any, A>>(actionCreator: C, dispatch: D): C;
|
||||
declare export function bindActionCreators<A, K, C: ActionCreators<K, A>, D: ReduxDispatch<any, A>>(actionCreators: C, dispatch: D): C;
|
||||
// declare export function bindActionCreators<A, C: ActionCreator<A, any>, D: Dispatch>(actionCreator: C, dispatch: D): C;
|
||||
// declare export function bindActionCreators<A, K, C: ActionCreators<K, A>, D: Dispatch>(actionCreators: C, dispatch: D): C;
|
||||
|
||||
declare export function combineReducers<O: Object, A>(reducers: O): CombinedReducer<$ObjMap<O, <S>(r: Reducer<S, any>) => S>, A>;
|
||||
|
||||
declare export var compose: $Compose;
|
||||
}
|
||||
|
||||
}
|
||||
|
138
src/js/flowtype/redux_v3.x.x00.js
Normal file
138
src/js/flowtype/redux_v3.x.x00.js
Normal file
@ -0,0 +1,138 @@
|
||||
// flow-typed signature: ba132c96664f1a05288f3eb2272a3c35
|
||||
// flow-typed version: c4bbd91cfc/redux_v3.x.x/flow_>=v0.33.x
|
||||
// from : https://github.com/hmeerlo/redux-thunk-flow/blob/master/flow-typed/npm/redux_v3.x.x.js
|
||||
// declare module 'redux' {
|
||||
|
||||
// /*
|
||||
|
||||
// S = State
|
||||
// A = Action
|
||||
|
||||
// */
|
||||
|
||||
// /* NEW: We create a few extra action and dispatch types */
|
||||
// declare export type ThunkAction<S, R> = (dispatch: Dispatch<S, any>, getState: () => S) => R;
|
||||
// declare type PromiseAction<R> = { type: string, payload: Promise<R> };
|
||||
// declare type ThunkDispatch<S> = <R>(action: ThunkAction<S, R>) => R;
|
||||
// declare type PromiseDispatch = <R>(action: PromiseAction<R>) => Promise<R>;
|
||||
// declare type PlainDispatch<A: {type: $Subtype<string>}> = (action: A) => A;
|
||||
// /* NEW: Dispatch is now a combination of these different dispatch types */
|
||||
// declare export type Dispatch<S, A> = PlainDispatch<A> & ThunkDispatch<S> & PromiseDispatch;
|
||||
|
||||
// declare export type MiddlewareAPI<S, A> = {
|
||||
// dispatch: Dispatch<S, A>;
|
||||
// getState(): S;
|
||||
// };
|
||||
|
||||
// declare export type Store<S, A> = {
|
||||
// // rewrite MiddlewareAPI members in order to get nicer error messages (intersections produce long messages)
|
||||
// dispatch: Dispatch<S, A>;
|
||||
// getState(): S;
|
||||
// subscribe(listener: () => void): () => void;
|
||||
// replaceReducer(nextReducer: Reducer<S, A>): void
|
||||
// };
|
||||
|
||||
// declare type Reducer<S, A> = (state: S, action: A) => S;
|
||||
|
||||
// declare export type Middleware<S, A> =
|
||||
// (api: MiddlewareAPI<S, A>) =>
|
||||
// (next: Dispatch<S, A>) => Dispatch<S, A>;
|
||||
|
||||
// declare type StoreCreator<S, A> = {
|
||||
// (reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A>): Store<S, A>;
|
||||
// (reducer: Reducer<S, A>, preloadedState: S, enhancer?: StoreEnhancer<S, A>): Store<S, A>;
|
||||
// };
|
||||
|
||||
// declare type StoreEnhancer<S, A> = (next: StoreCreator<S, A>) => StoreCreator<S, A>;
|
||||
|
||||
// declare function createStore<S, A>(reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A>): Store<S, A>;
|
||||
// declare function createStore<S, A>(reducer: Reducer<S, A>, preloadedState: S, enhancer?: StoreEnhancer<S, A>): Store<S, A>;
|
||||
|
||||
// declare function applyMiddleware<S, A>(...middlewares: Array<Middleware<S, A>>): StoreEnhancer<S, A>;
|
||||
|
||||
// declare type ActionCreator<A, B> = (...args: Array<B>) => A;
|
||||
// declare type ActionCreators<K, A> = { [key: K]: ActionCreator<A, any> };
|
||||
|
||||
// declare function bindActionCreators<S, A, C: ActionCreator<A, any>>(actionCreator: C, dispatch: Dispatch<S, A>): C;
|
||||
// declare function bindActionCreators<S, A, K, C: ActionCreators<K, A>>(actionCreators: C, dispatch: Dispatch<S, A>): C;
|
||||
|
||||
// declare function combineReducers<O: Object, A>(reducers: O): Reducer<$ObjMap<O, <S>(r: Reducer<S, any>) => S>, A>;
|
||||
|
||||
// declare function compose<S, A>(...fns: Array<StoreEnhancer<S, A>>): Function;
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// flow-typed signature: cca4916b0213065533df8335c3285a4a
|
||||
// flow-typed version: cab04034e7/redux_v3.x.x/flow_>=v0.55.x
|
||||
|
||||
declare module 'redux' {
|
||||
|
||||
/*
|
||||
|
||||
S = State
|
||||
A = Action
|
||||
D = Dispatch
|
||||
|
||||
*/
|
||||
|
||||
declare export type DispatchAPI<A> = (action: A) => A;
|
||||
// declare export type Dispatch<A: { type: $Subtype<string> }> = DispatchAPI<A>;
|
||||
|
||||
declare export type ThunkAction<S, A> = (dispatch: Dispatch<S, any>, getState: () => S) => Promise<void> | void;
|
||||
declare export type ThunkDispatch<S, A> = (action: ThunkAction<S, A>) => void;
|
||||
|
||||
declare export type PlainDispatch<A: {type: $Subtype<string>}> = DispatchAPI<A>;
|
||||
/* NEW: Dispatch is now a combination of these different dispatch types */
|
||||
declare export type Dispatch<S, A> = PlainDispatch<A> & ThunkDispatch<S, A>;
|
||||
|
||||
// declare export type ThunkAction<S, D> = (dispatch: D, getState: () => S) => Promise<void> | void;
|
||||
// declare type ThunkDispatch<S, D> = (action: ThunkAction<S, D & ThunkDispatch<S, D>>) => void;
|
||||
|
||||
declare export type MiddlewareAPI<S, A> = {
|
||||
dispatch: Dispatch<S, A>;
|
||||
getState(): S;
|
||||
};
|
||||
|
||||
declare export type Store<S, A, D = Dispatch<S, A>> = {
|
||||
// rewrite MiddlewareAPI members in order to get nicer error messages (intersections produce long messages)
|
||||
dispatch: D;
|
||||
getState(): S;
|
||||
subscribe(listener: () => void): () => void;
|
||||
replaceReducer(nextReducer: Reducer<S, A>): void
|
||||
};
|
||||
|
||||
declare export type Reducer<S, A> = (state: S | void, action: A) => S;
|
||||
|
||||
declare export type CombinedReducer<S, A> = (state: $Shape<S> & {} | void, action: A) => S;
|
||||
|
||||
declare export type Middleware<S, A> =
|
||||
(api: MiddlewareAPI<S, A>) =>
|
||||
(next: PlainDispatch<A>) => PlainDispatch<A>;
|
||||
|
||||
declare export type StoreCreator<S, A, D = Dispatch<S, A>> = {
|
||||
(reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
|
||||
(reducer: Reducer<S, A>, preloadedState: S, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
|
||||
};
|
||||
|
||||
declare export type StoreEnhancer<S, A, D = Dispatch<S, A>> = (next: StoreCreator<S, A, D>) => StoreCreator<S, A, D>;
|
||||
|
||||
declare export function createStore<S, A, D>(reducer: Reducer<S, A>, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
|
||||
declare export function createStore<S, A, D>(reducer: Reducer<S, A>, preloadedState?: S, enhancer?: StoreEnhancer<S, A, D>): Store<S, A, D>;
|
||||
|
||||
declare export function applyMiddleware<S, A, D>(...middlewares: Array<Middleware<S, A>>): StoreEnhancer<S, A, D>;
|
||||
|
||||
declare export type ActionCreator<A, B> = (...args: Array<B>) => A;
|
||||
declare export type ActionCreators<K, A> = { [key: K]: ActionCreator<A, any> };
|
||||
|
||||
declare export function bindActionCreators<A, C: ActionCreator<A, any>, D: DispatchAPI<A>>(actionCreator: C, dispatch: D): C;
|
||||
declare export function bindActionCreators<A, K, C: ActionCreators<K, A>, D: DispatchAPI<A>>(actionCreators: C, dispatch: D): C;
|
||||
// declare export function bindActionCreators<A, C: ActionCreator<A, any>, D: Dispatch>(actionCreator: C, dispatch: D): C;
|
||||
// declare export function bindActionCreators<A, K, C: ActionCreators<K, A>, D: Dispatch>(actionCreators: C, dispatch: D): C;
|
||||
|
||||
declare export function combineReducers<O: Object, A>(reducers: O): CombinedReducer<$ObjMap<O, <S>(r: Reducer<S, any>) => S>, A>;
|
||||
|
||||
declare export var compose: $Compose;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ export type Account = {
|
||||
loaded: boolean;
|
||||
+network: string;
|
||||
+deviceID: string;
|
||||
+deviceState: ?string;
|
||||
+deviceState: string;
|
||||
+index: number;
|
||||
+addressPath: Array<number>;
|
||||
+address: string;
|
||||
@ -44,7 +44,7 @@ const createAccount = (state: State, action: AddressCreateAction): State => {
|
||||
loaded: false,
|
||||
network: action.network,
|
||||
deviceID: action.device.features ? action.device.features.device_id : '0',
|
||||
deviceState: action.device.state,
|
||||
deviceState: action.device.state || 'undefined',
|
||||
index: action.index,
|
||||
addressPath: action.path,
|
||||
address: action.address,
|
||||
|
@ -9,17 +9,18 @@ import * as CONNECT from '../actions/constants/TrezorConnect';
|
||||
import type { Action, TrezorDevice } from '../flowtype';
|
||||
|
||||
export type State = {
|
||||
opened: boolean;
|
||||
device: ?TrezorDevice;
|
||||
instances: ?Array<TrezorDevice>;
|
||||
windowType: ?string;
|
||||
opened: false;
|
||||
} | {
|
||||
opened: true;
|
||||
device: TrezorDevice;
|
||||
instances?: Array<TrezorDevice>;
|
||||
windowType?: string;
|
||||
}
|
||||
|
||||
const initialState: State = {
|
||||
opened: false,
|
||||
device: null,
|
||||
instances: null,
|
||||
windowType: null
|
||||
opened: false
|
||||
// instances: null,
|
||||
// windowType: null
|
||||
};
|
||||
|
||||
export default function modal(state: State = initialState, action: Action): State {
|
||||
@ -28,50 +29,42 @@ export default function modal(state: State = initialState, action: Action): Stat
|
||||
|
||||
case RECEIVE.REQUEST_UNVERIFIED :
|
||||
return {
|
||||
...state,
|
||||
device: action.device,
|
||||
opened: true,
|
||||
device: action.device,
|
||||
windowType: action.type
|
||||
}
|
||||
|
||||
case CONNECT.REMEMBER_REQUEST :
|
||||
return {
|
||||
...state,
|
||||
opened: true,
|
||||
device: action.device,
|
||||
instances: action.instances,
|
||||
opened: true,
|
||||
windowType: action.type
|
||||
};
|
||||
case CONNECT.FORGET_REQUEST :
|
||||
case CONNECT.DISCONNECT_REQUEST :
|
||||
return {
|
||||
...state,
|
||||
device: action.device,
|
||||
opened: true,
|
||||
device: action.device,
|
||||
windowType: action.type
|
||||
};
|
||||
|
||||
case CONNECT.TRY_TO_DUPLICATE :
|
||||
return {
|
||||
...state,
|
||||
device: action.device,
|
||||
opened: true,
|
||||
device: action.device,
|
||||
windowType: action.type
|
||||
};
|
||||
|
||||
case DEVICE.CHANGED :
|
||||
if (state.opened && state.device && action.device.path === state.device.path && action.device.isUsedElsewhere) {
|
||||
return {
|
||||
...initialState,
|
||||
};
|
||||
if (state.opened && action.device.path === state.device.path && action.device.isUsedElsewhere) {
|
||||
return initialState
|
||||
}
|
||||
return state;
|
||||
|
||||
case DEVICE.DISCONNECT :
|
||||
if (state.device && action.device.path === state.device.path) {
|
||||
return {
|
||||
...initialState,
|
||||
}
|
||||
if (state.opened && action.device.path === state.device.path) {
|
||||
return initialState
|
||||
}
|
||||
return state;
|
||||
|
||||
@ -89,16 +82,16 @@ export default function modal(state: State = initialState, action: Action): Stat
|
||||
case UI.INVALID_PIN :
|
||||
case UI.REQUEST_PASSPHRASE :
|
||||
return {
|
||||
...state,
|
||||
device: action.payload.device,
|
||||
opened: true,
|
||||
device: action.payload.device,
|
||||
windowType: action.type
|
||||
};
|
||||
|
||||
case UI.REQUEST_BUTTON :
|
||||
console.log("REQBUT", action)
|
||||
return {
|
||||
...state,
|
||||
opened: true,
|
||||
device: action.payload.device,
|
||||
windowType: action.payload.code
|
||||
}
|
||||
|
||||
@ -108,9 +101,7 @@ export default function modal(state: State = initialState, action: Action): Stat
|
||||
case CONNECT.FORGET :
|
||||
case CONNECT.FORGET_SINGLE :
|
||||
case CONNECT.REMEMBER :
|
||||
return {
|
||||
...initialState,
|
||||
};
|
||||
return initialState;
|
||||
|
||||
default:
|
||||
return state;
|
||||
|
@ -13,7 +13,7 @@ export type Token = {
|
||||
+symbol: string;
|
||||
+address: string;
|
||||
+ethAddress: string; // foreign key
|
||||
+decimals: string;
|
||||
+decimals: number;
|
||||
balance: string;
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@ import type {
|
||||
State,
|
||||
Dispatch,
|
||||
Action,
|
||||
ThunkAction,
|
||||
AsyncAction,
|
||||
GetState,
|
||||
RouterLocationState,
|
||||
@ -155,10 +156,11 @@ const RouterService: Middleware = (api: MiddlewareAPI) => (next: MiddlewareDispa
|
||||
if (redirectPath) {
|
||||
console.warn("Redirecting...")
|
||||
// override action to keep routerReducer sync
|
||||
action.payload.state = pathToParams(redirectPath);
|
||||
action.payload.pathname = redirectPath;
|
||||
const url: string = redirectPath;
|
||||
action.payload.state = pathToParams(url);
|
||||
action.payload.pathname = url;
|
||||
// change url
|
||||
api.dispatch( replace(redirectPath) );
|
||||
api.dispatch( replace(url) );
|
||||
} else {
|
||||
action.payload.state = requestedParams;
|
||||
}
|
||||
|
@ -58,18 +58,8 @@ const TrezorConnectService: Middleware = (api: MiddlewareAPI) => (next: Middlewa
|
||||
api.dispatch( TrezorConnectActions.deviceDisconnect(action.device) );
|
||||
|
||||
} else if (action.type === CONNECT.REMEMBER_REQUEST) {
|
||||
// TODO: 2 modals at once
|
||||
if (prevModalState.opened && prevModalState.windowType === CONNECT.REMEMBER_REQUEST) {
|
||||
api.dispatch({
|
||||
type: CONNECT.FORGET,
|
||||
device: api.getState().modal.device
|
||||
});
|
||||
|
||||
api.dispatch({
|
||||
type: CONNECT.FORGET,
|
||||
device: prevModalState.device
|
||||
});
|
||||
}
|
||||
api.dispatch(ModalActions.onRememberRequest(prevModalState));
|
||||
|
||||
} else if (action.type === CONNECT.FORGET) {
|
||||
//api.dispatch( TrezorConnectActions.forgetDevice(action.device) );
|
||||
@ -121,7 +111,7 @@ const TrezorConnectService: Middleware = (api: MiddlewareAPI) => (next: Middlewa
|
||||
api.dispatch( DiscoveryActions.check() );
|
||||
} else if (action.type === CONNECT.DUPLICATE) {
|
||||
api.dispatch( TrezorConnectActions.onDuplicateDevice() );
|
||||
} else if (action.type === DEVICE.ACQUIRED || action.type === CONNECT.SELECT_DEVICE) {
|
||||
} else if (action.type === CONNECT.ACQUIRED || action.type === CONNECT.SELECT_DEVICE) {
|
||||
api.dispatch( TrezorConnectActions.getSelectedDeviceState() );
|
||||
} else if (action.type === CONNECT.COIN_CHANGED) {
|
||||
api.dispatch( TrezorConnectActions.coinChanged( action.payload.network ) );
|
||||
|
Loading…
Reference in New Issue
Block a user