I'm still struggling with Drizzle, trying to dispatch my own action. Based on the Drizzle box, I added the following to HomeContainer:
import Home from './Home';
import {drizzleConnect} from 'drizzle-react';
import * as actions from '../../store/actions/actions';
// May still need this even with data function to refresh component on updates for this contract.
const mapStateToProps = state => {
return {
accounts: state.accounts,
SimpleStorage: state.contracts.SimpleStorage,
TutorialToken: state.contracts.TutorialToken,
Series: state.contracts.Series,
drizzleStatus: state.drizzleStatus,
rates: state.rates.ethRate
}
};
const mapDispatchToProps = dispatch => {
return {
onGetEthRate: (fiatSymbol) => {console.log(dispatch); dispatch(actions.getEthRate(fiatSymbol));}
};
};
const HomeContainer = drizzleConnect(Home, mapStateToProps, mapDispatchToProps);
export default HomeContainer;
The getEthRate action creator looks like this:
export const getEthRate = (fiatSymbol) => {
console.log("Getting ETH rate for " + fiatSymbol);
return {
type: actionTypes.GET_ETH_RATE,
fiatSymbol: fiatSymbol
};
};
And then I registered a saga to process that action in rootSaga.js:
export default function* root() {
yield all(
drizzleSagas.map(saga => fork(saga)),
takeEvery(actionTypes.GET_ETH_RATE, getEthRateSaga)
);
}
But the following saga is never triggered, as I never see the log in the console:
export function* getEthRateSaga(action) {
console.log("Fetching ETH rate for " + action.fiatSymbol);
try {
const response = yield http.get('/price?fsym=ETH&tsyms=' + action.fiatSymbol);
const rate = response.data[action.fiatSymbol];
yield put(actions.updateEthRate(action.fiatSymbol, rate));
} catch(error) {
console.error(error);
}
}
And based on the Redux dev console, the GET_ETH_RATE action is not even dispatched, so I'm wondering if mapDispatchToProps works with drizzleConnect.