diff --git a/src/actions/BlockchainActions.js b/src/actions/BlockchainActions.js index 9dde3442..e0efb270 100644 --- a/src/actions/BlockchainActions.js +++ b/src/actions/BlockchainActions.js @@ -51,10 +51,14 @@ export const subscribe = (networkName: string): PromiseAction => 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): 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 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): 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; } }; \ No newline at end of file diff --git a/src/actions/DiscoveryActions.js b/src/actions/DiscoveryActions.js index fc1636a2..be0ddb03 100644 --- a/src/actions/DiscoveryActions.js +++ b/src/actions/DiscoveryActions.js @@ -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 diff --git a/src/actions/ReceiveActions.js b/src/actions/ReceiveActions.js index a039db9e..116a5c15 100644 --- a/src/actions/ReceiveActions.js +++ b/src/actions/ReceiveActions.js @@ -73,13 +73,19 @@ export const showAddress = (path: Array): 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, }); diff --git a/src/components/modals/index.js b/src/components/modals/index.js index e73bfdbf..1b75af8f 100644 --- a/src/components/modals/index.js +++ b/src/components/modals/index.js @@ -89,8 +89,14 @@ const getDeviceContextModal = (props: Props) => { return ; case 'ButtonRequest_SignTx': { - const sendForm = props.selectedAccount.network && props.selectedAccount.network.type === 'ethereum' ? props.sendFormEthereum : props.sendFormRipple; - return ; + if (!props.selectedAccount.network) return null; + switch (props.selectedAccount.network.type) { + case 'ethereum': + return ; + case 'ripple': + return ; + default: return null; + } } case 'ButtonRequest_ProtectCall':