Withdrawal fee calculation (2%) + realtime balance.updated event - #1119
Merged
Akanimoh12 merged 2 commits intoJul 25, 2026
Conversation
…altime event Closes Akanimoh12#941, Akanimoh12#951 - withdrawals: compute a 2% (configurable via WITHDRAWAL_FEE_BPS) fee on prepareWithdrawal, send the net amount on-chain, and return fee/netAmount in the response. - realtime: add a typed `balance.updated` Socket.IO event, auth-enforced via the existing user:<id> room, and emit it after a tip is confirmed. - fix pre-existing merge-artifact duplication (app.ts imports/mounts, AppError.ts ServiceUnavailableError, prisma schema.prisma User model and TipStatus enum) that broke the build for every test on this branch. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Owner
|
Please resolve conflicts |
…ime-balance-941-951
|
@Godbrand0 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Akanimoh12
merged commit Jul 25, 2026
27b152c
into
Akanimoh12:test-implement-drips
4 of 5 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
balance.updatedrealtime event.#941 — Withdrawal fee calculation
calculateWithdrawalFeepure function (backend/src/modules/withdrawals/withdrawals.service.ts) that splits a gross withdrawal amount intofeeandnetAmount, floored so the platform never over-charges.WITHDRAWAL_FEE_BPS(env var, default200= 2%), wired throughsrc/config/env.tsandsrc/config/index.ts, documented in.env.example.prepareWithdrawalnow sendsnetAmount(post-fee) on-chain and returnsfee/netAmountin the response.fee/netAmountonPOST /withdrawals/prepare.#951 — Realtime balance.updated event
balance.updatedSocket.IO server event (backend/src/realtime/types.ts) andemitBalanceUpdated(backend/src/realtime/gateway.ts), exported from the realtime barrel.notification.created: delivered only to theuser:<id>room, which a socket may only join if its authenticatedauthUser.idmatches.PATCH /tips/:txHash/confirm— confirming a tip changes the recipient's withdrawable balance, so their sockets are notified (best-effort; failures are logged, not surfaced as a 500 for an already-successful confirmation).backend/src/realtime/gateway.test.tscovering: delivery to the balance owner after subscribing, rejection of subscribing to another user's room, and rejection of unauthenticated connections. Plus two new tests intips.test.tsfor the confirm → emit wiring.Also fixed (blocking both issues)
The
test-implement-dripsbranch had pre-existing merge-artifact duplication that brokenpm run typecheck/testfor essentially every module:src/app.ts— duplicated/malformed import block (syntax error) and a duplicate router mount.src/common/errors/AppError.ts—ServiceUnavailableErrordeclared twice.prisma/schema.prisma—Usermodel had every relation field duplicated, andTipStatusenum was declared twice (schema failedprisma generate).These were reconciled by keeping the more complete duplicate and removing the redundant one — no behavioral changes beyond making the branch buildable/testable again.
Test plan
npm run typecheck— no new errors (pre-existing unrelated errors incredit.service.ts/x.test.tsremain, not touched by this PR)npm run lint— 0 errors (pre-existing warnings only)npx vitest run src/modules/withdrawals/withdrawals.test.ts— 9/9 passingnpx vitest run src/realtime/gateway.test.ts— 3/3 passingnpx vitest run src/modules/tips/tips.test.ts -t confirm— 7/7 passing (includes 2 new balance.updated tests)docker compose up, and unrelated bugs incredit,x,authmodules) — not introduced by this PR.