Skip to content

Commit 1bf3801

Browse files
feat: redesign UI of the phishing warning page (#176)
* feat: new ui v1 - messy code for mvp * feat: correct twitter logo * chore: cleanup code * chore: cleanup code * chore: fixing tests * chore: cleanup * chore: tests now pass * chore: cleanup comments * chore: fixed tests for Proceed anyway * rename portfolio button to back top safety * fix tests * feat: design system ui updates (#177) * fix: redirect to portfolio so that the client handles the url * fix: update ubuntu version * fix: set all ubuntu ci versions to 24.04 to fix dependancy issues * fix: bring back ubuntu-latest * fix: try ubuntu-22 packages * fix: bring back depends * fix: npx playwright install-deps * chore: remove build folder * chore: add build folder * test: tests now pass --------- Co-authored-by: George Marshall <[email protected]>
1 parent aa9790c commit 1bf3801

13 files changed

Lines changed: 210 additions & 266 deletions

.github/workflows/build-lint-test.yml

Lines changed: 10 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -76,114 +76,39 @@ jobs:
7676
test:
7777
name: Run Playwright tests
7878
timeout-minutes: 60
79-
runs-on: ubuntu-latest
79+
runs-on: ubuntu-latest # This currently uses Ubuntu 22.04
8080
needs:
8181
- prepare
8282
strategy:
8383
matrix:
8484
node-version: [16.x, 18.x, 20.x]
8585
steps:
8686
- uses: actions/checkout@v3
87+
8788
- name: Use Node.js ${{ matrix.node-version }}
8889
uses: actions/setup-node@v3
8990
with:
9091
node-version: ${{ matrix.node-version }}
9192
cache: 'yarn'
93+
9294
- run: yarn --immutable --immutable-cache
93-
- name: Install Playwright System Dependencies
94-
env:
95-
DEBIAN_FRONTEND: noninteractive
96-
# https://github.com/microsoft/playwright/blob/release-1.47/packages/playwright-core/src/server/registry/nativeDeps.ts
97-
run: |
98-
sudo apt-get update
99-
sudo apt-get install -y --no-install-recommends \
100-
fonts-freefont-ttf \
101-
fonts-ipafont-gothic \
102-
fonts-liberation \
103-
fonts-noto-color-emoji \
104-
fonts-tlwg-loma-otf \
105-
fonts-unifont \
106-
fonts-wqy-zenhei \
107-
gstreamer1.0-libav \
108-
gstreamer1.0-plugins-bad \
109-
gstreamer1.0-plugins-base \
110-
gstreamer1.0-plugins-good \
111-
libasound2t64 \
112-
libatk-bridge2.0-0t64 \
113-
libatk1.0-0t64 \
114-
libatomic1 \
115-
libatspi2.0-0t64 \
116-
libcairo-gobject2 \
117-
libcairo2 \
118-
libcups2t64 \
119-
libdbus-1-3 \
120-
libdrm2 \
121-
libenchant-2-2 \
122-
libepoxy0 \
123-
libevent-2.1-7t64 \
124-
libflite1 \
125-
libfontconfig1 \
126-
libfreetype6 \
127-
libgbm1 \
128-
libgdk-pixbuf-2.0-0 \
129-
libgles2 \
130-
libglib2.0-0t64 \
131-
libgstreamer-gl1.0-0 \
132-
libgstreamer-plugins-bad1.0-0 \
133-
libgstreamer-plugins-base1.0-0 \
134-
libgstreamer1.0-0 \
135-
libgtk-3-0t64 \
136-
libharfbuzz-icu0 \
137-
libharfbuzz0b \
138-
libhyphen0 \
139-
libicu74 \
140-
libjpeg-turbo8 \
141-
liblcms2-2 \
142-
libmanette-0.2-0 \
143-
libnspr4 \
144-
libnss3 \
145-
libopus0 \
146-
libpango-1.0-0 \
147-
libpangocairo-1.0-0 \
148-
libpng16-16t64 \
149-
libsecret-1-0 \
150-
libsoup-3.0-0 \
151-
libvpx9 \
152-
libwayland-client0 \
153-
libwayland-egl1 \
154-
libwayland-server0 \
155-
libwebp7 \
156-
libwebpdemux2 \
157-
libwoff1 \
158-
libx11-6 \
159-
libx11-xcb1 \
160-
libx264-164 \
161-
libxcb-shm0 \
162-
libxcb1 \
163-
libxcomposite1 \
164-
libxcursor1 \
165-
libxdamage1 \
166-
libxext6 \
167-
libxfixes3 \
168-
libxi6 \
169-
libxkbcommon0 \
170-
libxml2 \
171-
libxrandr2 \
172-
libxrender1 \
173-
libxslt1.1 \
174-
xfonts-cyrillic \
175-
xfonts-scalable \
176-
xvfb
95+
96+
- name: Install Playwright Dependencies
97+
run: npx playwright install-deps
98+
17799
- name: Install Playwright Browsers
178100
run: yarn playwright install chrome chromium firefox msedge
101+
179102
- name: Run Playwright tests
180103
run: yarn test
104+
181105
- uses: actions/upload-artifact@v3
182106
if: always()
183107
with:
184108
name: playwright-report
185109
path: playwright-report/
186110
retention-days: 30
111+
187112
- name: Require clean working directory
188113
shell: bash
189114
run: |

build/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ const minifiedLockdownSource = path.join(
2323

2424
const filesFromPackages = [
2525
{
26-
source: require.resolve(
27-
'@metamask/design-tokens/src/css/design-tokens.css',
28-
),
26+
source: require.resolve('@metamask/design-tokens/styles.css'),
2927
filename: 'design-tokens.css',
3028
},
3129
{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"test": "yarn playwright test"
2424
},
2525
"dependencies": {
26-
"@metamask/design-tokens": "^1.12.0",
26+
"@metamask/design-tokens": "^4.0.0",
2727
"@metamask/object-multiplex": "^2.0.0",
2828
"@metamask/post-message-stream": "^8.0.0",
2929
"eth-phishing-detect": "^1.2.0",

src/index.ts

Lines changed: 18 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { toASCII, toUnicode } from 'punycode/';
1+
import { toUnicode } from 'punycode/';
22
import { pipeline } from 'readable-stream';
3-
import PhishingDetector from 'eth-phishing-detect/src/detector';
43
import { WindowPostMessageStream } from '@metamask/post-message-stream';
54
import ObjectMultiplex from '@metamask/object-multiplex';
65

@@ -93,50 +92,8 @@ function isValidSuspectHref(href: string) {
9392
return disallowedProtocols.indexOf(parsedSuspectHref.protocol) < 0;
9493
}
9594

96-
const newIssueUrls = {
97-
metamask: 'https://github.com/MetaMask/eth-phishing-detect/issues/new',
98-
phishfort: 'https://github.com/phishfort/phishfort-lists/issues/new',
99-
};
100-
101-
const metamaskConfigUrl =
102-
'https://raw.githubusercontent.com/MetaMask/eth-phishing-detect/master/src/config.json';
103-
104-
/**
105-
* Determines whether the given URL was blocked by our phishing configuration or not.
106-
*
107-
* @param href - The blocked URL.
108-
* @returns `true` if this URL is blocked by our phishing configuration, `false` otherwise.
109-
*/
110-
async function isBlockedByMetamask(href: string) {
111-
try {
112-
const response = await fetch(metamaskConfigUrl, { cache: 'no-cache' });
113-
if (!response.ok) {
114-
throw new Error(`Received non-200 response: ${response.status}`);
115-
}
116-
const config = await response.json();
117-
const detector = new PhishingDetector([
118-
{
119-
allowlist: config.whitelist,
120-
blocklist: config.blacklist,
121-
fuzzylist: config.fuzzylist,
122-
tolerance: config.tolerance,
123-
name: 'MetaMask',
124-
version: config.version,
125-
},
126-
]);
127-
const { hostname } = new URL(href);
128-
129-
const punycodeHostname = toASCII(hostname);
130-
const phishingTestResponse = detector.check(punycodeHostname);
131-
console.debug('Phishing config test results:', phishingTestResponse);
132-
133-
return phishingTestResponse.result;
134-
} catch (error) {
135-
console.error(error);
136-
// default to assuming that it is blocked by our configuration
137-
return true;
138-
}
139-
}
95+
const newIssueUrl =
96+
'https://github.com/MetaMask/eth-phishing-detect/issues/new';
14097

14198
/**
14299
* Extract hostname and href from the query string.
@@ -181,20 +138,6 @@ function start() {
181138
]);
182139
const phishingSafelistStream = mux.createStream('metamask-phishing-safelist');
183140

184-
const backToSafetyLink = document.getElementById('back-to-safety');
185-
if (!backToSafetyLink) {
186-
throw new Error('Unable to locate back to safety link');
187-
}
188-
189-
backToSafetyLink.addEventListener('click', async () => {
190-
phishingSafelistStream.write({
191-
jsonrpc: '2.0',
192-
method: 'backToSafetyPhishingWarning',
193-
params: [],
194-
id: createRandomId(),
195-
});
196-
});
197-
198141
const { hash } = new URL(window.location.href);
199142
const hashContents = hash.slice(1); // drop leading '#' from hash
200143
const hashQueryString = new URLSearchParams(hashContents);
@@ -222,10 +165,7 @@ function start() {
222165
)}&body=${encodeURIComponent(toUnicode(suspectHrefUnicode))}`;
223166

224167
newIssueLink.addEventListener('click', async () => {
225-
const listName = (await isBlockedByMetamask(suspectHref))
226-
? 'metamask'
227-
: 'phishfort';
228-
window.location.href = `${newIssueUrls[listName]}${newIssueParams}`;
168+
window.location.href = `${newIssueUrl}${newIssueParams}`;
229169
});
230170

231171
const continueLink = document.getElementById('unsafe-continue');
@@ -251,4 +191,18 @@ function start() {
251191

252192
// To know when the event listener has been added, to mitigate an e2e race condition
253193
continueLink.setAttribute('data-testid', 'unsafe-continue-loaded');
194+
195+
const portfolioLink = document.getElementById('portfolio-link');
196+
if (!portfolioLink) {
197+
throw new Error('Unable to locate portfolio link');
198+
}
199+
200+
portfolioLink.addEventListener('click', async () => {
201+
phishingSafelistStream.write({
202+
jsonrpc: '2.0',
203+
method: 'backToSafetyPhishingWarning',
204+
params: [],
205+
id: createRandomId(),
206+
});
207+
});
254208
}

0 commit comments

Comments
 (0)