1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Fix missing transaction notifications (#18323)

This commit is contained in:
Matthew Walsh 2023-03-29 12:19:50 +01:00 committed by GitHub
parent f32d71ba1a
commit 12bd9b0b94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 14 deletions

View File

@ -826,10 +826,12 @@ export default class MetamaskController extends EventEmitter {
const originMetadata = subjectMetadataState.subjectMetadata[origin]; const originMetadata = subjectMetadataState.subjectMetadata[origin];
this.platform._showNotification( this.platform
originMetadata?.name ?? origin, ._showNotification(originMetadata?.name ?? origin, message)
message, .catch((error) => {
); log.error('Failed to create notification', error);
});
return null; return null;
}, },
showInAppNotification: (origin, message) => { showInAppNotification: (origin, message) => {
@ -969,7 +971,12 @@ export default class MetamaskController extends EventEmitter {
); );
rpcPrefs = matchingNetworkConfig?.rpcPrefs ?? {}; rpcPrefs = matchingNetworkConfig?.rpcPrefs ?? {};
} }
this.platform.showTransactionNotification(txMeta, rpcPrefs);
try {
await this.platform.showTransactionNotification(txMeta, rpcPrefs);
} catch (error) {
log.error('Failed to create transaction notification', error);
}
const { txReceipt } = txMeta; const { txReceipt } = txMeta;

View File

@ -113,19 +113,19 @@ export default class ExtensionPlatform {
} }
} }
showTransactionNotification(txMeta, rpcPrefs) { async showTransactionNotification(txMeta, rpcPrefs) {
const { status, txReceipt: { status: receiptStatus } = {} } = txMeta; const { status, txReceipt: { status: receiptStatus } = {} } = txMeta;
if (status === TransactionStatus.confirmed) { if (status === TransactionStatus.confirmed) {
// There was an on-chain failure // There was an on-chain failure
receiptStatus === '0x0' receiptStatus === '0x0'
? this._showFailedTransaction( ? await this._showFailedTransaction(
txMeta, txMeta,
'Transaction encountered an error.', 'Transaction encountered an error.',
) )
: this._showConfirmedTransaction(txMeta, rpcPrefs); : await this._showConfirmedTransaction(txMeta, rpcPrefs);
} else if (status === TransactionStatus.failed) { } else if (status === TransactionStatus.failed) {
this._showFailedTransaction(txMeta); await this._showFailedTransaction(txMeta);
} }
} }
@ -157,7 +157,7 @@ export default class ExtensionPlatform {
await browser.tabs.remove(tabId); await browser.tabs.remove(tabId);
} }
_showConfirmedTransaction(txMeta, rpcPrefs) { async _showConfirmedTransaction(txMeta, rpcPrefs) {
this._subscribeToNotificationClicked(); this._subscribeToNotificationClicked();
const url = getBlockExplorerLink(txMeta, rpcPrefs); const url = getBlockExplorerLink(txMeta, rpcPrefs);
@ -170,10 +170,10 @@ export default class ExtensionPlatform {
const message = `Transaction ${nonce} confirmed! ${ const message = `Transaction ${nonce} confirmed! ${
url.length ? `View on ${view}` : '' url.length ? `View on ${view}` : ''
}`; }`;
this._showNotification(title, message, url); await this._showNotification(title, message, url);
} }
_showFailedTransaction(txMeta, errorMessage) { async _showFailedTransaction(txMeta, errorMessage) {
const nonce = parseInt(txMeta.txParams.nonce, 16); const nonce = parseInt(txMeta.txParams.nonce, 16);
const title = 'Failed transaction'; const title = 'Failed transaction';
let message = `Transaction ${nonce} failed! ${ let message = `Transaction ${nonce} failed! ${
@ -184,12 +184,13 @@ export default class ExtensionPlatform {
message = `Transaction failed! ${errorMessage || txMeta.err.message}`; message = `Transaction failed! ${errorMessage || txMeta.err.message}`;
} }
///: END:ONLY_INCLUDE_IN ///: END:ONLY_INCLUDE_IN
this._showNotification(title, message); await this._showNotification(title, message);
} }
async _showNotification(title, message, url) { async _showNotification(title, message, url) {
const iconUrl = await browser.runtime.getURL('../../images/icon-64.png'); const iconUrl = await browser.runtime.getURL('../../images/icon-64.png');
browser.notifications.create(url, {
await browser.notifications.create(url, {
type: 'basic', type: 'basic',
title, title,
iconUrl, iconUrl,

View File

@ -102,6 +102,7 @@ async function defineAndRunBuildTasks() {
'navigator', 'navigator',
'harden', 'harden',
'console', 'console',
'Image', // Used by browser to generate notifications
// globals chrome driver needs to function (test env) // globals chrome driver needs to function (test env)
/cdc_[a-zA-Z0-9]+_[a-zA-Z]+/iu, /cdc_[a-zA-Z0-9]+_[a-zA-Z]+/iu,
'performance', 'performance',