update Account page when location changed

pull/2/merge
Szymon Lesisz 6 years ago
parent 9020ecc176
commit f2a7c0c150

@ -48,7 +48,7 @@ export const init = (): ThunkAction => {
} }
} }
export const update = (): ThunkAction => { export const update = (initAccountAction: () => ThunkAction): ThunkAction => {
return (dispatch: Dispatch, getState: GetState): void => { return (dispatch: Dispatch, getState: GetState): void => {
const { const {
abstractAccount, abstractAccount,
@ -57,7 +57,7 @@ export const update = (): ThunkAction => {
const isLocationChanged: boolean = router.location.pathname !== abstractAccount.location; const isLocationChanged: boolean = router.location.pathname !== abstractAccount.location;
if (isLocationChanged) { if (isLocationChanged) {
dispatch( init() ); dispatch( init() );
return; initAccountAction();
} }
} }
} }

@ -39,21 +39,6 @@ export const init = (): ThunkAction => {
} }
} }
export const update = (): ThunkAction => {
return (dispatch: Dispatch, getState: GetState): void => {
const {
abstractAccount,
router
} = getState();
const isLocationChanged: boolean = router.location.pathname !== abstractAccount.location;
if (isLocationChanged) {
dispatch( init() );
}
}
}
export const dispose = (): Action => { export const dispose = (): Action => {
return { return {
type: RECEIVE.DISPOSE type: RECEIVE.DISPOSE
@ -119,7 +104,6 @@ export const showAddress = (address_n: Array<number>): AsyncAction => {
export default { export default {
init, init,
update,
dispose, dispose,
showAddress, showAddress,
showUnverifiedAddress showUnverifiedAddress

@ -211,21 +211,6 @@ export const init = (): ThunkAction => {
} }
} }
export const update = (): ThunkAction => {
return (dispatch: Dispatch, getState: GetState): void => {
const {
abstractAccount,
router
} = getState();
const isLocationChanged: boolean = router.location.pathname !== abstractAccount.location;
if (isLocationChanged) {
dispatch( init() );
return;
}
}
}
export const dispose = (): Action => { export const dispose = (): Action => {
return { return {
type: SEND.DISPOSE type: SEND.DISPOSE
@ -890,7 +875,6 @@ export const onSend = (): AsyncAction => {
export default { export default {
init, init,
update,
dispose, dispose,
toggleAdvanced, toggleAdvanced,

@ -36,22 +36,6 @@ export const init = (): ThunkAction => {
} }
} }
export const update = (): ThunkAction => {
return (dispatch: Dispatch, getState: GetState): void => {
const {
abstractAccount,
router
} = getState();
const isLocationChanged: boolean = router.location.pathname !== abstractAccount.location;
if (isLocationChanged) {
dispatch( init() );
return;
}
}
}
export const dispose = (): Action => { export const dispose = (): Action => {
return { return {
type: SUMMARY.DISPOSE type: SUMMARY.DISPOSE

@ -58,7 +58,7 @@ const _render = (props: Props, state: AccountState): React$Element<string> => {
let address = `${account.address.substring(0, 20)}...`; let address = `${account.address.substring(0, 20)}...`;
let className = 'address hidden'; let className = 'address hidden';
let button = ( let button = (
<button disabled={ !discovery.completed } onClick={ event => props.showAddress(account.addressPath) }> <button disabled={ device.connected && !discovery.completed } onClick={ event => props.showAddress(account.addressPath) }>
<span>Show full address</span> <span>Show full address</span>
</button> </button>
); );
@ -126,7 +126,6 @@ const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps>
return { return {
abstractAccountActions: bindActionCreators(AbstractAccountActions, dispatch), abstractAccountActions: bindActionCreators(AbstractAccountActions, dispatch),
initAccount: bindActionCreators(ReceiveActions.init, dispatch), initAccount: bindActionCreators(ReceiveActions.init, dispatch),
updateAccount: bindActionCreators(ReceiveActions.update, dispatch),
disposeAccount: bindActionCreators(ReceiveActions.dispose, dispatch), disposeAccount: bindActionCreators(ReceiveActions.dispose, dispatch),
showAddress: bindActionCreators(ReceiveActions.showAddress, dispatch), showAddress: bindActionCreators(ReceiveActions.showAddress, dispatch),
}; };

@ -8,7 +8,7 @@ import { findDevice } from '../../../utils/reducerUtils';
// import * as AbstractAccountActions from '../../actions/AbstractAccountActions'; // import * as AbstractAccountActions from '../../actions/AbstractAccountActions';
import { default as AbstractAccountActions } from '../../../actions/AbstractAccountActions'; import { default as AbstractAccountActions } from '../../../actions/AbstractAccountActions';
import type { State, TrezorDevice } from '../../../flowtype'; import type { State, TrezorDevice, Action, ThunkAction } from '../../../flowtype';
import type { Account } from '../../../reducers/AccountsReducer'; import type { Account } from '../../../reducers/AccountsReducer';
import type { Discovery } from '../../../reducers/DiscoveryReducer'; import type { Discovery } from '../../../reducers/DiscoveryReducer';
@ -21,9 +21,8 @@ export type StateProps = {
export type DispatchProps = { export type DispatchProps = {
abstractAccountActions: typeof AbstractAccountActions, abstractAccountActions: typeof AbstractAccountActions,
initAccount: typeof AbstractAccountActions.init, initAccount: () => ThunkAction,
updateAccount: typeof AbstractAccountActions.update, disposeAccount: () => Action,
disposeAccount: typeof AbstractAccountActions.dispose,
} }
export type Props = StateProps & DispatchProps; export type Props = StateProps & DispatchProps;
@ -50,8 +49,8 @@ export default class AbstractAccount<P> extends Component<Props & P, AccountStat
} }
componentWillReceiveProps(props: Props & P) { componentWillReceiveProps(props: Props & P) {
this.props.abstractAccountActions.update();
this.props.updateAccount(); this.props.abstractAccountActions.update( this.props.initAccount );
const currentState = props.abstractAccount; const currentState = props.abstractAccount;

@ -25,9 +25,6 @@ type StateProps = BaseStateProps & {
} }
type DispatchProps = BaseDispatchProps & { type DispatchProps = BaseDispatchProps & {
initAccount: typeof SendFormActions.init,
updateAccount: typeof SendFormActions.update,
disposeAccount: typeof SendFormActions.dispose,
sendFormActions: typeof SendFormActions sendFormActions: typeof SendFormActions
} }
@ -51,8 +48,7 @@ const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps>
return { return {
abstractAccountActions: bindActionCreators(AbstractAccountActions, dispatch), abstractAccountActions: bindActionCreators(AbstractAccountActions, dispatch),
sendFormActions: bindActionCreators(SendFormActions, dispatch), sendFormActions: bindActionCreators(SendFormActions, dispatch),
initAccount: bindActionCreators(SendFormActions.init, dispatch), initAccount: bindActionCreators(SendFormActions.init, dispatch),
updateAccount: bindActionCreators(SendFormActions.update, dispatch),
disposeAccount: bindActionCreators(SendFormActions.dispose, dispatch), disposeAccount: bindActionCreators(SendFormActions.dispose, dispatch),
}; };
} }

@ -25,9 +25,6 @@ type StateProps = BaseStateProps & {
} }
type DispatchProps = BaseDispatchProps & { type DispatchProps = BaseDispatchProps & {
initAccount: typeof SummaryActions.init,
updateAccount: typeof SummaryActions.update,
disposeAccount: typeof SummaryActions.dispose,
onDetailsToggle: typeof SummaryActions.onDetailsToggle, onDetailsToggle: typeof SummaryActions.onDetailsToggle,
addToken: typeof TokenActions.add, addToken: typeof TokenActions.add,
loadTokens: typeof TokenActions.load, loadTokens: typeof TokenActions.load,
@ -54,8 +51,7 @@ const mapDispatchToProps: MapDispatchToProps<Dispatch, OwnProps, DispatchProps>
return { return {
abstractAccountActions: bindActionCreators(AbstractAccountActions, dispatch), abstractAccountActions: bindActionCreators(AbstractAccountActions, dispatch),
initAccount: bindActionCreators(SummaryActions.init, dispatch), initAccount: bindActionCreators(SummaryActions.init, dispatch),
updateAccount: bindActionCreators(SummaryActions.update, dispatch),
disposeAccount: bindActionCreators(SummaryActions.dispose, dispatch), disposeAccount: bindActionCreators(SummaryActions.dispose, dispatch),
onDetailsToggle: bindActionCreators(SummaryActions.onDetailsToggle, dispatch), onDetailsToggle: bindActionCreators(SummaryActions.onDetailsToggle, dispatch),

Loading…
Cancel
Save