Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions packages/web/src/common/store/pages/audio-rewards/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
SpecifierWithAmount,
Name,
Feature,
ChallengeName
ChallengeName,
FailureReason
} from '@audius/common/models'
import {
IntKeys,
Expand Down Expand Up @@ -221,6 +222,14 @@ type ErrorResult = SpecifierWithAmount & {
error: unknown
}

const isAlreadyClaimedErrorMessage = (errorMessage: string) => {
const normalizedError = errorMessage.toUpperCase()
return (
normalizedError.includes(FailureReason.ALREADY_DISBURSED) ||
normalizedError.includes(FailureReason.ALREADY_SENT)
)
}

async function claimRewardsForChallenge({
sdk,
userId,
Expand Down Expand Up @@ -256,8 +265,14 @@ async function claimRewardsForChallenge({
})
)
.then((res) => {
if (res?.data?.[0]?.error) {
throw new Error(res.data[0].error)
const claimError = res?.data?.[0]?.error
if (claimError && !isAlreadyClaimedErrorMessage(claimError)) {
throw new Error(claimError)
}
// ALREADY_DISBURSED/ALREADY_SENT means the reward was already
// processed; treat it as a successful outcome for client state.
if (claimError) {
return res
}
track(
make({
Expand Down
Loading