/* ============================================================
   ChadCoin — data + shared components
   ============================================================ */
const { useState, useEffect, useRef } = React;

/* ─── Solana / réseau ───────────────────────────────────── */
const HELIUS_RPC             = "https://mainnet.helius-rpc.com/?api-key=3c18c7fa-c72d-49ed-a3ec-49c0f63a55ad";
const CHD_MINT               = "CktvyfZ4V9fyRzrFQfmnNX4UTpT4PDnrDZXNXsBsiQV9";
const SOL_MINT               = "So11111111111111111111111111111111111111112";
const TBTC_MINT              = "6DNSN2BJsaPFdFFc1zP37kkeNe4Usc1Sqkzr9C9vPWcU";
const SLIPPAGE_BPS           = 50;
const PROGRAM_ID             = "7EvYneUQeZZBgodUxggqxiEDfv4Cqhp3NcXDhvcFkNQg";
const STATE_PDA              = "5on2kDKFpNKmEW2vWJ5U37VgwZA7SPs56KNrEFZcqvPt";
const VAULT_TBTC             = "GQDf3fkiLSdjHLyzK5pxmKG8tjbq1X6Mq2AiQ7RnivmQ";
const TOKEN_PROGRAM_ID       = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
const ASSOC_TOKEN_PROGRAM_ID = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJe1bmd";
const SYSTEM_PROGRAM_ID      = "11111111111111111111111111111111";

