Skip to content

[버그] 보스 분배금 로직이 잘못되었던 문제 수정#87

Merged
spde3289 merged 2 commits intodevelopfrom
fix/boss-reward-distribution-calculation
Jan 29, 2026
Merged

[버그] 보스 분배금 로직이 잘못되었던 문제 수정#87
spde3289 merged 2 commits intodevelopfrom
fix/boss-reward-distribution-calculation

Conversation

@spde3289
Copy link
Owner

개요

경매장 판매 후 실수령액 기준으로 분배하는 과정에서 팀원 송금 시 발생하는 수수료를 고려하지 않아
분배 비율을 수동으로 변경할 경우 계산 결과가 잘못되는 문제를 수정하고 송금해야 하는 금액을 추가함

구조 변경

normalizeMembers

  • 분배 모드에 따라 멤버들의 비율을 정규화하는 함수

calculateFairBaseProfit

  • 경매장 실수령액과 송금 수수료를 고려해 모든 멤버가 비율대로 최종 수령액을 갖게 되도록 하는 기준 금액을 계산

computeMemberShare

  • 멤버 한 명에 대한 분배 결과를 계산
  • 팀원은 송금 수수료를 고려해 필요한 송금액을 역산

@spde3289 spde3289 self-assigned this Jan 29, 2026
@spde3289 spde3289 added the fix 버그 수정 label Jan 29, 2026
@cr-gpt
Copy link

cr-gpt bot commented Jan 29, 2026

Seems you are using me but didn't get OPENAI_API_KEY seted in Variables/Secrets for this repo. you could follow readme for more information

@vercel
Copy link

vercel bot commented Jan 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
maple-helper Ready Ready Preview Jan 29, 2026 2:55pm

@spde3289 spde3289 merged commit 47ddba0 into develop Jan 29, 2026
2 checks passed
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@spde3289 spde3289 changed the title [버그 수정] 보스 분배금 로직이 잘못되었던 문제 수정 [버그] 보스 분배금 로직이 잘못되었던 문제 수정 Jan 30, 2026
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

이 PR은 파티 분배금 계산 로직을 수정하여 송금 수수료를 고려하도록 변경하고, 이로 인해 발생했던 계산 오류를 해결합니다. 새로운 로직은 모든 파티원이 설정된 비율에 맞게 최종 금액을 수령할 수 있도록 하는 '공정한 기준 이익' 개념을 도입하여 문제를 해결합니다. 전반적으로 좋은 방향의 수정이지만, distributeProfitByPercent 유틸리티 함수에서 발견된 몇 가지 잠재적인 문제점(치명적인 버그 포함)과 설계 개선점에 대한 피드백을 남깁니다.

Comment on lines 63 to 90
export const distributeProfitByPercent = (
totalProfit: number,
feeRate: number,
members: Member[],
mode: Mode,
) => {
const memberCount = members.length
): DistributionResult[] => {
const normalizedMembers = normalizeMembers(members, mode)

const fee = memberCount >= 2 ? Math.floor((totalProfit * feeRate) / 100) : 0
const distributable = totalProfit - fee
const activeOwnerIndex = 0
const ownerMember = normalizedMembers[activeOwnerIndex]

const results: DistributionResult[] = members.map((m) => ({
...m,
amount:
mode === 'MANUAL'
? Math.floor((distributable * m.ratio) / 100)
: Math.floor(distributable / memberCount),
}))
const fairBaseProfit = calculateFairBaseProfit(
totalProfit,
ownerMember.ratio,
feeRate,
)

const distributed = results.reduce((sum, r) => sum + r.amount, 0)
const remainder = distributable - distributed
const results = normalizedMembers.map((member, idx) =>
computeMemberShare(
member,
fairBaseProfit,
feeRate,
idx === activeOwnerIndex, // isOwner check
),
)

return { results, remainder }
return results
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

이 함수는 더 단순하고 견고하게 리팩토링할 수 있습니다. 현재 normalizeMembers 함수에 의존하고 있는데, 이 함수는 상위 훅의 로직을 중복 구현하고 있으며 빈 멤버 배열이 전달될 경우 크래시를 유발할 수 있습니다. 또한, 함수가 불필요하게 mode에 의존하고 있습니다.

modenormalizeMembers에 대한 의존성을 제거하여 이 함수를 순수한 계산 유틸리티로 만들고, 상위 훅이 멤버 비율을 설정하도록 책임을 위임하는 것이 좋습니다. 이렇게 하면 관심사가 명확히 분리되고 잠재적인 크래시를 해결할 수 있습니다. 아래 제안을 적용한 후에는 normalizeMembers 함수를 삭제하고, usePartyDistribution.ts에서 distributeProfitByPercent를 호출하는 부분도 mode를 전달하지 않도록 수정해야 합니다.

export const distributeProfitByPercent = (
  totalProfit: number,
  feeRate: number,
  members: Member[],
): DistributionResult[] => {
  if (members.length === 0) {
    return [];
  }

  const activeOwnerIndex = 0;
  const ownerMember = members[activeOwnerIndex];

  const fairBaseProfit = calculateFairBaseProfit(
    totalProfit,
    ownerMember.ratio,
    feeRate,
  );

  const results = members.map((member, idx) =>
    computeMemberShare(
      member,
      fairBaseProfit,
      feeRate,
      idx === activeOwnerIndex, // isOwner check
    ),
  );

  return results;
};

Comment on lines +71 to +72
const activeOwnerIndex = 0
const ownerMember = normalizedMembers[activeOwnerIndex]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

분배 주체인 파티장이 항상 배열의 첫 번째(index 0) 멤버라고 가정하고 있습니다. 이는 유연하지 못한 설계이며, 향후 멤버 순서를 변경하거나 다른 파티장을 지정하는 기능이 추가될 경우 버그를 유발할 수 있습니다. 파티장의 ID를 함수에 전달하거나 Member 타입에 isOwner 같은 플래그를 추가하여 명시적으로 파티장을 식별하는 것이 더 견고한 접근 방식입니다.

@spde3289 spde3289 deleted the fix/boss-reward-distribution-calculation branch February 1, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix 버그 수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant