Skip to content

fix(checkout): remove fabricated batch transaction results - #960

Open
nasalehj wants to merge 1 commit into
MettaChain:mainfrom
nasalehj:fix/issue-813-real-batch-checkout
Open

fix(checkout): remove fabricated batch transaction results#960
nasalehj wants to merge 1 commit into
MettaChain:mainfrom
nasalehj:fix/issue-813-real-batch-checkout

Conversation

@nasalehj

@nasalehj nasalehj commented Aug 26, 2026

Copy link
Copy Markdown

Summary

Addresses part of #813

This slice removes fabricated batch checkout success and failure behavior from the frontend. Checkout now uses the connected wallet address, validates cart and slippage inputs before submission, and exposes an explicit executor boundary whose success result requires an observed successful receipt. The repository currently has no deployed batch-purchase or multicall ABI, address, function signature, or payment semantics, so the concrete chain adapter is intentionally not fabricated.

Why

The previous checkout waited for a timer, used Math.random() to select a failure branch, and returned a generated transaction hash without contacting a wallet or blockchain. That made the UI report purchases that never occurred and made failures nondeterministic. The new service fails closed when no configured executor exists and only returns success after an executor reports a successful receipt.

What was built

File What it contains
src/lib/batchTransaction.ts Deterministic cart, wallet, amount, and slippage validation; per-item quote/minimum amount calculation; executor interface; receipt-gated success; decoded provider/user errors; honest unconfigured-network failure.
src/components/CartSidebar.tsx Uses the existing wallet store address and removes the hardcoded checkout wallet.
src/lib/__tests__/batchTransaction.test.ts Nine focused tests covering validation, disconnected wallets, missing configuration, successful receipt handling, reverted receipts, decoded provider errors, user rejection, and slippage calculations.

The service tests inject an executor so receipt and error behavior can be verified without inventing a contract ABI or making network calls.

Integration changes outside src/lib/

  • src/components/CartSidebar.tsx — uses the canonical wallet store address and no longer supplies a placeholder account.

Acceptance criteria coverage

  • executeBatchPurchase submits a real transaction for the connected account and resolves success: true only after on-chain confirmation (receipt observed); no code path returns a fabricated hash. — Fabricated hashes and submission behavior are removed; the real chain adapter remains blocked by the missing deployed contract ABI/address and call semantics.
  • The 20% Math.random() failure branch and the setTimeout simulation are gone. (src/lib/batchTransaction.ts and static inspection — no timer/random simulation remains)
  • The per-item slippage math is either validated against the on-chain min-out or documented as an estimate with the real values computed from the quote. (src/lib/batchTransaction.ts, calculateMinimumAmount, and batchTransaction.test.ts — quote-derived estimates are passed to the executor seam)
  • src/lib/tests/batchTransaction.test.ts is rewritten to mock wagmi/viem and assert: success returns the real hash; user rejection returns success: false with a decoded reason; disconnected wallet is rejected before any submission. (src/lib/__tests__/batchTransaction.test.ts — deterministic executor tests cover real executor hash, user rejection, decoded revert data, and no-call disconnected validation)
  • npm run typecheck, npm test, and npm run lint pass. — Existing unrelated syntax errors, test-environment mock failures, and a missing eslint-plugin-jsdoc dependency prevent these repository-wide gates from passing.

Deliberately deferred

  • Concrete wagmi/viem batch transaction adapter — the repository does not contain a deployed batch/multicall contract address, ABI, function signature, or payment/token semantics from which a safe call can be implemented.
  • On-chain validation of minimum amounts — depends on the deferred contract call and quote format.
  • Dynamic volatility-based slippage and EIP-712 typed-data slippage intent — explicitly out of scope in the issue.

Test plan

  • npx prettier --check src/lib/batchTransaction.ts src/lib/__tests__/batchTransaction.test.ts src/components/CartSidebar.tsx — all matched files pass.
  • npm test -- --runInBand src/lib/__tests__/batchTransaction.test.ts — 9/9 passing (9 rewritten tests).
  • npm run validate:env — passes in development.
  • npm run typecheck — blocked by pre-existing syntax errors in unrelated files including src/app/compare/page.tsx, src/components/ComparisonBar.tsx, src/components/PropertyCard.tsx, src/components/TransactionConfirmation.tsx, src/lib/toast.ts, and src/stories/ResponsiveContainerExample.stories.ts.
  • npm test -- --runInBand — 63/140 suites passing; 986/1145 tests passing. Failures include existing viem mock incompatibility, Vitest/CommonJS incompatibilities, missing modules, and unrelated component/test failures.
  • npx eslint src/lib/batchTransaction.ts src/lib/__tests__/batchTransaction.test.ts src/components/CartSidebar.tsx --max-warnings=0 — blocked before linting because eslint-plugin-jsdoc is not installed.
  • npm run build — stops at the same pre-existing typecheck failures.

Env vars / Notes

No new environment variables.

No deployment or migration changes are included. The executor interface is the integration seam for the deployed contract details; until those details are added, valid checkout attempts return an explicit configuration error rather than claiming an on-chain purchase.

@nasalehj
nasalehj force-pushed the fix/issue-813-real-batch-checkout branch from 90340fe to b3987dc Compare August 26, 2026 13:41
@drips-wave

drips-wave Bot commented Aug 26, 2026

Copy link
Copy Markdown

@nasalehj 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! 🚀

Learn more about application limits

@drips-wave

drips-wave Bot commented Aug 26, 2026

Copy link
Copy Markdown

Hey @nasalehj! 👋 It looks like this PR isn't linked to any issue.

If this PR is for one of the issues assigned to you as part of a Wave, please link it to ensure your contribution is tracked properly. You can do this by adding a keyword to the PR description (e.g., Closes #123), or by clicking a button below:

Issue Title
#814 middleware.ts falls back to a hardcoded JWT secret: forged auth-token cookies verify when AUTH_SECRET is unset Link to this issue
#813 Cart checkout fabricates transaction results: executeBatchPurchase never submits to the chain Link to this issue
#816 Delete orphaned Pages Router file src/pages/security/TransactionSecurity.tsx Link to this issue
#815 useAuth reports authentication from cookie presence and fabricates userAddress: client auth state is a mock Link to this issue

ℹ️ Learn more about linking PRs to issues

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.

1 participant