Skip to content

v11.16.2 #24852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 30, 2024
Merged
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [11.16.2]
### Fixed
- Fix gas fee displays on the Scroll network ([#24854](https://github.com/MetaMask/metamask-extension/pull/24854))

## [11.16.1]
### Changed
- Update Smart Transactions opt-in moda ([#24771](https://github.com/MetaMask/metamask-extension/pull/24771))

## [11.16.0]
### Added
Expand Down Expand Up @@ -4750,7 +4756,8 @@ Update styles and spacing on the critical error page ([#20350](https://github.c
- Added the ability to restore accounts from seed words.


[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v11.16.1...HEAD
[Unreleased]: https://github.com/MetaMask/metamask-extension/compare/v11.16.2...HEAD
[11.16.2]: https://github.com/MetaMask/metamask-extension/compare/v11.16.1...v11.16.2
[11.16.1]: https://github.com/MetaMask/metamask-extension/compare/v11.16.0...v11.16.1
[11.16.0]: https://github.com/MetaMask/metamask-extension/compare/v11.15.6...v11.16.0
[11.15.6]: https://github.com/MetaMask/metamask-extension/compare/v11.15.5...v11.15.6
Expand Down
11 changes: 10 additions & 1 deletion app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ import rawFirstTimeState from './first-time-state';
import getFirstPreferredLangCode from './lib/get-first-preferred-lang-code';
import getObjStructure from './lib/getObjStructure';
import setupEnsIpfsResolver from './lib/ens-ipfs/setup';
import { deferredPromise, getPlatform } from './lib/util';
import {
deferredPromise,
getPlatform,
shouldEmitDappViewedEvent,
} from './lib/util';

/* eslint-enable import/first */

Expand Down Expand Up @@ -466,6 +470,11 @@ function emitDappViewedMetricEvent(
connectSitePermissions,
preferencesController,
) {
const { metaMetricsId } = controller.metaMetricsController.state;
if (!shouldEmitDappViewedEvent(metaMetricsId)) {
return;
}

// A dapp may have other permissions than eth_accounts.
// Since we are only interested in dapps that use Ethereum accounts, we bail out otherwise.
if (!hasProperty(connectSitePermissions.permissions, 'eth_accounts')) {
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/controllers/app-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export default class AppStateController extends EventEmitter {
showAccountBanner: true,
trezorModel: null,
currentPopupId: undefined,
newPrivacyPolicyToastClickedOrClosed: null,
newPrivacyPolicyToastShownDate: null,
// This key is only used for checking if the user had set advancedGasFee
// prior to Migration 92.3 where we split out the setting to support
// multiple networks.
Expand All @@ -65,8 +67,6 @@ export default class AppStateController extends EventEmitter {
'0x539': true,
},
surveyLinkLastClickedOrClosed: null,
newPrivacyPolicyToastClickedOrClosed: null,
newPrivacyPolicyToastShownDate: null,
signatureSecurityAlertResponses: {},
// States used for displaying the changed network toast
switchedNetworkDetails: null,
Expand Down
27 changes: 15 additions & 12 deletions app/scripts/lib/rpc-method-middleware/handlers/request-accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
MetaMetricsEventName,
MetaMetricsEventCategory,
} from '../../../../../shared/constants/metametrics';
import { shouldEmitDappViewedEvent } from '../../util';

/**
* This method attempts to retrieve the Ethereum accounts available to the
Expand Down Expand Up @@ -114,18 +115,20 @@ async function requestEthereumAccountsHandler(
const isFirstVisit = !Object.keys(metamaskState.permissionHistory).includes(
origin,
);
sendMetrics({
event: MetaMetricsEventName.DappViewed,
category: MetaMetricsEventCategory.InpageProvider,
referrer: {
url: origin,
},
properties: {
is_first_visit: isFirstVisit,
number_of_accounts: Object.keys(metamaskState.accounts).length,
number_of_accounts_connected: numberOfConnectedAccounts,
},
});
if (shouldEmitDappViewedEvent(metamaskState.metaMetricsId)) {
sendMetrics({
event: MetaMetricsEventName.DappViewed,
category: MetaMetricsEventCategory.InpageProvider,
referrer: {
url: origin,
},
properties: {
is_first_visit: isFirstVisit,
number_of_accounts: Object.keys(metamaskState.accounts).length,
number_of_accounts_connected: numberOfConnectedAccounts,
},
});
}
} else {
// This should never happen, because it should be caught in the
// above catch clause
Expand Down
14 changes: 14 additions & 0 deletions app/scripts/lib/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '../../../shared/constants/app';
import { isPrefixedFormattedHexString } from '../../../shared/modules/network.utils';
import {
shouldEmitDappViewedEvent,
addUrlProtocolPrefix,
deferredPromise,
formatTxMetaForRpcResult,
Expand Down Expand Up @@ -255,6 +256,19 @@ describe('app utils', () => {
});
});

describe('shouldEmitDappViewedEvent', () => {
it('should return true for valid metrics IDs', () => {
expect(shouldEmitDappViewedEvent('fake-metrics-id-fd20')).toStrictEqual(
true,
);
});
it('should return false for invalid metrics IDs', () => {
expect(
shouldEmitDappViewedEvent('fake-metrics-id-invalid'),
).toStrictEqual(false);
});
});

describe('formatTxMetaForRpcResult', () => {
it('should correctly format the tx meta object (EIP-1559)', () => {
const txMeta = {
Expand Down
19 changes: 19 additions & 0 deletions app/scripts/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,25 @@ export function isWebUrl(urlString: string): boolean {
);
}

/**
* Determines whether to emit a MetaMetrics event for a given metaMetricsId.
* Relies on the last 4 characters of the metametricsId. Assumes the IDs are evenly distributed.
* If metaMetricsIds are distributed evenly, this should be a 1% sample rate
*
* @param metaMetricsId - The metametricsId to use for the event.
* @returns Whether to emit the event or not.
*/
export function shouldEmitDappViewedEvent(metaMetricsId: string): boolean {
if (metaMetricsId === null) {
return false;
}

const lastFourCharacters = metaMetricsId.slice(-4);
const lastFourCharactersAsNumber = parseInt(lastFourCharacters, 16);

return lastFourCharactersAsNumber % 100 === 0;
}

type FormattedTransactionMeta = {
blockHash: string | null;
blockNumber: string | null;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metamask-crx",
"version": "11.16.1",
"version": "11.16.2",
"private": true,
"repository": {
"type": "git",
Expand Down
40 changes: 34 additions & 6 deletions test/e2e/tests/metrics/dapp-viewed.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@ const waitForDappConnected = async (driver) => {
};

describe('Dapp viewed Event @no-mmi', function () {
const validFakeMetricsId = 'fake-metrics-fd20';
it('is not sent when metametrics ID is not valid', async function () {
async function mockSegment(mockServer) {
return [await mockedDappViewedEndpoint(mockServer)];
}

await withFixtures(
{
dapp: true,
fixtures: new FixtureBuilder()
.withMetaMetricsController({
metaMetricsId: 'invalid-metrics-id',
participateInMetaMetrics: true,
})
.build(),
title: this.test.fullTitle(),
testSpecificMock: mockSegment,
},
async ({ driver, mockedEndpoint: mockedEndpoints }) => {
await driver.navigate();
await unlockWallet(driver);
await connectToDapp(driver);
const events = await getEventPayloads(driver, mockedEndpoints);
assert.equal(events.length, 0);
},
);
});

it('is sent when navigating to dapp with no account connected', async function () {
async function mockSegment(mockServer) {
return [await mockedDappViewedEndpoint(mockServer)];
Expand All @@ -75,7 +103,7 @@ describe('Dapp viewed Event @no-mmi', function () {
dapp: true,
fixtures: new FixtureBuilder()
.withMetaMetricsController({
metaMetricsId: 'fake-metrics-id',
metaMetricsId: validFakeMetricsId, // 1% sample rate for dapp viewed event
participateInMetaMetrics: true,
})
.build(),
Expand Down Expand Up @@ -110,7 +138,7 @@ describe('Dapp viewed Event @no-mmi', function () {
dapp: true,
fixtures: new FixtureBuilder()
.withMetaMetricsController({
metaMetricsId: 'fake-metrics-id',
metaMetricsId: validFakeMetricsId,
participateInMetaMetrics: true,
})
.build(),
Expand Down Expand Up @@ -148,7 +176,7 @@ describe('Dapp viewed Event @no-mmi', function () {
dapp: true,
fixtures: new FixtureBuilder()
.withMetaMetricsController({
metaMetricsId: 'fake-metrics-id',
metaMetricsId: validFakeMetricsId,
participateInMetaMetrics: true,
})
.build(),
Expand Down Expand Up @@ -191,7 +219,7 @@ describe('Dapp viewed Event @no-mmi', function () {
dapp: true,
fixtures: new FixtureBuilder()
.withMetaMetricsController({
metaMetricsId: 'fake-metrics-id',
metaMetricsId: validFakeMetricsId,
participateInMetaMetrics: true,
})
.build(),
Expand Down Expand Up @@ -228,7 +256,7 @@ describe('Dapp viewed Event @no-mmi', function () {
dapp: true,
fixtures: new FixtureBuilder()
.withMetaMetricsController({
metaMetricsId: 'fake-metrics-id',
metaMetricsId: validFakeMetricsId,
participateInMetaMetrics: true,
})
.build(),
Expand Down Expand Up @@ -282,7 +310,7 @@ describe('Dapp viewed Event @no-mmi', function () {
dapp: true,
fixtures: new FixtureBuilder()
.withMetaMetricsController({
metaMetricsId: 'fake-metrics-id',
metaMetricsId: validFakeMetricsId,
participateInMetaMetrics: true,
})
.build(),
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/metrics/permissions-approved.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('Permissions Approved Event', function () {
dapp: true,
fixtures: new FixtureBuilder()
.withMetaMetricsController({
metaMetricsId: 'fake-metrics-id',
metaMetricsId: 'fake-metrics-fd20',
participateInMetaMetrics: true,
})
.build(),
Expand Down
2 changes: 1 addition & 1 deletion ui/helpers/constants/privacy-policy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This date indicates the date of the latest privacy policy document
const PRIVACY_POLICY_DATE = '2024-06-04T00:00:00Z';
const PRIVACY_POLICY_DATE = '2099-06-04T00:00:00Z';

export { PRIVACY_POLICY_DATE };
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ import {
TextColor,
} from '../../../../../helpers/constants/design-system';
import { useDraftTransactionWithTxParams } from '../../../hooks/useDraftTransactionWithTxParams';
import { getNativeCurrency } from '../../../../../ducks/metamask/metamask';
import MultilayerFeeMessage from '../../multilayer-fee-message/multi-layer-fee-message';
import {
Icon,
IconName,
Text,
} from '../../../../../components/component-library';
import { addHexes } from '../../../../../../shared/modules/conversion.utils';

const renderHeartBeatIfNotInTest = () =>
process.env.IN_TEST ? null : <LoadingHeartBeat />;
Expand All @@ -41,54 +40,26 @@ const ConfirmLegacyGasDisplay = ({ 'data-testid': dataTestId } = {}) => {
const isMainnet = useSelector(getIsMainnet);
const useCurrencyRateCheck = useSelector(getUseCurrencyRateCheck);
const { useNativeCurrencyAsPrimaryCurrency } = useSelector(getPreferences);
const nativeCurrency = useSelector(getNativeCurrency);
const unapprovedTxs = useSelector(getUnapprovedTransactions);
const transactionData = useDraftTransactionWithTxParams();
const txData = useSelector((state) => txDataSelector(state));
const { id: transactionId, dappSuggestedGasFees } = txData;
const { id: transactionId, dappSuggestedGasFees, layer1GasFee } = txData;
const transaction = Object.keys(transactionData).length
? transactionData
: unapprovedTxs[transactionId] || {};
const { hexMinimumTransactionFee, hexMaximumTransactionFee } = useSelector(
(state) => transactionFeeSelector(state, transaction),
);
const { layer1GasFee } = txData;
const hasLayer1GasFee = layer1GasFee !== undefined;

if (hasLayer1GasFee) {
return [
<TransactionDetailItem
key="legacy-total-item"
data-testid={dataTestId}
detailTitle={t('transactionDetailLayer2GasHeading')}
detailTotal={
<UserPreferencedCurrencyDisplay
type={PRIMARY}
value={hexMinimumTransactionFee}
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
numberOfDecimals={18}
/>
}
detailText={
useCurrencyRateCheck && (
<UserPreferencedCurrencyDisplay
type={SECONDARY}
value={hexMinimumTransactionFee}
hideLabel={Boolean(useNativeCurrencyAsPrimaryCurrency)}
/>
)
}
noBold
flexWidthValues
/>,
<MultilayerFeeMessage
key="confirm-layer-1"
transaction={txData}
layer2fee={hexMinimumTransactionFee}
nativeCurrency={nativeCurrency}
/>,
];
}
const estimatedHexMinFeeTotal = addHexes(
hexMinimumTransactionFee,
layer1GasFee ?? '0x0',
);

const estimatedHexMaxFeeTotal = addHexes(
hexMaximumTransactionFee,
layer1GasFee ?? '0x0',
);

return (
<TransactionDetailItem
Expand Down Expand Up @@ -141,7 +112,7 @@ const ConfirmLegacyGasDisplay = ({ 'data-testid': dataTestId } = {}) => {
{renderHeartBeatIfNotInTest()}
<UserPreferencedCurrencyDisplay
type={SECONDARY}
value={hexMinimumTransactionFee}
value={estimatedHexMinFeeTotal}
hideLabel={Boolean(useNativeCurrencyAsPrimaryCurrency)}
/>
</div>
Expand All @@ -152,7 +123,7 @@ const ConfirmLegacyGasDisplay = ({ 'data-testid': dataTestId } = {}) => {
{renderHeartBeatIfNotInTest()}
<UserPreferencedCurrencyDisplay
type={PRIMARY}
value={hexMinimumTransactionFee}
value={estimatedHexMinFeeTotal}
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
numberOfDecimals={6}
/>
Expand All @@ -168,7 +139,7 @@ const ConfirmLegacyGasDisplay = ({ 'data-testid': dataTestId } = {}) => {
<UserPreferencedCurrencyDisplay
key="editGasSubTextFeeAmount"
type={PRIMARY}
value={hexMaximumTransactionFee}
value={estimatedHexMaxFeeTotal}
hideLabel={!useNativeCurrencyAsPrimaryCurrency}
/>
</div>
Expand Down
Loading
Loading