Skip to content

Commit

Permalink
fix(points): only fetch config if points are enabled (valora-inc#5278)
Browse files Browse the repository at this point in the history
### Description

As the title.

### Test plan

n/a
### Related issues

- Related to RET-1044

### Backwards compatibility

Y

### Network scalability

Y
  • Loading branch information
kathaypacific authored and shottah committed May 15, 2024
1 parent 6799cf0 commit f17f480
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/points/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ import pointsReducer, {
getPointsConfigSucceeded,
} from 'src/points/slice'
import { ClaimHistory, GetHistoryResponse } from 'src/points/types'
import { getFeatureGate } from 'src/statsig'
import { StatsigFeatureGates } from 'src/statsig/types'
import * as fetchWithTimeout from 'src/utils/fetchWithTimeout'
import networkConfig from 'src/web3/networkConfig'
import { createMockStore } from 'test/utils'

jest.mock('src/statsig')

const MOCK_HISTORY_RESPONSE: GetHistoryResponse = {
data: [
{
Expand Down Expand Up @@ -174,6 +178,9 @@ 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 @@ -266,4 +273,15 @@ 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()
})
})
8 changes: 8 additions & 0 deletions src/points/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
getPointsConfigSucceeded,
} from 'src/points/slice'
import { GetHistoryResponse, isPointsActivity } from 'src/points/types'
import { getFeatureGate } from 'src/statsig'
import { StatsigFeatureGates } from 'src/statsig/types'
import Logger from 'src/utils/Logger'
import { fetchWithTimeout } from 'src/utils/fetchWithTimeout'
import { safely } from 'src/utils/safely'
Expand Down Expand Up @@ -77,6 +79,12 @@ 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

0 comments on commit f17f480

Please sign in to comment.