Refresh on Network Change (#261)
* configure gitignore * create CONFIG_NODE_CHANGE_INTENT action, action creator, and type * pass changeNodeIntent intstead of changeNode to Header * create saga for handling node changes that will refresh only when network changes
This commit is contained in:
parent
aefb155b82
commit
a06298afa1
|
@ -52,3 +52,6 @@ dll
|
||||||
webpack_config/server.key
|
webpack_config/server.key
|
||||||
webpack_config/server.crt
|
webpack_config/server.crt
|
||||||
webpack_config/server.csr
|
webpack_config/server.csr
|
||||||
|
|
||||||
|
|
||||||
|
v8-compile-cache-0/
|
||||||
|
|
|
@ -24,3 +24,13 @@ export function changeGasPrice(value: number): interfaces.ChangeGasPriceAction {
|
||||||
value
|
value
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type TChangeNodeIntent = typeof changeNodeIntent;
|
||||||
|
export function changeNodeIntent(
|
||||||
|
payload: string
|
||||||
|
): interfaces.ChangeNodeIntentAction {
|
||||||
|
return {
|
||||||
|
type: TypeKeys.CONFIG_NODE_CHANGE_INTENT,
|
||||||
|
payload
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { TypeKeys } from './constants';
|
import { TypeKeys } from './constants';
|
||||||
|
|
||||||
/*** Change Language ***/
|
/*** Change Language ***/
|
||||||
export interface ChangeLanguageAction {
|
export interface ChangeLanguageAction {
|
||||||
type: TypeKeys.CONFIG_LANGUAGE_CHANGE;
|
type: TypeKeys.CONFIG_LANGUAGE_CHANGE;
|
||||||
|
@ -18,8 +19,15 @@ export interface ChangeGasPriceAction {
|
||||||
value: number;
|
value: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*** Change Node ***/
|
||||||
|
export interface ChangeNodeIntentAction {
|
||||||
|
type: TypeKeys.CONFIG_NODE_CHANGE_INTENT;
|
||||||
|
payload: string;
|
||||||
|
}
|
||||||
|
|
||||||
/*** Union Type ***/
|
/*** Union Type ***/
|
||||||
export type ConfigAction =
|
export type ConfigAction =
|
||||||
| ChangeNodeAction
|
| ChangeNodeAction
|
||||||
| ChangeLanguageAction
|
| ChangeLanguageAction
|
||||||
| ChangeGasPriceAction;
|
| ChangeGasPriceAction
|
||||||
|
| ChangeNodeIntentAction;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
export enum TypeKeys {
|
export enum TypeKeys {
|
||||||
CONFIG_LANGUAGE_CHANGE = 'CONFIG_LANGUAGE_CHANGE',
|
CONFIG_LANGUAGE_CHANGE = 'CONFIG_LANGUAGE_CHANGE',
|
||||||
CONFIG_NODE_CHANGE = 'CONFIG_NODE_CHANGE',
|
CONFIG_NODE_CHANGE = 'CONFIG_NODE_CHANGE',
|
||||||
|
CONFIG_NODE_CHANGE_INTENT = 'CONFIG_NODE_CHANGE_INTENT',
|
||||||
CONFIG_GAS_PRICE = 'CONFIG_GAS_PRICE'
|
CONFIG_GAS_PRICE = 'CONFIG_GAS_PRICE'
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
import { TChangeGasPrice, TChangeLanguage, TChangeNode } from 'actions/config';
|
import {
|
||||||
|
TChangeGasPrice,
|
||||||
|
TChangeLanguage,
|
||||||
|
TChangeNodeIntent
|
||||||
|
} from 'actions/config';
|
||||||
import logo from 'assets/images/logo-myetherwallet.svg';
|
import logo from 'assets/images/logo-myetherwallet.svg';
|
||||||
import { Dropdown, ColorDropdown } from 'components/ui';
|
import { Dropdown, ColorDropdown } from 'components/ui';
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
|
@ -22,13 +26,13 @@ interface Props {
|
||||||
gasPriceGwei: number;
|
gasPriceGwei: number;
|
||||||
|
|
||||||
changeLanguage: TChangeLanguage;
|
changeLanguage: TChangeLanguage;
|
||||||
changeNode: TChangeNode;
|
changeNodeIntent: TChangeNodeIntent;
|
||||||
changeGasPrice: TChangeGasPrice;
|
changeGasPrice: TChangeGasPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Header extends Component<Props, {}> {
|
export default class Header extends Component<Props, {}> {
|
||||||
public render() {
|
public render() {
|
||||||
const { languageSelection, changeNode, nodeSelection } = this.props;
|
const { languageSelection, changeNodeIntent, nodeSelection } = this.props;
|
||||||
const selectedLanguage = languageSelection;
|
const selectedLanguage = languageSelection;
|
||||||
const selectedNode = NODES[nodeSelection];
|
const selectedNode = NODES[nodeSelection];
|
||||||
const selectedNetwork = NETWORKS[selectedNode.network];
|
const selectedNetwork = NETWORKS[selectedNode.network];
|
||||||
|
@ -114,7 +118,7 @@ export default class Header extends Component<Props, {}> {
|
||||||
<a>Add Custom Node</a>
|
<a>Add Custom Node</a>
|
||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
onChange={changeNode}
|
onChange={changeNodeIntent}
|
||||||
size="smr"
|
size="smr"
|
||||||
color="white"
|
color="white"
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import {
|
import {
|
||||||
changeGasPrice as dChangeGasPrice,
|
changeGasPrice as dChangeGasPrice,
|
||||||
changeLanguage as dChangeLanguage,
|
changeLanguage as dChangeLanguage,
|
||||||
changeNode as dChangeNode,
|
changeNodeIntent as dChangeNodeIntent,
|
||||||
TChangeGasPrice,
|
TChangeGasPrice,
|
||||||
TChangeLanguage,
|
TChangeLanguage,
|
||||||
TChangeNode
|
TChangeNodeIntent
|
||||||
} from 'actions/config';
|
} from 'actions/config';
|
||||||
import { AlphaAgreement, Footer, Header } from 'components';
|
import { AlphaAgreement, Footer, Header } from 'components';
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
|
@ -21,7 +21,7 @@ interface Props {
|
||||||
gasPriceGwei: number;
|
gasPriceGwei: number;
|
||||||
|
|
||||||
changeLanguage: TChangeLanguage;
|
changeLanguage: TChangeLanguage;
|
||||||
changeNode: TChangeNode;
|
changeNodeIntent: TChangeNodeIntent;
|
||||||
changeGasPrice: TChangeGasPrice;
|
changeGasPrice: TChangeGasPrice;
|
||||||
}
|
}
|
||||||
class TabSection extends Component<Props, {}> {
|
class TabSection extends Component<Props, {}> {
|
||||||
|
@ -34,7 +34,7 @@ class TabSection extends Component<Props, {}> {
|
||||||
gasPriceGwei,
|
gasPriceGwei,
|
||||||
|
|
||||||
changeLanguage,
|
changeLanguage,
|
||||||
changeNode,
|
changeNodeIntent,
|
||||||
changeGasPrice
|
changeGasPrice
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class TabSection extends Component<Props, {}> {
|
||||||
gasPriceGwei,
|
gasPriceGwei,
|
||||||
|
|
||||||
changeLanguage,
|
changeLanguage,
|
||||||
changeNode,
|
changeNodeIntent,
|
||||||
changeGasPrice
|
changeGasPrice
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -73,5 +73,5 @@ function mapStateToProps(state: AppState) {
|
||||||
export default connect(mapStateToProps, {
|
export default connect(mapStateToProps, {
|
||||||
changeGasPrice: dChangeGasPrice,
|
changeGasPrice: dChangeGasPrice,
|
||||||
changeLanguage: dChangeLanguage,
|
changeLanguage: dChangeLanguage,
|
||||||
changeNode: dChangeNode
|
changeNodeIntent: dChangeNodeIntent
|
||||||
})(TabSection);
|
})(TabSection);
|
||||||
|
|
|
@ -1,13 +1,26 @@
|
||||||
import { SagaIterator } from 'redux-saga';
|
import { SagaIterator } from 'redux-saga';
|
||||||
import { takeEvery } from 'redux-saga/effects';
|
import { call, put, select, takeEvery } from 'redux-saga/effects';
|
||||||
|
import { changeNode } from 'actions/config';
|
||||||
|
import { NODES } from 'config/data';
|
||||||
|
|
||||||
|
import { getNodeConfig } from 'selectors/config';
|
||||||
// @HACK For now we reload the app when doing a language swap to force non-connected
|
// @HACK For now we reload the app when doing a language swap to force non-connected
|
||||||
// data to reload. Also the use of timeout to avoid using additional actions for now.
|
// data to reload. Also the use of timeout to avoid using additional actions for now.
|
||||||
function* reload(): SagaIterator {
|
function* reload(): SagaIterator {
|
||||||
setTimeout(() => location.reload(), 250);
|
setTimeout(() => location.reload(), 250);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function* handleNodeChangeIntent(action): SagaIterator {
|
||||||
|
const nodeConfig = yield select(getNodeConfig);
|
||||||
|
const currentNetwork = nodeConfig.network;
|
||||||
|
const actionNetwork = NODES[action.payload].network;
|
||||||
|
yield put(changeNode(action.payload));
|
||||||
|
if (currentNetwork !== actionNetwork) {
|
||||||
|
yield call(reload);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default function* handleConfigChanges(): SagaIterator {
|
export default function* handleConfigChanges(): SagaIterator {
|
||||||
yield takeEvery('CONFIG_NODE_CHANGE', reload);
|
yield takeEvery('CONFIG_NODE_CHANGE_INTENT', handleNodeChangeIntent);
|
||||||
yield takeEvery('CONFIG_LANGUAGE_CHANGE', reload);
|
yield takeEvery('CONFIG_LANGUAGE_CHANGE', reload);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue