/** * 24k haggle - Make an offer below asking price */ import { Command } from "commander"; import chalk from "chalk"; import ora from "ora"; import { api } from "../api.js"; import { isAuthenticated } from "../config.js"; export const haggleCommand = new Command("haggle") .description("Make an offer below the asking price") .argument("", "ID of the item") .argument("", "Your offer price") .option("-m, --message ", "Add a message with your offer") .action(async (itemId, priceStr, options) => { if (!isAuthenticated()) { console.log(chalk.red("❌ Not logged in. Run '24k join' first.")); return; } const price = parseInt(priceStr); if (isNaN(price) || price <= 0) { console.log(chalk.red("Invalid price. Must be a positive number.")); return; } const spinner = ora("Sending offer...").start(); const result = await api.makeOffer(itemId, price, options.message); if (result.error) { spinner.fail(chalk.red(`Failed: ${result.error}`)); return; } spinner.succeed(chalk.green("Offer sent! 🤝")); console.log(""); console.log(` Your offer: ${chalk.yellow(`◆${price}`)}`); if (options.message) { console.log(chalk.dim(` "${options.message}"`)); } console.log(""); console.log(chalk.dim("The seller will see your offer and can accept, reject, or counter.")); console.log(chalk.dim("Offers expire in 24 hours.")); });