* Allow specifying derivation path on account creation (#57) * Allow specifying derivation path on account creation * Improve linting and formatting * Highlight input field when der-path is invalid * Fix header * Hide advanced options * Add tests * Fix name * Improve styling * Change names * Fix case * Add arrow icon * Add smooth transition * Refactor tests Co-authored-by: Bartłomiej Rutkowski <bar.rutkow@gmail.com> * [CI Skip] 0.22.0-beta.7 skip-checks: true * Import account derivation path (#59) * Import account derivation path * Fix test * fix scroll * Lint fix * add tests to importSeed Co-authored-by: Bartłomiej Rutkowski <bartek@ethworks.io> Co-authored-by: Kamil <kamil@ethworks.io> * [CI Skip] 0.22.0-beta.8 skip-checks: true * Hover and copy button (#58) * copy button and change hover * working on * add Toast * chage address width * Minor fixes * Add cursor: hand * Finish merge Co-authored-by: Kamil <kamil@ethworks.io> Co-authored-by: ivan <ivanruch@gmail.com> * [CI Skip] 0.22.0-beta.9 skip-checks: true * Fix build * [CI Skip] 0.23.0-beta.0 skip-checks: true * [CI Skip] Undo Github Actions version bump * [CI Skip] 0.23.0-beta.5 skip-checks: true * Add derive screen (#60) * Add derivation screen * Remove "///password" from derivation path placeholder * Refactor tests Co-authored-by: Bartłomiej Rutkowski <bar.rutkow@gmail.com> Co-authored-by: Anze1m <bartek@ethworks.io> * Improve account menu; fix linting (#61) * Fix test * Fix account menu * Fix linting * [CI Skip] 0.23.0-beta.6 skip-checks: true * Add proper account decoding (#62) * Add proper account decoding * Improve tests and error handling * Fix linting * Add refactoring * Update packages/extension/src/background/handlers/Extension.ts Co-Authored-By: Ivan Rukhavets <ivanruch@gmail.com> * Fix test * Fix linting * Fix actions * Slight UX improvement * Add big red button * Change red button to orange * Wrap in useCallback * Fix linting * Add proper password checking method * Fix linting Co-authored-by: Ivan Rukhavets <ivanruch@gmail.com> * [CI Skip] 0.23.0-beta.7 skip-checks: true * Apply merge fixes (#65) * Fix linting * CI * [CI Skip] 0.24.0-beta.1 skip-checks: true * CR requests * [CI Skip] 0.24.0-beta.2 skip-checks: true * [CI Skip] 0.24.0-beta.2 skip-checks: true Co-authored-by: Ivan Rukhavets <ivanruch@gmail.com> Co-authored-by: Github Actions <action@github.com> Co-authored-by: Kamil <kamil@ethworks.io> |
||
|---|---|---|
| .. | ||
| src | ||
| LICENSE | ||
| package.json | ||
| README.md | ||
@polkadot/extension-dapp
A basic extractor that manipulates the window.injectedWeb3 to retrieve all the providers added to the page. It has a number of utilities -
web3Enable(dappName: string): Promise<InjectedExtension[]>- to be called before anything else, retrieves the list of all injected extensions/providersweb3Accounts(): Promise<InjectedAccountWithMeta[]>- returns a list of all the injected accounts, accross all extensions (source in meta)web3AccountsSubscribe(cb: (accounts: InjectedAccountWithMeta[]) => any): Promise<Unsubcall>- subscribes to the accounts accross all extensions, returning a full list as changes are madeweb3FromAddress(address: string): Promise<InjectedExtension>- Retrieves a provider for a specific addressweb3FromSource(name: string): Promise<InjectedExtension>- Retrieves a provider identified by the nameisWeb3Injected: boolean- boolean to indicate ifinjectedWeb3was found on the pageweb3EnablePromise: Promise<InjectedExtension[]> | null-nullor the promise as a result of the last call toweb3Enable
Usage
import { web3Accounts, web3Enable, web3FromAddress, web3ListRpcProviders, web3UseRpcProvider } from '@polkadot/extension-dapp';
// returns an array of all the injected sources
// (this needs to be called first, before other requests)
const allInjected = await web3Enable('my cool dapp');
// returns an array of { address, meta: { name, source } }
// meta.source contains the name of the extension that provides this account
const allAccounts = await web3Accounts();
// finds an injector for an address
const injector = await web3FromAddress('5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE');
// sets the signer for the address on the @polkadot/api
api.setSigner(injector.signer);
// sign and send out transaction - notice here that the address of the account (as retrieved injected)
// is passed through as the param to the `signAndSend`, the API then calls the extension to present
// to the user and get it signed. Once completex, the api sends the tx + signature via the normal process
api.tx.balances
.transfer('5C5555yEXUcmEJ5kkcCMvdZjUo7NGJiQJMS7vZXEeoMhj3VQ', 123456)
.signAndSend('5DTestUPts3kjeXSTMyerHihn1uwMfLj8vU8sqF7qYrFabHE', (status) => { ... });
// retrieve all the RPC providers from a particular source. this returns a map
// of string->ProviderMeta, where the string represents an unique key to identify
// a provider, and ProviderMeta shows metadata about this provider
const allProviders = web3ListRpcProviders('polkadot-js');
// assuming one of the keys in `allProviders` is 'kusama-cc3', we can then use that provider
const { provider } = web3UseRpcProvider('polkadot-js', 'kusama-cc3');
const head = await provider.send('chain_getHeader', []); // shows latest header