Skip to content

feat: vibe coded fixes#1

Merged
thedevbirb merged 1 commit intomainfrom
nico/fixes
Aug 8, 2025
Merged

feat: vibe coded fixes#1
thedevbirb merged 1 commit intomainfrom
nico/fixes

Conversation

@merklefruit
Copy link
Collaborator

@merklefruit merklefruit commented Aug 8, 2025

This pull request introduces several improvements and fixes across both the backend (Rust/Axum) and frontend (Next.js) of the Trustee DEX application. The main highlights include the addition of a comprehensive integration guide, enhancements to type safety and data flow, minor API and state handling adjustments, and frontend code cleanup for consistency and usability.

Documentation and Integration Guide

  • Added a detailed INTEGRATION.md file that documents the architecture, API endpoints, data flow, type definitions, development setup, testing, troubleshooting, and future enhancements for the frontend-backend integration.

Backend Improvements

  • Made AppState, EncumberedHoldings, and InternalBalances structs clonable and improved their documentation/comments for better clarity and thread safety. [1] [2] [3]
  • Updated the PrivateOrder, PublicOrder, and OrderStatus types to derive Eq and made relevant methods const fn for improved type safety and performance. [1] [2] [3]
  • Improved the orderbook filtering logic for clarity and performance by simplifying iterator usage.

Backend API and State Handling

  • Added TODOs and placeholders in order creation and withdrawal handlers to clarify areas needing further implementation, and removed unnecessary explicit initialization of internal balances. [1] [2] [3]
  • Updated imports and tracing initialization for consistency and to prepare for future RPC client usage.

Frontend Code Cleanup and Usability

  • Unified and standardized import formatting, improved string consistency (single/double quotes), and replaced the wallet disconnect logic with the idiomatic wagmi hook for improved reliability. [1] [2] [3] [4] [5] [6] [7]

These changes collectively improve the maintainability, clarity, and developer experience of the project.


Most important changes:

Documentation and Integration

  • Added a comprehensive INTEGRATION.md guide covering architecture, API endpoints, data flows, shared types, setup, testing, troubleshooting, and future enhancements.

Backend: Type Safety and State Handling

  • Made key structs (AppState, EncumberedHoldings, InternalBalances) clonable and improved documentation for safer concurrency and clarity. [1] [2] [3]
  • Updated PrivateOrder, PublicOrder, and OrderStatus to derive Eq and use const fn where possible, enhancing type safety and performance. [1] [2] [3]

Backend: API Logic

  • Added TODOs and placeholders for encumbered wallet handling and withdrawal logic, clarifying future implementation needs and removing unnecessary initialization. [1] [2] [3]
  • Simplified orderbook filtering logic for better readability and performance.
  • Updated imports and tracing initialization for consistency and future extensibility.

Frontend: Code Consistency and Usability

  • Standardized import statements, improved string usage, and replaced custom wallet disconnect logic with the wagmi hook for better reliability and code style. [1] [2] [3] [4] [5] [6] [7]

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces comprehensive improvements across documentation, backend type safety, and frontend code consistency for the Trustee DEX application. The main focus is on enhancing maintainability, fixing type mismatches, and standardizing code style.

  • Added comprehensive integration documentation with architecture overview, API endpoints, and development setup
  • Enhanced backend type safety with Clone and Eq derives, improved struct documentation, and const fn methods
  • Standardized frontend imports, string usage, and replaced custom wallet disconnect logic with wagmi hooks

Reviewed Changes

Copilot reviewed 11 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
package.json Added root package.json with development scripts for concurrent frontend/backend development
frontend/lib/types.ts Fixed typo in PublicOrder type (assert_boughtasset_bought) and standardized quotes
frontend/lib/api.ts Updated API client with corrected port, improved error handling, and standardized parameter types
frontend/app/page.tsx Major code cleanup including import standardization, quote consistency, and wagmi hook adoption
crates/primitives/src/lib.rs Enhanced type safety with Eq derives and const fn methods for better performance
crates/backend/src/state/orderbook.rs Simplified orderbook filtering logic for better readability and performance
crates/backend/src/state/mod.rs Made AppState cloneable for improved thread safety
crates/backend/src/state/balance.rs Enhanced balance structures with better documentation and Clone derives
crates/backend/src/main.rs Updated imports and tracing initialization for consistency
crates/backend/src/api/handlers.rs Added TODOs for incomplete implementation areas and removed unnecessary initialization
INTEGRATION.md Added comprehensive integration guide covering architecture, setup, and troubleshooting
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

}

pub fn as_filled(&mut self) {
pub const fn as_filled(&mut self) {
Copy link

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

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

The const fn keyword cannot be used with methods that take &mut self as they can modify state at runtime. This will cause a compilation error.

Suggested change
pub const fn as_filled(&mut self) {
pub fn as_filled(&mut self) {

Copilot uses AI. Check for mistakes.
} from "./types";

const base = 'http://127.0.0.1:8080'; // same-origin; change to your backend origin if needed
const base = "http://127.0.0.1:3000"; // Backend runs on port 3000
Copy link

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

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

The backend URL is hardcoded to port 3000, but according to the PR description and other files, the backend runs on port 8080. This mismatch will cause API calls to fail.

Suggested change
const base = "http://127.0.0.1:3000"; // Backend runs on port 3000
const base = "http://127.0.0.1:8080"; // Backend runs on port 8080

Copilot uses AI. Check for mistakes.
Comment on lines +104 to +106
// TODO: Get encumbered wallet from user's existing wallets or create new one
// For now, use a placeholder - this needs to be implemented properly
let encumbered_wallet = Address::from([0u8; 20]); // Placeholder
Copy link

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

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

Using a zero address as a placeholder for the encumbered wallet will cause issues when this order is processed, as transactions to the zero address are invalid.

Suggested change
// TODO: Get encumbered wallet from user's existing wallets or create new one
// For now, use a placeholder - this needs to be implemented properly
let encumbered_wallet = Address::from([0u8; 20]); // Placeholder
// Get encumbered wallet from user's existing wallets or create new one
let encumbered_wallet = if let Some(&wallet_addr) = state.wallet_owners.get(&address) {
wallet_addr
} else {
// Create a new encumbered wallet for the user
let wallet = tee::generate_encumbered_wallet();
let wallet_addr = wallet.address();
state.encumbered_wallets.push(wallet);
state.wallet_owners.insert(address, wallet_addr);
wallet_addr
};

Copilot uses AI. Check for mistakes.
const s = BigInt(i || '0') * (BigInt(10) ** BigInt(decimals)) + BigInt(dPadded || '0');
const [i, d = ""] = amountDecimal.split(".");
const dPadded = (d + "0".repeat(decimals)).slice(0, decimals);
const multiplier = BigInt("1" + "0".repeat(decimals));
Copy link

Copilot AI Aug 8, 2025

Choose a reason for hiding this comment

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

Creating the multiplier string by concatenation and then converting to BigInt is inefficient. Use BigInt(10) ** BigInt(decimals) for better performance.

Suggested change
const multiplier = BigInt("1" + "0".repeat(decimals));
const multiplier = BigInt(10) ** BigInt(decimals);

Copilot uses AI. Check for mistakes.
@thedevbirb thedevbirb merged commit 8410a04 into main Aug 8, 2025
1 of 3 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.

3 participants