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:
parent
4aa578e016
commit
41892ea68b
@ -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}`);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user