{"version":3,"sources":["../src/NotificationServicesPushController/utils/get-notification-data.ts"],"sourcesContent":["import { BigNumber } from 'bignumber.js';\n\ntype FormatOptions = {\n  decimalPlaces?: number;\n  shouldEllipse?: boolean;\n};\nconst defaultFormatOptions = {\n  decimalPlaces: 4,\n};\n\n/**\n * Calculates the token amount based on the given value and decimals.\n *\n * @param value - The value to calculate the token amount from.\n * @param decimals - The number of decimals to use for the calculation.\n * @returns The calculated token amount.\n */\nexport function calcTokenAmount(value: string, decimals: number) {\n  const multiplier = Math.pow(10, Number(decimals || 0));\n  return new BigNumber(String(value)).div(multiplier);\n}\n\n/**\n * Calculates the number of leading zeros in the fractional part of a number.\n *\n * This function converts a number or a string representation of a number into\n * its decimal form and then counts the number of leading zeros present in the\n * fractional part of the number. This is useful for determining the precision\n * of very small numbers.\n *\n * @param num - The number to analyze, which can be in the form\n * of a number or a string.\n * @returns The count of leading zeros in the fractional part of the number.\n */\nexport const getLeadingZeroCount = (num: number | string) => {\n  const numToString = new BigNumber(num, 10).toString(10);\n  const fractionalPart = numToString.split('.')[1] ?? '';\n  return fractionalPart.match(/^0*/u)?.[0]?.length || 0;\n};\n\n/**\n * This formats a number using Intl\n * It abbreviates large numbers (using K, M, B, T)\n * And abbreviates small numbers in 2 ways:\n * - Will format to the given number of decimal places\n * - Will format up to 4 decimal places\n * - Will ellipse the number if longer than given decimal places\n *\n * @param numericAmount - The number to format\n * @param opts - The options to use when formatting\n * @returns The formatted number\n */\nexport const formatAmount = (numericAmount: number, opts?: FormatOptions) => {\n  // create options with defaults\n  const options = { ...defaultFormatOptions, ...opts };\n\n  const leadingZeros = getLeadingZeroCount(numericAmount);\n  const isDecimal = numericAmount.toString().includes('.') || leadingZeros > 0;\n  const isLargeNumber = numericAmount > 999;\n\n  const handleShouldEllipse = (decimalPlaces: number) =>\n    Boolean(options?.shouldEllipse) && leadingZeros >= decimalPlaces;\n\n  if (isLargeNumber) {\n    return Intl.NumberFormat('en-US', {\n      notation: 'compact',\n      compactDisplay: 'short',\n      maximumFractionDigits: 2,\n    }).format(numericAmount);\n  }\n\n  if (isDecimal) {\n    const ellipse = handleShouldEllipse(options.decimalPlaces);\n    const formattedValue = Intl.NumberFormat('en-US', {\n      minimumFractionDigits: ellipse ? options.decimalPlaces : undefined,\n      maximumFractionDigits: options.decimalPlaces,\n    }).format(numericAmount);\n\n    return ellipse ? `${formattedValue}...` : formattedValue;\n  }\n\n  // Default to showing the raw amount\n  return numericAmount.toString();\n};\n\nexport const getAmount = (\n  amount: string,\n  decimals: string,\n  options?: FormatOptions,\n) => {\n  if (!amount || !decimals) {\n    return '';\n  }\n\n  const numericAmount = calcTokenAmount(\n    amount,\n    parseFloat(decimals),\n  ).toNumber();\n\n  return formatAmount(numericAmount, options);\n};\n"],"mappings":";AAAA,SAAS,iBAAiB;AAM1B,IAAM,uBAAuB;AAAA,EAC3B,eAAe;AACjB;AASO,SAAS,gBAAgB,OAAe,UAAkB;AAC/D,QAAM,aAAa,KAAK,IAAI,IAAI,OAAO,YAAY,CAAC,CAAC;AACrD,SAAO,IAAI,UAAU,OAAO,KAAK,CAAC,EAAE,IAAI,UAAU;AACpD;AAcO,IAAM,sBAAsB,CAAC,QAAyB;AAC3D,QAAM,cAAc,IAAI,UAAU,KAAK,EAAE,EAAE,SAAS,EAAE;AACtD,QAAM,iBAAiB,YAAY,MAAM,GAAG,EAAE,CAAC,KAAK;AACpD,SAAO,eAAe,MAAM,MAAM,IAAI,CAAC,GAAG,UAAU;AACtD;AAcO,IAAM,eAAe,CAAC,eAAuB,SAAyB;AAE3E,QAAM,UAAU,EAAE,GAAG,sBAAsB,GAAG,KAAK;AAEnD,QAAM,eAAe,oBAAoB,aAAa;AACtD,QAAM,YAAY,cAAc,SAAS,EAAE,SAAS,GAAG,KAAK,eAAe;AAC3E,QAAM,gBAAgB,gBAAgB;AAEtC,QAAM,sBAAsB,CAAC,kBAC3B,QAAQ,SAAS,aAAa,KAAK,gBAAgB;AAErD,MAAI,eAAe;AACjB,WAAO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