diff --git a/src/js/actions/AbstractAccountActions.js b/src/js/actions/AbstractAccountActions.js index 95d228af..b6be9edb 100644 --- a/src/js/actions/AbstractAccountActions.js +++ b/src/js/actions/AbstractAccountActions.js @@ -25,6 +25,7 @@ export const init = (): ThunkAction => { const selected: ?TrezorDevice = findSelectedDevice( getState().connect ); if (!selected) return; + if (!selected.state || !selected.features) return; const { config } = getState().localStorage; const coin: ?Coin = config.coins.find(c => c.network === urlParams.network); @@ -54,10 +55,11 @@ export const update = (initAccountAction: () => ThunkAction): ThunkAction => { abstractAccount, router } = getState(); - const isLocationChanged: boolean = router.location.pathname !== abstractAccount.location; + const isLocationChanged: boolean = (!abstractAccount || router.location.pathname !== abstractAccount.location); if (isLocationChanged) { dispatch( init() ); - initAccountAction(); + if (abstractAccount !== null) + initAccountAction(); } } } diff --git a/src/js/actions/SendFormActions.js b/src/js/actions/SendFormActions.js index f72feeb2..9afdfd75 100644 --- a/src/js/actions/SendFormActions.js +++ b/src/js/actions/SendFormActions.js @@ -159,7 +159,7 @@ export const getFeeLevels = (symbol: string, gasPrice: BigNumber | string, gasLi export const init = (): ThunkAction => { return (dispatch: Dispatch, getState: GetState): void => { - const accountState: AccountState = getState().abstractAccount; + const accountState: ?AccountState = getState().abstractAccount; const { location } = getState().router; const urlParams: RouterLocationState = location.state; @@ -221,7 +221,9 @@ export const toggleAdvanced = (address: string): Action => { export const validation = (): ThunkAction => { return (dispatch: Dispatch, getState: GetState): void => { - const accountState: AccountState = getState().abstractAccount; + const accountState: ?AccountState = getState().abstractAccount; + if (!accountState) return; + const state: State = getState().sendForm; const errors: {[k: string]: string} = {}; @@ -380,7 +382,7 @@ export const onAddressChange = (address: string): ThunkAction => { export const onAmountChange = (amount: string): ThunkAction => { return (dispatch: Dispatch, getState: GetState): void => { - const accountState: AccountState = getState().abstractAccount; + const accountState: ?AccountState = getState().abstractAccount; const currentState: State = getState().sendForm; const isToken: boolean = currentState.selectedCurrency !== currentState.coinSymbol; const touched = { ...currentState.touched }; @@ -406,7 +408,8 @@ export const onAmountChange = (amount: string): ThunkAction => { export const onCurrencyChange = (currency: any): ThunkAction => { return (dispatch: Dispatch, getState: GetState): void => { - const accountState: AccountState = getState().abstractAccount; + const accountState: ?AccountState = getState().abstractAccount; + if (!accountState) return; const currentState: State = getState().sendForm; const isToken: boolean = currency.value !== currentState.coinSymbol; @@ -465,7 +468,8 @@ export const onCurrencyChange = (currency: any): ThunkAction => { export const onSetMax = (): ThunkAction => { return (dispatch: Dispatch, getState: GetState): void => { - const accountState: AccountState = getState().abstractAccount; + const accountState: ?AccountState = getState().abstractAccount; + if (!accountState) return; const currentState: State = getState().sendForm; const isToken: boolean = currentState.selectedCurrency !== currentState.coinSymbol; const touched = { ...currentState.touched }; @@ -510,14 +514,12 @@ export const onSetMax = (): ThunkAction => { export const onFeeLevelChange = (feeLevel: FeeLevel): ThunkAction => { return (dispatch: Dispatch, getState: GetState): void => { - const accountState: AccountState = getState().abstractAccount; + const accountState: ?AccountState = getState().abstractAccount; + if (!accountState) return; const currentState: State = getState().sendForm; const isToken: boolean = currentState.selectedCurrency !== currentState.coinSymbol; - const { config } = getState().localStorage; - if (!config) return; - const coin: ?Coin = config.coins.find(c => c.network === accountState.network); - if (!coin) return; + const coin: Coin = accountState.coin; const state: State = { ...currentState, @@ -563,7 +565,8 @@ export const onFeeLevelChange = (feeLevel: FeeLevel): ThunkAction => { export const updateFeeLevels = (): ThunkAction => { return (dispatch: Dispatch, getState: GetState): void => { - const accountState: AccountState = getState().abstractAccount; + const accountState: ?AccountState = getState().abstractAccount; + if (!accountState) return; const currentState: State = getState().sendForm; const isToken: boolean = currentState.selectedCurrency !== currentState.coinSymbol; @@ -604,7 +607,8 @@ export const updateFeeLevels = (): ThunkAction => { export const onGasPriceChange = (gasPrice: string): ThunkAction => { return (dispatch: Dispatch, getState: GetState): void => { - const accountState: AccountState = getState().abstractAccount; + const accountState: ?AccountState = getState().abstractAccount; + if (!accountState) return; const currentState: State = getState().sendForm; const isToken: boolean = currentState.selectedCurrency !== accountState.network; @@ -652,7 +656,8 @@ export const onGasPriceChange = (gasPrice: string): ThunkAction => { export const onGasLimitChange = (gasLimit: string): ThunkAction => { return (dispatch: Dispatch, getState: GetState): void => { - const accountState: AccountState = getState().abstractAccount; + const accountState: ?AccountState = getState().abstractAccount; + if (!accountState) return; const currentState: State = getState().sendForm; const isToken: boolean = currentState.selectedCurrency !== currentState.coinSymbol; @@ -723,7 +728,9 @@ export const onSend = (): AsyncAction => { //return onSendERC20(); return async (dispatch: Dispatch, getState: GetState): Promise => { - const accountState: AccountState = getState().abstractAccount; + const accountState: ?AccountState = getState().abstractAccount; + if (!accountState) return; + const currentState: State = getState().sendForm; const web3instance: ?Web3Instance = getState().web3.filter(w3 => w3.network === accountState.network)[0]; const account: ?Account = findAccount(getState().accounts, accountState.index, accountState.deviceState, accountState.network); diff --git a/src/js/components/modal/ConfirmAddress.js b/src/js/components/modal/ConfirmAddress.js index 9a5f8c0b..64265942 100644 --- a/src/js/components/modal/ConfirmAddress.js +++ b/src/js/components/modal/ConfirmAddress.js @@ -10,6 +10,7 @@ import type { Props } from './index'; const ConfirmAddress = (props: Props) => { const { accounts, abstractAccount } = props; + if (!abstractAccount) return null; const account = findAccount(accounts, abstractAccount.index, abstractAccount.deviceState, abstractAccount.network); if (!account) return null; @@ -46,6 +47,8 @@ export const ConfirmUnverifiedAddress = (props: Props): any => { showAddress } = props.receiveActions; + if(!abstractAccount) return null; + const account = findAccount(accounts, abstractAccount.index, abstractAccount.deviceState, abstractAccount.network); if (!account) return null; diff --git a/src/js/components/wallet/account/AbstractAccount.js b/src/js/components/wallet/account/AbstractAccount.js index 99d4b774..0915e422 100644 --- a/src/js/components/wallet/account/AbstractAccount.js +++ b/src/js/components/wallet/account/AbstractAccount.js @@ -52,14 +52,14 @@ export default class AbstractAccount

extends Component d.deviceState === device.state && d.network === currentState.network); + const discovery = props.discovery.find(d => d.deviceState === device.state && d.network === accountState.network); // if (!discovery) return; - const account = props.accounts.find(a => a.deviceState === currentState.deviceState && a.index === currentState.index && a.network === currentState.network); - + const account = props.accounts.find(a => a.deviceState === accountState.deviceState && a.index === accountState.index && a.network === accountState.network); let deviceStatusNotification: ?React$Element = null; if (account) { @@ -90,9 +90,9 @@ export default class AbstractAccount

extends Component { const props = this.props; - const currentState = props.abstractAccount; + const accountState = props.abstractAccount; - if (!currentState.deviceState) { + if (!accountState) { return (

); } @@ -105,7 +105,7 @@ export default class AbstractAccount

extends ComponentDevice with state {currentState.deviceState} not found); + return (

Device with state {accountState.deviceState} not found
); } if (!account) { diff --git a/src/js/components/wallet/send/AdvancedForm.js b/src/js/components/wallet/send/AdvancedForm.js index 6515e0f4..1801b966 100644 --- a/src/js/components/wallet/send/AdvancedForm.js +++ b/src/js/components/wallet/send/AdvancedForm.js @@ -8,7 +8,10 @@ import type { Props } from './index'; const AdvancedForm = (props: Props) => { - const { network } = props.abstractAccount; + const abstractAccount = props.abstractAccount; + if (!abstractAccount) return null; + + const { network } = abstractAccount; const { coinSymbol, selectedCurrency, diff --git a/src/js/components/wallet/send/SendForm.js b/src/js/components/wallet/send/SendForm.js index 9522b1a0..9a16567c 100644 --- a/src/js/components/wallet/send/SendForm.js +++ b/src/js/components/wallet/send/SendForm.js @@ -28,11 +28,12 @@ const _render = (props: Props, state: AccountState): React$Element => { discovery, deviceStatusNotification } = state; + const abstractAccount = props.abstractAccount; - if (!device || !account || !discovery) return
; + if (!device || !account || !discovery || !abstractAccount) return
; const tokens = findAccountTokens(props.tokens, account); - const { network } = props.abstractAccount; + const { network } = abstractAccount; const { address, @@ -61,7 +62,7 @@ const _render = (props: Props, state: AccountState): React$Element => { onSend, } = props.sendFormActions; - const selectedCoin = props.abstractAccount.coin; + const selectedCoin = abstractAccount.coin; const fiatRate = props.fiat.find(f => f.network === network); const tokensSelectData = tokens.map(t => { diff --git a/src/js/components/wallet/summary/Summary.js b/src/js/components/wallet/summary/Summary.js index f924f3d2..b06e78b4 100644 --- a/src/js/components/wallet/summary/Summary.js +++ b/src/js/components/wallet/summary/Summary.js @@ -33,10 +33,11 @@ const _render = (props: Props, state: AccountState): React$Element => { account, deviceStatusNotification } = state; + const abstractAccount = props.abstractAccount; - if (!device || !account) return
; + if (!device || !account || !abstractAccount) return
; - const abstractAccount = props.abstractAccount; + const tokens = findAccountTokens(props.tokens, account); const explorerLink: string = `${abstractAccount.coin.explorer.address}${account.address}`; diff --git a/src/js/components/wallet/summary/SummaryDetails.js b/src/js/components/wallet/summary/SummaryDetails.js index 8d5c45c8..ca5981a2 100644 --- a/src/js/components/wallet/summary/SummaryDetails.js +++ b/src/js/components/wallet/summary/SummaryDetails.js @@ -5,9 +5,11 @@ import React from 'react'; import BigNumber from 'bignumber.js'; import type { Props as BaseProps } from './index'; +import type { Coin } from '../../../reducers/LocalStorageReducer'; type Props = { - coin: $PropertyType<$ElementType, 'coin'>, + // coin: $PropertyType<$ElementType, 'coin'>, + coin: Coin, summary: $ElementType, balance: string, network: string, diff --git a/src/js/reducers/AbstractAccountReducer.js b/src/js/reducers/AbstractAccountReducer.js index e5c83454..5c816696 100644 --- a/src/js/reducers/AbstractAccountReducer.js +++ b/src/js/reducers/AbstractAccountReducer.js @@ -14,36 +14,12 @@ export type State = { +deviceInstance: ?number; +network: string; +coin: Coin; - location: string; -} - -export const initialState: State = { - index: 0, - deviceState: '0', - deviceId: '0', - deviceInstance: null, - network: '', - coin: { - name: '', - network: '', - symbol: '', - bip44: '', - defaultGasLimit: 0, - defaultGasLimitTokens: 0, - defaultGasPrice: 0, - explorer: { - tx: '', - address: '' - }, - tokens: '', - backends: [] - }, - location: '', - + +location: string; }; +export const initialState: ?State = null; -export default (state: State = initialState, action: Action): State => { +export default (state: ?State = initialState, action: Action): ?State => { switch (action.type) {