Skip to content

Latest commit

 

History

History
70 lines (59 loc) · 2.3 KB

File metadata and controls

70 lines (59 loc) · 2.3 KB

Style Guide — OrbitPay

Rust (Smart Contracts)

Formatting

  • Use rustfmt with default settings: cargo fmt
  • Max line width: 100 characters
  • Use 4-space indentation (Rust default)

Naming Conventions

  • Functions: snake_casecreate_withdrawal, get_threshold
  • Structs: PascalCaseWithdrawalRequest, PayrollStream
  • Enums: PascalCaseStreamStatus, VoteChoice
  • Constants: SCREAMING_SNAKE_CASEMAX_SIGNERS
  • Modules: snake_casestorage, types, errors

Code Organization

Each contract follows this file structure:

contract_name/src/
├── lib.rs       # Public contract functions (this is the API surface)
├── types.rs     # Data structures (structs, enums)
├── storage.rs   # Storage keys + get/set helpers
├── errors.rs    # Error enum
└── test.rs      # Unit tests

Error Handling

  • Always return Result<T, ContractError> from public functions
  • Use descriptive error variants
  • Number error variants sequentially
  • Add doc comments to each error explaining when it triggers

Testing

  • Every public function must have at least one test
  • Test happy path AND error cases
  • Use #[should_panic] for expected failures
  • Use env.mock_all_auths() in tests

TypeScript (Frontend & SDK)

Formatting

  • Use Prettier with default settings
  • Max line width: 100 characters
  • Use 2-space indentation
  • Semicolons: yes
  • Single quotes: yes
  • Trailing commas: all

Naming Conventions

  • Components: PascalCaseWalletButton, StreamCard
  • Files (components): PascalCase.tsxWalletButton.tsx
  • Files (hooks): camelCase.tsuseTreasury.ts
  • Files (utils): camelCase.tsnetwork.ts
  • Functions: camelCaseconnectWallet, buildTransaction
  • Constants: SCREAMING_SNAKE_CASENETWORK, CONTRACTS
  • Types/Interfaces: PascalCaseStreamStatus, Proposal

React Conventions

  • Use functional components only
  • Use 'use client' directive for interactive components
  • Prefer hooks over class components
  • Keep components focused and small (< 150 lines)
  • Extract logic into custom hooks

CSS

  • Use Tailwind utility classes
  • Avoid inline styles
  • Use design tokens from tailwind.config.ts
  • Dark mode first (via dark class on <html>)