Skip to content

fix: convert acbuAmount to Decimal type in transferService#102

Merged
Junman140 merged 1 commit intoPi-Defi-world:mainfrom
coderolisa:fix/acbu-amount-decimal-conversion
Mar 27, 2026
Merged

fix: convert acbuAmount to Decimal type in transferService#102
Junman140 merged 1 commit intoPi-Defi-world:mainfrom
coderolisa:fix/acbu-amount-decimal-conversion

Conversation

@coderolisa
Copy link
Copy Markdown

@coderolisa coderolisa commented Mar 26, 2026

acbuAmount was being passed as a string to prisma.transaction.create(), but the schema expects a Decimal type. This can cause type or precision issues. Convert the string amount to Decimal using new Decimal() before passing to Prisma, consistent with the pattern used in mintController.ts and rewardService.ts.

The amount string is already validated to ensure it's a positive number with up to 7 decimal places before conversion.

Summary by CodeRabbit

  • Bug Fixes
    • Improved precision handling for transfer amounts to ensure accurate storage and calculation of transaction values.

CLOSE #34

acbuAmount was being passed as a string to prisma.transaction.create(),
but the schema expects a Decimal type. This can cause type or precision
issues. Convert the string amount to Decimal using new Decimal() before
passing to Prisma, consistent with the pattern used in mintController.ts
and rewardService.ts.

The amount string is already validated to ensure it's a positive number
with up to 7 decimal places before conversion.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 26, 2026

📝 Walkthrough

Walkthrough

The transferService.ts file was updated to convert the amount parameter from a string to a Decimal type when storing the acbuAmount field in the database transaction record. A Decimal import from Prisma's runtime library was added to support this conversion.

Changes

Cohort / File(s) Summary
Type Conversion for Database Persistence
src/services/transfer/transferService.ts
Added Decimal import and updated createTransfer to store acbuAmount as new Decimal(amount) instead of raw string value when persisting to database.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Poem

A hop, a skip, through decimal lands,
Where strings transform to types so grand,
The rabbit's work makes data tight,
Each transaction now typed just right! 🐰✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: convert acbuAmount to Decimal type in transferService' directly and precisely summarizes the main change: converting acbuAmount to the Decimal type in the transferService file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/services/transfer/transferService.ts (1)

6-6: Use the public Prisma Decimal API instead of internal runtime modules.

The import from @prisma/client/runtime/library accesses Prisma's internal runtime module, which is not part of the public API surface and may change without notice across version upgrades. Use Prisma.Decimal from @prisma/client instead—this is the documented and supported way to construct Decimal values.

Suggested change
-import { Decimal } from "@prisma/client/runtime/library";
+import { Prisma } from "@prisma/client";

At line 105 (or wherever the Decimal is instantiated):

-      acbuAmount: new Decimal(amount),
+      acbuAmount: new Prisma.Decimal(amount),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/services/transfer/transferService.ts` at line 6, The code imports Decimal
from the internal module "@prisma/client/runtime/library"; replace that import
with the public Prisma export by importing { Prisma } from "@prisma/client" and
update any instantiation/usages of Decimal (the symbol "Decimal") in
transferService.ts to use Prisma.Decimal (e.g., new Prisma.Decimal(...) or
Prisma.Decimal(...)) so you rely on the supported public API rather than
internal runtime modules.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/services/transfer/transferService.ts`:
- Line 6: The code imports Decimal from the internal module
"@prisma/client/runtime/library"; replace that import with the public Prisma
export by importing { Prisma } from "@prisma/client" and update any
instantiation/usages of Decimal (the symbol "Decimal") in transferService.ts to
use Prisma.Decimal (e.g., new Prisma.Decimal(...) or Prisma.Decimal(...)) so you
rely on the supported public API rather than internal runtime modules.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5b605204-09c9-41db-94c2-a48b5bb03a82

📥 Commits

Reviewing files that changed from the base of the PR and between 367b222 and d779951.

📒 Files selected for processing (1)
  • src/services/transfer/transferService.ts

@Junman140 Junman140 merged commit df26da8 into Pi-Defi-world:main Mar 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decimal vs string for acbuAmount in transfer

2 participants