Skip to content

Commit

Permalink
fix: add timeout when MM active method hangs (#2240)
Browse files Browse the repository at this point in the history
* fix: add timeout when MM active method hangs

* chore: remove console.log

* fix: test add delay inside provide

* test: fix logic
  • Loading branch information
juanmahidalgo committed Apr 30, 2024
1 parent 4e28e17 commit eb46453
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 13 additions & 2 deletions webapp/src/modules/wallet/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { select } from 'redux-saga/effects'
import { delay, select } from 'redux-saga/effects'
import { expectSaga } from 'redux-saga-test-plan'
import {
CONNECT_WALLET_FAILURE,
Expand All @@ -8,7 +8,7 @@ import {
} from 'decentraland-dapps/dist/modules/wallet/actions'
import { isConnecting } from 'decentraland-dapps/dist/modules/wallet/selectors'
import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types'
import { formatBalance, waitForWalletConnectionAndIdentityIfConnecting } from './utils'
import { WAIT_FOR_WALLET_CONNECTION_TIMEOUT, formatBalance, waitForWalletConnectionAndIdentityIfConnecting } from './utils'

describe('when formatting the balance', () => {
describe('and the number is 0', () => {
Expand Down Expand Up @@ -58,4 +58,15 @@ describe('when waiting for the wallet to connect', () => {
.run()
})
})

describe('and the wallet connection times out', () => {
it('should finish waiting after the timeout', () => {
return expectSaga(waitForWalletConnectionAndIdentityIfConnecting)
.provide([
[select(isConnecting), true],
[delay(WAIT_FOR_WALLET_CONNECTION_TIMEOUT), void 0]
])
.run()
})
})
})
6 changes: 4 additions & 2 deletions webapp/src/modules/wallet/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'ethers'
import { race, select, take } from 'redux-saga/effects'
import { delay, race, select, take } from 'redux-saga/effects'
import { getConnectedProvider } from 'decentraland-dapps/dist/lib/eth'
import {
CONNECT_WALLET_FAILURE,
Expand All @@ -13,6 +13,7 @@ import { config } from '../../config'
import { GENERATE_IDENTITY_FAILURE, GENERATE_IDENTITY_SUCCESS } from '../identity/actions'

export const TRANSACTIONS_API_URL = config.get('TRANSACTIONS_API_URL')
export const WAIT_FOR_WALLET_CONNECTION_TIMEOUT = 10000 // 10 seconds timeout

export function shortenAddress(address: string) {
if (address) {
Expand Down Expand Up @@ -49,7 +50,8 @@ export function* waitForWalletConnectionAndIdentityIfConnecting() {
if (isConnectingToWallet) {
const { success } = (yield race({
success: take(CONNECT_WALLET_SUCCESS),
failure: take(CONNECT_WALLET_FAILURE)
failure: take(CONNECT_WALLET_FAILURE),
timeout: delay(WAIT_FOR_WALLET_CONNECTION_TIMEOUT)
})) as { success: ConnectWalletSuccessAction; failure: ConnectWalletFailureAction }
if (success) {
yield race({
Expand Down

0 comments on commit eb46453

Please sign in to comment.