Skip to content

Commit

Permalink
Merge pull request #1692 from oasisprotocol/lw/fix-wallet-balances
Browse files Browse the repository at this point in the history
Fix continuously refreshing balances in wallet slice
  • Loading branch information
lukaw3d authored Sep 29, 2023
2 parents 672d5fe + b25b307 commit 76e1414
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
11 changes: 11 additions & 0 deletions playwright/tests/refreshing-balance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ test('Account selector should refresh balances on network change', async ({ page
await expect(page.getByTestId('account-choice')).toContainText('456.0')
await page.getByRole('button', { name: /Select/ }).click()
})

test('Accounts page should continuously refresh balance', async ({ page }) => {
await page.getByTestId('account-selector').click()
await expect(page.getByTestId('account-balance-summary')).toContainText('123.0')
await expect(page.getByTestId('account-choice')).toContainText('123.0')
await mockApi(page, 456)
await page.waitForRequest('**/chain/account/info/*', { timeout: 60_000 })
await expect(page.getByTestId('account-balance-summary')).toContainText('456.0')
await expect(page.getByTestId('account-choice')).toContainText('456.0')
// If balance in AccountSelector is not refreshed then making transactions with new balance will fail.
})
4 changes: 3 additions & 1 deletion src/app/state/account/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { getExplorerAPIs } from '../network/saga'
import { takeLatestCancelable } from '../takeLatestCancelable'
import { stakingActions } from '../staking'
import { fetchAccount as stakingFetchAccount } from '../staking/saga'
import { refreshAccount as walletRefreshAccount } from '../wallet/saga'
import { transactionActions } from '../transaction'
import { selectAddress } from '../wallet/selectors'
import { selectAccountAddress, selectAccountAvailableBalance } from './selectors'
import { getAccountBalanceWithFallback } from '../../lib/getAccountBalanceWithFallback'

const ACCOUNT_REFETCHING_INTERVAL = 30 * 1000
const ACCOUNT_REFETCHING_INTERVAL = process.env.REACT_APP_E2E_TEST ? 5 * 1000 : 30 * 1000
const TRANSACTIONS_LIMIT = 20

export function* fetchAccount(action: PayloadAction<string>) {
Expand Down Expand Up @@ -124,6 +125,7 @@ export function* fetchingOnAccountPage() {
if (staleAvailableBalance !== refreshedAccount.available) {
yield* call(fetchAccount, startAction)
yield* call(stakingFetchAccount, startAction)
yield* call(walletRefreshAccount, address)
}
}
} finally {
Expand Down
2 changes: 1 addition & 1 deletion src/app/state/wallet/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function* refreshAccountOnParaTimeTransaction() {
}
}

function* refreshAccount(address: string) {
export function* refreshAccount(address: string) {
const from = yield* select(selectAddress)
const wallets = yield* select(selectWallets)
const matchingWallets = Object.values(wallets).filter(
Expand Down

0 comments on commit 76e1414

Please sign in to comment.