|
|
|
@ -54,12 +54,12 @@ var inpageProvider = new MetamaskInpageProvider(metamaskStream) |
|
|
|
|
inpageProvider.setMaxListeners(100) |
|
|
|
|
|
|
|
|
|
// set up a listener for when MetaMask is locked
|
|
|
|
|
onMessage('metamasksetlocked', ({ data: { type } }) => { isEnabled = false }) |
|
|
|
|
onMessage('metamasksetlocked', () => { isEnabled = false }) |
|
|
|
|
|
|
|
|
|
// augment the provider with its enable method
|
|
|
|
|
inpageProvider.enable = function ({ force } = {}) { |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
providerHandle = ({ data: { type, error } }) => { |
|
|
|
|
providerHandle = ({ data: { error } }) => { |
|
|
|
|
if (typeof error !== 'undefined') { |
|
|
|
|
reject(error) |
|
|
|
|
} else { |
|
|
|
@ -119,18 +119,14 @@ inpageProvider._metamask = new Proxy({ |
|
|
|
|
* @returns {Promise<boolean>} - Promise resolving to true if this domain has been previously approved |
|
|
|
|
*/ |
|
|
|
|
isApproved: function() { |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
isApprovedHandle = ({ data: { caching, isApproved, error, type } }) => { |
|
|
|
|
if (typeof error !== 'undefined') { |
|
|
|
|
reject(error) |
|
|
|
|
} else { |
|
|
|
|
return new Promise((resolve) => { |
|
|
|
|
isApprovedHandle = ({ data: { caching, isApproved } }) => { |
|
|
|
|
if (caching) { |
|
|
|
|
resolve(!!isApproved) |
|
|
|
|
} else { |
|
|
|
|
resolve(false) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
onMessage('ethereumisapproved', isApprovedHandle, true) |
|
|
|
|
window.postMessage({ type: 'ETHEREUM_IS_APPROVED' }, '*') |
|
|
|
|
}) |
|
|
|
@ -142,14 +138,10 @@ inpageProvider._metamask = new Proxy({ |
|
|
|
|
* @returns {Promise<boolean>} - Promise resolving to true if MetaMask is currently unlocked |
|
|
|
|
*/ |
|
|
|
|
isUnlocked: function () { |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
isUnlockedHandle = ({ data: { isUnlocked, error, type } }) => { |
|
|
|
|
if (typeof error !== 'undefined') { |
|
|
|
|
reject(error) |
|
|
|
|
} else { |
|
|
|
|
return new Promise((resolve) => { |
|
|
|
|
isUnlockedHandle = ({ data: { isUnlocked } }) => { |
|
|
|
|
resolve(!!isUnlocked) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
onMessage('metamaskisunlocked', isUnlockedHandle, true) |
|
|
|
|
window.postMessage({ type: 'METAMASK_IS_UNLOCKED' }, '*') |
|
|
|
|
}) |
|
|
|
|