1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +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];
this.platform._showNotification(
originMetadata?.name ?? origin,
message,
);
this.platform
._showNotification(originMetadata?.name ?? origin, message)
.catch((error) => {
log.error('Failed to create notification', error);
});
return null;
},
showInAppNotification: (origin, message) => {
@ -969,7 +971,12 @@ export default class MetamaskController extends EventEmitter {
);
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;

View File

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

View File

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