/* ---------- Icons (inline SVG, stroke style) ---------- */
const Ic = {
  wallet: (p) => (
    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" {...p}>
      <rect x="3" y="6" width="18" height="14" rx="3"/><path d="M3 10h18"/><circle cx="16.5" cy="14" r="1.2" fill="currentColor" stroke="none"/>
    </svg>
  ),
  bolt: (p) => (<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M13 2 4 14h7l-1 8 9-12h-7l1-8z"/></svg>),
  shield: (p) => (<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 3 5 6v6c0 4 3 7 7 9 4-2 7-5 7-9V6l-7-3z"/><path d="m9 12 2 2 4-4"/></svg>),
  globe: (p) => (<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3c2.5 2.5 2.5 15 0 18M12 3c-2.5 2.5-2.5 15 0 18"/></svg>),
  unlock: (p) => (<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="4.5" y="10.5" width="15" height="10" rx="2.5"/><path d="M8 10.5V7a4 4 0 0 1 7.5-2"/></svg>),
  chart: (p) => (<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M4 19V5M4 19h16"/><path d="m7 14 3-3 3 2 5-6"/></svg>),
  arrow: (p) => (<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M5 12h14M13 6l6 6-6 6"/></svg>),
  arrowDown: (p) => (<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 5v14M6 13l6 6 6-6"/></svg>),
  swap: (p) => (<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M7 4v13M7 4 4 7M7 4l3 3M17 20V7M17 20l3-3M17 20l-3-3"/></svg>),
  gear: (p) => (<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="12" cy="12" r="3"/><path d="M12 2v3M12 19v3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M2 12h3M19 12h3M4.9 19.1 7 17M17 7l2.1-2.1"/></svg>),
  x: (p) => (<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" {...p}><path d="M6 6l12 12M18 6 6 18"/></svg>),
  plus: (p) => (<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" {...p}><path d="M12 5v14M5 12h14"/></svg>),
  check: (p) => (<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="m5 12 5 5L20 6"/></svg>),
  checkBig: (p) => (<svg width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="m5 12 5 5L20 6"/></svg>),
  ext: (p) => (<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M14 5h5v5M19 5l-8 8M11 5H6a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h11a2 2 0 0 0 2-2v-5"/></svg>),
  copy: (p) => (<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="9" y="9" width="11" height="11" rx="2.5"/><path d="M5 15V5a2 2 0 0 1 2-2h8"/></svg>),
  info: (p) => (<svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" {...p}><circle cx="12" cy="12" r="9"/><path d="M12 11v5M12 8h.01"/></svg>),
  lock: (p) => (<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" {...p}><rect x="5" y="11" width="14" height="9" rx="2"/><path d="M8 11V8a4 4 0 0 1 8 0v3"/></svg>),
  fire: (p) => (<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 3c1 3-1 4-1 6a3 3 0 0 0 6 0c0-1 0-2-.5-3 2 1.5 3.5 4 3.5 7a8 8 0 0 1-16 0c0-4 3-6 4-9 .8 1 1.5 1.5 4-1z"/></svg>),
};

/* ---------- Coin marks ---------- */
function BtcCoin({ size = 30 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 40 40" className="coin">
      <defs>
        <linearGradient id="btcg" x1="0" y1="0" x2="0" y2="1">
          <stop offset="0" stopColor="#FFB14D"/><stop offset="1" stopColor="#F7931A"/>
        </linearGradient>
      </defs>
      <circle cx="20" cy="20" r="20" fill="url(#btcg)"/>
      <path d="M26 17.4c.3-2-1.2-3-3.3-3.7l.7-2.7-1.7-.4-.7 2.6c-.4-.1-.9-.2-1.3-.3l.7-2.7-1.6-.4-.7 2.7-3.4-.8-.4 1.8s1.2.3 1.2.3c.7.2.8.6.8 1l-1.9 7.7c-.1.2-.3.5-.8.4 0 0-1.2-.3-1.2-.3l-.8 1.9 3.2.8-.7 2.8 1.6.4.7-2.7c.5.1.9.2 1.3.3l-.7 2.7 1.7.4.7-2.8c2.8.5 4.9.3 5.8-2.2.7-2 0-3.2-1.5-4 1.1-.2 1.9-1 2.1-2.4zm-3.8 5.3c-.5 2-3.9.9-5 .6l.9-3.6c1.1.3 4.6.8 4.1 3zm.5-5.4c-.5 1.8-3.3.9-4.2.7l.8-3.3c.9.2 3.9.6 3.4 2.6z" fill="#23130a"/>
    </svg>
  );
}
/* Real CHD brand logo (uploaded) */
function ChdLogo({ size = 30, radius }) {
  return (
    <img src="assets/chd-logo.png" alt="ChadCoin" width={size} height={size}
      style={{ borderRadius: radius != null ? radius : size * 0.28, display:"block", flexShrink:0 }} />
  );
}
const ChdCoin = ChdLogo; // CHD token now uses the real brand mark everywhere
function SolMark({ size = 26 }) {
  return (
    <svg width={size} height={size} viewBox="0 0 40 40">
      <defs><linearGradient id="solg" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stopColor="#9945FF"/><stop offset="1" stopColor="#14F195"/></linearGradient></defs>
      <circle cx="20" cy="20" r="20" fill="#13100b"/>
      <g fill="url(#solg)">
        <path d="M12 15.5c.2-.2.5-.3.8-.3h14.4c.4 0 .6.5.3.8l-2.6 2.6c-.2.2-.5.3-.8.3H9.9c-.4 0-.6-.5-.3-.8l2.4-2.6z"/>
        <path d="M12 25c.2-.2.5-.3.8-.3h14.4c.4 0 .6.5.3.8l-2.6 2.5c-.2.2-.5.3-.8.3H9.9c-.4 0-.6-.5-.3-.8L12 25z" opacity=".85"/>
        <path d="M27.2 20.2c-.2-.2-.5-.3-.8-.3H12c-.4 0-.6.4-.3.7l2.6 2.6c.2.2.5.3.8.3h14.4c.4 0 .6-.5.3-.8l-2.6-2.5z" opacity=".93"/>
      </g>
    </svg>
  );
}

/* ============================================================
   Real wallet logos (simplified brand marks, self-contained SVG)
   ============================================================ */
const WalletLogos = {
  google: (s) => (
    <svg width={s} height={s} viewBox="0 0 40 40"><rect width="40" height="40" rx="11" fill="#fff" stroke="#E6E3DD"/>
      <path d="M28.6 20.2c0-.6-.1-1.2-.2-1.8H20v3.5h4.8a4.1 4.1 0 0 1-1.8 2.7v2.2h2.9c1.7-1.6 2.7-3.9 2.7-6.6z" fill="#4285F4"/>
      <path d="M20 29c2.4 0 4.5-.8 6-2.2l-2.9-2.2c-.8.5-1.8.9-3.1.9-2.4 0-4.4-1.6-5.1-3.8h-3v2.3A9 9 0 0 0 20 29z" fill="#34A853"/>
      <path d="M14.9 19.7c-.2-.5-.3-1.1-.3-1.7s.1-1.2.3-1.7v-2.3h-3a9 9 0 0 0 0 8.1l3-2.4z" fill="#FBBC05"/>
      <path d="M20 12.5c1.3 0 2.5.5 3.5 1.4l2.6-2.6A9 9 0 0 0 11.9 14l3 2.3c.7-2.2 2.7-3.8 5.1-3.8z" fill="#EA4335"/></svg>
  ),
  phantom: (s) => (
    <svg width={s} height={s} viewBox="0 0 40 40"><rect width="40" height="40" rx="11" fill="#AB9FF2"/>
      <path d="M20 10c-5.6 0-10.2 4.5-10.4 10.2 0 .1 0 6.6 0 6.6 0 .9 1.1 1.4 1.8.8l1.7-1.4c.4-.3 1-.3 1.4 0l1.8 1.5c.4.3 1 .3 1.4 0l1.8-1.5c.4-.3 1-.3 1.4 0l1.8 1.5c.4.3 1 .3 1.4 0l1.7-1.4c.7-.6 1.8-.1 1.8.8 0 0 .4-6.4.4-6.6C30.2 14.5 25.6 10 20 10z" fill="#fff"/>
      <ellipse cx="17" cy="19.5" rx="1.7" ry="3" fill="#534BB1"/><ellipse cx="23" cy="19.5" rx="1.7" ry="3" fill="#534BB1"/></svg>
  ),
  solflare: (s) => (
    <svg width={s} height={s} viewBox="0 0 40 40"><defs><linearGradient id="sf" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stopColor="#FFC03A"/><stop offset="1" stopColor="#FC7227"/></linearGradient></defs>
      <rect width="40" height="40" rx="11" fill="url(#sf)"/>
      <circle cx="20" cy="20" r="5.2" fill="#fff"/>
      <g stroke="#fff" strokeWidth="2.1" strokeLinecap="round"><path d="M20 9v3.4"/><path d="M20 27.6V31"/><path d="M9 20h3.4"/><path d="M27.6 20H31"/><path d="M12.2 12.2l2.4 2.4"/><path d="M25.4 25.4l2.4 2.4"/><path d="M27.8 12.2l-2.4 2.4"/><path d="M14.6 25.4l-2.4 2.4"/></g></svg>
  ),
  backpack: (s) => (
    <svg width={s} height={s} viewBox="0 0 40 40"><rect width="40" height="40" rx="11" fill="#E33E3F"/>
      <path d="M13.5 21a6.5 6.5 0 0 1 13 0v6.5a1.5 1.5 0 0 1-1.5 1.5H15a1.5 1.5 0 0 1-1.5-1.5V21z" fill="#fff"/>
      <path d="M17 14.5c0-1.7 6-1.7 6 0" fill="none" stroke="#fff" strokeWidth="2" strokeLinecap="round"/>
      <rect x="17.5" y="24" width="5" height="5" rx="1.3" fill="#E33E3F"/>
      <path d="M14 21.5h12" stroke="#E33E3F" strokeWidth="1.6"/></svg>
  ),
  coinbase: (s) => (
    <svg width={s} height={s} viewBox="0 0 40 40"><rect width="40" height="40" rx="11" fill="#1652F0"/>
      <circle cx="20" cy="20" r="9.5" fill="none" stroke="#fff" strokeWidth="3"/>
      <rect x="16.5" y="16.5" width="7" height="7" rx="1.6" fill="#fff"/></svg>
  ),
  magiceden: (s) => (
    <svg width={s} height={s} viewBox="0 0 40 40"><defs><linearGradient id="me" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stopColor="#E42575"/><stop offset="1" stopColor="#9945FF"/></linearGradient></defs>
      <rect width="40" height="40" rx="11" fill="#17141C"/>
      <path d="M12 27V15.5c0-.8 1-1.2 1.6-.6l4.2 4.4c.3.3.8.3 1.1 0l4.2-4.4c.6-.6 1.6-.2 1.6.6V27" fill="none" stroke="url(#me)" strokeWidth="2.6" strokeLinecap="round" strokeLinejoin="round"/>
      <circle cx="28" cy="24" r="1.6" fill="url(#me)"/></svg>
  ),
  trust: (s) => (
    <svg width={s} height={s} viewBox="0 0 40 40"><defs><linearGradient id="tw" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stopColor="#3375BB"/><stop offset="1" stopColor="#0500FF"/></linearGradient></defs>
      <rect width="40" height="40" rx="11" fill="url(#tw)"/>
      <path d="M20 10l8 2.8v6.2c0 5-3.3 8.6-8 10.3-4.7-1.7-8-5.3-8-10.3v-6.2L20 10z" fill="#fff"/>
      <path d="M20 13.4v13.2c3.2-1.3 5.4-3.9 5.4-7.5v-3.9L20 13.4z" fill="#3375BB"/></svg>
  ),
  ledger: (s) => (
    <svg width={s} height={s} viewBox="0 0 40 40"><rect width="40" height="40" rx="11" fill="#000"/>
      <path d="M13 13h8v2.6h-5.4V25H13V13z" fill="#fff"/>
      <path d="M27 27h-8v-2.6h5.4V15H27v12z" fill="#fff"/></svg>
  ),
  coin98: (s) => (
    <svg width={s} height={s} viewBox="0 0 40 40"><defs><linearGradient id="c98" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stopColor="#F2C24B"/><stop offset="1" stopColor="#D29A2A"/></linearGradient></defs>
      <rect width="40" height="40" rx="11" fill="#0B0B0C"/>
      <circle cx="20" cy="20" r="9.5" fill="url(#c98)"/>
      <text x="20" y="24.2" textAnchor="middle" fontFamily="JetBrains Mono, monospace" fontWeight="700" fontSize="10" fill="#0B0B0C">98</text></svg>
  ),
  bitget: (s) => (
    <svg width={s} height={s} viewBox="0 0 40 40"><rect width="40" height="40" rx="11" fill="#0E0E10"/>
      <path d="M18 11l-6 6.5 7 7.5-3.5 4h6l6-6.5-7-7.5L24 11h-6z" fill="#00F0C8"/></svg>
  ),
  walletconnect: (s) => (
    <svg width={s} height={s} viewBox="0 0 40 40"><rect width="40" height="40" rx="11" fill="#3396FF"/>
      <path d="M13 17.8c3.9-3.8 10.1-3.8 14 0l.5.5c.2.2.2.5 0 .7l-1.6 1.6c-.1.1-.3.1-.4 0l-.7-.6c-2.7-2.7-7.1-2.7-9.8 0l-.7.7c-.1.1-.3.1-.4 0l-1.6-1.6c-.2-.2-.2-.5 0-.7l1.2-.6z" fill="#fff"/></svg>
  ),
};
function WalletLogo({ id, size = 40 }) {
  const fn = WalletLogos[id];
  return fn ? fn(size) : <div className="wallet-ic" style={{ width:size, height:size, background:"#222", color:"#fff" }}>?</div>;
}
function WalletTile({ w, size = 40 }) {
  return <WalletLogo id={w.id} size={size} />;
}

/* ---------- Data ---------- */
const WALLETS = [
  { id:"google",        name:"Connexion Google", tag:"Quick", type:"social" },
  { id:"phantom",       name:"Phantom",          detected:true },
  { id:"solflare",      name:"Solflare",         detected:true },
  { id:"backpack",      name:"Backpack" },
  { id:"coinbase",      name:"Coinbase Wallet" },
  { id:"magiceden",     name:"Magic Eden" },
  { id:"trust",         name:"Trust Wallet" },
  { id:"ledger",        name:"Ledger" },
  { id:"coin98",        name:"Coin98" },
  { id:"bitget",        name:"Bitget Wallet" },
  { id:"walletconnect", name:"WalletConnect" },
];

const STEPS = [
  { n:"1", t:"Connecte ton wallet", d:"Phantom, Solflare, Coinbase, Kraken… N'importe quel wallet Solana. Aucune inscription, aucun KYC." },
  { n:"2", t:"Échange SOL → CHD", d:"Swap instantané via Jupiter en quelques secondes. Frais de réseau inférieurs à 0,001 $." },
  { n:"3", t:"Accumule des satoshis", d:"Chaque CHD = 1 satoshi de vrai Bitcoin. Quand le BTC monte, tes CHD valent plus." },
  { n:"4", t:"Récupère ton Bitcoin", d:"À tout moment, brûle tes CHD pour récupérer l'équivalent exact en tBTC. Garanti 1:1." },
];

const FEATURES = [
  { ic:"shield", t:"100 % Bitcoin-backed", d:"Chaque CHD est garanti par du vrai Bitcoin (tBTC) verrouillé dans le smart contract. Vérifiable on-chain à tout instant." },
  { ic:"bolt",   t:"Instantané et quasi gratuit", d:"Solana règle les transactions en moins d'une seconde, pour des frais inférieurs à 0,001 $." },
  { ic:"lock",   t:"Peg garanti par le code", d:"1 CHD = 1 satoshi, toujours. Le contrat te garantit de pouvoir brûler tes CHD contre du tBTC quand tu veux." },
  { ic:"globe",  t:"Pensé pour l'Afrique", d:"Accéder au Bitcoin depuis n'importe quel téléphone, sans banque — pour toute l'Afrique francophone." },
  { ic:"unlock", t:"Totalement décentralisé", d:"Contrat open-source sur Solana. Aucune permission, aucun intermédiaire. Tes fonds t'appartiennent." },
  { ic:"chart",  t:"Suit le Bitcoin", d:"Quand le BTC double, la valeur en dollars de tes CHD double. Tu accumules des sats à chaque achat." },
];

const CHECKS = [
  "Aucune inscription ni KYC requis",
  "Frais de transaction inférieurs à 0,001 $",
  "Compatible Phantom, Solflare, Backpack, Coinbase…",
  "Peg 1:1 Bitcoin garanti par le contrat",
  "Revendable à tout moment contre du tBTC",
];

const TOKENOMICS = [
  { v:"2,1 quadrillions", l:"Supply maximum (21M BTC)" },
  { v:"1 satoshi", l:"Valeur de 1 CHD" },
  { v:"100 %", l:"Collatéral tBTC" },
  { v:"Solana", l:"Blockchain" },
];

const CHAIN_LINKS = [
  { t:"Programme Solana", href:"https://solscan.io/account/7EvYneUQeZZBgodUxggqxiEDfv4Cqhp3NcXDhvcFkNQg" },
  { t:"CHD Mint", href:"https://solscan.io/token/CktvyfZ4V9fyRzrFQfmnNX4UTpT4PDnrDZXNXsBsiQV9" },
  { t:"DEXScreener", href:"https://dexscreener.com/solana/6x48wPfsLrZPF7q9hi2XoqBnoJjgoyXERGgoBGBGq2CZ" },
  { t:"Birdeye", href:"https://birdeye.so/token/CktvyfZ4V9fyRzrFQfmnNX4UTpT4PDnrDZXNXsBsiQV9" },
  { t:"Pool Meteora", href:"https://meteora.ag/dammv2/6x48wPfsLrZPF7q9hi2XoqBnoJjgoyXERGgoBGBGq2CZ" },
];

const FAQS = [
  { q:"Qu'est-ce que ChadCoin (CHD) exactement ?", a:"ChadCoin est un token sur la blockchain Solana entièrement adossé au Bitcoin. Chaque CHD représente exactement 1 satoshi (0,00000001 BTC). Quand tu achètes des CHD, tu accumules du Bitcoin sous forme de satoshis." },
  { q:"Comment le peg 1:1 est-il garanti ?", a:"Le smart contract garantit que chaque CHD peut être brûlé à tout moment contre exactement 1 satoshi de tBTC. Le vault contient toujours autant de tBTC qu'il y a de CHD en circulation — tout est vérifiable on-chain." },
  { q:"De quel wallet ai-je besoin ?", a:"N'importe quel wallet Solana : Phantom (recommandé pour débuter), Solflare, Backpack, Coinbase Wallet, Kraken… Le wallet doit contenir un peu de SOL pour payer les frais de réseau (environ 0,001 $)." },
  { q:"Puis-je récupérer mon Bitcoin à tout moment ?", a:"Oui, à tout moment. Tu peux brûler tes CHD via le protocole pour récupérer l'équivalent exact en tBTC. Le processus est instantané et garanti par le contrat. Le tBTC peut ensuite être échangé contre du vrai BTC." },
  { q:"Quels sont les risques ?", a:"Comme tout actif crypto, la valeur en dollars suit le prix du Bitcoin — elle peut monter ou baisser. Le protocole est audité et le peg 1:1 est garanti par le code. Le principal risque est la volatilité du BTC, pas le protocole." },
];

/* rates for the simulated swap */
const SOL_USD = 168.0;
const BTC_USD = 104000;
const CHD_USD = BTC_USD / 1e8;           // 1 CHD = 1 sat
const CHD_PER_SOL = SOL_USD / CHD_USD;   // ~ how many CHD per 1 SOL

function fmt(n, max = 2) {
  return n.toLocaleString("fr-FR", { maximumFractionDigits:max });
}
function shortAddr(a){ return a.slice(0,4) + "…" + a.slice(-4); }

Object.assign(window, {
  Ic, BtcCoin, ChdCoin, ChdLogo, SolMark, WalletTile, WalletLogo,
  WALLETS, STEPS, FEATURES, CHECKS, TOKENOMICS, CHAIN_LINKS, FAQS,
  SOL_USD, BTC_USD, CHD_USD, CHD_PER_SOL, fmt, shortAddr,
  HELIUS_RPC, CHD_MINT, SOL_MINT, TBTC_MINT, SLIPPAGE_BPS,
  PROGRAM_ID, STATE_PDA, VAULT_TBTC, TOKEN_PROGRAM_ID, ASSOC_TOKEN_PROGRAM_ID, SYSTEM_PROGRAM_ID,
});
