1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-28 03:08:30 +00:00

change "if" to "switch"

This commit is contained in:
Szymon Lesisz 2018-12-11 15:08:02 +01:00
parent 6d3722c493
commit 128d238037
4 changed files with 71 additions and 35 deletions

View File

@ -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) {
case 'ethereum':
await dispatch(EthereumBlockchainActions.subscribe(networkName)); await dispatch(EthereumBlockchainActions.subscribe(networkName));
} else if (network.type === 'ripple') { break;
case 'ripple':
await dispatch(RippleBlockchainActions.subscribe(networkName)); 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) {
case 'ethereum':
await dispatch(EthereumBlockchainActions.onBlockMined(shortcut)); await dispatch(EthereumBlockchainActions.onBlockMined(shortcut));
} else if (network.type === 'ripple') { break;
case 'ripple':
await dispatch(RippleBlockchainActions.onBlockMined(shortcut)); 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) {
case 'ethereum':
// this is not working until blockchain-link will start support blockbook backends
await dispatch(EthereumBlockchainActions.onNotification()); await dispatch(EthereumBlockchainActions.onNotification());
} else if (network.type === 'ripple') { break;
case 'ripple':
await dispatch(RippleBlockchainActions.onNotification(payload)); 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) {
case 'ethereum':
await dispatch(EthereumBlockchainActions.onError(shortcut)); await dispatch(EthereumBlockchainActions.onError(shortcut));
} else if (network.type === 'ripple') { break;
// await dispatch(RippleBlockchainActions.onError(shortcut)); case 'ripple':
// this error is handled in BlockchainReducer
// await dispatch(RippleBlockchainActions.onBlockMined(shortcut));
break;
default: break;
} }
}; };

View File

@ -131,11 +131,14 @@ const begin = (device: TrezorDevice, networkName: string): AsyncAction => async
let startAction: DiscoveryStartAction; let startAction: DiscoveryStartAction;
try { try {
if (network.type === 'ethereum') { switch (network.type) {
case 'ethereum':
startAction = await dispatch(EthereumDiscoveryActions.begin(device, network)); startAction = await dispatch(EthereumDiscoveryActions.begin(device, network));
} else if (network.type === 'ripple') { break;
case 'ripple':
startAction = await dispatch(RippleDiscoveryActions.begin(device, network)); startAction = await dispatch(RippleDiscoveryActions.begin(device, network));
} else { break;
default:
throw new Error(`DiscoveryActions.begin: Unknown network type: ${network.type}`); throw new Error(`DiscoveryActions.begin: Unknown network type: ${network.type}`);
} }
} catch (error) { } catch (error) {
@ -180,11 +183,14 @@ 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) {
case 'ethereum':
account = await dispatch(EthereumDiscoveryActions.discoverAccount(device, discoveryProcess)); account = await dispatch(EthereumDiscoveryActions.discoverAccount(device, discoveryProcess));
} else if (network.type === 'ripple') { break;
case 'ripple':
account = await dispatch(RippleDiscoveryActions.discoverAccount(device, discoveryProcess)); account = await dispatch(RippleDiscoveryActions.discoverAccount(device, discoveryProcess));
} else { break;
default:
throw new Error(`DiscoveryActions.discoverAccount: Unknown network type: ${network.type}`); throw new Error(`DiscoveryActions.discoverAccount: Unknown network type: ${network.type}`);
} }
} catch (error) { } catch (error) {

View File

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

View File

@ -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':