change "if" to "switch"

pull/260/head
Szymon Lesisz 6 years ago
parent 6d3722c493
commit 128d238037

@ -51,10 +51,14 @@ export const subscribe = (networkName: string): PromiseAction<void> => async (di
const network = config.networks.find(c => c.shortcut === networkName);
if (!network) return;
if (network.type === 'ethereum') {
await dispatch(EthereumBlockchainActions.subscribe(networkName));
} else if (network.type === 'ripple') {
await dispatch(RippleBlockchainActions.subscribe(networkName));
switch (network.type) {
case 'ethereum':
await dispatch(EthereumBlockchainActions.subscribe(networkName));
break;
case 'ripple':
await dispatch(RippleBlockchainActions.subscribe(networkName));
break;
default: break;
}
};
@ -66,10 +70,14 @@ export const onBlockMined = (payload: $ElementType<BlockchainBlock, 'payload'>):
const network = config.networks.find(c => c.shortcut === shortcut);
if (!network) return;
if (network.type === 'ethereum') {
await dispatch(EthereumBlockchainActions.onBlockMined(shortcut));
} else if (network.type === 'ripple') {
await dispatch(RippleBlockchainActions.onBlockMined(shortcut));
switch (network.type) {
case 'ethereum':
await dispatch(EthereumBlockchainActions.onBlockMined(shortcut));
break;
case 'ripple':
await dispatch(RippleBlockchainActions.onBlockMined(shortcut));
break;
default: break;
}
};
@ -79,10 +87,15 @@ export const onNotification = (payload: $ElementType<BlockchainNotification, 'pa
const network = config.networks.find(c => c.shortcut === shortcut);
if (!network) return;
if (network.type === 'ethereum') {
await dispatch(EthereumBlockchainActions.onNotification());
} else if (network.type === 'ripple') {
await dispatch(RippleBlockchainActions.onNotification(payload));
switch (network.type) {
case 'ethereum':
// this is not working until blockchain-link will start support blockbook backends
await dispatch(EthereumBlockchainActions.onNotification());
break;
case 'ripple':
await dispatch(RippleBlockchainActions.onNotification(payload));
break;
default: break;
}
};
@ -94,9 +107,14 @@ export const onError = (payload: $ElementType<BlockchainError, 'payload'>): Prom
const network = config.networks.find(c => c.shortcut === shortcut);
if (!network) return;
if (network.type === 'ethereum') {
await dispatch(EthereumBlockchainActions.onError(shortcut));
} else if (network.type === 'ripple') {
// await dispatch(RippleBlockchainActions.onError(shortcut));
switch (network.type) {
case 'ethereum':
await dispatch(EthereumBlockchainActions.onError(shortcut));
break;
case 'ripple':
// this error is handled in BlockchainReducer
// await dispatch(RippleBlockchainActions.onBlockMined(shortcut));
break;
default: break;
}
};

@ -131,12 +131,15 @@ const begin = (device: TrezorDevice, networkName: string): AsyncAction => async
let startAction: DiscoveryStartAction;
try {
if (network.type === 'ethereum') {
startAction = await dispatch(EthereumDiscoveryActions.begin(device, network));
} else if (network.type === 'ripple') {
startAction = await dispatch(RippleDiscoveryActions.begin(device, network));
} else {
throw new Error(`DiscoveryActions.begin: Unknown network type: ${network.type}`);
switch (network.type) {
case 'ethereum':
startAction = await dispatch(EthereumDiscoveryActions.begin(device, network));
break;
case 'ripple':
startAction = await dispatch(RippleDiscoveryActions.begin(device, network));
break;
default:
throw new Error(`DiscoveryActions.begin: Unknown network type: ${network.type}`);
}
} catch (error) {
dispatch({
@ -180,12 +183,15 @@ const discoverAccount = (device: TrezorDevice, discoveryProcess: Discovery): Asy
const { completed, accountIndex } = discoveryProcess;
let account: Account;
try {
if (network.type === 'ethereum') {
account = await dispatch(EthereumDiscoveryActions.discoverAccount(device, discoveryProcess));
} else if (network.type === 'ripple') {
account = await dispatch(RippleDiscoveryActions.discoverAccount(device, discoveryProcess));
} else {
throw new Error(`DiscoveryActions.discoverAccount: Unknown network type: ${network.type}`);
switch (network.type) {
case 'ethereum':
account = await dispatch(EthereumDiscoveryActions.discoverAccount(device, discoveryProcess));
break;
case 'ripple':
account = await dispatch(RippleDiscoveryActions.discoverAccount(device, discoveryProcess));
break;
default:
throw new Error(`DiscoveryActions.discoverAccount: Unknown network type: ${network.type}`);
}
} catch (error) {
// handle not supported firmware error

@ -73,13 +73,19 @@ export const showAddress = (path: Array<number>): AsyncAction => async (dispatch
};
let response;
if (network.type === 'ethereum') {
response = await TrezorConnect.ethereumGetAddress(params);
} else {
response = await TrezorConnect.rippleGetAddress(params);
switch (network.type) {
case 'ethereum':
response = await TrezorConnect.ethereumGetAddress(params);
break;
case 'ripple':
response = await TrezorConnect.rippleGetAddress(params);
break;
default:
response = { payload: { error: `ReceiveActions.showAddress: Unknown network type: ${network.type}` } };
break;
}
if (response && response.success) {
if (response.success) {
dispatch({
type: RECEIVE.SHOW_ADDRESS,
});

@ -89,8 +89,14 @@ const getDeviceContextModal = (props: Props) => {
return <PassphraseType device={modal.device} />;
case 'ButtonRequest_SignTx': {
const sendForm = props.selectedAccount.network && props.selectedAccount.network.type === 'ethereum' ? props.sendFormEthereum : props.sendFormRipple;
return <ConfirmSignTx device={modal.device} sendForm={sendForm} />;
if (!props.selectedAccount.network) return null;
switch (props.selectedAccount.network.type) {
case 'ethereum':
return <ConfirmSignTx device={modal.device} sendForm={props.sendFormEthereum} />;
case 'ripple':
return <ConfirmSignTx device={modal.device} sendForm={props.sendFormRipple} />;
default: return null;
}
}
case 'ButtonRequest_ProtectCall':

Loading…
Cancel
Save