From 12bbbe200427ee51a95b72815ae73852ff00448f Mon Sep 17 00:00:00 2001 From: Zeeshan Akram <97m.zeeshan@gmail.com> Date: Fri, 29 Mar 2024 10:37:31 +0000 Subject: [PATCH] fix: ProjectToken.RevenueSplitLeft mapping --- src/mappings/token/index.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/mappings/token/index.ts b/src/mappings/token/index.ts index 34009cc75..dd12863ae 100644 --- a/src/mappings/token/index.ts +++ b/src/mappings/token/index.ts @@ -757,21 +757,21 @@ export async function processRevenueSplitLeftEvent({ }: EventHandlerContext<'ProjectToken.RevenueSplitLeft'>) { const account = await getTokenAccountByMemberByTokenOrFail(overlay, memberId, tokenId) account.stakedAmount -= unstakedAmount - const token = await overlay.getRepository(CreatorToken).getByIdOrFail(tokenId.toString()) - if (token.currentRevenueShareId) { - // TODO: refactor this as should be true all the times, might be a good idea to panic + + const revenueShareParticipation = ( + await overlay + .getRepository(RevenueShareParticipation) + .getManyByRelation('accountId', account.id) + ).find((participation) => participation.recovered === false) + + if (revenueShareParticipation) { + revenueShareParticipation.recovered = true + const revenueShare = await overlay .getRepository(RevenueShare) - .getByIdOrFail(token.currentRevenueShareId) + .getByIdOrFail(revenueShareParticipation.revenueShareId || '') + revenueShare.participantsNum -= 1 - const qRevenueShareParticipation = ( - await overlay - .getRepository(RevenueShareParticipation) - .getManyByRelation('accountId', account.id) - ).find((participation) => participation.recovered === false) - if (qRevenueShareParticipation) { - qRevenueShareParticipation.recovered = true - } } }