From 3512c271e21e126ab8bdb8458083be5c29e8011d Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Fri, 5 Oct 2018 09:03:51 +0200 Subject: [PATCH] FirmwareUpdate: notification button click + "cancel" action conditionally --- src/actions/RouterActions.js | 8 +++- .../App/components/UpdateFirmware/index.js | 6 +-- .../Wallet/views/FirmwareUpdate/index.js | 42 +++++++++++++++---- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/actions/RouterActions.js b/src/actions/RouterActions.js index 1c1c91eb..e1101652 100644 --- a/src/actions/RouterActions.js +++ b/src/actions/RouterActions.js @@ -320,9 +320,13 @@ export const gotoBridgeUpdate = (): ThunkAction => (dispatch: Dispatch): void => /* * Go to UpdateFirmware page +* Called from App notification */ -export const gotoFirmwareUpdate = (): ThunkAction => (dispatch: Dispatch): void => { - dispatch(goto('/firmware-update')); +export const gotoFirmwareUpdate = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => { + const { selectedDevice } = getState().wallet; + if (!selectedDevice || !selectedDevice.features) return; + const devUrl: string = `${selectedDevice.features.device_id}${selectedDevice.instance ? `:${selectedDevice.instance}` : ''}`; + dispatch(goto(`/device/${devUrl}/firmware-update`)); }; /* diff --git a/src/components/notifications/App/components/UpdateFirmware/index.js b/src/components/notifications/App/components/UpdateFirmware/index.js index 94d2e74a..c14c9e29 100644 --- a/src/components/notifications/App/components/UpdateFirmware/index.js +++ b/src/components/notifications/App/components/UpdateFirmware/index.js @@ -14,10 +14,8 @@ export default (props: Props) => { title="Firmware update" actions={ [{ - label: 'Read more', - callback: async () => { - - }, + label: 'Update', + callback: props.routerActions.gotoFirmwareUpdate, }] } /> diff --git a/src/views/Wallet/views/FirmwareUpdate/index.js b/src/views/Wallet/views/FirmwareUpdate/index.js index 10f82440..21ae031e 100644 --- a/src/views/Wallet/views/FirmwareUpdate/index.js +++ b/src/views/Wallet/views/FirmwareUpdate/index.js @@ -1,13 +1,32 @@ +/* @flow */ + import React from 'react'; +import { bindActionCreators } from 'redux'; +import { connect } from 'react-redux'; +import { NavLink } from 'react-router-dom'; + import styled from 'styled-components'; import { H1 } from 'components/Heading'; import P from 'components/Paragraph'; import colors from 'config/colors'; import Link from 'components/Link'; import Button from 'components/Button'; -import { connect } from 'react-redux'; -import { NavLink } from 'react-router-dom'; + import { FONT_SIZE } from 'config/variables'; +import * as deviceUtils from 'utils/device'; + +import * as RouterActions from 'actions/RouterActions'; + +import type { + TrezorDevice, + State, + Dispatch, +} from 'flowtype'; + +type Props = { + device: ?TrezorDevice; + cancel: typeof RouterActions.selectFirstAvailableDevice, +} const Wrapper = styled.section` display: flex; @@ -31,7 +50,7 @@ const StyledP = styled(P)` padding: 0 0 15px 0; `; -const FirmwareUpdate = () => ( +const FirmwareUpdate = (props: Props) => ( @@ -114,10 +133,19 @@ const FirmwareUpdate = () => ( - - I’ll do that later. - + {deviceUtils.isDeviceAccessible(props.device) && ( + + I’ll do that later. + + )} ); -export default connect(null, null)(FirmwareUpdate); +export default connect( + (state: State) => ({ + device: state.wallet.selectedDevice, + }), + (dispatch: Dispatch) => ({ + cancel: bindActionCreators(RouterActions.selectFirstAvailableDevice, dispatch), + }), +)(FirmwareUpdate);