-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ Update middleware for hwWallet remove login moddleware and add hwW…
…allet
- Loading branch information
Osvaldo Vega
committed
Apr 24, 2019
1 parent
149e750
commit 6c20e0d
Showing
5 changed files
with
82 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import actionTypes from '../../constants/actions'; | ||
import { accountLoggedOut } from '../../actions/account'; | ||
import { dialogDisplayed, dialogHidden } from '../../actions/dialog'; | ||
import { successToastDisplayed, errorToastDisplayed, infoToastDisplayed } from '../../actions/toaster'; | ||
import { HW_MSG } from '../../constants/hwConstants'; | ||
import Alert from '../../components/dialog/alert'; | ||
|
||
const hwWalletMiddleware = store => next => (action) => { | ||
const { ipc } = window; | ||
|
||
if (action.type === actionTypes.storeCreated && ipc) { | ||
const util = require('util'); | ||
|
||
store.dispatch({ | ||
type: actionTypes.settingsUpdated, | ||
data: { isHarwareWalletConnected: false }, | ||
}); | ||
|
||
ipc.on('hwConnected', (event, { model }) => { | ||
store.dispatch({ | ||
type: actionTypes.settingsUpdated, | ||
data: { isHarwareWalletConnected: true }, | ||
}); | ||
|
||
store.dispatch(successToastDisplayed({ label: `${model} connected` })); | ||
}); | ||
|
||
ipc.on('hwDisconnected', (event, { model }) => { | ||
const state = store.getState(); | ||
const { account } = state; | ||
|
||
if (account.address) { | ||
store.dispatch(dialogDisplayed({ | ||
childComponent: Alert, | ||
childComponentProps: { | ||
title: 'You are disconnected', | ||
text: `There is no connection to the ${model}. Please check the cables if it happened by accident.`, | ||
closeDialog: () => { | ||
store.dispatch(dialogHidden()); | ||
location.reload(); // eslint-disable-line | ||
}, | ||
}, | ||
})); | ||
|
||
store.dispatch(accountLoggedOut()); | ||
} | ||
|
||
store.dispatch({ | ||
type: actionTypes.settingsUpdated, | ||
data: { isHarwareWalletConnected: false }, | ||
}); | ||
|
||
store.dispatch(successToastDisplayed({ label: `${model} disconnected` })); | ||
}); | ||
|
||
ipc.on('trezorButtonCallback', (event, data) => { | ||
store.dispatch(infoToastDisplayed({ | ||
label: util.format(HW_MSG.TREZOR_ASK_FOR_CONFIRMATION, data), | ||
})); | ||
}); | ||
|
||
ipc.on('trezorParamMessage', (event, data) => { | ||
store.dispatch(infoToastDisplayed({ label: HW_MSG[data] })); | ||
}); | ||
|
||
ipc.on('trezorError', () => { | ||
store.dispatch(errorToastDisplayed({ label: HW_MSG.ERROR_OR_DEVICE_IS_NOT_CONNECTED })); | ||
}); | ||
} | ||
|
||
next(action); | ||
}; | ||
|
||
export default hwWalletMiddleware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters