Add Web3AccountsOptions to web3FromAddress function (#617)

* ss58Format

* fix

* fix

* fix

* fix

* fix

* lint

* Update packages/extension-dapp/src/index.ts

Co-authored-by: Jaco Greeff <jacogr@gmail.com>

* lint

* lint

Co-authored-by: Jaco Greeff <jacogr@gmail.com>
This commit is contained in:
Forrest 2021-01-13 19:55:19 +08:00 committed by GitHub
parent 4aa578e016
commit 41892ea68b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,7 @@
import type { Injected, InjectedAccount, InjectedAccountWithMeta, InjectedExtension, InjectedExtensionInfo, InjectedProviderWithMeta, InjectedWindow, ProviderList, Unsubcall, Web3AccountsOptions } from '@polkadot/extension-inject/types';
import { u8aEq } from '@polkadot/util';
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
import { documentReadyPromise } from './util';
@ -184,7 +185,13 @@ export async function web3FromAddress (address: string): Promise<InjectedExtensi
}
const accounts = await web3Accounts();
const found = address && accounts.find((account): boolean => account.address === address);
let found: InjectedAccountWithMeta | undefined;
if (address) {
const accountU8a = decodeAddress(address);
found = accounts.find((account): boolean => u8aEq(decodeAddress(account.address), accountU8a));
}
if (!found) {
throw new Error(`web3FromAddress: Unable to find injected ${address}`);