2018-03-16 01:29:45 +01:00
|
|
|
const connect = require('react-redux').connect
|
2018-03-22 01:41:47 +01:00
|
|
|
const t = require('../i18n-helper').getMessage
|
2018-03-16 01:29:45 +01:00
|
|
|
|
|
|
|
const metamaskConnect = (mapStateToProps, mapDispatchToProps) => {
|
|
|
|
return connect(
|
|
|
|
_higherOrderMapStateToProps(mapStateToProps),
|
|
|
|
mapDispatchToProps
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const _higherOrderMapStateToProps = (mapStateToProps) => {
|
2018-03-23 17:51:32 +01:00
|
|
|
let _t
|
|
|
|
let currentLocale
|
2018-03-19 19:53:54 +01:00
|
|
|
return (state, ownProps = {}) => {
|
|
|
|
const stateProps = mapStateToProps
|
|
|
|
? mapStateToProps(state, ownProps)
|
|
|
|
: ownProps
|
2018-03-23 17:51:32 +01:00
|
|
|
if (currentLocale !== state.metamask.currentLocale) {
|
|
|
|
currentLocale = state.metamask.currentLocale
|
|
|
|
_t = t.bind(null, state.localeMessages)
|
|
|
|
}
|
|
|
|
stateProps.t = _t
|
2018-03-16 01:29:45 +01:00
|
|
|
return stateProps
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = metamaskConnect
|