Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1578,33 +1578,6 @@
"count": 70
}
},
"packages/notification-services-controller/src/NotificationServicesPushController/services/services.ts": {
"@typescript-eslint/naming-convention": {
"count": 1
}
},
"packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-data.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 5
},
"@typescript-eslint/prefer-nullish-coalescing": {
"count": 1
},
"id-denylist": {
"count": 1
}
},
"packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 5
},
"@typescript-eslint/naming-convention": {
"count": 2
},
"id-length": {
"count": 9
}
},
"packages/phishing-controller/src/BulkTokenScan.test.ts": {
"@typescript-eslint/explicit-function-return-type": {
"count": 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export type RegToken = {
*/
export type PushTokenRequest = {
addresses: string[];
// API response uses snake_case for this property
// eslint-disable-next-line @typescript-eslint/naming-convention
registration_token: {
token: string;
platform: 'extension' | 'mobile' | 'portfolio';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const defaultFormatOptions = {
* @param decimals - The number of decimals to use for the calculation.
* @returns The calculated token amount.
*/
export function calcTokenAmount(value: string, decimals: number) {
export function calcTokenAmount(value: string, decimals: number): BigNumber {
const multiplier = Math.pow(10, Number(decimals || 0));
return new BigNumber(String(value)).div(multiplier);
}
Expand All @@ -28,14 +28,14 @@ export function calcTokenAmount(value: string, decimals: number) {
* fractional part of the number. This is useful for determining the precision
* of very small numbers.
*
* @param num - The number to analyze, which can be in the form
* @param numericValue - The number to analyze, which can be in the form
* of a number or a string.
* @returns The count of leading zeros in the fractional part of the number.
*/
export const getLeadingZeroCount = (num: number | string) => {
const numToString = new BigNumber(num, 10).toString(10);
export const getLeadingZeroCount = (numericValue: number | string): number => {
const numToString = new BigNumber(numericValue, 10).toString(10);
const fractionalPart = numToString.split('.')[1] ?? '';
return fractionalPart.match(/^0*/u)?.[0]?.length || 0;
return fractionalPart.match(/^0*/u)?.[0]?.length ?? 0;
};

/**
Expand All @@ -50,15 +50,18 @@ export const getLeadingZeroCount = (num: number | string) => {
* @param opts - The options to use when formatting
* @returns The formatted number
*/
export const formatAmount = (numericAmount: number, opts?: FormatOptions) => {
export const formatAmount = (
numericAmount: number,
opts?: FormatOptions,
): string => {
// create options with defaults
const options = { ...defaultFormatOptions, ...opts };

const leadingZeros = getLeadingZeroCount(numericAmount);
const isDecimal = numericAmount.toString().includes('.') || leadingZeros > 0;
const isLargeNumber = numericAmount > 999;

const handleShouldEllipse = (decimalPlaces: number) =>
const handleShouldEllipse = (decimalPlaces: number): boolean =>
Boolean(options?.shouldEllipse) && leadingZeros >= decimalPlaces;

if (isLargeNumber) {
Expand Down Expand Up @@ -87,7 +90,7 @@ export const getAmount = (
amount: string,
decimals: string,
options?: FormatOptions,
) => {
): string => {
if (!amount || !decimals) {
return '';
}
Expand Down
Loading
Loading