|
|
@ -56,45 +56,31 @@ inpageProvider.setMaxListeners(100) |
|
|
|
// set up a listener for when MetaMask is locked
|
|
|
|
// set up a listener for when MetaMask is locked
|
|
|
|
onMessage('metamasksetlocked', () => { isEnabled = false }) |
|
|
|
onMessage('metamasksetlocked', () => { isEnabled = false }) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// set up a listener for privacy mode responses
|
|
|
|
|
|
|
|
onMessage('ethereumproviderlegacy', ({ data: { selectedAddress } }) => { |
|
|
|
|
|
|
|
isEnabled = true |
|
|
|
|
|
|
|
inpageProvider.publicConfigStore.updateState({ selectedAddress }) |
|
|
|
|
|
|
|
}, true) |
|
|
|
|
|
|
|
|
|
|
|
// augment the provider with its enable method
|
|
|
|
// augment the provider with its enable method
|
|
|
|
inpageProvider.enable = function ({ force } = {}) { |
|
|
|
inpageProvider.enable = function ({ force } = {}) { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
providerHandle = ({ data: { error } }) => { |
|
|
|
providerHandle = ({ data: { error, selectedAddress } }) => { |
|
|
|
if (typeof error !== 'undefined') { |
|
|
|
if (typeof error !== 'undefined') { |
|
|
|
reject(error) |
|
|
|
reject(error) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
window.removeEventListener('message', providerHandle) |
|
|
|
window.removeEventListener('message', providerHandle) |
|
|
|
// wait for the publicConfig store to populate with an account
|
|
|
|
inpageProvider.publicConfigStore.updateState({ selectedAddress }) |
|
|
|
const publicConfig = new Promise((resolve) => { |
|
|
|
|
|
|
|
const { selectedAddress } = inpageProvider.publicConfigStore.getState() |
|
|
|
|
|
|
|
inpageProvider._metamask.isUnlocked().then(unlocked => { |
|
|
|
|
|
|
|
if (!unlocked || selectedAddress) { |
|
|
|
|
|
|
|
resolve() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
inpageProvider.publicConfigStore.on('update', ({ selectedAddress }) => { |
|
|
|
|
|
|
|
selectedAddress && resolve() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// wait for the background to update with an account
|
|
|
|
// wait for the background to update with an account
|
|
|
|
const ethAccounts = new Promise((resolveAccounts, rejectAccounts) => { |
|
|
|
|
|
|
|
inpageProvider.sendAsync({ method: 'eth_accounts', params: [] }, (error, response) => { |
|
|
|
inpageProvider.sendAsync({ method: 'eth_accounts', params: [] }, (error, response) => { |
|
|
|
if (error) { |
|
|
|
if (error) { |
|
|
|
rejectAccounts(error) |
|
|
|
reject(error) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
resolveAccounts(response.result) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Promise.all([ethAccounts, publicConfig]) |
|
|
|
|
|
|
|
.then(([selectedAddress]) => { |
|
|
|
|
|
|
|
isEnabled = true |
|
|
|
isEnabled = true |
|
|
|
resolve(selectedAddress) |
|
|
|
resolve(response.result) |
|
|
|
|
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch(reject) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
onMessage('ethereumprovider', providerHandle, true) |
|
|
|
onMessage('ethereumprovider', providerHandle, true) |
|
|
|