Skip to content

Commit

Permalink
fix(Refresh): fix refresh from tx list
Browse files Browse the repository at this point in the history
  • Loading branch information
plondon committed Jun 23, 2018
1 parent bff515b commit 87707e4
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default ({ coreSagas }) => {
search: ''
}
yield put(actions.form.initialize('ethTransactions', initialValues))
yield put(actions.core.data.ethereum.fetchTransactions())
yield put(actions.core.data.ethereum.fetchTransactions(true))
} catch (e) {
yield put(actions.logs.logErrorMessage(logLocation, 'initialized', e))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,12 @@ import Loading from './template.loading'
import Success from './template.success'

class Pages extends React.PureComponent {
constructor (props) {
super(props)
this.handleRefresh = this.handleRefresh.bind(this)
}

handleRefresh () {
this.props.actions.initialized()
}

render () {
const { data } = this.props

return data.cata({
Success: (value) => <Success transactions={value} />,
Failure: () => <DataError onClick={() => this.handleRefresh()} />,
Failure: () => <DataError onClick={() => this.props.onRefresh()} />,
Loading: () => <Loading />,
NotAsked: () => <Loading />
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ import { actions } from 'data'
import Content from './template'

class ContentContainer extends React.PureComponent {
constructor (props) {
super(props)
this.handleRefresh = this.handleRefresh.bind(this)
}

componentDidMount () {
this.props.actions.initialized()
this.props.txActions.initialized()
}

handleRefresh () {
this.props.dataActions.fetchData()
this.props.txActions.initialized()
}

render () {
const { actions, empty, pages, search } = this.props
return <Content empty={empty} search={search} pages={pages} actions={actions} />
const { empty, pages, search } = this.props
return <Content empty={empty} search={search} pages={pages} onRefresh={this.handleRefresh} />
}
}

Expand All @@ -22,7 +32,8 @@ const mapStateToProps = state => ({
})

const mapDispatchToProps = (dispatch) => ({
actions: bindActionCreators(actions.components.bchTransactions, dispatch)
dataActions: bindActionCreators(actions.core.data.bch, dispatch),
txActions: bindActionCreators(actions.components.bchTransactions, dispatch)
})

export default connect(mapStateToProps, mapDispatchToProps)(ContentContainer)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Success = props => {
<Wrapper>
{props.empty
? props.search ? <EmptyTx /> : <Empty />
: props.pages.map((value, index) => <Pages key={index} data={value} actions={props.actions} />)
: props.pages.map((value, index) => <Pages key={index} data={value} onRefresh={props.onRefresh} />)
}
</Wrapper>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MenuContainer extends React.PureComponent {
render () {
return this.props.data.cata({
Success: (value) => <Menu accounts={value.data} handleClickReporting={() => this.props.actions.reportClicked()} />,
Failure: (message) => <div>{message}</div>,
Failure: (message) => <div />,
Loading: () => <div />,
NotAsked: () => <div />
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,12 @@ import Loading from './template.loading'
import Success from './template.success'

class Pages extends React.PureComponent {
constructor (props) {
super(props)
this.handleRefresh = this.handleRefresh.bind(this)
}

handleRefresh () {
this.props.actions.initialized()
}

render () {
const { data } = this.props

return data.cata({
Success: (value) => <Success transactions={value} />,
Failure: () => <DataError onClick={() => this.handleRefresh()} />,
Failure: () => <DataError onClick={() => this.props.onRefresh()} />,
Loading: () => <Loading />,
NotAsked: () => <Loading />
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ import { actions } from 'data'
import Content from './template'

class ContentContainer extends React.PureComponent {
constructor (props) {
super(props)
this.handleRefresh = this.handleRefresh.bind(this)
}

componentDidMount () {
this.props.actions.initialized()
this.props.txActions.initialized()
}

handleRefresh () {
this.props.dataActions.fetchData()
this.props.txActions.initialized()
}

render () {
const { actions, empty, pages, search } = this.props
return <Content empty={empty} search={search} pages={pages} actions={actions} />
const { empty, pages, search } = this.props
return <Content empty={empty} search={search} pages={pages} onRefresh={this.handleRefresh} />
}
}

Expand All @@ -22,7 +32,8 @@ const mapStateToProps = state => ({
})

const mapDispatchToProps = (dispatch) => ({
actions: bindActionCreators(actions.components.btcTransactions, dispatch)
dataActions: bindActionCreators(actions.core.data.bitcoin, dispatch),
txActions: bindActionCreators(actions.components.btcTransactions, dispatch)
})

export default connect(mapStateToProps, mapDispatchToProps)(ContentContainer)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Success = props => {
<Wrapper>
{props.empty
? props.search ? <EmptyTx /> : <Empty />
: props.pages.map((value, index) => <Pages key={index} data={value} actions={props.actions} />)
: props.pages.map((value, index) => <Pages key={index} data={value} onRefresh={props.onRefresh} />)
}
</Wrapper>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MenuContainer extends React.PureComponent {
render () {
return this.props.data.cata({
Success: (value) => <Menu accounts={value.data} handleClickReporting={() => this.props.actions.reportClicked()} />,
Failure: (message) => <div>{message}</div>,
Failure: (message) => <div />,
Loading: () => <div />,
NotAsked: () => <div />
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,12 @@ import Loading from './template.loading'
import Success from './template.success'

class Pages extends React.PureComponent {
constructor (props) {
super(props)
this.handleRefresh = this.handleRefresh.bind(this)
}

handleRefresh () {
this.props.actions.initialized()
}

render () {
const { data } = this.props

return data.cata({
Success: (value) => <Success transactions={value} />,
Failure: () => <DataError onClick={() => this.handleRefresh()} />,
Failure: () => <DataError onClick={() => this.props.onRefresh()} />,
Loading: () => <Loading />,
NotAsked: () => <Loading />
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,31 @@ import { actions } from 'data'
import Content from './template'

class ContentContainer extends React.PureComponent {
constructor (props) {
super(props)
this.handleRefresh = this.handleRefresh.bind(this)
}

componentDidMount () {
this.props.actions.initialized()
this.props.txActions.initialized()
}

render () {
const { actions, empty, pages, search } = this.props
handleRefresh () {
this.props.dataActions.fetchData()
this.props.txActions.initialized()
}

return <Content empty={empty} search={search} pages={pages} actions={actions} />
render () {
const { empty, pages, search } = this.props
return <Content empty={empty} search={search} pages={pages} onRefresh={this.handleRefresh} />
}
}

const mapStateToProps = state => getData(state)

const mapDispatchToProps = (dispatch) => ({
actions: bindActionCreators(actions.components.ethTransactions, dispatch)
dataActions: bindActionCreators(actions.core.data.ethereum, dispatch),
txActions: bindActionCreators(actions.components.ethTransactions, dispatch)
})

export default connect(mapStateToProps, mapDispatchToProps)(ContentContainer)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Success = props => {
<Wrapper>
{props.empty
? props.search ? <EmptyTx /> : <Empty />
: props.pages.map((value, index) => <Pages key={index} data={value} actions={props.actions} />)
: props.pages.map((value, index) => <Pages key={index} data={value} onRefresh={props.onRefresh} />)
}
</Wrapper>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const fetchRatesSuccess = (data) => ({ type: AT.FETCH_ETHEREUM_RATES_SUCC
export const fetchRatesFailure = (error) => ({ type: AT.FETCH_ETHEREUM_RATES_FAILURE, payload: error })

// FETCH_ETHEREUM_TRANSACTIONS
export const fetchTransactions = () => ({ type: AT.FETCH_ETHEREUM_TRANSACTIONS })
export const fetchTransactions = (reset) => ({ type: AT.FETCH_ETHEREUM_TRANSACTIONS, payload: { reset } })
export const fetchTransactionsLoading = (reset) => ({ type: AT.FETCH_ETHEREUM_TRANSACTIONS_LOADING, payload: { reset } })
export const fetchTransactionsSuccess = (transactions, reset) => ({ type: AT.FETCH_ETHEREUM_TRANSACTIONS_SUCCESS, payload: { transactions, reset } })
export const fetchTransactionsFailure = (error) => ({ type: AT.FETCH_ETHEREUM_TRANSACTIONS_FAILURE, payload: error })
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,19 @@ export default ({ api }) => {
}
}

const fetchTransactions = function * ({ type, payload }) {
const fetchTransactions = function * (action) {
try {
const { payload } = action
const { reset } = payload
const defaultAccountR = yield select(selectors.kvStore.ethereum.getContext)
const address = defaultAccountR.getOrFail('Could not get ethereum context.')
const pages = yield select(S.getTransactions)
const nextPage = length(pages)
yield put(A.fetchTransactionsLoading())
yield put(A.fetchTransactionsLoading(reset))
const data = yield call(api.getEthereumTransactions, address, nextPage)
const txs = path([address, 'txns'], data)
if (isNil(txs)) return
yield put(A.fetchTransactionsSuccess(txs))
yield put(A.fetchTransactionsSuccess(txs, reset))
} catch (e) {
yield put(A.fetchTransactionsFailure(e.message))
}
Expand Down

0 comments on commit 87707e4

Please sign in to comment.