Skip to content

Commit

Permalink
fix(points): prevent sagas spawning if points are disabled (#5385)
Browse files Browse the repository at this point in the history
### Description

As the title. Rather than remembering to check the remote config in each
saga, catch it all at the root level. We should not start talking to the
points DB yet.

### Test plan

n/a

### Related issues

n/a

### Backwards compatibility

Y

### Network scalability

If a new NetworkId and/or Network are added in the future, the changes
in this PR will:

- [x] Continue to work without code changes, OR trigger a compilation
error (guaranteeing we find it when a new network is added)
  • Loading branch information
kathaypacific committed May 6, 2024
1 parent 9aae469 commit 7eb6fd7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
16 changes: 0 additions & 16 deletions src/points/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import pointsReducer, {
trackPointsEvent,
} from 'src/points/slice'
import { ClaimHistory, GetHistoryResponse } from 'src/points/types'
import { getFeatureGate } from 'src/statsig'
import { StatsigFeatureGates } from 'src/statsig/types'
import Logger from 'src/utils/Logger'
import * as fetchWithTimeout from 'src/utils/fetchWithTimeout'
import networkConfig from 'src/web3/networkConfig'
Expand Down Expand Up @@ -230,9 +228,6 @@ describe('getHistory', () => {
describe('getPointsConfig', () => {
beforeEach(() => {
jest.clearAllMocks()
jest
.mocked(getFeatureGate)
.mockImplementation((gate) => gate === StatsigFeatureGates.SHOW_POINTS)
})

it('fetches and sets points config', async () => {
Expand Down Expand Up @@ -325,17 +320,6 @@ describe('getPointsConfig', () => {
.not.put(getPointsConfigSucceeded(expect.anything()))
.run()
})

it('does not fetch if points are not enabled', async () => {
jest.mocked(getFeatureGate).mockReturnValue(false)

await expectSaga(getPointsConfig)
.not.put(getPointsConfigStarted())
.not.put(getPointsConfigSucceeded(expect.anything()))
.run()

expect(mockFetch).not.toHaveBeenCalled()
})
})

describe('sendPointsEvent', () => {
Expand Down
16 changes: 8 additions & 8 deletions src/points/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {
} from 'src/points/slice'
import {
GetHistoryResponse,
isPointsActivityId,
isClaimActivityId,
PointsEvent,
isClaimActivityId,
isPointsActivityId,
} from 'src/points/types'
import { getFeatureGate } from 'src/statsig'
import { StatsigFeatureGates } from 'src/statsig/types'
Expand Down Expand Up @@ -100,12 +100,6 @@ export function* getHistory({ payload: params }: ReturnType<typeof getHistorySta
}

export function* getPointsConfig() {
const showPoints = getFeatureGate(StatsigFeatureGates.SHOW_POINTS)
if (!showPoints) {
Logger.info(TAG, 'Points feature is disabled, not fetching points config')
return
}

yield* put(getPointsConfigStarted())

try {
Expand Down Expand Up @@ -215,6 +209,12 @@ export function* watchAppMounted() {
}

export function* pointsSaga() {
const showPoints = getFeatureGate(StatsigFeatureGates.SHOW_POINTS)
if (!showPoints) {
Logger.info(TAG, 'Points feature is disabled, not spawning points sagas')
return
}

yield* spawn(watchGetHistory)
yield* spawn(watchGetConfig)
yield* spawn(watchTrackPointsEvent)
Expand Down

0 comments on commit 7eb6fd7

Please sign in to comment.