{"version":3,"file":"BP7_cPWX.js","sources":["../../../../utilities/chia-display-utils.ts"],"sourcesContent":["export const shortHex = (hexString: string | undefined) => {\n  return hexString ? `0x${hexString.substr(0, 10)}` : undefined;\n};\n\nexport const formatXchPrice = (xchAmount: number, fullPrecision = false) => {\n  if (fullPrecision) {\n    return xchAmount + ' XCH';\n  }\n  if (xchAmount >= 1000) {\n    return parseFloat(xchAmount.toFixed(0)).toLocaleString('en') + ' XCH';\n  } else if (xchAmount >= 0.00001) {\n    return parseFloat(xchAmount.toFixed(6)).toLocaleString('en', { maximumFractionDigits: 6 }) + ' XCH';\n  } else {\n    const mojoAmount = xchAmount * 10 ** 12;\n    return new Intl.NumberFormat().format(mojoAmount) + ' mojo' + (mojoAmount > 1 ? 's' : '');\n  }\n};\n\nexport function mojosToXchString(mojos: string) {\n  // The float precision of JavaScript is too bad to convert the large amount of mojos to XCH without rounding.\n  // Therefore, a different approach is used: Handling it as string and placing a decimal point.\n\n  const xchElements = [];\n  const mojosElements = String(mojos).split('').reverse();\n\n  let numDec = 12; // Conversion factor = 1/ (10^numDec)\n  let decPlaced = false;\n\n  for (const digit of mojosElements) {\n    xchElements.push(digit);\n    numDec--;\n    if (!decPlaced && numDec === 0) {\n      decPlaced = true;\n      xchElements.push('.');\n    }\n  }\n\n  if (!decPlaced) {\n    for (let i = numDec; i > 0; i--) {\n      xchElements.push('0');\n    }\n    xchElements.push('0.');\n  } else if (numDec === 0) {\n    xchElements.push('0');\n  }\n\n  return xchElements.reverse().join('');\n}\n"],"names":["formatXchPrice","xchAmount","fullPrecision","mojoAmount"],"mappings":"AAIO,MAAMA,EAAiB,CAACC,EAAmBC,EAAgB,KAAU,CAC1E,GAAIA,EACF,OAAOD,EAAY,OAErB,GAAIA,GAAa,IACR,OAAA,WAAWA,EAAU,QAAQ,CAAC,CAAC,EAAE,eAAe,IAAI,EAAI,OACjE,GAAWA,GAAa,KACtB,OAAO,WAAWA,EAAU,QAAQ,CAAC,CAAC,EAAE,eAAe,KAAM,CAAE,sBAAuB,CAAG,CAAA,EAAI,OACxF,CACC,MAAAE,EAAaF,EAAY,KACxB,OAAA,IAAI,KAAK,aAAe,EAAA,OAAOE,CAAU,EAAI,SAAWA,EAAa,EAAI,IAAM,GACxF,CACF"}