Skip to content

Commit

Permalink
Merge branch 'main' into bump-swaps-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmire committed Dec 11, 2024
2 parents b9bcce0 + 54e0a8a commit f0b8d7d
Show file tree
Hide file tree
Showing 91 changed files with 7,411 additions and 500 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
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
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 f0b8d7d

Please sign in to comment.