1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-13 20:08:56 +00:00

fixed abstractAccount default State

This commit is contained in:
Szymon Lesisz 2018-05-10 18:36:25 +02:00
parent cf863664b7
commit c3079bc8d9
9 changed files with 54 additions and 59 deletions

View File

@ -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();
}
}
}

View File

@ -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<any> => {
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);

View File

@ -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;

View File

@ -52,14 +52,14 @@ export default class AbstractAccount<P> extends Component<Props & P, AccountStat
this.props.abstractAccountActions.update( this.props.initAccount );
const currentState = props.abstractAccount;
const accountState = props.abstractAccount;
if (!accountState) return;
const device = findDevice(props.devices, currentState.deviceState, currentState.deviceId, currentState.deviceInstance);
const device = findDevice(props.devices, accountState.deviceState, accountState.deviceId, accountState.deviceInstance);
if (!device) return;
const discovery = props.discovery.find(d => 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<typeof Notification> = null;
if (account) {
@ -90,9 +90,9 @@ export default class AbstractAccount<P> extends Component<Props & P, AccountStat
render(): ?React$Element<string> {
const props = this.props;
const currentState = props.abstractAccount;
const accountState = props.abstractAccount;
if (!currentState.deviceState) {
if (!accountState) {
return (<section><Notification className="info" title="Loading device" /></section>);
}
@ -105,7 +105,7 @@ export default class AbstractAccount<P> extends Component<Props & P, AccountStat
// const device = findDevice(props.devices, accountState.deviceState, accountState.deviceId, accountState.deviceInstance);
if (!device) {
return (<section>Device with state {currentState.deviceState} not found</section>);
return (<section>Device with state {accountState.deviceState} not found</section>);
}
if (!account) {

View File

@ -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,

View File

@ -28,11 +28,12 @@ const _render = (props: Props, state: AccountState): React$Element<string> => {
discovery,
deviceStatusNotification
} = state;
const abstractAccount = props.abstractAccount;
if (!device || !account || !discovery) return <section></section>;
if (!device || !account || !discovery || !abstractAccount) return <section></section>;
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<string> => {
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 => {

View File

@ -33,10 +33,11 @@ const _render = (props: Props, state: AccountState): React$Element<string> => {
account,
deviceStatusNotification
} = state;
if (!device || !account) return <section></section>;
const abstractAccount = props.abstractAccount;
if (!device || !account || !abstractAccount) return <section></section>;
const tokens = findAccountTokens(props.tokens, account);
const explorerLink: string = `${abstractAccount.coin.explorer.address}${account.address}`;

View File

@ -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<BaseProps, 'abstractAccount'>, 'coin'>,
// coin: $PropertyType<$ElementType<BaseProps, 'abstractAccount'>, 'coin'>,
coin: Coin,
summary: $ElementType<BaseProps, 'summary'>,
balance: string,
network: string,

View File

@ -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) {