From 4a280bb0e3281c2209c17c06b872e794896391e6 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Wed, 20 Jan 2021 13:59:01 -0330 Subject: [PATCH 1/3] Restore `data` provider event This event is deprecated, and is not part of EIP-1193. However we did not plan to remove this; it was removed accidentally as part of #109. It should now behave exactly as it did in v6. --- src/MetaMaskInpageProvider.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/MetaMaskInpageProvider.ts b/src/MetaMaskInpageProvider.ts index ec861c01..8f92516c 100644 --- a/src/MetaMaskInpageProvider.ts +++ b/src/MetaMaskInpageProvider.ts @@ -267,6 +267,9 @@ export default class MetaMaskInpageProvider extends SafeEventEmitter { } else if (method === 'metamask_chainChanged') { this._handleChainChanged(params); } else if (EMITTED_NOTIFICATIONS.includes(method)) { + // deprecated + this.emit('data', payload); + this.emit('message', { type: method, data: params, From 36239187645d2b6753c3d806d13ce1019cbe2f8c Mon Sep 17 00:00:00 2001 From: Erik Marks Date: Wed, 20 Jan 2021 09:43:58 -0800 Subject: [PATCH 2/3] Refactor, update warnings --- src/MetaMaskInpageProvider.ts | 4 +--- src/messages.ts | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/MetaMaskInpageProvider.ts b/src/MetaMaskInpageProvider.ts index 8f92516c..deb97e26 100644 --- a/src/MetaMaskInpageProvider.ts +++ b/src/MetaMaskInpageProvider.ts @@ -267,15 +267,13 @@ export default class MetaMaskInpageProvider extends SafeEventEmitter { } else if (method === 'metamask_chainChanged') { this._handleChainChanged(params); } else if (EMITTED_NOTIFICATIONS.includes(method)) { - // deprecated - this.emit('data', payload); - this.emit('message', { type: method, data: params, }); // deprecated + this.emit('data', payload); this.emit('notification', payload.params.result); } else if (method === 'METAMASK_STREAM_FAILURE') { connectionStream.destroy( diff --git a/src/messages.ts b/src/messages.ts index af44adef..c718d1a3 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -21,10 +21,10 @@ const messages = { sendDeprecation: `MetaMask: 'ethereum.send(...)' is deprecated and may be removed in the future. Please use 'ethereum.sendAsync(...)' or 'ethereum.request(...)' instead.\nFor more information, see: https://eips.ethereum.org/EIPS/eip-1193`, // deprecated events events: { - close: `MetaMask: The event 'close' is deprecated and may be removed in the future. Please use 'disconnect' instead.\nFor more information, see: https://eips.ethereum.org/EIPS/eip-1193`, - data: `MetaMask: The event 'data' is deprecated and may be removed in the future.`, - networkChanged: `MetaMask: The event 'networkChanged' is deprecated and may be removed in the future. Please use 'chainChanged' instead.\nFor more information, see: https://eips.ethereum.org/EIPS/eip-1193`, - notification: `MetaMask: The event 'notification' is deprecated and may be removed in the future. Please use 'message' instead.\nFor more information, see: https://eips.ethereum.org/EIPS/eip-1193`, + close: `MetaMask: The event 'close' is deprecated and may be removed in the future. Please use 'disconnect' instead.\nFor more information, see: https://eips.ethereum.org/EIPS/eip-1193#disconnect`, + data: `MetaMask: The event 'data' is deprecated and will be removed in the future. Use 'message' instead.\nFor more information, see: https://eips.ethereum.org/EIPS/eip-1193#message`, + networkChanged: `MetaMask: The event 'networkChanged' is deprecated and may be removed in the future. Use 'chainChanged' instead.\nFor more information, see: https://eips.ethereum.org/EIPS/eip-1193#chainchanged`, + notification: `MetaMask: The event 'notification' is deprecated and may be removed in the future. Use 'message' instead.\nFor more information, see: https://eips.ethereum.org/EIPS/eip-1193#message`, }, // misc experimentalMethods: `MetaMask: 'ethereum._metamask' exposes non-standard, experimental methods. They may be removed or changed without warning.`, From e0f1782ce4ac5fd4e3cf5524aff6737bba2d8537 Mon Sep 17 00:00:00 2001 From: Erik Marks Date: Wed, 20 Jan 2021 09:50:14 -0800 Subject: [PATCH 3/3] Restore order of 'data' event --- src/MetaMaskInpageProvider.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/MetaMaskInpageProvider.ts b/src/MetaMaskInpageProvider.ts index deb97e26..dc61ee2d 100644 --- a/src/MetaMaskInpageProvider.ts +++ b/src/MetaMaskInpageProvider.ts @@ -267,13 +267,16 @@ export default class MetaMaskInpageProvider extends SafeEventEmitter { } else if (method === 'metamask_chainChanged') { this._handleChainChanged(params); } else if (EMITTED_NOTIFICATIONS.includes(method)) { + // deprecated + // emitted here because that was the original order + this.emit('data', payload); + this.emit('message', { type: method, data: params, }); // deprecated - this.emit('data', payload); this.emit('notification', payload.params.result); } else if (method === 'METAMASK_STREAM_FAILURE') { connectionStream.destroy(