Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
salimtb authored Jan 8, 2025
2 parents c7f0f2c + 8d9fa1a commit e981d4e
Show file tree
Hide file tree
Showing 67 changed files with 2,409 additions and 469 deletions.
15 changes: 11 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ workflows:
requires:
- prep-deps
- prep-build-test-flask-mv2:
<<: *main_master_rc_only
requires:
- prep-deps
- prep-build-test-mmi:
Expand Down Expand Up @@ -283,10 +282,14 @@ workflows:
- prep-deps
- prep-build
- prep-build-mv2
- trigger-beta-build
- prep-build-mmi
- prep-build-flask
- prep-build-flask-mv2
- prep-build-test
- prep-build-test-mv2
- prep-build-test-flask
- prep-build-test-flask-mv2
- trigger-beta-build
- prep-build-storybook
- prep-build-ts-migration-dashboard
- benchmark
Expand Down Expand Up @@ -701,10 +704,10 @@ jobs:
name: Build extension for testing
command: yarn build:test:flask:mv2
- run:
name: Move test build to 'dist-test-flask' to avoid conflict with production build
name: Move test build to 'dist-test-flask-mv2' to avoid conflict with production build
command: mv ./dist ./dist-test-flask-mv2
- run:
name: Move test zips to 'builds-test-flask' to avoid conflict with production build
name: Move test zips to 'builds-test-flask-mv2' to avoid conflict with production build
command: mv ./builds ./builds-test-flask-mv2
- persist_to_workspace:
root: .
Expand Down Expand Up @@ -1306,8 +1309,12 @@ jobs:
destination: builds-mv2
- store_artifacts:
path: builds-test
- store_artifacts:
path: builds-test-mv2
- store_artifacts:
path: builds-test-flask
- store_artifacts:
path: builds-test-flask-mv2
- store_artifacts:
path: test-artifacts
destination: test-artifacts
Expand Down
12 changes: 12 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions app/scripts/constants/sentry-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export const SENTRY_BACKGROUND_STATE = {
},
AuthenticationController: {
isSignedIn: false,
sessionData: {
profile: true,
accessToken: false,
expiresIn: true,
},
},
NetworkOrderController: {
orderedNetworkList: [],
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/controllers/preferences-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ describe('preferences controller', () => {
privacyMode: false,
showFiatInTestnets: false,
showTestNetworks: false,
smartTransactionsMigrationApplied: false,
smartTransactionsOptInStatus: true,
useNativeCurrencyAsPrimaryCurrency: true,
hideZeroBalanceTokens: false,
Expand Down Expand Up @@ -762,6 +763,7 @@ describe('preferences controller', () => {
showExtensionInFullSizeView: false,
showFiatInTestnets: false,
showTestNetworks: false,
smartTransactionsMigrationApplied: false,
smartTransactionsOptInStatus: true,
useNativeCurrencyAsPrimaryCurrency: true,
hideZeroBalanceTokens: false,
Expand Down
13 changes: 13 additions & 0 deletions app/scripts/controllers/preferences-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export type Preferences = {
showFiatInTestnets: boolean;
showTestNetworks: boolean;
smartTransactionsOptInStatus: boolean;
smartTransactionsMigrationApplied: boolean;
showNativeTokenAsMainBalance: boolean;
useNativeCurrencyAsPrimaryCurrency: boolean;
hideZeroBalanceTokens: boolean;
Expand All @@ -129,6 +130,7 @@ export type PreferencesControllerState = Omit<
PreferencesState,
| 'showTestNetworks'
| 'smartTransactionsOptInStatus'
| 'smartTransactionsMigrationApplied'
| 'privacyMode'
| 'tokenSortConfig'
| 'useMultiRpcMigration'
Expand Down Expand Up @@ -217,6 +219,7 @@ export const getDefaultPreferencesControllerState =
showFiatInTestnets: false,
showTestNetworks: false,
smartTransactionsOptInStatus: true,
smartTransactionsMigrationApplied: false,
showNativeTokenAsMainBalance: false,
useNativeCurrencyAsPrimaryCurrency: true,
hideZeroBalanceTokens: false,
Expand Down Expand Up @@ -406,6 +409,16 @@ const controllerMetadata = {
preferences: {
persist: true,
anonymous: true,
properties: {
smartTransactionsOptInStatus: {
persist: true,
anonymous: true,
},
smartTransactionsMigrationApplied: {
persist: true,
anonymous: true,
},
},
},
ipfsGateway: {
persist: true,
Expand Down
12 changes: 7 additions & 5 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,13 @@ import {
TransactionType,
} from '@metamask/transaction-controller';

///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
import {
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
getLocalizedSnapManifest,
stripSnapPrefix,
///: END:ONLY_INCLUDE_IF
isSnapId,
} from '@metamask/snaps-utils';
///: END:ONLY_INCLUDE_IF

import { Interface } from '@ethersproject/abi';
import { abiERC1155, abiERC721 } from '@metamask/metamask-eth-abis';
Expand Down Expand Up @@ -245,8 +246,6 @@ import {
} from '../../shared/lib/transactions-controller-utils';
import { getProviderConfig } from '../../shared/modules/selectors/networks';
import { endTrace, trace } from '../../shared/lib/trace';
// eslint-disable-next-line import/no-restricted-paths
import { isSnapId } from '../../ui/helpers/utils/snaps';
import { BridgeStatusAction } from '../../shared/types/bridge-status';
import { ENVIRONMENT } from '../../development/build/constants';
import fetchWithCache from '../../shared/lib/fetch-with-cache';
Expand Down Expand Up @@ -2271,7 +2270,10 @@ export default class MetamaskController extends EventEmitter {
const smartTransactionsControllerMessenger =
this.controllerMessenger.getRestricted({
name: 'SmartTransactionsController',
allowedActions: ['NetworkController:getNetworkClientById'],
allowedActions: [
'NetworkController:getNetworkClientById',
'NetworkController:getState',
],
allowedEvents: ['NetworkController:stateChange'],
});
this.smartTransactionsController = new SmartTransactionsController({
Expand Down
187 changes: 187 additions & 0 deletions app/scripts/migrations/135.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import { SmartTransaction } from '@metamask/smart-transactions-controller/dist/types';
import { migrate, VersionedData } from './135';

const prevVersion = 134;

describe('migration #135', () => {
const mockSmartTransaction: SmartTransaction = {
uuid: 'test-uuid',
};

it('should update the version metadata', async () => {
const oldStorage: VersionedData = {
meta: { version: prevVersion },
data: {},
};

const newStorage = await migrate(oldStorage);
expect(newStorage.meta).toStrictEqual({ version: 135 });
});

it('should set stx opt-in to true and migration flag when stx opt-in status is null', async () => {
const oldStorage: VersionedData = {
meta: { version: prevVersion },
data: {
PreferencesController: {
preferences: {
smartTransactionsOptInStatus: null,
},
},
},
};

const newStorage = await migrate(oldStorage);
expect(
newStorage.data.PreferencesController?.preferences
?.smartTransactionsOptInStatus,
).toBe(true);
expect(
newStorage.data.PreferencesController?.preferences
?.smartTransactionsMigrationApplied,
).toBe(true);
});

it('should set stx opt-in to true and migration flag when stx opt-in status is undefined', async () => {
const oldStorage: VersionedData = {
meta: { version: prevVersion },
data: {
PreferencesController: {},
},
};

const newStorage = await migrate(oldStorage);
expect(
newStorage.data.PreferencesController?.preferences
?.smartTransactionsOptInStatus,
).toBe(true);
expect(
newStorage.data.PreferencesController?.preferences
?.smartTransactionsMigrationApplied,
).toBe(true);
});

it('should set stx opt-in to true and migration flag when stx opt-in is false and no existing mainnet smart transactions', async () => {
const oldStorage: VersionedData = {
meta: { version: prevVersion },
data: {
PreferencesController: {
preferences: {
smartTransactionsOptInStatus: false,
},
},
SmartTransactionsController: {
smartTransactionsState: {
smartTransactions: {
'0x1': [], // Empty mainnet transactions
'0xAA36A7': [mockSmartTransaction], // Sepolia has transactions
},
},
},
},
};

const newStorage = await migrate(oldStorage);
expect(
newStorage.data.PreferencesController?.preferences
?.smartTransactionsOptInStatus,
).toBe(true);
expect(
newStorage.data.PreferencesController?.preferences
?.smartTransactionsMigrationApplied,
).toBe(true);
});

it('should not change stx opt-in when stx opt-in is false but has existing smart transactions, but should set migration flag', async () => {
const oldStorage: VersionedData = {
meta: { version: prevVersion },
data: {
PreferencesController: {
preferences: {
smartTransactionsOptInStatus: false,
},
},
SmartTransactionsController: {
smartTransactionsState: {
smartTransactions: {
'0x1': [mockSmartTransaction],
},
},
},
},
};

const newStorage = await migrate(oldStorage);
expect(
newStorage.data.PreferencesController?.preferences
?.smartTransactionsOptInStatus,
).toBe(false);
expect(
newStorage.data.PreferencesController?.preferences
?.smartTransactionsMigrationApplied,
).toBe(true);
});

it('should not change stx opt-in when stx opt-in is already true, but should set migration flag', async () => {
const oldStorage: VersionedData = {
meta: { version: prevVersion },
data: {
PreferencesController: {
preferences: {
smartTransactionsOptInStatus: true,
},
},
},
};

const newStorage = await migrate(oldStorage);
expect(
newStorage.data.PreferencesController?.preferences
?.smartTransactionsOptInStatus,
).toBe(true);
expect(
newStorage.data.PreferencesController?.preferences
?.smartTransactionsMigrationApplied,
).toBe(true);
});

it('should initialize preferences object if it does not exist', async () => {
const oldStorage: VersionedData = {
meta: { version: prevVersion },
data: {
PreferencesController: {
preferences: {
smartTransactionsOptInStatus: true,
},
},
},
};

const newStorage = await migrate(oldStorage);
expect(newStorage.data.PreferencesController?.preferences).toBeDefined();
expect(
newStorage.data.PreferencesController?.preferences
?.smartTransactionsMigrationApplied,
).toBe(true);
});

it('should capture exception if PreferencesController state is invalid', async () => {
const sentryCaptureExceptionMock = jest.fn();
global.sentry = {
captureException: sentryCaptureExceptionMock,
};

const oldStorage = {
meta: { version: prevVersion },
data: {
PreferencesController: 'invalid',
},
} as unknown as VersionedData;

await migrate(oldStorage);

expect(sentryCaptureExceptionMock).toHaveBeenCalledTimes(1);
expect(sentryCaptureExceptionMock).toHaveBeenCalledWith(
new Error('Invalid PreferencesController state: string'),
);
});
});
Loading

0 comments on commit e981d4e

Please sign in to comment.