diff --git a/components/brave_rewards/resources/extension/brave_rewards/background/reducers/grant_panel_reducer.ts b/components/brave_rewards/resources/extension/brave_rewards/background/reducers/grant_panel_reducer.ts index 2adecb6f2d0d..6b806950c53b 100644 --- a/components/brave_rewards/resources/extension/brave_rewards/background/reducers/grant_panel_reducer.ts +++ b/components/brave_rewards/resources/extension/brave_rewards/background/reducers/grant_panel_reducer.ts @@ -157,7 +157,7 @@ export const grantPanelReducer = (state: RewardsExtension.State | undefined, act }) if (grantIndex > -1) { - grants = state.grants.splice(1, grantIndex) + grants = state.grants.splice(grantIndex, 1) currentGrant = undefined } diff --git a/components/brave_rewards/resources/ui/reducers/grant_reducer.ts b/components/brave_rewards/resources/ui/reducers/grant_reducer.ts index f9d33bb30bbd..6c6c15d6ac48 100644 --- a/components/brave_rewards/resources/ui/reducers/grant_reducer.ts +++ b/components/brave_rewards/resources/ui/reducers/grant_reducer.ts @@ -153,7 +153,7 @@ const grantReducer: Reducer = (state: Rewards.State, }) if (grantIndex > -1) { - state.grants.splice(1, grantIndex) + state.grants.splice(grantIndex, 1) currentGrant = undefined } diff --git a/components/test/brave_rewards/ui/reducers/grant_reducer_test.ts b/components/test/brave_rewards/ui/reducers/grant_reducer_test.ts index 4a92e207f663..892f2f608861 100644 --- a/components/test/brave_rewards/ui/reducers/grant_reducer_test.ts +++ b/components/test/brave_rewards/ui/reducers/grant_reducer_test.ts @@ -325,6 +325,42 @@ describe('Grant Reducer', () => { } ] + expect(assertion).toEqual({ + rewardsData: expectedState + }) + }) + it('deletes last grant', () => { + const initialState = { + ...defaultState + } + initialState.grants = [ + { + promotionId: 'test-promotion-id-2', + expiryTime: 0, + probi: '', + type: 'ads', + captcha: 'data:image/jpeg;base64,XXX', + hint: 'blue' + } + ] + initialState.currentGrant = { + promotionId: 'test-promotion-id-2', + expiryTime: 0, + probi: '', + type: 'ads' + } + + const assertion = reducers({ + rewardsData: initialState + }, { + type: types.ON_GRANT_DELETE, + payload: {} + }) + + const expectedState: Rewards.State = { ...defaultState } + expectedState.currentGrant = undefined + expectedState.grants = [] + expect(assertion).toEqual({ rewardsData: expectedState })