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); const network = config.networks.find(c => c.shortcut === networkName);
if (!network) return; if (!network) return;
if (network.type === 'ethereum') { switch (network.type) {
await dispatch(EthereumBlockchainActions.subscribe(networkName)); case 'ethereum':
} else if (network.type === 'ripple') { await dispatch(EthereumBlockchainActions.subscribe(networkName));
await dispatch(RippleBlockchainActions.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); const network = config.networks.find(c => c.shortcut === shortcut);
if (!network) return; if (!network) return;
if (network.type === 'ethereum') { switch (network.type) {
await dispatch(EthereumBlockchainActions.onBlockMined(shortcut)); case 'ethereum':
} else if (network.type === 'ripple') { await dispatch(EthereumBlockchainActions.onBlockMined(shortcut));
await dispatch(RippleBlockchainActions.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); const network = config.networks.find(c => c.shortcut === shortcut);
if (!network) return; if (!network) return;
if (network.type === 'ethereum') { switch (network.type) {
await dispatch(EthereumBlockchainActions.onNotification()); case 'ethereum':
} else if (network.type === 'ripple') { // this is not working until blockchain-link will start support blockbook backends
await dispatch(RippleBlockchainActions.onNotification(payload)); 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); const network = config.networks.find(c => c.shortcut === shortcut);
if (!network) return; if (!network) return;
if (network.type === 'ethereum') { switch (network.type) {
await dispatch(EthereumBlockchainActions.onError(shortcut)); case 'ethereum':
} else if (network.type === 'ripple') { await dispatch(EthereumBlockchainActions.onError(shortcut));
// await dispatch(RippleBlockchainActions.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; let startAction: DiscoveryStartAction;
try { try {
if (network.type === 'ethereum') { switch (network.type) {
startAction = await dispatch(EthereumDiscoveryActions.begin(device, network)); case 'ethereum':
} else if (network.type === 'ripple') { startAction = await dispatch(EthereumDiscoveryActions.begin(device, network));
startAction = await dispatch(RippleDiscoveryActions.begin(device, network)); break;
} else { case 'ripple':
throw new Error(`DiscoveryActions.begin: Unknown network type: ${network.type}`); startAction = await dispatch(RippleDiscoveryActions.begin(device, network));
break;
default:
throw new Error(`DiscoveryActions.begin: Unknown network type: ${network.type}`);
} }
} catch (error) { } catch (error) {
dispatch({ dispatch({
@ -180,12 +183,15 @@ const discoverAccount = (device: TrezorDevice, discoveryProcess: Discovery): Asy
const { completed, accountIndex } = discoveryProcess; const { completed, accountIndex } = discoveryProcess;
let account: Account; let account: Account;
try { try {
if (network.type === 'ethereum') { switch (network.type) {
account = await dispatch(EthereumDiscoveryActions.discoverAccount(device, discoveryProcess)); case 'ethereum':
} else if (network.type === 'ripple') { account = await dispatch(EthereumDiscoveryActions.discoverAccount(device, discoveryProcess));
account = await dispatch(RippleDiscoveryActions.discoverAccount(device, discoveryProcess)); break;
} else { case 'ripple':
throw new Error(`DiscoveryActions.discoverAccount: Unknown network type: ${network.type}`); account = await dispatch(RippleDiscoveryActions.discoverAccount(device, discoveryProcess));
break;
default:
throw new Error(`DiscoveryActions.discoverAccount: Unknown network type: ${network.type}`);
} }
} catch (error) { } catch (error) {
// handle not supported firmware error // handle not supported firmware error

@ -73,13 +73,19 @@ export const showAddress = (path: Array<number>): AsyncAction => async (dispatch
}; };
let response; let response;
if (network.type === 'ethereum') { switch (network.type) {
response = await TrezorConnect.ethereumGetAddress(params); case 'ethereum':
} else { response = await TrezorConnect.ethereumGetAddress(params);
response = await TrezorConnect.rippleGetAddress(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({ dispatch({
type: RECEIVE.SHOW_ADDRESS, type: RECEIVE.SHOW_ADDRESS,
}); });

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

Loading…
Cancel
Save