Skip to content

Commit

Permalink
chore: fix file/folder structure & reduce duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
JSoufer committed Jul 18, 2024
1 parent 55032d0 commit 985ea0f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 63 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getErrorMessage } from '@metamask/utils';

import { notificationsErrors } from './helpers/constants';
import Engine from '../../core/Engine';
import { Notification } from '../../util/notifications';
import { notificationsErrors } from '../constants';
import Engine from '../../../core/Engine';
import { Notification } from '../../../util/notifications';

const {
AuthenticationController,
Expand Down
4 changes: 2 additions & 2 deletions app/util/notifications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export * from './constants';
export * from './setupAndroidChannels';
export * from './settings';
export * from './hooks';
export * from './notification.util';
export * from './push-permissions';
export * from './methods';
export * from './pushPermissions';
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Web3Provider } from '@ethersproject/providers';
import { toHex } from '@metamask/controller-utils';
import { NotificationServicesController } from '@metamask/notification-services-controller';
import Engine from '../../core/Engine';
import Engine from '../../../core/Engine';
import { BigNumber } from 'bignumber.js';
import { IconName } from '../../component-library/components/Icons/Icon';
import images from '../../images/image-icons';
import { hexWEIToDecETH, hexWEIToDecGWEI } from '../conversions';
import { calcTokenAmount } from '../transactions';
import { TRIGGER_TYPES } from './constants';
import { Notification } from './types';
import { IconName } from '../../../component-library/components/Icons/Icon';
import images from '../../../images/image-icons';
import { hexWEIToDecETH, hexWEIToDecGWEI } from '../../conversions';
import { calcTokenAmount } from '../../transactions';
import { TRIGGER_TYPES } from '../constants';
import { Notification } from '../types';

const { UI } = NotificationServicesController;

Expand Down Expand Up @@ -344,29 +344,6 @@ export function getBlockExplorerByChainId(chainId: number) {
return undefined;
}

/**
* Formats an ISO date string into a more readable format.
*
* @param isoDateString - The ISO date string to format.
* @returns The formatted date string.
*/
export function formatIsoDateString(isoDateString: string) {
const date = new Date(isoDateString);

const options = {
year: 'numeric' as const,
month: 'short' as const,
day: 'numeric' as const,
hour: 'numeric' as const,
minute: 'numeric' as const,
hour12: true,
};

const formattedDate = new Intl.DateTimeFormat('en-US', options).format(date);

return formattedDate;
}

export function hasNetworkFeeFields(
notification: NotificationServicesController.Types.OnChainRawNotification,
): notification is NotificationServicesController.Types.OnChainRawNotificationsWithNetworkFields {
Expand Down Expand Up @@ -450,14 +427,6 @@ export const getNetworkFees = async (
}
};

/**
* Checks if a given URL is an IPFS URL.
*
* @param url - The URL to check.
* @returns True if the URL is an IPFS URL, false otherwise.
*/
export const isIpfsURL = (url: string): boolean => url.startsWith('ipfs://');

export const getNotificationBadge = (trigger_type: string) => {
switch (trigger_type) {
case TRIGGER_TYPES.ERC20_SENT:
Expand Down Expand Up @@ -495,25 +464,6 @@ export const TRUNCATED_ADDRESS_START_CHARS = 7;
// `${TRUNCATED_ADDRESS_START_CHARS}...${TRUNCATED_ADDRESS_END_CHARS}`
export const TRUNCATED_ADDRESS_END_CHARS = 5;

/**
* Shortens an Ethereum address for display, preserving the beginning and end.
* Returns the given address if it is no longer than 10 characters.
* Shortened addresses are 13 characters long.
*
* Example output: 0xabcde...12345
*
* @param {string} address - The address to shorten.
* @returns {string} The shortened address, or the original if it was no longer
* than 10 characters.
*/
export function shortenAddress(address = '') {
return shortenString(address, {
truncatedCharLimit: TRUNCATED_NAME_CHAR_LIMIT,
truncatedStartChars: TRUNCATED_ADDRESS_START_CHARS,
truncatedEndChars: TRUNCATED_ADDRESS_END_CHARS,
});
}

/**
* Shortens the given string, preserving the beginning and end.
* Returns the string it is no longer than truncatedCharLimit.
Expand Down
2 changes: 2 additions & 0 deletions app/util/notifications/methods/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './fcmHelper';
export * from './common';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import notifee, { AuthorizationStatus } from '@notifee/react-native';
import { Alert } from 'react-native';

import { strings } from '../../../locales/i18n';
import Device from '../../util/device';
import Device from '../device';
import { mmStorage } from './settings';
import { STORAGE_IDS } from './settings/storage/constants';
import Logger from '../Logger';
Expand Down

0 comments on commit 985ea0f

Please sign in to comment.