mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-13 20:45:05 +00:00
Fix web3 unset (#1467)
* initial mvp * First functioning pass * Add token balance shim * Add working web3 implementation * Fix tests * Fix tsc errors * Implement token batch splitting * Undo logger change * Fix linting errors * Revert makeconfig change * Add typing to token proxy + use string interpolation * Remove useless parameter * Remove logging * Use type coercion to fix proxied methods * Update shepherd * Update to typescript 2.8.1 * Fix merged typings * Address PR comments * replace myc-shepherd with mycrypto-shepherd * fix web3 nodes not unsetting * Fix tscheck * Strip web3 network prefix from node dropdown
This commit is contained in:
parent
bfc004638f
commit
5e76b9f04c
@ -38,6 +38,7 @@ import {
|
||||
} from 'selectors/config';
|
||||
import { NetworkConfig } from 'types/network';
|
||||
import { connect } from 'react-redux';
|
||||
import { stripWeb3Network } from 'libs/nodes';
|
||||
|
||||
interface DispatchProps {
|
||||
changeLanguage: TChangeLanguage;
|
||||
@ -119,7 +120,7 @@ class Header extends Component<Props, State> {
|
||||
...rest,
|
||||
name: (
|
||||
<span>
|
||||
{label.network} <small>({label.service})</small>
|
||||
{stripWeb3Network(label.network)} <small>({label.service})</small>
|
||||
</span>
|
||||
)
|
||||
};
|
||||
@ -160,7 +161,7 @@ class Header extends Component<Props, State> {
|
||||
color="white"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{console.log(nodeSelection)}
|
||||
<div
|
||||
className={classnames({
|
||||
'Header-branding-right-dropdown': true,
|
||||
|
@ -5,14 +5,19 @@ import Modal, { IButton } from 'components/ui/Modal';
|
||||
import { AppState } from 'reducers';
|
||||
import { resetWallet, TResetWallet } from 'actions/wallet';
|
||||
import translate, { translateRaw } from 'translations';
|
||||
import { TWeb3UnsetNode, web3UnsetNode } from 'actions/config';
|
||||
|
||||
interface Props extends RouteComponentProps<{}> {
|
||||
// State
|
||||
wallet: AppState['wallet']['inst'];
|
||||
// Actions
|
||||
interface DispatchProps {
|
||||
web3UnsetNode: TWeb3UnsetNode;
|
||||
resetWallet: TResetWallet;
|
||||
}
|
||||
|
||||
interface StateProps {
|
||||
wallet: AppState['wallet']['inst'];
|
||||
}
|
||||
|
||||
type Props = DispatchProps & StateProps & RouteComponentProps<{}>;
|
||||
|
||||
interface State {
|
||||
nextLocation: RouteComponentProps<{}>['location'] | null;
|
||||
openModal: boolean;
|
||||
@ -65,6 +70,7 @@ class LogOutPromptClass extends React.Component<Props, State> {
|
||||
private onConfirm = () => {
|
||||
const { nextLocation: next } = this.state;
|
||||
this.props.resetWallet();
|
||||
this.props.web3UnsetNode();
|
||||
this.setState(
|
||||
{
|
||||
openModal: false,
|
||||
@ -84,5 +90,6 @@ function mapStateToProps(state: AppState) {
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, {
|
||||
resetWallet
|
||||
resetWallet,
|
||||
web3UnsetNode
|
||||
})(withRouter<Props>(LogOutPromptClass));
|
||||
|
@ -51,6 +51,8 @@ export const getShepherdManualMode = () =>
|
||||
redux.store.getState().providerBalancer.balancerConfig.manual;
|
||||
export const getShepherdOffline = () =>
|
||||
redux.store.getState().providerBalancer.balancerConfig.offline;
|
||||
export const getShepherdNetwork = () =>
|
||||
redux.store.getState().providerBalancer.balancerConfig.network;
|
||||
|
||||
export const makeWeb3Network = (network: string) => `WEB3_${network}`;
|
||||
export const stripWeb3Network = (network: string) => network.replace('WEB3_', '');
|
||||
|
@ -40,7 +40,8 @@ import {
|
||||
shepherd,
|
||||
shepherdProvider,
|
||||
stripWeb3Network,
|
||||
makeProviderConfig
|
||||
makeProviderConfig,
|
||||
getShepherdNetwork
|
||||
} from 'libs/nodes';
|
||||
|
||||
export function* pollOfflineStatus(): SagaIterator {
|
||||
@ -149,7 +150,7 @@ export function* handleNodeChangeIntent({
|
||||
|
||||
if (isAutoNode(nodeIdToSwitchTo)) {
|
||||
shepherd.auto();
|
||||
if (currentConfig.network !== nextNodeConfig.network) {
|
||||
if (getShepherdNetwork() !== nextNodeConfig.network) {
|
||||
yield apply(shepherd, shepherd.switchNetworks, [nextNodeConfig.network]);
|
||||
}
|
||||
} else {
|
||||
|
@ -13,7 +13,6 @@ import {
|
||||
getNodeId,
|
||||
getStaticAltNodeIdToWeb3,
|
||||
getNetworkNameByChainId,
|
||||
getNetworkConfig,
|
||||
getWeb3Node
|
||||
} from 'selectors/config';
|
||||
import { setupWeb3Node, Web3Service, isWeb3Node } from 'libs/nodes/web3';
|
||||
@ -26,7 +25,6 @@ import {
|
||||
stripWeb3Network,
|
||||
shepherdProvider
|
||||
} from 'libs/nodes';
|
||||
import { NetworkConfig } from 'shared/types/network';
|
||||
import { StaticNodeConfig } from 'shared/types/node';
|
||||
import { showNotification } from 'actions/notifications';
|
||||
import translate from 'translations';
|
||||
@ -108,16 +106,10 @@ export function* unsetWeb3NodeOnWalletEvent(action: SetWalletAction): SagaIterat
|
||||
return;
|
||||
}
|
||||
|
||||
const network: NetworkConfig = yield select(getNetworkConfig);
|
||||
const altNodeId: string = yield select(getStaticAltNodeIdToWeb3);
|
||||
|
||||
if (getShepherdManualMode()) {
|
||||
yield apply(shepherd, shepherd.auto);
|
||||
}
|
||||
yield apply(shepherd, shepherd.switchNetworks, [stripWeb3Network(network.name)]);
|
||||
|
||||
const altNode = yield select(getStaticAltNodeIdToWeb3);
|
||||
// forcefully switch back to a node with the same network as MetaMask/Mist
|
||||
yield put(changeNodeForce(altNode));
|
||||
yield put(changeNodeForce(altNodeId));
|
||||
}
|
||||
|
||||
export function* unsetWeb3Node(): SagaIterator {
|
||||
@ -127,16 +119,10 @@ export function* unsetWeb3Node(): SagaIterator {
|
||||
return;
|
||||
}
|
||||
|
||||
const network: NetworkConfig = yield select(getNetworkConfig);
|
||||
const altNodeId: string = yield select(getStaticAltNodeIdToWeb3);
|
||||
|
||||
if (getShepherdManualMode()) {
|
||||
yield apply(shepherd, shepherd.auto);
|
||||
}
|
||||
yield apply(shepherd, shepherd.switchNetworks, [stripWeb3Network(network.name)]);
|
||||
|
||||
const altNode = yield select(getStaticAltNodeIdToWeb3);
|
||||
// forcefully switch back to a node with the same network as MetaMask/Mist
|
||||
yield put(changeNodeForce(altNode));
|
||||
yield put(changeNodeForce(altNodeId));
|
||||
}
|
||||
|
||||
export const web3 = [
|
||||
|
@ -22,8 +22,7 @@ import {
|
||||
isStaticNodeId,
|
||||
getStaticNodeFromId,
|
||||
getCustomNodeFromId,
|
||||
getStaticAltNodeIdToWeb3,
|
||||
getNetworkConfig
|
||||
getStaticAltNodeIdToWeb3
|
||||
} from 'selectors/config';
|
||||
import { Web3Wallet } from 'libs/wallet';
|
||||
import { showNotification } from 'actions/notifications';
|
||||
@ -270,25 +269,17 @@ describe('handleNodeChangeIntent*', () => {
|
||||
});
|
||||
|
||||
describe('unsetWeb3Node*', () => {
|
||||
const node = 'web3';
|
||||
const alternativeNodeId = 'eth_mycrypto';
|
||||
const mockNodeId = 'web3';
|
||||
const gen = unsetWeb3Node();
|
||||
|
||||
it('should select getNode', () => {
|
||||
expect(gen.next().value).toEqual(select(getNodeId));
|
||||
});
|
||||
|
||||
it('should get the current network', () => {
|
||||
expect(gen.next(node).value).toEqual(select(getNetworkConfig));
|
||||
});
|
||||
|
||||
it('should switch networks', () => {
|
||||
expect(gen.next({ name: '' }).value).toEqual(apply(shepherd, shepherd.switchNetworks, ['']));
|
||||
});
|
||||
|
||||
it('should select an alternative node to web3', () => {
|
||||
// get a 'no visual difference' error here
|
||||
expect(gen.next().value).toEqual(select(getStaticAltNodeIdToWeb3));
|
||||
expect(gen.next(mockNodeId).value).toEqual(select(getStaticAltNodeIdToWeb3));
|
||||
});
|
||||
|
||||
it('should put changeNodeForce', () => {
|
||||
@ -317,14 +308,6 @@ describe('unsetWeb3NodeOnWalletEvent*', () => {
|
||||
expect(gen.next().value).toEqual(select(getNodeId));
|
||||
});
|
||||
|
||||
it('should get the current network', () => {
|
||||
expect(gen.next(mockNodeId).value).toEqual(select(getNetworkConfig));
|
||||
});
|
||||
|
||||
it('should switch networks', () => {
|
||||
expect(gen.next({ name: '' }).value).toEqual(apply(shepherd, shepherd.switchNetworks, ['']));
|
||||
});
|
||||
|
||||
it('should select an alternative node to web3', () => {
|
||||
expect(gen.next(mockNodeId).value).toEqual(select(getStaticAltNodeIdToWeb3));
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user