diff --git a/src/js/actions/AbstractAccountActions.js b/src/js/actions/AbstractAccountActions.js index 343905bd..ed217ea5 100644 --- a/src/js/actions/AbstractAccountActions.js +++ b/src/js/actions/AbstractAccountActions.js @@ -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, diff --git a/src/js/actions/DiscoveryActions.js b/src/js/actions/DiscoveryActions.js index d6a68558..9ca9c46f 100644 --- a/src/js/actions/DiscoveryActions.js +++ b/src/js/actions/DiscoveryActions.js @@ -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; diff --git a/src/js/actions/LocalStorageActions.js b/src/js/actions/LocalStorageActions.js index 425f08a6..41ec1b51 100644 --- a/src/js/actions/LocalStorageActions.js +++ b/src/js/actions/LocalStorageActions.js @@ -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); diff --git a/src/js/actions/LogActions.js b/src/js/actions/LogActions.js index 970471ea..b8131795 100644 --- a/src/js/actions/LogActions.js +++ b/src/js/actions/LogActions.js @@ -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 - }); + dispatch({ + type: LOG.CLOSE + }); + } else { + dispatch({ + type: LOG.OPEN + }); + } } } diff --git a/src/js/actions/ModalActions.js b/src/js/actions/ModalActions.js index 3ec55692..662fed47 100644 --- a/src/js/actions/ModalActions.js +++ b/src/js/actions/ModalActions.js @@ -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, diff --git a/src/js/actions/NotificationActions.js b/src/js/actions/NotificationActions.js index 07384db6..39a219ab 100644 --- a/src/js/actions/NotificationActions.js +++ b/src/js/actions/NotificationActions.js @@ -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 => { - dispatch({ - type: NOTIFICATION.CLOSE, - payload: { - devicePath: entry.devicePath - } - }) + if (typeof entry.devicePath === 'string') { + dispatch({ + type: NOTIFICATION.CLOSE, + payload: { + devicePath: entry.devicePath + } + }) + } }); } } diff --git a/src/js/actions/ReceiveActions.js b/src/js/actions/ReceiveActions.js index bcc6b05b..a48cf9a4 100644 --- a/src/js/actions/ReceiveActions.js +++ b/src/js/actions/ReceiveActions.js @@ -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, diff --git a/src/js/actions/SendFormActions.js b/src/js/actions/SendFormActions.js index 1be79bf3..323b8edb 100644 --- a/src/js/actions/SendFormActions.js +++ b/src/js/actions/SendFormActions.js @@ -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 }; diff --git a/src/js/actions/SummaryActions.js b/src/js/actions/SummaryActions.js index 39716f81..149593ba 100644 --- a/src/js/actions/SummaryActions.js +++ b/src/js/actions/SummaryActions.js @@ -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, diff --git a/src/js/actions/TokenActions.js b/src/js/actions/TokenActions.js index 8de88489..f895aff7 100644 --- a/src/js/actions/TokenActions.js +++ b/src/js/actions/TokenActions.js @@ -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'; diff --git a/src/js/actions/TrezorConnectActions.js b/src/js/actions/TrezorConnectActions.js index 20caf845..81475174 100644 --- a/src/js/actions/TrezorConnectActions.js +++ b/src/js/actions/TrezorConnectActions.js @@ -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): Array => { }); } -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 = getState().accounts.find(a => a.deviceState === device.state); @@ -463,9 +469,11 @@ export const forgetDevice = (device: any): AsyncAction => { } } -export const gotoDeviceSettings = (device: any): AsyncAction => { +export const gotoDeviceSettings = (device: TrezorDevice): ThunkAction => { return (dispatch: Dispatch, getState: GetState): void => { - dispatch( push(`/device/${ device.features.device_id }/settings`) ); + if (device.features) { + dispatch( push(`/device/${ device.features.device_id }/settings`) ); + } } } @@ -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; diff --git a/src/js/actions/constants/TrezorConnect.js b/src/js/actions/constants/TrezorConnect.js index db6cc452..44982797 100644 --- a/src/js/actions/constants/TrezorConnect.js +++ b/src/js/actions/constants/TrezorConnect.js @@ -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'; \ No newline at end of file +export const DEVICE_STATE_EXCEPTION: 'connect__device_state_exception' = 'connect__device_state_exception'; \ No newline at end of file diff --git a/src/js/actions/constants/wallet.js b/src/js/actions/constants/wallet.js index fd93b50a..0b0299fb 100644 --- a/src/js/actions/constants/wallet.js +++ b/src/js/actions/constants/wallet.js @@ -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'; \ No newline at end of file +export const TOGGLE_DEVICE_DROPDOWN: 'wallet__toggle_dropdown' = 'wallet__toggle_dropdown'; +export const SET_INITIAL_URL: 'wallet__set_initial_url' = 'wallet__set_initial_url'; \ No newline at end of file diff --git a/src/js/components/landing/LandingPage.js b/src/js/components/landing/LandingPage.js index 3e7c650a..00d11d75 100644 --- a/src/js/components/landing/LandingPage.js +++ b/src/js/components/landing/LandingPage.js @@ -60,7 +60,7 @@ export default (props: Props) => { body = ; } else if (connectError || bridgeRoute) { css += ' install-bridge'; - body = ; + body = ; } else if (props.wallet.ready && devices.length < 1) { css += ' connect-device'; body = ; diff --git a/src/js/components/landing/index.js b/src/js/components/landing/index.js index 05b6bc98..1c66c0e3 100644 --- a/src/js/components/landing/index.js +++ b/src/js/components/landing/index.js @@ -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, + modal: $ElementType, + web3: $ElementType, + wallet: $ElementType, + connect: $ElementType, + router: $ElementType } type DispatchProps = { - foo: () => string + } type OwnProps = { } -const mapStateToProps: MapStateToProps = (state: State): Props => { +export type Props = StateProps & DispatchProps; + +const mapStateToProps: MapStateToProps = (state: State): StateProps => { return { localStorage: state.localStorage, modal: state.modal, @@ -38,10 +40,10 @@ const mapStateToProps: MapStateToProps = (state: State): }; } -const mapDispatchToProps: MapDispatchToProps = (dispatch: Dispatch) => { +const mapDispatchToProps: MapDispatchToProps = (dispatch: Dispatch): DispatchProps => { return { - foo: ():string => { return "A"; } + }; } -export default connect(mapStateToProps, null)(LandingPage); \ No newline at end of file +export default connect(mapStateToProps, mapDispatchToProps)(LandingPage); \ No newline at end of file diff --git a/src/js/components/modal/InvalidPin.js b/src/js/components/modal/InvalidPin.js index 5f7f6a4b..bd313be5 100644 --- a/src/js/components/modal/InvalidPin.js +++ b/src/js/components/modal/InvalidPin.js @@ -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 (
diff --git a/src/js/components/modal/Passphrase.js b/src/js/components/modal/Passphrase.js index a597371c..db226fa3 100644 --- a/src/js/components/modal/Passphrase.js +++ b/src/js/components/modal/Passphrase.js @@ -28,12 +28,15 @@ export default class PinModal extends Component { 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 { render(): any { + if (!this.props.modal.opened) return null; + const { device, } = this.props.modal; diff --git a/src/js/components/modal/Pin.js b/src/js/components/modal/Pin.js index b4e6cf45..cb5e018d 100644 --- a/src/js/components/modal/Pin.js +++ b/src/js/components/modal/Pin.js @@ -104,6 +104,9 @@ export default class Pin extends Component { } render(): any { + + if (!this.props.modal.opened) return null; + const { onPinSubmit } = this.props.modalActions; const { device } = this.props.modal; const { pin } = this.state; diff --git a/src/js/components/modal/RememberDevice.js b/src/js/components/modal/RememberDevice.js index 6dd1c69e..7ae24b5e 100644 --- a/src/js/components/modal/RememberDevice.js +++ b/src/js/components/modal/RememberDevice.js @@ -33,8 +33,9 @@ export default class RememberDevice extends Component { // 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 { } render(): any { + if (!this.props.modal.opened) return null; const { device, instances } = this.props.modal; const { onForgetDevice, onRememberDevice } = this.props.modalActions; diff --git a/src/js/components/modal/index.js b/src/js/components/modal/index.js index d3972930..2f4f1053 100644 --- a/src/js/components/modal/index.js +++ b/src/js/components/modal/index.js @@ -62,6 +62,9 @@ const Fade = ({ children, ...props }) => ( class Modal extends Component { render() { + + if (!this.props.modal.opened) return null; + const { opened, windowType } = this.props.modal; let component = null; diff --git a/src/js/flowtype/index.js b/src/js/flowtype/index.js index 8b9a1ce1..b1a691d1 100644 --- a/src/js/flowtype/index.js +++ b/src/js/flowtype/index.js @@ -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; export type MiddlewareAPI = ReduxMiddlewareAPI; export type Middleware = ReduxMiddleware; +export type ThunkAction = ReduxThunkAction; +export type AsyncAction = ReduxAsyncAction; + export type Store = ReduxStore; export type GetState = () => State; -export type AsyncAction = ReduxThunkAction; diff --git a/src/js/flowtype/react-router-redux.js b/src/js/flowtype/react-router-redux.js index 93934141..b04d0640 100644 --- a/src/js/flowtype/react-router-redux.js +++ b/src/js/flowtype/react-router-redux.js @@ -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(state?: S, action: A): S; declare export function routerReducer(state?: State, action: any): State; diff --git a/src/js/flowtype/redux_v3.x.x.1.js b/src/js/flowtype/redux_v3.x.x.1.js deleted file mode 100644 index a0b7e4db..00000000 --- a/src/js/flowtype/redux_v3.x.x.1.js +++ /dev/null @@ -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 = (action: A) => A; - // declare export type Dispatch }> = DispatchAPI; - /* NEW: Dispatch is now a combination of these different dispatch types */ - declare export type Dispatch = PlainDispatch & ThunkDispatch; - - // declare export type ThunkAction = (dispatch: Dispatch, getState: () => S) => Promise | void; - //declare export type ThunkAction = (dispatch: PlainDispatch | ThunkDispatch, getState: () => S) => Promise | void; - declare export type ThunkAction = (dispatch: ThunkDispatch, getState: () => S) => Promise | void; - //declare export type ThunkDispatch = (action: ThunkAction) => void; - declare export type ThunkDispatch = (action: PlainDispatch | ThunkDispatch) => void; - - declare export type PlainDispatch}> = DispatchAPI; - - // declare export type ThunkAction = (dispatch: D, getState: () => S) => Promise | void; - // declare type ThunkDispatch = (action: ThunkAction>) => void; - - declare export type MiddlewareAPI = { - dispatch: ThunkDispatch; - // dispatch: (action: PlainDispatch | ThunkDispatch) => void; - getState(): S; - }; - - declare export type Middleware = - (api: MiddlewareAPI) => - (next: PlainDispatch) => PlainDispatch; - - declare export type Store> = { - // 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): void - }; - - declare export type Reducer = (state: S | void, action: A) => S; - - declare export type CombinedReducer = (state: $Shape & {} | void, action: A) => S; - - declare export type StoreCreator> = { - (reducer: Reducer, enhancer?: StoreEnhancer): Store; - (reducer: Reducer, preloadedState: S, enhancer?: StoreEnhancer): Store; - }; - - declare export type StoreEnhancer> = (next: StoreCreator) => StoreCreator; - - declare export function createStore(reducer: Reducer, enhancer?: StoreEnhancer): Store; - declare export function createStore(reducer: Reducer, preloadedState?: S, enhancer?: StoreEnhancer): Store; - - declare export function applyMiddleware(...middlewares: Array>): StoreEnhancer; - - declare export type ActionCreator = (...args: Array) => A; - declare export type ActionCreators = { [key: K]: ActionCreator }; - - declare export function bindActionCreators, D: DispatchAPI>(actionCreator: C, dispatch: D): C; - declare export function bindActionCreators, D: DispatchAPI>(actionCreators: C, dispatch: D): C; - - declare export function combineReducers(reducers: O): CombinedReducer<$ObjMap(r: Reducer) => S>, A>; - - declare export var compose: $Compose; - } - \ No newline at end of file diff --git a/src/js/flowtype/redux_v3.x.x.js b/src/js/flowtype/redux_v3.x.x.js index e043119b..d51acdc5 100644 --- a/src/js/flowtype/redux_v3.x.x.js +++ b/src/js/flowtype/redux_v3.x.x.js @@ -1,72 +1,75 @@ -// 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 = (action: A) => A; - // declare export type Dispatch }> = DispatchAPI; - - declare export type ThunkAction = (dispatch: Dispatch, getState: () => S) => Promise | void; - declare export type ThunkDispatch = (action: ThunkAction) => void; - - declare export type PlainDispatch}> = DispatchAPI; - /* NEW: Dispatch is now a combination of these different dispatch types */ - declare export type Dispatch = PlainDispatch & ThunkDispatch; - - // declare export type ThunkAction = (dispatch: D, getState: () => S) => Promise | void; - // declare type ThunkDispatch = (action: ThunkAction>) => void; - - declare export type MiddlewareAPI = { - dispatch: Dispatch; - getState(): S; - }; - - declare export type Store> = { - // 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): void - }; - - declare export type Reducer = (state: S | void, action: A) => S; - - declare export type CombinedReducer = (state: $Shape & {} | void, action: A) => S; - - declare export type Middleware = - (api: MiddlewareAPI) => - (next: PlainDispatch) => PlainDispatch; - - declare export type StoreCreator> = { - (reducer: Reducer, enhancer?: StoreEnhancer): Store; - (reducer: Reducer, preloadedState: S, enhancer?: StoreEnhancer): Store; - }; - - declare export type StoreEnhancer> = (next: StoreCreator) => StoreCreator; - - declare export function createStore(reducer: Reducer, enhancer?: StoreEnhancer): Store; - declare export function createStore(reducer: Reducer, preloadedState?: S, enhancer?: StoreEnhancer): Store; - - declare export function applyMiddleware(...middlewares: Array>): StoreEnhancer; - - declare export type ActionCreator = (...args: Array) => A; - declare export type ActionCreators = { [key: K]: ActionCreator }; - - declare export function bindActionCreators, D: DispatchAPI>(actionCreator: C, dispatch: D): C; - declare export function bindActionCreators, D: DispatchAPI>(actionCreators: C, dispatch: D): C; - // declare export function bindActionCreators, D: Dispatch>(actionCreator: C, dispatch: D): C; - // declare export function bindActionCreators, D: Dispatch>(actionCreators: C, dispatch: D): C; - - declare export function combineReducers(reducers: O): CombinedReducer<$ObjMap(r: Reducer) => S>, A>; - - declare export var compose: $Compose; - } - \ No newline at end of file + /* + + S = State + A = Action + D = Dispatch + + */ + + declare export type DispatchAPI = (action: A) => A; + // old Dispatch needs to stay as it is, because also "react-redux" is using this type + declare export type Dispatch }> = DispatchAPI; + + declare export type ThunkAction = (dispatch: ReduxDispatch, getState: () => S) => void; + declare export type AsyncAction = (dispatch: ReduxDispatch, getState: () => S) => Promise; + + declare export type ThunkDispatch = (action: ThunkAction) => void; + declare export type AsyncDispatch = (action: AsyncAction) => Promise; + declare export type PlainDispatch}> = DispatchAPI; + /* NEW: Dispatch is now a combination of these different dispatch types */ + declare export type ReduxDispatch = PlainDispatch & ThunkDispatch & AsyncDispatch; + + declare export type MiddlewareAPI = { + // dispatch: Dispatch; + // dispatch: (action: A | ThunkAction) => A | void; + // dispatch: PlainDispatch | () => A; + // dispatch: ( A | ThunkAction | void ) => void; + dispatch: ReduxDispatch; + // dispatch: Dispatch; + // dispatch: D; + getState(): S; + }; + + declare export type Middleware = + (api: MiddlewareAPI) => + (next: PlainDispatch) => PlainDispatch; + + declare export type Store> = { + // 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): void + }; + + declare export type Reducer = (state: S | void, action: A) => S; + + declare export type CombinedReducer = (state: $Shape & {} | void, action: A) => S; + + declare export type StoreCreator> = { + (reducer: Reducer, enhancer?: StoreEnhancer): Store; + (reducer: Reducer, preloadedState: S, enhancer?: StoreEnhancer): Store; + }; + + declare export type StoreEnhancer> = (next: StoreCreator) => StoreCreator; + + declare export function createStore(reducer: Reducer, enhancer?: StoreEnhancer): Store; + declare export function createStore(reducer: Reducer, preloadedState?: S, enhancer?: StoreEnhancer): Store; + + declare export function applyMiddleware(...middlewares: Array>): StoreEnhancer; + + // declare export type ActionCreator = (...args: Array) => A; + declare export type ActionCreator = (...args: Array) => any; + declare export type ActionCreators = { [key: K]: ActionCreator }; + + declare export function bindActionCreators, D: ReduxDispatch>(actionCreator: C, dispatch: D): C; + declare export function bindActionCreators, D: ReduxDispatch>(actionCreators: C, dispatch: D): C; + // declare export function bindActionCreators, D: Dispatch>(actionCreator: C, dispatch: D): C; + // declare export function bindActionCreators, D: Dispatch>(actionCreators: C, dispatch: D): C; + + declare export function combineReducers(reducers: O): CombinedReducer<$ObjMap(r: Reducer) => S>, A>; + + declare export var compose: $Compose; +} diff --git a/src/js/flowtype/redux_v3.x.x00.js b/src/js/flowtype/redux_v3.x.x00.js new file mode 100644 index 00000000..7d18527b --- /dev/null +++ b/src/js/flowtype/redux_v3.x.x00.js @@ -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 = (dispatch: Dispatch, getState: () => S) => R; +// declare type PromiseAction = { type: string, payload: Promise }; +// declare type ThunkDispatch = (action: ThunkAction) => R; +// declare type PromiseDispatch = (action: PromiseAction) => Promise; +// declare type PlainDispatch}> = (action: A) => A; +// /* NEW: Dispatch is now a combination of these different dispatch types */ +// declare export type Dispatch = PlainDispatch & ThunkDispatch & PromiseDispatch; + +// declare export type MiddlewareAPI = { +// dispatch: Dispatch; +// getState(): S; +// }; + +// declare export type Store = { +// // rewrite MiddlewareAPI members in order to get nicer error messages (intersections produce long messages) +// dispatch: Dispatch; +// getState(): S; +// subscribe(listener: () => void): () => void; +// replaceReducer(nextReducer: Reducer): void +// }; + +// declare type Reducer = (state: S, action: A) => S; + +// declare export type Middleware = +// (api: MiddlewareAPI) => +// (next: Dispatch) => Dispatch; + +// declare type StoreCreator = { +// (reducer: Reducer, enhancer?: StoreEnhancer): Store; +// (reducer: Reducer, preloadedState: S, enhancer?: StoreEnhancer): Store; +// }; + +// declare type StoreEnhancer = (next: StoreCreator) => StoreCreator; + +// declare function createStore(reducer: Reducer, enhancer?: StoreEnhancer): Store; +// declare function createStore(reducer: Reducer, preloadedState: S, enhancer?: StoreEnhancer): Store; + +// declare function applyMiddleware(...middlewares: Array>): StoreEnhancer; + +// declare type ActionCreator = (...args: Array) => A; +// declare type ActionCreators = { [key: K]: ActionCreator }; + +// declare function bindActionCreators>(actionCreator: C, dispatch: Dispatch): C; +// declare function bindActionCreators>(actionCreators: C, dispatch: Dispatch): C; + +// declare function combineReducers(reducers: O): Reducer<$ObjMap(r: Reducer) => S>, A>; + +// declare function compose(...fns: Array>): 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 = (action: A) => A; + // declare export type Dispatch }> = DispatchAPI; + + declare export type ThunkAction = (dispatch: Dispatch, getState: () => S) => Promise | void; + declare export type ThunkDispatch = (action: ThunkAction) => void; + + declare export type PlainDispatch}> = DispatchAPI; + /* NEW: Dispatch is now a combination of these different dispatch types */ + declare export type Dispatch = PlainDispatch & ThunkDispatch; + + // declare export type ThunkAction = (dispatch: D, getState: () => S) => Promise | void; + // declare type ThunkDispatch = (action: ThunkAction>) => void; + + declare export type MiddlewareAPI = { + dispatch: Dispatch; + getState(): S; + }; + + declare export type Store> = { + // 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): void + }; + + declare export type Reducer = (state: S | void, action: A) => S; + + declare export type CombinedReducer = (state: $Shape & {} | void, action: A) => S; + + declare export type Middleware = + (api: MiddlewareAPI) => + (next: PlainDispatch) => PlainDispatch; + + declare export type StoreCreator> = { + (reducer: Reducer, enhancer?: StoreEnhancer): Store; + (reducer: Reducer, preloadedState: S, enhancer?: StoreEnhancer): Store; + }; + + declare export type StoreEnhancer> = (next: StoreCreator) => StoreCreator; + + declare export function createStore(reducer: Reducer, enhancer?: StoreEnhancer): Store; + declare export function createStore(reducer: Reducer, preloadedState?: S, enhancer?: StoreEnhancer): Store; + + declare export function applyMiddleware(...middlewares: Array>): StoreEnhancer; + + declare export type ActionCreator = (...args: Array) => A; + declare export type ActionCreators = { [key: K]: ActionCreator }; + + declare export function bindActionCreators, D: DispatchAPI>(actionCreator: C, dispatch: D): C; + declare export function bindActionCreators, D: DispatchAPI>(actionCreators: C, dispatch: D): C; + // declare export function bindActionCreators, D: Dispatch>(actionCreator: C, dispatch: D): C; + // declare export function bindActionCreators, D: Dispatch>(actionCreators: C, dispatch: D): C; + + declare export function combineReducers(reducers: O): CombinedReducer<$ObjMap(r: Reducer) => S>, A>; + + declare export var compose: $Compose; + } + \ No newline at end of file diff --git a/src/js/reducers/AccountsReducer.js b/src/js/reducers/AccountsReducer.js index 7a1c236d..de1d2f9c 100644 --- a/src/js/reducers/AccountsReducer.js +++ b/src/js/reducers/AccountsReducer.js @@ -15,7 +15,7 @@ export type Account = { loaded: boolean; +network: string; +deviceID: string; - +deviceState: ?string; + +deviceState: string; +index: number; +addressPath: Array; +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, diff --git a/src/js/reducers/ModalReducer.js b/src/js/reducers/ModalReducer.js index 295901de..e1e9f812 100644 --- a/src/js/reducers/ModalReducer.js +++ b/src/js/reducers/ModalReducer.js @@ -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; - windowType: ?string; + opened: false; +} | { + opened: true; + device: TrezorDevice; + instances?: Array; + 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; diff --git a/src/js/reducers/TokensReducer.js b/src/js/reducers/TokensReducer.js index 77b6304b..b6262199 100644 --- a/src/js/reducers/TokensReducer.js +++ b/src/js/reducers/TokensReducer.js @@ -13,7 +13,7 @@ export type Token = { +symbol: string; +address: string; +ethAddress: string; // foreign key - +decimals: string; + +decimals: number; balance: string; } diff --git a/src/js/services/RouterService.js b/src/js/services/RouterService.js index 58f94f12..522fc111 100644 --- a/src/js/services/RouterService.js +++ b/src/js/services/RouterService.js @@ -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; } diff --git a/src/js/services/TrezorConnectService.js b/src/js/services/TrezorConnectService.js index 9884b4d3..65f3ea84 100644 --- a/src/js/services/TrezorConnectService.js +++ b/src/js/services/TrezorConnectService.js @@ -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 ) );