mirror of
https://github.com/status-im/MyCrypto.git
synced 2025-01-19 15:42:41 +00:00
01fc5f1a89
* Start splitting networks into their own reducers * Split out nodes and networks into their own reducers * Cleanup file structure * Make selectors for new state * Change custom network typing * re-type repo * Fix up components to use selectors, work on fixing sagas * Provide consistency in naming, fix more sagas * Get non web3 node switching working * Split config rehydration off into a different file for store * Inline auth for custom nodes * Include typing for app state * moar selectors * Get web3 working + cleanup sagas * Cleanup tsc errors * Use forof loop instead of foreach for clearing pruning custom networks * Add reducer tests for new redux state * Export needed variables * Add console error * Remove old comment * Work on saga tests * Get passing existing saga tests * Fix more tests * Remove irrlevant tests * add console error * Get rest of tests passing * Fix merge errors * Remove random text * Fix store saving * Fix selector lib only grabbing from static nodes * Fix custom node removal crashing app * Infer selected network via node * Prune custom networks properly on node removal * Infer network name from chainid from selecting state * Cleanup tsc errors * Remove MEW nodes for main and testnet
58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
import { TypeKeys as WalletTypeKeys } from 'actions/wallet/constants';
|
|
import { Web3Wallet } from 'libs/wallet';
|
|
import { SagaIterator } from 'redux-saga';
|
|
import { select, put, takeEvery, call } from 'redux-saga/effects';
|
|
import { changeNodeIntent, TypeKeys, web3SetNode } from 'actions/config';
|
|
import { getNodeId, getStaticAltNodeIdToWeb3, getNetworkNameByChainId } from 'selectors/config';
|
|
import { setupWeb3Node, Web3Service } from 'libs/nodes/web3';
|
|
import { Web3NodeConfig } from 'types/node';
|
|
|
|
export function* initWeb3Node(): SagaIterator {
|
|
const { networkId, lib } = yield call(setupWeb3Node);
|
|
const network = yield select(getNetworkNameByChainId, networkId);
|
|
|
|
const config: Web3NodeConfig = {
|
|
isCustom: false,
|
|
network,
|
|
service: Web3Service,
|
|
lib,
|
|
estimateGas: false,
|
|
hidden: true
|
|
};
|
|
|
|
yield put(web3SetNode({ id: 'web3', config }));
|
|
}
|
|
|
|
// unset web3 as the selected node if a non-web3 wallet has been selected
|
|
export function* unsetWeb3NodeOnWalletEvent(action): SagaIterator {
|
|
const node = yield select(getNodeId);
|
|
const newWallet = action.payload;
|
|
const isWeb3Wallet = newWallet instanceof Web3Wallet;
|
|
|
|
if (node !== 'web3' || isWeb3Wallet) {
|
|
return;
|
|
}
|
|
|
|
const altNode = yield select(getStaticAltNodeIdToWeb3);
|
|
// switch back to a node with the same network as MetaMask/Mist
|
|
yield put(changeNodeIntent(altNode));
|
|
}
|
|
|
|
export function* unsetWeb3Node(): SagaIterator {
|
|
const node = yield select(getNodeId);
|
|
|
|
if (node !== 'web3') {
|
|
return;
|
|
}
|
|
|
|
const altNode = yield select(getStaticAltNodeIdToWeb3);
|
|
// switch back to a node with the same network as MetaMask/Mist
|
|
yield put(changeNodeIntent(altNode));
|
|
}
|
|
|
|
export const web3 = [
|
|
takeEvery(TypeKeys.CONFIG_NODE_WEB3_UNSET, unsetWeb3Node),
|
|
takeEvery(WalletTypeKeys.WALLET_SET, unsetWeb3NodeOnWalletEvent),
|
|
takeEvery(WalletTypeKeys.WALLET_RESET, unsetWeb3NodeOnWalletEvent)
|
|
];
|