@metamask-previews/notification-services-controller 0.10.0-preview-557a8fcb → 0.10.0-preview-3c1aabe6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-notification-data.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-data.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-notification-data.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,qBAAqB;AAMzC,MAAM,oBAAoB,GAAG;IAC3B,aAAa,EAAE,CAAC;CACjB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,QAAgB;IAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAC;IACvD,OAAO,IAAI,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAoB,EAAE,EAAE;IAC1D,MAAM,WAAW,GAAG,IAAI,SAAS,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACxD,MAAM,cAAc,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IACvD,OAAO,cAAc,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;AACxD,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,aAA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,EACvB,EAAE;IACF,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE;QACxB,OAAO,EAAE,CAAC;KACX;IAED,MAAM,aAAa,GAAG,eAAe,CACnC,MAAM,EACN,UAAU,CAAC,QAAQ,CAAC,CACrB,CAAC,QAAQ,EAAE,CAAC;IAEb,OAAO,YAAY,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;AAC9C,CAAC,CAAC","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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/notification-services-controller",
|
|
3
|
-
"version": "0.10.0-preview-
|
|
3
|
+
"version": "0.10.0-preview-3c1aabe6",
|
|
4
4
|
"description": "Manages New MetaMask decentralized Notification system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -102,7 +102,7 @@
|
|
|
102
102
|
"@contentful/rich-text-html-renderer": "^16.5.2",
|
|
103
103
|
"@metamask/base-controller": "^7.0.1",
|
|
104
104
|
"@metamask/controller-utils": "^11.3.0",
|
|
105
|
-
"bignumber.js": "^
|
|
105
|
+
"bignumber.js": "^9.1.2",
|
|
106
106
|
"firebase": "^10.11.0",
|
|
107
107
|
"loglevel": "^1.8.1",
|
|
108
108
|
"uuid": "^8.3.2"
|