/// 与 Web `evmRecharge.ts` 对齐：根据 protocol / networkName 解析 EVM chainId。
int? resolveEvmChainId(String protocol, String networkName) {
  final p = protocol.toLowerCase().trim();
  final n = networkName.toLowerCase().trim();
  if (p.contains('tron') || n == 'trc20') {
    return null;
  }
  if (n == 'bep20' || p.contains('bsc') || p.contains('bnb')) {
    return 56;
  }
  if ((n == 'erc20' || n == 'erc-20') && p.contains('arbitrum')) {
    return 42161;
  }
  if ((n == 'erc20' || n == 'erc-20') &&
      (p.contains('polygon') || p.contains('matic'))) {
    return 137;
  }
  if ((n == 'erc20' || n == 'erc-20') && p.contains('base')) {
    return 8453;
  }
  if ((n == 'erc20' || n == 'erc-20') && p.contains('optimism')) {
    return 10;
  }
  if (n == 'erc20' || n == 'erc-20' || p.contains('ethereum') || p == 'eth') {
    return 1;
  }
  if (p.contains('polygon') || p.contains('matic')) {
    return 137;
  }
  if (p.contains('arbitrum')) {
    return 42161;
  }
  if (p.contains('base')) {
    return 8453;
  }
  if (p.contains('optimism')) {
    return 10;
  }
  return null;
}

/// USDT 精度：主网 6，其它常见链 18（与 Web 一致）。
int erc20DecimalsForChain(int chainId) {
  if (chainId == 1) {
    return 6;
  }
  return 18;
}

String chainIdToCaip2(int chainId) => 'eip155:$chainId';

String chainIdHex(int chainId) => '0x${chainId.toRadixString(16)}';
