Skip to content

Commit

Permalink
Merge pull request #1809 from CityOfZion/feature/add-polling-to-activity
Browse files Browse the repository at this point in the history
feature: adds polling to activity tab
  • Loading branch information
comountainclimber authored Mar 1, 2019
2 parents 82c883c + 7ee21c8 commit 2c9ada3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`TransactionHistoryPanel renders without crashing 1`] = `
<withData(Connect(withData(withProps(Connect(withActions(Connect(withProgress(withProgressComponents(Connect(withActions(Connect(withActions(Connect(withCall(Connect(withData(Connect(withProgress(withProps(Connect(withData(TransactionHistory))))))))))))))))))))))
<withData(Connect(withData(withProps(Connect(withActions(Connect(withProgress(withProgressComponents(Connect(withActions(Connect(withActions(Connect(withCall(Connect(withData(Connect(withProgress(withProps(Connect(withData(Connect(Connect(withProgress(LoadedNotifier)))))))))))))))))))))))))
address="AWy7RNBVr9vDadRMK9p7i7Z1tL7GrLAxoh"
dispatch={[Function]}
store={
Expand Down
2 changes: 1 addition & 1 deletion app/components/Send/SendPanel/SendSuccess/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class SendSuccess extends React.Component<Props> {
<CheckMarkIcon className={styles.sendSuccessHeaderIcon} />
<div className={styles.sendSuccessHeaderInfo}>
<h1 className={styles.sendSuccessHeaderInfoText}>
{numberOfItems} {pluralize('Transfer', numberOfItems)} completed
{numberOfItems} {pluralize('Transfer', numberOfItems)} pending
</h1>
<p className={styles.sendSuccessParagraphText}>
{this.txFormattedDate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,29 @@ type Props = {
transactions: Array<Object>,
handleFetchAdditionalTxData: () => void,
handleGetPendingTransactionInfo: () => void,
handleRefreshTxData: () => void,
pendingTransactions: Array<Object>,
address: string,
}

const REFRESH_INTERVAL_MS = 30000

export default class TransactionHistory extends React.Component<Props> {
transactionDataInterval: IntervalID

static defaultProps = {
transactions: [],
pendingTransactions: [],
}

componentDidMount() {
this.addPolling()
}

componentWillUnmount() {
this.removePolling()
}

render() {
const { className, transactions } = this.props
const filteredPendingTransactions = this.pruneConfirmedTransactionsFromPending()
Expand All @@ -41,6 +54,19 @@ export default class TransactionHistory extends React.Component<Props> {
)
}

addPolling = () => {
this.transactionDataInterval = setInterval(async () => {
await this.props.handleGetPendingTransactionInfo()
this.props.handleRefreshTxData()
}, REFRESH_INTERVAL_MS)
}

removePolling = () => {
if (this.transactionDataInterval) {
clearInterval(this.transactionDataInterval)
}
}

pruneConfirmedTransactionsFromPending() {
const { transactions, pendingTransactions } = this.props
const confirmed = transactions.map(tx => tx.txid)
Expand Down
11 changes: 11 additions & 0 deletions app/components/TransactionHistory/TransactionHistoryPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import withProgressPanel from '../../../hocs/withProgressPanel'
import withAuthData from '../../../hocs/withAuthData'
import withNetworkData from '../../../hocs/withNetworkData'
import withLoadingProp from '../../../hocs/withLoadingProp'
import withSuccessNotification from '../../../hocs/withSuccessNotification'

const mapTransactionsDataToProps = transactions => ({
transactions,
Expand All @@ -21,6 +22,12 @@ const mapAccountActionsToProps = (actions, { net, address }) => ({
address,
shouldIncrementPagination: true,
}),
handleRefreshTxData: () =>
actions.call({
net,
address,
shouldIncrementPagination: false,
}),
})

const mapPendingTransactionActionsToProps = (actions, { net, address }) => ({
Expand All @@ -47,4 +54,8 @@ export default compose(
withData(getPendingTransactionInfo, mapPendingTransactionInfoToProps),
withLoadingProp(transactionHistoryActions),
withData(transactionHistoryActions, mapTransactionsDataToProps),
withSuccessNotification(
transactionHistoryActions,
'Received latest transaction information.',
),
)(TransactionHistoryPanel)
5 changes: 1 addition & 4 deletions app/containers/Dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Props = {
const REFRESH_INTERVAL_MS = 30000

export default class Dashboard extends Component<Props> {
walletDataInterval: ?number
walletDataInterval: ?IntervalID

componentDidMount() {
this.addPolling()
Expand Down Expand Up @@ -80,17 +80,14 @@ export default class Dashboard extends Component<Props> {
}

addPolling = () => {
// $FlowFixMe
this.walletDataInterval = setInterval(
this.props.loadWalletData,
REFRESH_INTERVAL_MS,
)
}

removePolling = () => {
// $FlowFixMe
if (this.walletDataInterval) {
// $FlowFixMe
clearInterval(this.walletDataInterval)
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/modules/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export const sendTransaction = ({
dispatch(
showSuccessNotification({
message:
'Transaction complete! Your balance will automatically update when the blockchain has processed it.',
'Transaction pending! Your balance will automatically update when the blockchain has processed it.',
}),
)
return resolve(response)
Expand Down

0 comments on commit 2c9ada3

Please sign in to comment.