Be explicit around the extension-dapp use (#46)

This commit is contained in:
Jaco Greeff 2019-06-03 11:10:03 +02:00 committed by GitHub
parent 451d266baf
commit c77d47ebe5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,7 +6,7 @@ A very simple scaffolding browser extension that injects a [@polkadot/api](https
As it stands, it does one thing: it _only_ manages accounts and allows the signing of transactions with those accounts. It does not inject providers for use by dapps at this early point, nor does it perform wallet functions where it constructs and submits txs to the network.
# Running
## Running
Currently is not packaged since it is under heavy development. As such you need to build it yourself. To use -
@ -22,26 +22,33 @@ Currently is not packaged since it is under heavy development. As such you need
- check "Enable add-on debugging"
- click on "Load Temporary Add-on" and point to `packages/extension/build/manifest.json`
- if developing, after making changes - reload the extension
3. When visiting `http://localhost:3000` or `https://polkadot.js.org/apps/` it will inject the extension (the manifest currently only lists these 2 endpoints)
3. When visiting `https://polkadot.js.org/apps/` it will inject the extension
Once added, you can create an account (via a generated seed) or import via an existing seed. The UI, when loaded, will show these accounts as `<account name> (extension)`
Once added, you can create an account (via a generated seed) or import via an existing seed. The [apps UI](https://github.com/polkadot-js/apps/), when loaded, will show these accounts as `<account name> (extension)`
# Development
## Development
The repo is split into a number of packages -
- [extension](packages/extension/) - All the injection and background processing logic (the main entry)
- [extension-ui](packages/extension-ui/) - The UI components for the extension
- [extension-ui](packages/extension-ui/) - The UI components for the extension, do build up the popup
- [extension-dapp](packages/extension-dapp/) - A convenience wrapper to work with the injected objects, simplifying data extraction for any dapp that wishes to integrate the extension (or any extension that supports the interface)
## Dapp developers
The actual in-depth technical breakdown is given in the next section for any dapp developer wishing to work with the raw objects injected into the window. However convenience wrappers are provided that allows for any dapp to use this extension (or any other extension that conforms to the interface) without
having to manage any additional info.
This approach is used to support multiple external signers in for instance [apps](https://github.com/polkadot-js/apps/). You can read more about the conenience wrapper [@polkadot/extension-dapp](packages/extension-dapp/) along with usage samples.
## Technical
The extension injects `injectedWeb3` into the global `window` object, exposing the following:
The extension injects `injectedWeb3` into the global `window` object, exposing the following: (This is meant to be generic accross extensions, allowing any dapp to utilize multiple signers, as they are available)
```js
window.injectedWeb3 = {
// this is the name for this extension, there could be multiples injected,
// each with their own keys
// each with their own keys, here `polkadot-js` is for this extension
'polkadot-js': {
// semver for the package
version: '0.1.0',
@ -80,7 +87,7 @@ interface Accounts {
// a signer that communicates with the extension via sendMessage
interface Signer extends SignerInterface {
// no specific signer extensions, exposes the `sign` interface for use by
// the polkadot-js API
// the polkadot-js API, confirming the the Signer interface for this API
}
```