Skip to content

Commit

Permalink
Fix missing transaction notifications (#18323)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewwalsh0 authored Mar 29, 2023
1 parent f32d71b commit 12bd9b0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
17 changes: 12 additions & 5 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;

Expand Down
19 changes: 10 additions & 9 deletions app/scripts/platforms/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -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! ${
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions development/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 12bd9b0

Please sign in to comment.