-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix accountsChanged notification #1413
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,19 +40,20 @@ class Port extends EventEmitter { | |
} | ||
|
||
export class BackgroundBridge extends EventEmitter { | ||
constructor({ webview, url, getRpcMethodMiddleware, shouldExposeAccounts, isMainFrame }) { | ||
constructor({ webview, url, getRpcMethodMiddleware, isMainFrame }) { | ||
super(); | ||
this.url = url; | ||
this.hostname = new URL(url).hostname; | ||
this.isMainFrame = isMainFrame; | ||
this._webviewRef = webview && webview.current; | ||
|
||
this.createMiddleware = getRpcMethodMiddleware; | ||
this.shouldExposeAccounts = shouldExposeAccounts; | ||
this.provider = Engine.context.NetworkController.provider; | ||
this.blockTracker = this.provider._blockTracker; | ||
this.port = new Port(this._webviewRef, isMainFrame); | ||
|
||
this.engine = null; | ||
|
||
const portStream = new MobilePortStream(this.port, url); | ||
// setup multiplexing | ||
const mux = setupMultiplex(portStream); | ||
|
@@ -81,14 +82,14 @@ export class BackgroundBridge extends EventEmitter { | |
* @param {*} outStream - The stream to provide over. | ||
*/ | ||
setupProviderConnection(outStream) { | ||
const engine = this.setupProviderEngine(); | ||
this.engine = this.setupProviderEngine(); | ||
|
||
// setup connection | ||
const providerStream = createEngineStream({ engine }); | ||
const providerStream = createEngineStream({ engine: this.engine }); | ||
|
||
pump(outStream, providerStream, outStream, err => { | ||
// handle any middleware cleanup | ||
engine._middleware.forEach(mid => { | ||
this.engine._middleware.forEach(mid => { | ||
if (mid.destroy && typeof mid.destroy === 'function') { | ||
mid.destroy(); | ||
} | ||
|
@@ -146,10 +147,7 @@ export class BackgroundBridge extends EventEmitter { | |
* @param {*} outStream - The stream to provide public config over. | ||
*/ | ||
setupPublicConfig(outStream) { | ||
const configStore = this.createPublicConfigStore({ | ||
// check the providerApprovalController's approvedOrigins | ||
checkIsEnabled: () => this.shouldExposeAccounts(this.hostname) | ||
}); | ||
const configStore = this.createPublicConfigStore(); | ||
|
||
const configStream = asStream(configStore); | ||
|
||
|
@@ -166,19 +164,15 @@ export class BackgroundBridge extends EventEmitter { | |
* Constructor helper: initialize a public config store. | ||
* This store is used to make some config info available to Dapps synchronously. | ||
*/ | ||
createPublicConfigStore({ checkIsEnabled }) { | ||
createPublicConfigStore() { | ||
// subset of state for metamask inpage provider | ||
const publicConfigStore = new ObservableStore(); | ||
|
||
const selectPublicState = ({ isUnlocked, selectedAddress, network }) => { | ||
const isEnabled = checkIsEnabled(); | ||
const isReady = isUnlocked && isEnabled; | ||
const selectPublicState = ({ isUnlocked, network }) => { | ||
const networkType = Engine.context.NetworkController.state.provider.type; | ||
const chainId = Object.keys(NetworkList).indexOf(networkType) > -1 && NetworkList[networkType].chainId; | ||
const result = { | ||
isUnlocked, | ||
isEnabled, | ||
selectedAddress: isReady ? selectedAddress.toLowerCase() : null, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this wasn't necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was previously, but no longer. The changes I made match what we did on the extension, and we removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should have already removed both tbh, but overlooked it. |
||
networkVersion: network, | ||
chainId: chainId ? `0x${parseInt(chainId, 10).toString(16)}` : null | ||
}; | ||
|
@@ -204,6 +198,10 @@ export class BackgroundBridge extends EventEmitter { | |
return publicConfigStore; | ||
} | ||
|
||
sendNotification(payload) { | ||
this.engine && this.engine.emit('notification', payload); | ||
} | ||
|
||
/** | ||
* The metamask-state of the various controllers, made available to the UI | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approvedHosts
andprevApprovedHosts
are always defined?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah,
approvedHosts
is set in the privacy reducer. Its initial state is{}
, and the clear action resets it to that.