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";
54import 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');
98import Web3 from 'web3' ;
109
1110import {
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
2017interface 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
2724function 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
3431function 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}
0 commit comments