Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
overwrite protection for window-provider
and walletRouter We had to protect our injected window.ethereum provider from being overwritten, because the load time is not deterministic with the content scripts. It was also important not to loose any provider that has been injected before we get there and to be able to switch back to them, so implemented a very minimal `window.walletRouter`, which keeps track of all the providers that we interact with and tried to set `window.ethereum`. The protection wasn't feasible to be implemented with Proxies because a property on the window object had to be protected and to do so the whole window object should have been replaced by the proxied object. (At least that's my current understanding.) Getters and setters can't be defined with a default value setting so it made sense to create `window.walletRouter`. Sadly the setter is not run if `Object.defineProprty` is used, and couldn't find any method to register these actions. Meaning we can't store those providers that tried to set the object using it. Eg. rabby wallet. When injecting the provider into `window.ethereum` multiple content scripts can set the same object, but the last one to set will be visible and used by the dApps. (Unless we protect our provider from being overwritten.) The load order of the extensions is based on their chromestore id, which is generated from the public key of the extension. This means that the content script of other extensions can start runing before us and after us, and we have no control over this. The content scripts are started based on the order defined by their ids but they run in parallel meaing their load and run time also affects the final order.
- Loading branch information