Skip to content

Commit

Permalink
Merge branch 'main' into fix/add-new-translations-for-multichain
Browse files Browse the repository at this point in the history
  • Loading branch information
sahar-fehri authored Dec 12, 2024
2 parents c2d8c6a + 2f0cc61 commit 7602183
Show file tree
Hide file tree
Showing 133 changed files with 9,117 additions and 2,008 deletions.
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ body:
- In production (default)
- In beta
- During release testing
- On the development branch
- On main branch
- On a feature branch
validations:
required: true
- type: input
Expand Down
3 changes: 2 additions & 1 deletion .github/guidelines/LABELING_GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ To merge your PR one of the following QA labels are required:
- **Run E2E Smoke**: This label will kick-off E2E testing and trigger a check to make sure the E2E tests pass.

### Optional labels:
- **regression-develop**: This label can manually be added to a bug report issue at the time of its creation if the bug is present on the development branch, i.e., `main`, but is not yet released in production.
- **regression-main**: This label can manually be added to a bug report issue at the time of its creation if the bug is present on the development branch, i.e., `main`, but is not yet released in production.
- **feature-branch-bug**: This label can manually be added to a bug report issue at the time of its creation if the bug is present on a feature branch, i.e., before merging to `main`.

### Labels prohibited when PR needs to be merged:
Any PR that includes one of the following labels can not be merged:
Expand Down
20 changes: 15 additions & 5 deletions .github/scripts/check-template-and-add-labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { TemplateType, templates } from './shared/template';
import { retrievePullRequest } from './shared/pull-request';

