Skip to content

Commit

Permalink
Merge branch 'develop' into jl/mmp-1033/preferences-controller-networ…
Browse files Browse the repository at this point in the history
…k-meta
  • Loading branch information
jiexi authored Sep 22, 2023
2 parents 623a52e + f690d9a commit aef5ebb
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 119 deletions.
18 changes: 1 addition & 17 deletions app/background.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,7 @@
<meta charset="utf-8">
</head>
<body>
<script src="./snow.js" type="text/javascript" charset="utf-8"></script>
<script src="./use-snow.js" type="text/javascript" charset="utf-8"></script>
<script src="./globalthis.js" type="text/javascript" charset="utf-8"></script>
<script src="./sentry-install.js" type="text/javascript" charset="utf-8"></script>
{{@if(it.applyLavaMoat)}}
<script src="./runtime-lavamoat.js" type="text/javascript" charset="utf-8"></script>
<script src="./lockdown-more.js" type="text/javascript" charset="utf-8"></script>
<script src="./policy-load.js" type="text/javascript" charset="utf-8"></script>
{{#else}}
<script src="./lockdown-install.js" type="text/javascript" charset="utf-8"></script>
<script src="./lockdown-run.js" type="text/javascript" charset="utf-8"></script>
<script src="./lockdown-more.js" type="text/javascript" charset="utf-8"></script>
<script src="./runtime-cjs.js" type="text/javascript" charset="utf-8"></script>
{{/if}}
{{@each(it.jsBundles) => val}}
<script src="{{val}}" type="text/javascript" charset="utf-8"></script>
{{/each}}
<script src="./load-background.js" type="text/javascript" charset="utf-8"></script>
<script src="./chromereload.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
18 changes: 1 addition & 17 deletions app/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@
<img class="loading-spinner" src="./images/spinner.gif" alt="" />
</div>
<div id="popover-content"></div>
<script src="./snow.js" type="text/javascript" charset="utf-8"></script>
<script src="./use-snow.js" type="text/javascript" charset="utf-8"></script>
<script src="./globalthis.js" type="text/javascript" charset="utf-8"></script>
<script src="./sentry-install.js" type="text/javascript" charset="utf-8"></script>
{{@if(it.applyLavaMoat)}}
<script src="./runtime-lavamoat.js" type="text/javascript" charset="utf-8"></script>
<script src="./lockdown-more.js" type="text/javascript" charset="utf-8"></script>
<script src="./policy-load.js" type="text/javascript" charset="utf-8"></script>
{{#else}}
<script src="./lockdown-install.js" type="text/javascript" charset="utf-8"></script>
<script src="./lockdown-run.js" type="text/javascript" charset="utf-8"></script>
<script src="./lockdown-more.js" type="text/javascript" charset="utf-8"></script>
<script src="./runtime-cjs.js" type="text/javascript" charset="utf-8"></script>
{{/if}}
{{@each(it.jsBundles) => val}}
<script src="{{val}}" type="text/javascript" charset="utf-8"></script>
{{/each}}
<script src="./load-app.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
18 changes: 1 addition & 17 deletions app/notification.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,6 @@
<img id="loading__spinner" src="./images/spinner.gif" alt="" />
</div>
<div id="popover-content"></div>
<script src="./snow.js" type="text/javascript" charset="utf-8"></script>
<script src="./use-snow.js" type="text/javascript" charset="utf-8"></script>
<script src="./globalthis.js" type="text/javascript" charset="utf-8"></script>
<script src="./sentry-install.js" type="text/javascript" charset="utf-8"></script>
{{@if(it.applyLavaMoat)}}
<script src="./runtime-lavamoat.js" type="text/javascript" charset="utf-8"></script>
<script src="./lockdown-more.js" type="text/javascript" charset="utf-8"></script>
<script src="./policy-load.js" type="text/javascript" charset="utf-8"></script>
{{#else}}
<script src="./lockdown-install.js" type="text/javascript" charset="utf-8"></script>
<script src="./lockdown-run.js" type="text/javascript" charset="utf-8"></script>
<script src="./lockdown-more.js" type="text/javascript" charset="utf-8"></script>
<script src="./runtime-cjs.js" type="text/javascript" charset="utf-8"></script>
{{/if}}
{{@each(it.jsBundles) => val}}
<script src="{{val}}" type="text/javascript" charset="utf-8"></script>
{{/each}}
<script src="./load-app.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
18 changes: 1 addition & 17 deletions app/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,6 @@
<img class="loading-spinner" src="./images/spinner.gif" alt="" />
</div>
<div id="popover-content"></div>
<script src="./snow.js" type="text/javascript" charset="utf-8"></script>
<script src="./use-snow.js" type="text/javascript" charset="utf-8"></script>
<script src="./globalthis.js" type="text/javascript" charset="utf-8"></script>
<script src="./sentry-install.js" type="text/javascript" charset="utf-8"></script>
{{@if(it.applyLavaMoat)}}
<script src="./runtime-lavamoat.js" type="text/javascript" charset="utf-8"></script>
<script src="./lockdown-more.js" type="text/javascript" charset="utf-8"></script>
<script src="./policy-load.js" type="text/javascript" charset="utf-8"></script>
{{#else}}
<script src="./lockdown-install.js" type="text/javascript" charset="utf-8"></script>
<script src="./lockdown-run.js" type="text/javascript" charset="utf-8"></script>
<script src="./lockdown-more.js" type="text/javascript" charset="utf-8"></script>
<script src="./runtime-cjs.js" type="text/javascript" charset="utf-8"></script>
{{/if}}
{{@each(it.jsBundles) => val}}
<script src="{{val}}" type="text/javascript" charset="utf-8"></script>
{{/each}}
<script src="./load-app.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
28 changes: 28 additions & 0 deletions app/scripts/load-app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// eslint-disable-next-line import/unambiguous
'use strict';

setTimeout(() => {
// eslint-disable-next-line spaced-comment
const scriptsToLoad = [
/* SCRIPTS */
];

const loadScript = (src) => {
const script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.onload = loadNext;
script.src = src;
document.body.appendChild(script);
};

loadNext();

function loadNext() {
if (scriptsToLoad.length) {
loadScript(scriptsToLoad.shift());
} else {
document.documentElement.classList.add('metamask-loaded');
}
}
}, 0);
72 changes: 58 additions & 14 deletions development/build/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,26 +714,27 @@ function createFactoredBuild({
case 'ui': {
renderHtmlFile({
htmlName: 'popup',
groupSet,
commonSet,
browserPlatforms,
applyLavaMoat,
});
renderHtmlFile({
htmlName: 'notification',
groupSet,
commonSet,
browserPlatforms,
applyLavaMoat,
isMMI: buildType === 'mmi',
});
renderHtmlFile({
htmlName: 'home',
browserPlatforms,
applyLavaMoat,
isMMI: buildType === 'mmi',
});
renderJavaScriptLoader({
groupSet,
commonSet,
browserPlatforms,
applyLavaMoat,
isMMI: buildType === 'mmi',
destinationFileName: 'load-app.js',
});
break;
}
Expand All @@ -745,6 +746,13 @@ function createFactoredBuild({
browserPlatforms,
applyLavaMoat,
});
renderJavaScriptLoader({
groupSet,
commonSet,
browserPlatforms,
applyLavaMoat,
destinationFileName: 'load-background.js',
});
if (process.env.ENABLE_MV3) {
const jsBundles = [
...commonSet.values(),
Expand Down Expand Up @@ -1210,29 +1218,65 @@ async function setEnvironmentVariables({
});
}

function renderHtmlFile({
htmlName,
function renderJavaScriptLoader({
groupSet,
commonSet,
browserPlatforms,
applyLavaMoat,
isMMI,
destinationFileName,
}) {
if (applyLavaMoat === undefined) {
throw new Error(
'build/scripts/renderHtmlFile - must specify "applyLavaMoat" option',
);
}
const htmlFilePath = `./app/${htmlName}.html`;
const htmlTemplate = readFileSync(htmlFilePath, 'utf8');

const jsBundles = [...commonSet.values(), ...groupSet.values()].map(
(label) => `./${label}.js`,
);
const htmlOutput = Sqrl.render(htmlTemplate, {
jsBundles,
applyLavaMoat,
isMMI,

const securityScripts = applyLavaMoat
? ['./runtime-lavamoat.js', './lockdown-more.js', './policy-load.js']
: [
'./lockdown-install.js',
'./lockdown-run.js',
'./lockdown-more.js',
'./runtime-cjs.js',
];

const requiredScripts = [
'./snow.js',
'./use-snow.js',
'./globalthis.js',
'./sentry-install.js',
...securityScripts,
...jsBundles,
];

browserPlatforms.forEach((platform) => {
const appLoadFilePath = './app/scripts/load-app.js';
const appLoadContents = readFileSync(appLoadFilePath, 'utf8');

const scriptDest = `./dist/${platform}/${destinationFileName}`;
const scriptOutput = appLoadContents.replace(
'/* SCRIPTS */',
`...${JSON.stringify(requiredScripts)}`,
);

writeFileSync(scriptDest, scriptOutput);
});
}

function renderHtmlFile({ htmlName, browserPlatforms, applyLavaMoat, isMMI }) {
if (applyLavaMoat === undefined) {
throw new Error(
'build/scripts/renderHtmlFile - must specify "applyLavaMoat" option',
);
}
const htmlFilePath = `./app/${htmlName}.html`;
const htmlTemplate = readFileSync(htmlFilePath, 'utf8');

const htmlOutput = Sqrl.render(htmlTemplate, { isMMI });
browserPlatforms.forEach((platform) => {
const dest = `./dist/${platform}/${htmlName}.html`;
// we dont have a way of creating async events atm
Expand Down
4 changes: 4 additions & 0 deletions development/build/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ function getCopyTargets(
src: './app/scripts/init-globals.js',
dest: 'init-globals.js',
},
{
src: './app/scripts/load-app.js',
dest: 'load-app.js',
},
{
src: shouldIncludeLockdown
? `./app/scripts/lockdown-run.js`
Expand Down
8 changes: 7 additions & 1 deletion test/e2e/webdriver/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,13 @@ class Driver {
// Navigation

async navigate(page = Driver.PAGES.HOME) {
return await this.driver.get(`${this.extensionUrl}/${page}.html`);
const response = await this.driver.get(`${this.extensionUrl}/${page}.html`);
// Wait for asyncronous JavaScript to load
await this.driver.wait(
until.elementLocated(this.buildLocator('.metamask-loaded')),
10 * 1000,
);
return response;
}

async getCurrentUrl() {
Expand Down
3 changes: 1 addition & 2 deletions test/scenarios/3. transactions/cancel transaction.csv
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ The total amount is shown.",
The recipient's hexadecimal address is shown in the activity list item.
The amount is shown in the activity list item.",
11,Cancel the transaction.,,"The transaction appears in the activity list.
The recipient's hexadecimal address is shown in the activity list item.
The amount is shown in the activity list item.",
12,Wait for the transaction to complete.,,Another activity item appears.,Two activity items; Send and Receive.
13,Open the Send activity list item.,,"The updated gas fees are shown in the item details.
The transaction status, recipient's address, nonce, amount, gas and total are shown in the item details.",
14,Expand the Activity log.,,"The created, submitted, cancel attempt and cancelled activity is shown in the activity log.",
15,Proceed to view the transaction on the block explorer.,,The block explorer opens in a new tab.,
16,Open the Receive activity list item.,,"The transaction status, recipient's address, nonce, amount, gas and total are shown in the item details.",
17,Proceed to view the transaction on the block explorer.,,The block explorer opens in a new tab.,
17,Proceed to view the transaction on the block explorer.,,The block explorer opens in a new tab.,
75 changes: 41 additions & 34 deletions ui/components/multichain/global-menu/global-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
getSelectedAddress,
getUnapprovedTransactions,
///: BEGIN:ONLY_INCLUDE_IN(snaps)
getNotifySnaps,
getUnreadNotificationsCount,
///: END:ONLY_INCLUDE_IN
} from '../../../selectors';
Expand All @@ -72,6 +73,10 @@ export const GlobalMenu = ({ closeMenu, anchorElement }) => {
const address = useSelector(getSelectedAddress);
const unapprovedTransactons = useSelector(getUnapprovedTransactions);

///: BEGIN:ONLY_INCLUDE_IN(snaps)
const notifySnaps = useSelector(getNotifySnaps);
///: END:ONLY_INCLUDE_IN

const hasUnapprovedTransactions =
Object.keys(unapprovedTransactons).length > 0;

Expand Down Expand Up @@ -167,40 +172,42 @@ export const GlobalMenu = ({ closeMenu, anchorElement }) => {
)}
{
///: BEGIN:ONLY_INCLUDE_IN(snaps)
<>
<MenuItem
iconName={IconName.Notification}
onClick={() => {
closeMenu();
history.push(NOTIFICATIONS_ROUTE);
}}
>
{t('notifications')}
{unreadNotificationsCount > 0 && (
<Text
as="span"
display={Display.InlineBlock}
justifyContent={JustifyContent.center}
alignItems={AlignItems.center}
backgroundColor={BackgroundColor.primaryDefault}
color={TextColor.primaryInverse}
padding={[0, 1, 0, 1]}
variant={TextVariant.bodyXs}
textAlign={TextAlign.Center}
data-testid="global-menu-notification-count"
style={{
borderRadius: '16px',
minWidth: '24px',
}}
marginInlineStart={2}
>
{unreadNotificationsCount > 99
? '99+'
: unreadNotificationsCount}
</Text>
)}
</MenuItem>
</>
notifySnaps.length ? (
<>
<MenuItem
iconName={IconName.Notification}
onClick={() => {
closeMenu();
history.push(NOTIFICATIONS_ROUTE);
}}
>
{t('notifications')}
{unreadNotificationsCount > 0 && (
<Text
as="span"
display={Display.InlineBlock}
justifyContent={JustifyContent.center}
alignItems={AlignItems.center}
backgroundColor={BackgroundColor.primaryDefault}
color={TextColor.primaryInverse}
padding={[0, 1, 0, 1]}
variant={TextVariant.bodyXs}
textAlign={TextAlign.Center}
data-testid="global-menu-notification-count"
style={{
borderRadius: '16px',
minWidth: '24px',
}}
marginInlineStart={2}
>
{unreadNotificationsCount > 99
? '99+'
: unreadNotificationsCount}
</Text>
)}
</MenuItem>
</>
) : null
///: END:ONLY_INCLUDE_IN(snaps)
}
<MenuItem
Expand Down
Loading

0 comments on commit aef5ebb

Please sign in to comment.