forked from adamlaska/MEWconnect-web-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.js
More file actions
54 lines (43 loc) · 1.16 KB
/
create.js
File metadata and controls
54 lines (43 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* eslint-disable */
export default class MewWalletConnector {
constructor(url) {
this.mewConnect = '';
this.provider = '';
this.url = url;
}
async activate() {
let account;
const { default: MewConnect } = await import('../../../src');
if (!MewConnect.Provider.isConnected) {
this.mewConnect = new MewConnect.Provider({ windowClosedError: true });
this.provider = this.mewConnect.makeWeb3Provider(1, this.url, true);
this.mewConnect.on('disconnected', () => {
// this.emitDeactivate();
});
account = await this.mewConnect
.enable()
.catch(() => {
throw new Error('The user rejected the request.');
})
.then(accounts => accounts[0]);
}
return { provider: this.provider, chainId: 1, account: account };
}
async getProvider(){
return this.provider;
}
async getChainId() {
return 1;
}
async getAccount() {
return this.provider.send('eth_accounts').then(accounts => accounts[0]);
}
deactivate() {
this.provider.close();
// this.emitDeactivate();
}
async close() {
this.provider.close();
// this.emitDeactivate();
}
}