enum RegressionStage {
Development,
DevelopmentFeature,
DevelopmentMain,
Testing,
Beta,
Production
Expand Down Expand Up @@ -202,8 +203,10 @@ function extractRegressionStageFromBugReportIssueBody(
const extractedAnswer = match ? match[1].trim() : undefined;

switch (extractedAnswer) {
case 'On the development branch':
return RegressionStage.Development;
case 'On a feature branch':
return RegressionStage.DevelopmentFeature;
case 'On main branch':
return RegressionStage.DevelopmentMain;
case 'During release testing':
return RegressionStage.Testing;
case 'In beta':
Expand Down Expand Up @@ -317,11 +320,18 @@ async function userBelongsToMetaMaskOrg(
// This function crafts appropriate label, corresponding to regression stage and release version.
function craftRegressionLabel(regressionStage: RegressionStage | undefined, releaseVersion: string | undefined): Label {
switch (regressionStage) {
case RegressionStage.Development:
case RegressionStage.DevelopmentFeature:
return {
name: `feature-branch-bug`,
color: '5319E7', // violet
description: `bug that was found on a feature branch, but not yet merged in main branch`,
};

case RegressionStage.DevelopmentMain:
return {
name: `regression-develop`,
color: '5319E7', // violet
description: `Regression bug that was found on development branch, but not yet present in production`,
description: `Regression bug that was found on main branch, but not yet present in production`,
};

case RegressionStage.Testing:
Expand Down
15 changes: 9 additions & 6 deletions .js.env.example
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Sign up and generate your own keys at pubnub.com
# Then rename this file to ".js.env" and rebuild the app
#
#
# In order for this feature to work properly, you need to
# build metamask-extension from source (https://github.com/MetaMask/metamask-extension)
# and set your the same values there.
#
#
# For more info take a look at https://github.com/MetaMask/metamask-extension/pull/5955

export MM_PUBNUB_SUB_KEY=""
export MM_PUBNUB_PUB_KEY=""
export MM_OPENSEA_KEY=""
export MM_ETHERSCAN_KEY=""
export MM_FOX_CODE="EXAMPLE_FOX_CODE"

# NOTE: Non-MetaMask only, will need to create an account and generate
Expand Down Expand Up @@ -70,6 +69,10 @@ export SEGMENT_FLUSH_EVENT_LIMIT="1"
# URL of security alerts API used to validate dApp requests.
export SECURITY_ALERTS_API_URL="https://security-alerts.api.cx.metamask.io"

# Enable Portfolio View
export PORTFOLIO_VIEW="true"


# Temporary mechanism to enable security alerts API prior to release.
export MM_SECURITY_ALERTS_API_ENABLED="true"
# Firebase
Expand All @@ -81,7 +84,7 @@ export FCM_CONFIG_MESSAGING_SENDER_ID=""
export FCM_CONFIG_APP_ID=""
export GOOGLE_SERVICES_B64_ANDROID=""
export GOOGLE_SERVICES_B64_IOS=""
#Notifications Feature Announcements
# Notifications Feature Announcements
export FEATURES_ANNOUNCEMENTS_ACCESS_TOKEN=
export FEATURES_ANNOUNCEMENTS_SPACE_ID=

Expand All @@ -96,8 +99,8 @@ export MM_PER_DAPP_SELECTED_NETWORK=""

export MM_CHAIN_PERMISSIONS=""

#Multichain feature flag specific to UI changes
# Multichain feature flag specific to UI changes
export MM_MULTICHAIN_V1_ENABLED=""

#Permissions Settings feature flag specific to UI changes
# Permissions Settings feature flag specific to UI changes
export MM_PERMISSIONS_SETTINGS_V1_ENABLED=""
18 changes: 16 additions & 2 deletions app/components/Nav/Main/RootRPCMethodsUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,34 @@ const RootRPCMethodsUI = (props) => {
);

const parameters = {
...analyticsParams,
time_to_mine: timeToMine,
estimated_vs_used_gasRatio: estimatedVsUsedGasRatio,
quote_vs_executionRatio: quoteVsExecutionRatio,
token_to_amount_received: tokenToAmountReceived.toString(),
is_smart_transaction: props.shouldUseSmartTransaction,
...smartTransactionMetricsProperties,
available_quotes: analyticsParams.available_quotes,
best_quote_source: analyticsParams.best_quote_source,
chain_id: analyticsParams.chain_id,
custom_slippage: analyticsParams.custom_slippage,
network_fees_USD: analyticsParams.network_fees_USD,
other_quote_selected: analyticsParams.other_quote_selected,
request_type: analyticsParams.request_type,
token_from: analyticsParams.token_from,
token_to: analyticsParams.token_to,
};
const sensitiveParameters = {
token_from_amount: analyticsParams.token_from_amount,
token_to_amount: analyticsParams.token_to_amount,
network_fees_ETH: analyticsParams.network_fees_ETH,
};

Logger.log('Swaps', 'Sending metrics event', event);

trackEvent(
createEventBuilder(event)
.addSensitiveProperties({ ...parameters })
.addProperties({ ...parameters })
.addSensitiveProperties({ ...sensitiveParameters })
.build(),
);
} catch (e) {
Expand Down
6 changes: 3 additions & 3 deletions app/components/Nav/Main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const Main = (props) => {
stopIncomingTransactionPolling();

if (showIncomingTransactionsNetworks[chainId]) {
startIncomingTransactionPolling([networkClientId]);
startIncomingTransactionPolling([chainId]);
}
}, [chainId, networkClientId, showIncomingTransactionsNetworks]);

Expand Down Expand Up @@ -178,11 +178,11 @@ const Main = (props) => {
removeNotVisibleNotifications();

BackgroundTimer.runBackgroundTimer(async () => {
await updateIncomingTransactions([props.networkClientId]);
await updateIncomingTransactions([props.chainId]);
}, AppConstants.TX_CHECK_BACKGROUND_FREQUENCY);
}
},
[backgroundMode, removeNotVisibleNotifications, props.networkClientId],
[backgroundMode, removeNotVisibleNotifications, props.chainId],
);

const initForceReload = () => {
Expand Down
7 changes: 7 additions & 0 deletions app/components/UI/AccountApproval/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ const mockInitialState = {
},
},
},
TokensController: {
allTokens: {
'0x1': {
'0xc4966c0d659d99699bfd7eb54d8fafee40e4a756': [],
},
},
},
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ const mockInitialState: DeepPartial<RootState> = {
},
},
TokenBalancesController: {
tokenBalances: { },
tokenBalances: {
'0x326836cc6cd09B5aa59B81A7F72F25FcC0136b95': {
'0x5': {
'0x326836cc6cd09B5aa59B81A7F72F25FcC0136b95': '0x2b46',
},
},
},
},
AccountsController: MOCK_ACCOUNTS_CONTROLLER_STATE,
},
Expand Down
13 changes: 13 additions & 0 deletions app/components/UI/AccountSelectorList/AccountSelector.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import { mockNetworkState } from '../../../util/test/network';
import { CHAIN_IDS } from '@metamask/transaction-controller';
import { AccountSelectorListProps } from './AccountSelectorList.types';

// eslint-disable-next-line import/no-namespace
import * as Utils from '../../hooks/useAccounts/utils';

const BUSINESS_ACCOUNT = '0xC4955C0d639D99699Bfd7Ec54d9FaFEe40e4D272';
const PERSONAL_ACCOUNT = '0xd018538C87232FF95acbCe4870629b75640a78E7';

