Skip to content

Commit

Permalink
chore: lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
georgewrmarshall committed Jan 23, 2025
1 parent 4a9a8a2 commit 5e4b506
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 97 deletions.
3 changes: 1 addition & 2 deletions app/components/UI/AccountApproval/styles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { StyleSheet } from 'react-native';
import Device from '../../../util/device';
import type { ThemeColors } from '@metamask/design-tokens';
import type { ThemeTypography } from '@metamask/design-tokens';
import type { ThemeColors, ThemeTypography } from '@metamask/design-tokens';

const createStyles = (colors: ThemeColors, typography: ThemeTypography) =>
StyleSheet.create({
Expand Down
3 changes: 1 addition & 2 deletions app/components/UI/Notification/Modal/styles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Third party dependencies.
import { StyleSheet, TextStyle } from 'react-native';
import { typography } from '@metamask/design-tokens';
import { ThemeColors } from '@metamask/design-tokens';
import { typography, ThemeColors } from '@metamask/design-tokens';

/**
* Style sheet function for AmbiguousAddressSheet component.
Expand Down
18 changes: 12 additions & 6 deletions app/components/UI/Ramp/components/PaymentMethodIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,18 @@ function getIconComponent(icon: PaymentIcon) {
}

/*
* With the integration of Expo, it introduced a compatibility layer (https://github.com/expo/vector-icons)
* around react-native-vector-icons which doesn't expose hasIcon anymore so we need to build our own based on
* the implementation https://github.com/oblador/react-native-vector-icons/blob/master/lib/create-icon-set.js#L158
*/
function hasIcon(IconComponent: { glyphMap: { [key: string]: number } }, name: string) {
return IconComponent?.glyphMap && Object.prototype.hasOwnProperty.call(IconComponent.glyphMap, name);
* With the integration of Expo, it introduced a compatibility layer (https://github.com/expo/vector-icons)
* around react-native-vector-icons which doesn't expose hasIcon anymore so we need to build our own based on
* the implementation https://github.com/oblador/react-native-vector-icons/blob/master/lib/create-icon-set.js#L158
*/
function hasIcon(
IconComponent: { glyphMap: { [key: string]: number } },
name: string,
) {
return (
IconComponent?.glyphMap &&
Object.prototype.hasOwnProperty.call(IconComponent.glyphMap, name)
);
}

function getIcon(icon: PaymentIcon) {
Expand Down
3 changes: 1 addition & 2 deletions app/components/UI/SDKFeedback/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ThemeColors } from '@metamask/design-tokens';
import type { ThemeTypography } from '@metamask/design-tokens';
import type { ThemeColors, ThemeTypography } from '@metamask/design-tokens';
import Icon, {
IconName,
IconSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import React, { useMemo, useRef } from 'react';

// External dependencies
import type { ThemeColors } from '@metamask/design-tokens';
import type { ThemeTypography } from '@metamask/design-tokens';
import type { ThemeColors, ThemeTypography } from '@metamask/design-tokens';
import { useNavigation } from '@react-navigation/native';
import { StyleSheet, View } from 'react-native';
import { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';
Expand Down
3 changes: 1 addition & 2 deletions app/components/Views/SDK/SDKSessionModal/SDKSessionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import React, { useEffect, useMemo, useRef, useState } from 'react';

// External dependencies
import type { ThemeColors } from '@metamask/design-tokens';
import type { ThemeTypography } from '@metamask/design-tokens';
import type { ThemeColors, ThemeTypography } from '@metamask/design-tokens';
import { useNavigation } from '@react-navigation/native';
import { StyleSheet, View } from 'react-native';
import { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ThemeColors } from '@metamask/design-tokens';
import type { ThemeTypography } from '@metamask/design-tokens';
import type { ThemeColors, ThemeTypography } from '@metamask/design-tokens';
import React, { useEffect, useState } from 'react';
import { StyleSheet, View } from 'react-native';
import { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ThemeColors } from '@metamask/design-tokens';
import type { ThemeTypography } from '@metamask/design-tokens';
import type { ThemeColors, ThemeTypography } from '@metamask/design-tokens';
import { useNavigation } from '@react-navigation/native';
import React, { useCallback, useEffect, useState } from 'react';
import { StyleSheet, View } from 'react-native';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';
import { strings } from '../../../../../locales/i18n';
import { useTheme } from '../../../../util/theme';

import type { ThemeColors } from '@metamask/design-tokens';
import type { ThemeTypography } from '@metamask/design-tokens';
import type { ThemeColors, ThemeTypography } from '@metamask/design-tokens';
import { RouteProp, useNavigation, useRoute } from '@react-navigation/native';
import { useSelector } from 'react-redux';
import Button, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ThemeColors } from '@metamask/design-tokens';
import type { ThemeTypography } from '@metamask/design-tokens';
import type { ThemeColors, ThemeTypography } from '@metamask/design-tokens';
import { TextStyle } from 'react-native';
import type { EdgeInsets } from 'react-native-safe-area-context';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Third party dependencies.
import { StyleSheet, TextStyle } from 'react-native';
import { typography } from '@metamask/design-tokens';
import type { ThemeColors } from '@metamask/design-tokens';
import { typography, ThemeColors } from '@metamask/design-tokens';

/**
* Style sheet function for AmbiguousAddressSheet component.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context';
import { strings } from '../../../../../locales/i18n';
import { useTheme } from '../../../../util/theme';

import type { ThemeColors } from '@metamask/design-tokens';
import type { ThemeTypography } from '@metamask/design-tokens';
import type { ThemeColors, ThemeTypography } from '@metamask/design-tokens';
import { SDKSelectorsIDs } from '../../../../../e2e/selectors/Settings/SDK.selectors';
import Icon, {
IconName,
Expand Down
100 changes: 56 additions & 44 deletions app/core/NotificationsManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,33 +123,37 @@ describe('NotificationManager', () => {
});

expect(title).toBe(strings('notifications.default_message_title'));
expect(message).toBe(strings('notifications.default_message_description'));
expect(message).toBe(
strings('notifications.default_message_description'),
);
});
});

describe('smartTransactionListener', () => {
const mockTransactionController = {
getTransactions: jest.fn(),
state: {
transactions: [{
id: '0x123',
txParams: {
nonce: '0x1',
from: '0x123'
transactions: [
{
id: '0x123',
txParams: {
nonce: '0x1',
from: '0x123',
},
chainId: '0x1',
time: 123,
status: 'failed' as TransactionMeta['status'],
error: { message: 'test error', rpc: { code: 0 }, name: 'Error' },
},
chainId: '0x1',
time: 123,
status: 'failed' as TransactionMeta['status'],
error: { message: 'test error', rpc: { code: 0 }, name: 'Error' }
}]
}
],
},
};

const mockControllerMessenger = {
subscribe: jest.fn(),
unsubscribe: jest.fn(),
subscribeOnceIf: jest.fn(),
tryUnsubscribe: jest.fn()
tryUnsubscribe: jest.fn(),
};

let showNotificationSpy: jest.SpyInstance;
Expand All @@ -160,19 +164,19 @@ describe('NotificationManager', () => {
value: {
TransactionController: mockTransactionController,
},
writable: true
writable: true,
});

Object.defineProperty(Engine, 'controllerMessenger', {
value: mockControllerMessenger,
writable: true
writable: true,
});
});

beforeEach(() => {
// Clear all mock interactions before each test
jest.clearAllMocks();

// Reset the notification manager before each test
notificationManager = NotificationManager.init({
navigation: mockNavigation,
Expand All @@ -183,7 +187,10 @@ describe('NotificationManager', () => {
});

// Create spy on the instance method
showNotificationSpy = jest.spyOn(notificationManager, '_showNotification');
showNotificationSpy = jest.spyOn(
notificationManager,
'_showNotification',
);
});

afterAll(() => {
Expand All @@ -197,16 +204,17 @@ describe('NotificationManager', () => {
transactionId: '0x123',
};

notificationManager.watchSubmittedTransaction({
notificationManager.watchSubmittedTransaction({
id: '0x123',
txParams: {
nonce: '0x1'
nonce: '0x1',
},
silent: false
silent: false,
});

// Get the subscriber callback
const subscriberCallback = mockControllerMessenger.subscribe.mock.calls[0][1];
const subscriberCallback =
mockControllerMessenger.subscribe.mock.calls[0][1];
await subscriberCallback(transaction);

expect(showNotificationSpy).toHaveBeenCalledWith({
Expand All @@ -217,29 +225,32 @@ describe('NotificationManager', () => {
});

it('shows a cancelled notification for cancelled smart transactions', async () => {
const mockTransaction = {
const mockTransaction = {
id: '0x123',
txParams: {
nonce: '0x1'
}
nonce: '0x1',
},
};
mockTransactionController.getTransactions.mockReturnValue([mockTransaction]);
mockTransactionController.getTransactions.mockReturnValue([
mockTransaction,
]);

const smartTransaction = {
status: SmartTransactionStatuses.CANCELLED,
transactionId: '0x123',
};

notificationManager.watchSubmittedTransaction({
notificationManager.watchSubmittedTransaction({
id: '0x123',
txParams: {
nonce: '0x1'
nonce: '0x1',
},
silent: false
silent: false,
});

// Get the subscriber callback
const subscriberCallback = mockControllerMessenger.subscribe.mock.calls[0][1];
const subscriberCallback =
mockControllerMessenger.subscribe.mock.calls[0][1];
await subscriberCallback(smartTransaction);

expect(showNotificationSpy).toHaveBeenCalledWith({
Expand All @@ -256,31 +267,32 @@ describe('NotificationManager', () => {
transactionId: '0x123',
};

notificationManager.watchSubmittedTransaction({
notificationManager.watchSubmittedTransaction({
id: '0x123',
txParams: {
nonce: '0x1'
nonce: '0x1',
},
silent: false
silent: false,
});

// Get the subscriber callback
const subscriberCallback = mockControllerMessenger.subscribe.mock.calls[0][1];
const subscriberCallback =
mockControllerMessenger.subscribe.mock.calls[0][1];
await subscriberCallback(transaction);

expect(mockControllerMessenger.unsubscribe).toHaveBeenCalledWith(
'SmartTransactionsController:smartTransaction',
subscriberCallback
subscriberCallback,
);
});

it('sets up transaction event listeners correctly', () => {
const transaction = {
const transaction = {
id: '0x123',
txParams: {
nonce: '0x1'
nonce: '0x1',
},
silent: false
silent: false,
};

notificationManager.watchSubmittedTransaction(transaction);
Expand All @@ -289,17 +301,17 @@ describe('NotificationManager', () => {
expect(mockControllerMessenger.subscribeOnceIf).toHaveBeenCalledWith(
'TransactionController:transactionConfirmed',
expect.any(Function),
expect.any(Function)
expect.any(Function),
);
expect(mockControllerMessenger.subscribeOnceIf).toHaveBeenCalledWith(
'TransactionController:transactionFailed',
expect.any(Function),
expect.any(Function)
expect.any(Function),
);
expect(mockControllerMessenger.subscribeOnceIf).toHaveBeenCalledWith(
'TransactionController:speedupTransactionAdded',
expect.any(Function),
expect.any(Function)
expect.any(Function),
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion app/core/SDKConnect/utils/isUUID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export const isUUID = (str: string) => {
const uuidRegex =
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
return uuidRegex.test(str);
};
};
25 changes: 15 additions & 10 deletions app/util/notifications/services/NotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import notifee, {
AndroidChannel,
} from '@notifee/react-native';

import { HandleNotificationCallback, LAUNCH_ACTIVITY, Notification, PressActionId } from '../types';
import {
HandleNotificationCallback,
LAUNCH_ACTIVITY,
Notification,
PressActionId,
} from '../types';

import { Linking, Platform, Alert as NativeAlert } from 'react-native';
import {
Expand Down Expand Up @@ -222,11 +227,11 @@ class NotificationsService {
};

getInitialNotification = async (
callback: HandleNotificationCallback
callback: HandleNotificationCallback,
): Promise<void> => {
const event = await notifee.getInitialNotification()
const event = await notifee.getInitialNotification();
if (event) {
callback(event.notification.data as Notification['data'])
callback(event.notification.data as Notification['data']);
}
};

Expand All @@ -241,12 +246,12 @@ class NotificationsService {
channelId,
title,
body,
data
data,
}: {
channelId: ChannelId
title: string
body?: string
data?: Notification['data']
channelId: ChannelId;
title: string;
body?: string;
data?: Notification['data'];
}): Promise<void> => {
await notifee.displayNotification({
title,
Expand All @@ -259,7 +264,7 @@ class NotificationsService {
pressAction: {
id: PressActionId.OPEN_NOTIFICATIONS_VIEW,
launchActivity: LAUNCH_ACTIVITY,
}
},
},
ios: {
launchImageName: 'Default',
Expand Down
Loading

0 comments on commit 5e4b506

Please sign in to comment.