Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix(wallet): adding sanity check for pag load handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Oct 25, 2020
1 parent a9bcc66 commit cb528db
Showing 2 changed files with 19 additions and 6 deletions.
24 changes: 19 additions & 5 deletions renderer/reducers/activity/reducer.js
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import { settingsSelectors } from 'reducers/settings'
import { fetchBalance } from 'reducers/balance'
import { fetchChannels } from 'reducers/channels'
import { fetchInfo, infoSelectors } from 'reducers/info'
import { walletSelectors } from 'reducers/wallet'
import { showError, showNotification } from 'reducers/notification'
import { createActivityPaginator } from './utils'
import { hasNextPage, isPageLoading } from './selectors'
@@ -255,19 +256,32 @@ export const loadPage = (reload = false) => async (dispatch, getState) => {
dispatch(setPageLoading(true))

await dispatch(fetchInfo())
const config = settingsSelectors.currentConfig(getState())
const blockHeight = infoSelectors.blockHeight(getState())
const state = getState()
const config = settingsSelectors.currentConfig(state)
const blockHeight = infoSelectors.blockHeight(state)
const activeWallet = walletSelectors.activeWallet(state)

// Checks to see if the currently active wallet is the same one as when the page load started.
const isStllActiveWallet = () => walletSelectors.activeWallet(getState()) === activeWallet

// It's possible that the grpc response is received after the wallet has been disconnected.
// See https://github.com/grpc/grpc-node/issues/1603
// Ensure that the items received belong to the currently active wallet.
const shouldUpdate = items => items && isStllActiveWallet()

const handlers = {
invoiceHandler: items => items && dispatch(receiveInvoices(items)),
paymentHandler: items => items && dispatch(receivePayments(items)),
transactionHandler: items => items && dispatch(receiveTransactions(items)),
invoiceHandler: items => shouldUpdate(items) && dispatch(receiveInvoices(items)),
paymentHandler: items => shouldUpdate(items) && dispatch(receivePayments(items)),
transactionHandler: items => shouldUpdate(items) && dispatch(receiveTransactions(items)),
}
const thisPaginator = reload ? createActivityPaginator(handlers) : getPaginator(handlers)

if (hasNextPage(getState())) {
const { pageSize } = config.activity
const { hasNextPage } = await thisPaginator(pageSize, blockHeight)
if (!isStllActiveWallet()) {
return
}
dispatch({ type: SET_HAS_NEXT_PAGE, value: hasNextPage })
}

1 change: 0 additions & 1 deletion renderer/reducers/transaction/reducer.js
Original file line number Diff line number Diff line change
@@ -97,7 +97,6 @@ export const receiveTransactions = (transactions, updateOnly = false) => async (
getState
) => {
const state = getState()

const currentAddresses = addressSelectors.currentAddresses(state)

// index of the last tx in `transactions`

0 comments on commit cb528db

Please sign in to comment.