interactions.js
export const loadAllOrders = async (exchange, dispatch) => {
// Fetch cancelled orders with the "Cancel" event stream
const cancelStream = await exchange.getPastEvents('Cancel', { fromBlock: 0, toBlock: 'latest' })
console.log(cancelStream)
}
我不知道问题是什么
如果您知道,请帮助
对不起,加上Content.js
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { exchangeSelector } from '../store/selectors'
import { loadAllOrders } from '../store/interactions'
class Content extends Component {
componentWillMount() {
this.loadBlockchainData(this.props.dispatch)
}
async loadBlockchainData(dispatch) {
await loadAllOrders(this.props.exchange, dispatch)
}
~~~
function mapStateToProps(state) {
return {
exchange: state.exchangeSelector
}
}
export default connect(mapStateToProps)(Content)
加上新代码
答案 0 :(得分:0)
无法读取未定义的属性“ getPastEvents”。这意味着当您调用函数x
时exchange
是undefined
。
loadAllOrders
因此,您必须像这样将参数传递到async loadBlockchainData(dispatch) {
await loadAllOrders(this.props.exchange, dispatch)
// You can not direct access to this.props with function in Class
// this.props just direct shaft access only in life cycle and render
}
中:
loadBlockchainData
在渲染器中调用此函数:
async loadBlockchainData(exchange, dispatch) {
await loadAllOrders(exchange, dispatch)
}
答案 1 :(得分:0)
可能你已经解决了或者放弃了,;) 但是对于未来的读者,请检查您的选择器文件并确保您的 exchangeSelector 如下所示:
const exchange = state => get(state, 'exchange.contract')
export const exchangeSelector = createSelector(exchange, e => e)
我忘了把 get,它确实在 undefined 中解决了交换....