Skip to content

Commit a1f12b9

Browse files
committed
add types to injecetd accounts
1 parent 6303215 commit a1f12b9

File tree

4 files changed

+12
-25
lines changed

4 files changed

+12
-25
lines changed

packages/extension-dapp/src/compat/singleSource.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ interface SingleWindow extends InjectedWindow {
3131
function transformAccounts (accounts: SingleSourceAccount[]): InjectedAccount[] {
3232
return accounts.map(({ address, name }): InjectedAccount => ({
3333
address,
34-
name
34+
name,
35+
type:"ethereum"
3536
}));
3637
}
3738

packages/extension-dapp/src/compat/web3Source.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
// Copyright 2019-2020 @polkadot/extension-dapp authors & contributors
22
// SPDX-License-Identifier: Apache-2.0
33

4-
// import type { Signer } from "@polkadot/api/types";
54
import type { Injected, InjectedAccount, InjectedWindow } from '@polkadot/extension-inject/types';
65

7-
// import detectEthereumProvider from '@metamask/detect-provider';
8-
const detectEthereumProvider = require('@metamask/detect-provider');
6+
import detectEthereumProvider from '@metamask/detect-provider';
7+
// const detectEthereumProvider = require('@metamask/detect-provider');
98
import Web3 from 'web3';
109

1110
import {
1211
//SignerPayloadJSON,
1312
SignerPayloadRaw, SignerResult
1413
} from '@polkadot/types/types';
1514

16-
//import { TypeRegistry } from '@polkadot/types/create';
17-
18-
//const registry = new TypeRegistry();
15+
console.log("UP TO DATE")
1916

2017
interface Web3Window extends InjectedWindow {
2118
web3: Web3;
@@ -26,31 +23,21 @@ interface Web3Window extends InjectedWindow {
2623
// transfor the Web3 accounts into a simple address/name array
2724
function transformAccounts(accounts: string[]): InjectedAccount[] {
2825
return accounts.map((acc, i) => {
29-
return { address: acc, name: 'MetaMask Address #' + i.toString() };
26+
return { address: acc, name: 'MetaMask Address #' + i.toString(), type:"ethereum" };
3027
});
3128
}
3229

3330
// add a compat interface of SingleSource to window.injectedWeb3
3431
function injectWeb3(win: Web3Window): void {
35-
// let accounts: InjectedAccount[] = [];
36-
37-
// we don't yet have an accounts subscribe on the interface, simply get the
38-
// accounts and store them, any get will resolve the last found values
39-
// win.web3.accounts$.subscribe((_accounts): void => {
40-
// accounts = transformAccounts(_accounts);
41-
// });
4232

4333
// decorate the compat interface
4434
win.injectedWeb3.Web3Source = {
45-
// // eslint-disable-next-line @typescript-eslint/no-unused-vars,@typescript-eslint/require-await
4635
enable: async (_: string): Promise<Injected> => {
4736
win.web3 = new Web3(win.ethereum);
48-
// // // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
49-
// await win.ethereum.enable();
5037

5138
const provider: any = await detectEthereumProvider({ mustBeMetaMask: true });
5239
await provider.request({ method: 'eth_requestAccounts' });
53-
// let mainAccount=(await win.web3.eth.getAccounts())[0]
40+
5441
return {
5542
accounts: {
5643
get: async (): Promise<InjectedAccount[]> => {
@@ -100,8 +87,6 @@ export default function initWeb3Source(): Promise<boolean> {
10087
console.log('initWeb3Source');
10188

10289
return new Promise((resolve): void => {
103-
// console.log('listening')
104-
// window.addEventListener("load", (): void => {
10590
console.log('loading web3');
10691
const win = window as Window & Web3Window;
10792

@@ -111,6 +96,5 @@ export default function initWeb3Source(): Promise<boolean> {
11196
} else {
11297
resolve(false);
11398
}
114-
// });
11599
});
116100
}

packages/extension-dapp/src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ function throwError (method: string): never {
2929
// internal helper to map from Array<InjectedAccount> -> Array<InjectedAccountWithMeta>
3030
function mapAccounts (source: string, list: InjectedAccount[], signer:Signer, ss58Format?: number): InjectedAccountWithMeta[] {
3131
return list.map(
32-
({ address, genesisHash, name }): InjectedAccountWithMeta => {
32+
({ address, genesisHash, name, type }): InjectedAccountWithMeta => {
3333
const encodedAddress = address.length === 42 ? address : encodeAddress(decodeAddress(address), ss58Format);
3434

3535
return {
3636
address: encodedAddress,
3737
meta: { genesisHash, name, source },
38-
signer
38+
signer,
39+
type
3940
};
4041
}
4142
);

packages/extension-inject/src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface InjectedAccount {
1515
address: string;
1616
genesisHash?: string | null;
1717
name?: string;
18-
type?: KeypairType;
18+
type: KeypairType;
1919
}
2020

2121
export interface InjectedAccountWithMeta {
@@ -25,6 +25,7 @@ export interface InjectedAccountWithMeta {
2525
name?: string;
2626
source: string;
2727
};
28+
type:KeypairType;
2829
signer:Signer;
2930
}
3031

0 commit comments

Comments
 (0)