Skip to content
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

Migrate-AvatarIcon #19023

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d3a501f
Migrate-AvatarIcon
thebinij May 5, 2023
02f8cf9
Merge branch 'develop' into #18883-Migrate-AvatarIcon
thebinij May 5, 2023
ba7a40b
Merge branch 'MetaMask:develop' into #18883-Migrate-AvatarIcon
thebinij May 5, 2023
f95a42b
fix depcheck issue
thebinij May 5, 2023
dc7686a
fix lint
thebinij May 5, 2023
af29692
Merge branch 'develop' into #18883-Migrate-AvatarIcon
thebinij May 8, 2023
58621a6
Label PRs based on the labels of the associated issue (#17603)
pedronfigueiredo May 8, 2023
881e8e8
Fix fail to reject multiple approval requests (#19050)
vinistevam May 8, 2023
2f6c61c
Update slider.component.js (#19035)
PrgrmrHarshShukla May 8, 2023
4a5a8f8
Changes to confirm-data and confirm-hexdata (#19041)
dhruvv173 May 8, 2023
89148d1
UX Multichain: Added extra margin for native token (#18988)
NidhiKJha May 8, 2023
c49862c
devDeps: [email protected]>2.1.1 (#18866)
legobeat May 8, 2023
b3dd20e
Working on some lint issues in 2 files. (#18633)
PrgrmrHarshShukla May 8, 2023
a7eb0b4
UX: Multichain: Account Details Fixes (#18999)
darkwing May 8, 2023
096e3cc
[MMI] adds mmi logic in home view (#18960)
zone-live May 8, 2023
7b47767
Part of #17670 & #18714: Replace Typography with Text component: nft-…
PrgrmrHarshShukla May 8, 2023
83a27e3
Fix #18916 - UX: Multichain: Network picker design updates (#18962)
darkwing May 8, 2023
3824841
UX: Multichain: Ensure network picker renders properly for long and s…
darkwing May 8, 2023
6f285f7
devDeps: [email protected]>4.27.6 (#18869)
legobeat May 8, 2023
6ffc516
Changes to custody-labels.js (#19038)
dhruvv173 May 8, 2023
13a68f5
UX: Multichain: Disable network and account picker when necessary (#1…
darkwing May 8, 2023
17ba54d
UX: Multichain: Update deprecated variables (#19058)
darkwing May 9, 2023
96722d5
Fix #19059 - Show network picker when locked (#19063)
darkwing May 9, 2023
368a644
Fix #19060 - Ensure there's multiple accounts before focusing search …
darkwing May 9, 2023
82bec3b
Fix popover scroll button WhatsNewPopup hiding (#19017)
dominikrudzki May 9, 2023
83450d3
UX Multichain: updated margin top for assets tab (#19071)
NidhiKJha May 9, 2023
9cb9632
Replaced all fa-icon-circle with INFO icon (#17539)
NidhiKJha May 9, 2023
9f3fbf3
Set network status to "unknown" when ID is invalid (#19068)
Gudahtt May 9, 2023
25c0e72
remove pre commit hook for branch names (#19077)
pedronfigueiredo May 9, 2023
83976bb
Made builds.yml variable errors more helpful (#19066)
ritave May 9, 2023
3e96600
Some style, accessibility and sematic html updates to modal sub compo…
georgewrmarshall May 9, 2023
fc92480
Adding ModalFocus component (#18979)
georgewrmarshall May 9, 2023
75243b3
Changes to edit-gas-display.component.js (#19037)
dhruvv173 May 10, 2023
d4ae39d
Part of #17670 & #18714: Replace Typography with Text component in to…
PrgrmrHarshShukla May 10, 2023
0ae9058
Adopt ApprovalType from core (#18567)
vinistevam May 10, 2023
c545e68
builds.yml: add env var EDITOR_URL (#19074)
legobeat May 10, 2023
f710af3
Re-enable tests for subscription-based RPC methods (#18994)
mcmire May 10, 2023
7b6231c
removed mmi fencing from copy icon in header (#19087)
NidhiKJha May 10, 2023
6d23752
Only recognize "blocked" status for built-in networks (#19069)
Gudahtt May 10, 2023
fbe2c7e
Fix script to build migrations by having it use the `.ts` template (#…
NicholasEllul May 10, 2023
803cd1b
feat: Refactor Transaction Confirmation selector (#18796)
OGPoyraz May 11, 2023
3329811
Add `getCurrentChainId` argument to `SignatureController` (#19078)
OGPoyraz May 11, 2023
3687861
fix: use approvals selector fn in permission selectors (#19095)
OGPoyraz May 11, 2023
8e98e7d
[FLASK] Create E2E test for snap_GetEntropy (#18998)
bowensanders May 11, 2023
6d7ba87
Fix mv3 beta build (#18690)
danjm Apr 26, 2023
76eea2f
Show Bridge button in TokenOverview component (#18630)
micaelae Apr 21, 2023
295ebda
Update outdated browser versions (#18721)
Gudahtt Apr 21, 2023
96614b5
Enable editing L2 gas on optimism (#18217)
jpuri Apr 26, 2023
7c9f592
Show Bridge button in TokenOverview component (#18630)
micaelae Apr 21, 2023
9b74b3b
Fixing issue with gasLimit in transaction being 0 (#18682)
jpuri Apr 21, 2023
e9c7bf5
revert yarn.lock changes
thebinij May 12, 2023
29b257d
rebasing
thebinij May 12, 2023
04015cd
replace old TEXT_ALIGN
thebinij May 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 177 additions & 0 deletions .github/scripts/label-prs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
import * as core from '@actions/core';
import { context, getOctokit } from '@actions/github';
import { GitHub } from '@actions/github/lib/utils';

main().catch((error: Error): void => {
console.error(error);
process.exit(1);
});

async function main(): Promise<void> {
const token = process.env.GITHUB_TOKEN;

if (!token) {
core.setFailed('GITHUB_TOKEN not found');
process.exit(1);
}

const octokit = getOctokit(token);

const headRef = context.payload.pull_request?.head.ref || '';

let issueNumber = await getIssueNumberFromPullRequestBody();
if (issueNumber === "") {
bailIfIsBranchNameInvalid(headRef);
bailIfIsNotFeatureBranch(headRef);
issueNumber = getIssueNumberFromBranchName(headRef);
}

if (Number(issueNumber) === 0) {
process.exit(0);
}

await updateLabels(octokit, issueNumber);
}

async function getIssueNumberFromPullRequestBody(): Promise<string> {
console.log("Checking if the PR's body references an issue...");

let ISSUE_LINK_IN_PR_DESCRIPTION_REGEX =
/(close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved)\s#\d+/gi;

const prBody = await getPullRequestBody();

let matches = prBody.match(ISSUE_LINK_IN_PR_DESCRIPTION_REGEX);
if (!matches || matches?.length === 0) {
console.log(
'No direct link can be drawn between the PR and an issue from the PR body because no issue number was referenced.',
);
return "";
}

if (matches?.length > 1) {
console.log(
'No direct link can be drawn between the PR and an issue from the PR body because more than one issue number was referenced.',
);
return "";
}

const ISSUE_NUMBER_REGEX = /\d+/;
const issueNumber = matches[0].match(ISSUE_NUMBER_REGEX)?.[0] || '';

console.log(`Found issue number ${issueNumber} in PR body.`);

return issueNumber;
}

async function getPullRequestBody(): Promise<string> {
if (context.eventName !== 'pull_request') {
console.log('This action should only run on pull_request events.');
process.exit(1);
}

const prBody = context.payload.pull_request?.body || '';
return prBody;
}

function bailIfIsBranchNameInvalid(branchName: string): void {
const BRANCH_REGEX =
/^(main|develop|(ci|chore|docs|feat|feature|fix|perf|refactor|revert|style)\/\d*(?:[-](?![-])\w*)*|Version-v\d+\.\d+\.\d+)$/;
const isValidBranchName = new RegExp(BRANCH_REGEX).test(branchName);

if (!isValidBranchName) {
console.log('This branch name does not follow the convention.');
console.log(
'Here are some example branch names that are accepted: "fix/123-description", "feat/123-longer-description", "feature/123", "main", "develop", "Version-v10.24.2".',
);
console.log(
'No issue could be linked to this PR, so no labels were copied',
);

process.exit(0);
}
}

function bailIfIsNotFeatureBranch(branchName: string): void {
if (
branchName === 'main' ||
branchName === 'develop' ||
branchName.startsWith('Version-v')
) {
console.log(`${branchName} is not a feature branch.`);
console.log(
'No issue could be linked to this PR, so no labels were copied',
);
process.exit(0);
}
}

async function updateLabels(octokit: InstanceType<typeof GitHub>, issueNumber: string): Promise<void> {
interface ILabel {
name: string;
};

const owner = context.repo.owner;
const repo = context.repo.repo;

const issue = await octokit.rest.issues.get({
owner: owner,
repo: repo,
issue_number: Number(issueNumber),
});

const getNameFromLabel = (label: ILabel): string => label.name

const issueLabels = issue.data.labels.map(label => getNameFromLabel(label as ILabel));

const prNumber = context.payload.number;

const pr = await octokit.rest.issues.get({
owner: owner,
repo: repo,
issue_number: prNumber,
});

const startingPRLabels = pr.data.labels.map(label => getNameFromLabel(label as ILabel));

const dedupedFinalPRLabels = [
...new Set([...startingPRLabels, ...issueLabels]),
];

const hasIssueAdditionalLabels = !sortedArrayEqual(
startingPRLabels,
dedupedFinalPRLabels,
);
if (hasIssueAdditionalLabels) {
await octokit.rest.issues.update({
owner,
repo,
issue_number: prNumber,
labels: dedupedFinalPRLabels,
});
}
}

function getIssueNumberFromBranchName(branchName: string): string {
console.log('Checking if the branch name references an issue...');

let issueNumber: string;
if (branchName.split('/').length > 1) {
issueNumber = branchName.split('/')[1].split('-')[0];
} else {
issueNumber = branchName.split('-')[0];
}

console.log(`Found issue number ${issueNumber} in branch name.`);

return issueNumber;
}

function sortedArrayEqual(array1: string[], array2: string[]): boolean {
const lengthsAreEqual = array1.length === array2.length;
const everyElementMatchesByIndex = array1.every(
(value: string, index: number): boolean => value === array2[index],
);

return lengthsAreEqual && everyElementMatchesByIndex;
}
32 changes: 32 additions & 0 deletions .github/workflows/label-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Label PR

on:
pull_request:
types: [assigned, opened, edited, synchronize, reopened]

jobs:
label-pr:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16'

- name: Install Yarn
run: npm install -g yarn

- name: Install dependencies
run: yarn

- name: Run PR labelling script
run: npm run label-prs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16 changes: 9 additions & 7 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import debounce from 'debounce-stream';
import log from 'loglevel';
import browser from 'webextension-polyfill';
import { storeAsStream } from '@metamask/obs-store';
///: BEGIN:ONLY_INCLUDE_IN(snaps)
import { ApprovalType } from '@metamask/controller-utils';
///: END:ONLY_INCLUDE_IN
import PortStream from 'extension-port-stream';

import { ethErrors } from 'eth-rpc-errors';
Expand All @@ -18,9 +21,6 @@ import {
ENVIRONMENT_TYPE_FULLSCREEN,
EXTENSION_MESSAGES,
PLATFORM_FIREFOX,
///: BEGIN:ONLY_INCLUDE_IN(snaps)
MESSAGE_TYPE,
///: END:ONLY_INCLUDE_IN
} from '../../shared/constants/app';
import {
REJECT_NOTIFICATION_CLOSE,
Expand Down Expand Up @@ -713,7 +713,9 @@ export function setupController(
// User Interface setup
//

updateBadge();
controller.txController.initApprovals().then(() => {
updateBadge();
});
controller.txController.on(
METAMASK_CONTROLLER_EVENTS.UPDATE_BADGE,
updateBadge,
Expand Down Expand Up @@ -800,11 +802,11 @@ export function setupController(
({ id, type }) => {
switch (type) {
///: BEGIN:ONLY_INCLUDE_IN(snaps)
case MESSAGE_TYPE.SNAP_DIALOG_ALERT:
case MESSAGE_TYPE.SNAP_DIALOG_PROMPT:
case ApprovalType.SnapDialogAlert:
case ApprovalType.SnapDialogPrompt:
controller.approvalController.accept(id, null);
break;
case MESSAGE_TYPE.SNAP_DIALOG_CONFIRMATION:
case ApprovalType.SnapDialogConfirmation:
controller.approvalController.accept(id, false);
break;
///: END:ONLY_INCLUDE_IN
Expand Down
5 changes: 2 additions & 3 deletions app/scripts/controllers/app-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import EventEmitter from 'events';
import { ObservableStore } from '@metamask/obs-store';
import { v4 as uuid } from 'uuid';
import log from 'loglevel';
import { ApprovalType } from '@metamask/controller-utils';
import { METAMASK_CONTROLLER_EVENTS } from '../metamask-controller';
import { MINUTE } from '../../../shared/constants/time';
import { AUTO_LOCK_TIMEOUT_ALARM } from '../../../shared/constants/alarms';
Expand All @@ -13,8 +14,6 @@ import {
ORIGIN_METAMASK,
} from '../../../shared/constants/app';

const APPROVAL_REQUEST_TYPE = 'unlock';

export default class AppStateController extends EventEmitter {
/**
* @param {object} opts
Expand Down Expand Up @@ -408,7 +407,7 @@ export default class AppStateController extends EventEmitter {
{
id: this._approvalRequestId,
origin: ORIGIN_METAMASK,
type: APPROVAL_REQUEST_TYPE,
type: ApprovalType.Unlock,
},
true,
)
Expand Down
19 changes: 10 additions & 9 deletions app/scripts/controllers/network/network-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,9 @@ function isErrorWithCode(error: unknown): error is { code: string | number } {
* @param value - The value to check.
*/
function assertNetworkId(value: any): asserts value is NetworkId {
assert(
/^\d+$/u.test(value) && !Number.isNaN(Number(value)),
'value is not a number',
);
if (!/^\d+$/u.test(value) || Number.isNaN(Number(value))) {
throw new Error('value is not a number');
}
}

/**
Expand Down Expand Up @@ -624,12 +623,14 @@ export class NetworkController extends EventEmitter {
supportsEIP1559 = results[1];
networkStatus = NetworkStatus.Available;
} catch (error) {
if (isErrorWithCode(error) && isErrorWithMessage(error)) {
if (isErrorWithCode(error)) {
let responseBody;
try {
responseBody = JSON.parse(error.message);
} catch {
// error.message must not be JSON
if (isInfura && isErrorWithMessage(error)) {
try {
responseBody = JSON.parse(error.message);
} catch {
// error.message must not be JSON
}
}

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,8 @@ export function testsForProviderType(providerType: ProviderType) {
// tests on the core side.

{ name: 'net_listening', numberOfParameters: 0 },
// TODO: Methods to add back when we add testing for subscribe middleware
// { name: 'eth_subscribe', numberOfParameters: 1 },
// { name: 'eth_unsubscribe', numberOfParameters: 1 },
{ name: 'eth_subscribe', numberOfParameters: 1 },
{ name: 'eth_unsubscribe', numberOfParameters: 1 },
{ name: 'custom_rpc_method', numberOfParameters: 1 },
{ name: 'net_peerCount', numberOfParameters: 0 },
{ name: 'parity_nextNonce', numberOfParameters: 1 },
Expand Down
Loading