Expand Down Expand Up @@ -125,6 +128,16 @@ const renderComponent = (

describe('AccountSelectorList', () => {
beforeEach(() => {
jest.spyOn(Utils, 'getAccountBalances').mockReturnValueOnce({
balanceETH: '1',
balanceFiat: '$3200.00',
balanceWeiHex: '',
});
jest.spyOn(Utils, 'getAccountBalances').mockReturnValueOnce({
balanceETH: '2',
balanceFiat: '$6400.00',
balanceWeiHex: '',
});
onSelectAccount.mockClear();
onRemoveImportedAccount.mockClear();
});
Expand Down
86 changes: 78 additions & 8 deletions app/components/UI/AssetOverview/AssetOverview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ import {
MOCK_ADDRESS_2,
} from '../../../util/test/accountsControllerTestUtils';
import { createBuyNavigationDetails } from '../Ramp/routes/utils';
import { getDecimalChainId } from '../../../util/networks';
import {
getDecimalChainId,
isPortfolioViewEnabled,
} from '../../../util/networks';
import { TokenOverviewSelectorsIDs } from '../../../../e2e/selectors/wallet/TokenOverview.selectors';
// eslint-disable-next-line import/no-namespace
import * as networks from '../../../util/networks';

const MOCK_CHAIN_ID = '0x1';

Expand Down Expand Up @@ -43,6 +48,15 @@ const mockInitialState = {
},
} as const,
},
CurrencyRateController: {
conversionRate: {
ETH: {
conversionDate: 1732572535.47,
conversionRate: 3432.53,
usdConversionRate: 3432.53,
},
},
},
},
settings: {
primaryCurrency: 'ETH',
Expand All @@ -51,6 +65,15 @@ const mockInitialState = {

const mockNavigate = jest.fn();
const navigate = mockNavigate;
const mockNetworkConfiguration = {
rpcEndpoints: [
{
networkClientId: 'mockNetworkClientId',
},
],
defaultRpcEndpointIndex: 0,
};

jest.mock('@react-navigation/native', () => {
const actualNav = jest.requireActual('@react-navigation/native');
return {
Expand All @@ -72,9 +95,21 @@ jest.mock('../../hooks/useStyles', () => ({
}),
}));

jest.mock('../../../core/Engine', () => ({
context: {
NetworkController: {
getNetworkConfigurationByChainId: jest
.fn()
.mockReturnValue(mockNetworkConfiguration),
setActiveNetwork: jest.fn().mockResolvedValue(undefined),
},
},
}));

const asset = {
balance: '400',
balanceFiat: '1500',
chainId: MOCK_CHAIN_ID,
logo: 'https://upload.wikimedia.org/wikipedia/commons/0/05/Ethereum_logo_2014.svg',
symbol: 'ETH',
name: 'Ethereum',
Expand All @@ -87,6 +122,10 @@ const asset = {
};

describe('AssetOverview', () => {
beforeEach(() => {
jest.spyOn(networks, 'isPortfolioViewEnabled').mockReturnValue(false);
});

it('should render correctly', async () => {
const container = renderWithProvider(
<AssetOverview asset={asset} displayBuyButton displaySwapsButton />,
Expand All @@ -95,6 +134,16 @@ describe('AssetOverview', () => {
expect(container).toMatchSnapshot();
});

it('should render correctly when portfolio view is enabled', async () => {
jest.spyOn(networks, 'isPortfolioViewEnabled').mockReturnValue(true);

const container = renderWithProvider(
<AssetOverview asset={asset} displayBuyButton displaySwapsButton />,
{ state: mockInitialState },
);
expect(container).toMatchSnapshot();
});

it('should handle buy button press', async () => {
const { getByTestId } = renderWithProvider(
<AssetOverview asset={asset} displayBuyButton displaySwapsButton />,
Expand Down Expand Up @@ -133,13 +182,34 @@ describe('AssetOverview', () => {
const swapButton = getByTestId('token-swap-button');
fireEvent.press(swapButton);

expect(navigate).toHaveBeenCalledWith('Swaps', {
params: {
sourcePage: 'MainView',
sourceToken: asset.address,
},
screen: 'SwapsAmountView',
});
if (isPortfolioViewEnabled()) {
expect(navigate).toHaveBeenCalledTimes(3);
expect(navigate).toHaveBeenNthCalledWith(1, 'RampBuy', {
screen: 'GetStarted',
params: {
address: asset.address,
chainId: getDecimalChainId(MOCK_CHAIN_ID),
},
});
expect(navigate).toHaveBeenNthCalledWith(2, 'SendFlowView', {});
expect(navigate).toHaveBeenNthCalledWith(3, 'Swaps', {
screen: 'SwapsAmountView',
params: {
sourcePage: 'MainView',
address: asset.address,
chainId: MOCK_CHAIN_ID,
},
});
} else {
expect(navigate).toHaveBeenCalledWith('Swaps', {
screen: 'SwapsAmountView',
params: {
sourcePage: 'MainView',
sourceToken: asset.address,
chainId: '0x1',
},
});
}
});

it('should not render swap button if displaySwapsButton is false', async () => {
Expand Down
Loading

0 comments on commit 7602183

Please sign in to comment.