-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Poll for defaultAccount to update dapp & overlay subscriptions #4417
Changes from 2 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 |
---|---|---|
|
@@ -22,6 +22,7 @@ export default class Personal { | |
this._started = false; | ||
|
||
this._lastDefaultAccount = '0x0'; | ||
this._pollTimerId = null; | ||
} | ||
|
||
get isStarted () { | ||
|
@@ -43,11 +44,13 @@ export default class Personal { | |
// doesn't work. Since the defaultAccount is critical to operation, we poll in exactly | ||
// same way we do in ../eth (ala same as eth_blockNumber) and update. This should be moved | ||
// to pub-sub as it becomes available | ||
_defaultAccount = () => { | ||
_defaultAccount = (timerDisabled = false) => { | ||
const nextTimeout = (timeout = 1000) => { | ||
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 doesn't feel right to make a call every second whereas this shouldn't really change... It's understandable for 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. Agreed. As said, not perfect, but beats each dapp having to do exactly this. (Or worse poll 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. What about using local storage events then ? 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. As a bugfix & stop-gap before push, I don't believe it is time well invested. In addition, all the instances don't actually share the same localStorage.
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. That's right |
||
setTimeout(() => { | ||
this._defaultAccount(); | ||
}, timeout); | ||
if (!timerDisabled) { | ||
this._pollTimerId = setTimeout(() => { | ||
this._defaultAccount(); | ||
}, timeout); | ||
} | ||
}; | ||
|
||
if (!this._api.transport.isConnected) { | ||
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. Instead of polling every 500ms when the transport is disconnected, we could use the transport events system to subscribe when connected, and unsubscribe when disconnected. 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 matches up with what we do in 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. Well, ok, true. However it's not because it's wrongly done in 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. As a bugfix, I'm not going to rewrite the full subscriptions module. "Wrong" is not correct - it is the original implementation, which works and does all the heavy lifting for subscriptions as it stands in the app. 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. Wrong might indeed be the wrong word (ehe). Inefficient then. But ok as a bug fix. Would really need to move to push from the WS ; currently we are making at least 4 requests per second 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. Agreed. Not optimal to say the least. |
||
|
@@ -109,6 +112,11 @@ export default class Personal { | |
case 'parity_setAccountMeta': | ||
this._accountsInfo(); | ||
return; | ||
|
||
case 'parity_setDappsAddresses': | ||
case 'parity_setNewDappsWhitelist': | ||
this._defaultAccount(true); | ||
return; | ||
} | ||
}); | ||
} | ||
|
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.
👍