@depay/web3-wallets-evm 12.4.2 → 13.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/esm/index.evm.js +53 -18
- package/dist/esm/index.js +34 -16
- package/dist/umd/index.evm.js +53 -17
- package/dist/umd/index.js +34 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -99,6 +99,15 @@ if(foundWallets.length == 1) {
|
|
|
99
99
|
}
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
+
### getConnectedWallets
|
|
103
|
+
|
|
104
|
+
`getConnectedWallets`: Returns an array of currently connected wallets.
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
let wallets = await getConnectedWallets();
|
|
108
|
+
// [<Wallet name='MetaMask'>, <Wallet name='Phantom'>]
|
|
109
|
+
```
|
|
110
|
+
|
|
102
111
|
### Name
|
|
103
112
|
|
|
104
113
|
`name:string`: Returns the name of the wallet.
|
package/dist/esm/index.evm.js
CHANGED
|
@@ -12,8 +12,8 @@ class Transaction {
|
|
|
12
12
|
|
|
13
13
|
// required
|
|
14
14
|
this.blockchain = blockchain;
|
|
15
|
-
this.from = from;
|
|
16
|
-
this.to = to;
|
|
15
|
+
this.from = (from && from.match('0x')) ? ethers.utils.getAddress(from) : from;
|
|
16
|
+
this.to = (to && to.match('0x')) ? ethers.utils.getAddress(to) : to;
|
|
17
17
|
|
|
18
18
|
// optional
|
|
19
19
|
this.value = _optionalChain$5([Transaction, 'access', _ => _.bigNumberify, 'call', _2 => _2(value, blockchain), 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
|
|
@@ -213,13 +213,13 @@ class WindowEthereum {
|
|
|
213
213
|
|
|
214
214
|
async account() {
|
|
215
215
|
if(!_optionalChain$4([window, 'optionalAccess', _15 => _15.ethereum])) { return undefined }
|
|
216
|
-
const accounts = await window.ethereum.request({ method: 'eth_accounts' });
|
|
216
|
+
const accounts = (await window.ethereum.request({ method: 'eth_accounts' })).map((address)=>ethers.utils.getAddress(address));
|
|
217
217
|
return accounts[0]
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
async connect() {
|
|
221
221
|
if(!_optionalChain$4([window, 'optionalAccess', _16 => _16.ethereum])) { return undefined }
|
|
222
|
-
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
|
|
222
|
+
const accounts = (await window.ethereum.request({ method: 'eth_requestAccounts' })).map((address)=>ethers.utils.getAddress(address));
|
|
223
223
|
return accounts[0]
|
|
224
224
|
}
|
|
225
225
|
|
|
@@ -227,7 +227,7 @@ class WindowEthereum {
|
|
|
227
227
|
let internalCallback;
|
|
228
228
|
switch (event) {
|
|
229
229
|
case 'account':
|
|
230
|
-
internalCallback = (accounts) => callback(accounts[0]);
|
|
230
|
+
internalCallback = (accounts) => callback(ethers.utils.getAddress(accounts[0]));
|
|
231
231
|
window.ethereum.on('accountsChanged', internalCallback);
|
|
232
232
|
break
|
|
233
233
|
}
|
|
@@ -462,14 +462,14 @@ class WalletConnect {
|
|
|
462
462
|
instance.on("connect", (error, payload) => {
|
|
463
463
|
if (error) { throw error }
|
|
464
464
|
const { accounts, chainId } = payload.params[0];
|
|
465
|
-
this.connectedAccounts = accounts;
|
|
465
|
+
this.connectedAccounts = accounts.map((account)=>ethers.utils.getAddress(account));
|
|
466
466
|
this.connectedChainId = chainId;
|
|
467
467
|
});
|
|
468
468
|
|
|
469
469
|
instance.on("session_update", (error, payload) => {
|
|
470
470
|
if (error) { throw error }
|
|
471
471
|
const { accounts, chainId } = payload.params[0];
|
|
472
|
-
this.connectedAccounts = accounts;
|
|
472
|
+
this.connectedAccounts = accounts.map((account)=>ethers.utils.getAddress(account));
|
|
473
473
|
this.connectedChainId = chainId;
|
|
474
474
|
});
|
|
475
475
|
|
|
@@ -505,12 +505,13 @@ class WalletConnect {
|
|
|
505
505
|
this.connector = this.newWalletConnectInstance();
|
|
506
506
|
}
|
|
507
507
|
|
|
508
|
-
|
|
508
|
+
let { accounts, chainId } = await this.connector.connect({ chainId: _optionalChain([options, 'optionalAccess', _ => _.chainId]) });
|
|
509
509
|
|
|
510
510
|
if(accounts instanceof Array && accounts.length) {
|
|
511
511
|
setConnectedInstance$1(this);
|
|
512
512
|
}
|
|
513
513
|
|
|
514
|
+
accounts = accounts.map((account)=>ethers.utils.getAddress(account));
|
|
514
515
|
this.connectedAccounts = accounts;
|
|
515
516
|
this.connectedChainId = chainId;
|
|
516
517
|
|
|
@@ -533,17 +534,35 @@ class WalletConnect {
|
|
|
533
534
|
|
|
534
535
|
switchTo(blockchainName) {
|
|
535
536
|
return new Promise((resolve, reject)=>{
|
|
537
|
+
let resolved, rejected;
|
|
536
538
|
const blockchain = Blockchain.findByName(blockchainName);
|
|
539
|
+
setTimeout(async()=>{
|
|
540
|
+
if(!(await this.connectedTo(blockchainName)) && !resolved && !rejected){
|
|
541
|
+
reject({ code: 'NOT_SUPPORTED' });
|
|
542
|
+
} else {
|
|
543
|
+
resolve();
|
|
544
|
+
}
|
|
545
|
+
}, 3000);
|
|
537
546
|
this.connector.sendCustomRequest({
|
|
538
547
|
method: 'wallet_switchEthereumChain',
|
|
539
548
|
params: [{ chainId: blockchain.id }],
|
|
540
|
-
}).then(
|
|
541
|
-
|
|
549
|
+
}).then(()=>{
|
|
550
|
+
resolved = true;
|
|
551
|
+
resolve();
|
|
552
|
+
}).catch((error)=> {
|
|
553
|
+
if(error && typeof error.message == 'string' && error.message.match('addEthereumChain')){ // chain not yet added
|
|
542
554
|
this.addNetwork(blockchainName)
|
|
543
|
-
.then(()=>this.switchTo(blockchainName).then(
|
|
544
|
-
|
|
555
|
+
.then(()=>this.switchTo(blockchainName).then(()=>{
|
|
556
|
+
resolved = true;
|
|
557
|
+
resolve();
|
|
558
|
+
}))
|
|
559
|
+
.catch(()=>{
|
|
560
|
+
rejected = true;
|
|
561
|
+
reject({ code: 'NOT_SUPPORTED' });
|
|
562
|
+
});
|
|
545
563
|
} else {
|
|
546
|
-
|
|
564
|
+
rejected = true;
|
|
565
|
+
reject({ code: 'NOT_SUPPORTED' });
|
|
547
566
|
}
|
|
548
567
|
});
|
|
549
568
|
})
|
|
@@ -575,8 +594,10 @@ class WalletConnect {
|
|
|
575
594
|
switch (event) {
|
|
576
595
|
case 'account':
|
|
577
596
|
internalCallback = (error, payload) => {
|
|
578
|
-
|
|
579
|
-
|
|
597
|
+
if(payload && payload.params && payload.params[0].accounts && payload.params[0].accounts instanceof Array) {
|
|
598
|
+
const accounts = payload.params[0].accounts.map((account)=>ethers.utils.getAddress(account));
|
|
599
|
+
callback(accounts[0]);
|
|
600
|
+
}
|
|
580
601
|
};
|
|
581
602
|
this.connector.on("session_update", internalCallback);
|
|
582
603
|
break
|
|
@@ -716,7 +737,7 @@ class WalletLink {
|
|
|
716
737
|
|
|
717
738
|
async account() {
|
|
718
739
|
if(this.connectedAccounts == undefined) { return }
|
|
719
|
-
return this.connectedAccounts[0]
|
|
740
|
+
return ethers.utils.getAddress(this.connectedAccounts[0])
|
|
720
741
|
}
|
|
721
742
|
|
|
722
743
|
async connect(options) {
|
|
@@ -726,6 +747,7 @@ class WalletLink {
|
|
|
726
747
|
if(accounts instanceof Array && accounts.length) {
|
|
727
748
|
setConnectedInstance(this);
|
|
728
749
|
}
|
|
750
|
+
accounts = accounts.map((account)=>ethers.utils.getAddress(account));
|
|
729
751
|
this.connectedAccounts = accounts;
|
|
730
752
|
this.connectedChainId = await this.connector.getChainId();
|
|
731
753
|
return accounts[0]
|
|
@@ -784,7 +806,7 @@ class WalletLink {
|
|
|
784
806
|
let internalCallback;
|
|
785
807
|
switch (event) {
|
|
786
808
|
case 'account':
|
|
787
|
-
internalCallback = (accounts) => callback(accounts[0]);
|
|
809
|
+
internalCallback = (accounts) => callback(ethers.utils.getAddress(accounts[0]));
|
|
788
810
|
this.connector.on('accountsChanged', internalCallback);
|
|
789
811
|
break
|
|
790
812
|
}
|
|
@@ -842,6 +864,19 @@ const getWallets = ()=>{
|
|
|
842
864
|
return availableWallets
|
|
843
865
|
};
|
|
844
866
|
|
|
867
|
+
const getConnectedWallets = async()=>{
|
|
868
|
+
|
|
869
|
+
let connectedWallets = (await Promise.all(
|
|
870
|
+
getWallets().map(async(wallet)=>{
|
|
871
|
+
if(await wallet.account()) {
|
|
872
|
+
return wallet
|
|
873
|
+
}
|
|
874
|
+
})
|
|
875
|
+
)).filter((value)=>!!value);
|
|
876
|
+
|
|
877
|
+
return connectedWallets
|
|
878
|
+
};
|
|
879
|
+
|
|
845
880
|
const supported = [
|
|
846
881
|
wallets.MetaMask,
|
|
847
882
|
wallets.Coinbase,
|
|
@@ -849,4 +884,4 @@ const supported = [
|
|
|
849
884
|
wallets.WalletLink
|
|
850
885
|
];
|
|
851
886
|
|
|
852
|
-
export { getWallets, supported, wallets };
|
|
887
|
+
export { getConnectedWallets, getWallets, supported, wallets };
|
package/dist/esm/index.js
CHANGED
|
@@ -13,8 +13,8 @@ class Transaction {
|
|
|
13
13
|
|
|
14
14
|
// required
|
|
15
15
|
this.blockchain = blockchain;
|
|
16
|
-
this.from = from;
|
|
17
|
-
this.to = to;
|
|
16
|
+
this.from = (from && from.match('0x')) ? ethers.utils.getAddress(from) : from;
|
|
17
|
+
this.to = (to && to.match('0x')) ? ethers.utils.getAddress(to) : to;
|
|
18
18
|
|
|
19
19
|
// optional
|
|
20
20
|
this.value = _optionalChain$8([Transaction, 'access', _ => _.bigNumberify, 'call', _2 => _2(value, blockchain), 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
|
|
@@ -214,13 +214,13 @@ class WindowEthereum {
|
|
|
214
214
|
|
|
215
215
|
async account() {
|
|
216
216
|
if(!_optionalChain$7([window, 'optionalAccess', _15 => _15.ethereum])) { return undefined }
|
|
217
|
-
const accounts = await window.ethereum.request({ method: 'eth_accounts' });
|
|
217
|
+
const accounts = (await window.ethereum.request({ method: 'eth_accounts' })).map((address)=>ethers.utils.getAddress(address));
|
|
218
218
|
return accounts[0]
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
async connect() {
|
|
222
222
|
if(!_optionalChain$7([window, 'optionalAccess', _16 => _16.ethereum])) { return undefined }
|
|
223
|
-
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
|
|
223
|
+
const accounts = (await window.ethereum.request({ method: 'eth_requestAccounts' })).map((address)=>ethers.utils.getAddress(address));
|
|
224
224
|
return accounts[0]
|
|
225
225
|
}
|
|
226
226
|
|
|
@@ -228,7 +228,7 @@ class WindowEthereum {
|
|
|
228
228
|
let internalCallback;
|
|
229
229
|
switch (event) {
|
|
230
230
|
case 'account':
|
|
231
|
-
internalCallback = (accounts) => callback(accounts[0]);
|
|
231
|
+
internalCallback = (accounts) => callback(ethers.utils.getAddress(accounts[0]));
|
|
232
232
|
window.ethereum.on('accountsChanged', internalCallback);
|
|
233
233
|
break
|
|
234
234
|
}
|
|
@@ -444,9 +444,10 @@ class WindowSolana {
|
|
|
444
444
|
}
|
|
445
445
|
|
|
446
446
|
async account() {
|
|
447
|
-
if(_optionalChain$3([window, 'optionalAccess', _7 => _7.solana
|
|
448
|
-
if(_optionalChain$3([window, 'optionalAccess', _9 => _9.
|
|
449
|
-
let
|
|
447
|
+
if(_optionalChain$3([window, 'optionalAccess', _7 => _7.solana]) == undefined){ return }
|
|
448
|
+
if(_optionalChain$3([window, 'optionalAccess', _8 => _8.solana, 'optionalAccess', _9 => _9.publicKey])) { return window.solana.publicKey.toString() }
|
|
449
|
+
let publicKey;
|
|
450
|
+
try { ({ publicKey } = await window.solana.connect({ onlyIfTrusted: true })); } catch (e) {}
|
|
450
451
|
if(publicKey){ return publicKey.toString() }
|
|
451
452
|
}
|
|
452
453
|
|
|
@@ -650,14 +651,14 @@ class WalletConnect {
|
|
|
650
651
|
instance.on("connect", (error, payload) => {
|
|
651
652
|
if (error) { throw error }
|
|
652
653
|
const { accounts, chainId } = payload.params[0];
|
|
653
|
-
this.connectedAccounts = accounts;
|
|
654
|
+
this.connectedAccounts = accounts.map((account)=>ethers.utils.getAddress(account));
|
|
654
655
|
this.connectedChainId = chainId;
|
|
655
656
|
});
|
|
656
657
|
|
|
657
658
|
instance.on("session_update", (error, payload) => {
|
|
658
659
|
if (error) { throw error }
|
|
659
660
|
const { accounts, chainId } = payload.params[0];
|
|
660
|
-
this.connectedAccounts = accounts;
|
|
661
|
+
this.connectedAccounts = accounts.map((account)=>ethers.utils.getAddress(account));
|
|
661
662
|
this.connectedChainId = chainId;
|
|
662
663
|
});
|
|
663
664
|
|
|
@@ -693,12 +694,13 @@ class WalletConnect {
|
|
|
693
694
|
this.connector = this.newWalletConnectInstance();
|
|
694
695
|
}
|
|
695
696
|
|
|
696
|
-
|
|
697
|
+
let { accounts, chainId } = await this.connector.connect({ chainId: _optionalChain([options, 'optionalAccess', _ => _.chainId]) });
|
|
697
698
|
|
|
698
699
|
if(accounts instanceof Array && accounts.length) {
|
|
699
700
|
setConnectedInstance$1(this);
|
|
700
701
|
}
|
|
701
702
|
|
|
703
|
+
accounts = accounts.map((account)=>ethers.utils.getAddress(account));
|
|
702
704
|
this.connectedAccounts = accounts;
|
|
703
705
|
this.connectedChainId = chainId;
|
|
704
706
|
|
|
@@ -781,8 +783,10 @@ class WalletConnect {
|
|
|
781
783
|
switch (event) {
|
|
782
784
|
case 'account':
|
|
783
785
|
internalCallback = (error, payload) => {
|
|
784
|
-
|
|
785
|
-
|
|
786
|
+
if(payload && payload.params && payload.params[0].accounts && payload.params[0].accounts instanceof Array) {
|
|
787
|
+
const accounts = payload.params[0].accounts.map((account)=>ethers.utils.getAddress(account));
|
|
788
|
+
callback(accounts[0]);
|
|
789
|
+
}
|
|
786
790
|
};
|
|
787
791
|
this.connector.on("session_update", internalCallback);
|
|
788
792
|
break
|
|
@@ -922,7 +926,7 @@ class WalletLink {
|
|
|
922
926
|
|
|
923
927
|
async account() {
|
|
924
928
|
if(this.connectedAccounts == undefined) { return }
|
|
925
|
-
return this.connectedAccounts[0]
|
|
929
|
+
return ethers.utils.getAddress(this.connectedAccounts[0])
|
|
926
930
|
}
|
|
927
931
|
|
|
928
932
|
async connect(options) {
|
|
@@ -932,6 +936,7 @@ class WalletLink {
|
|
|
932
936
|
if(accounts instanceof Array && accounts.length) {
|
|
933
937
|
setConnectedInstance(this);
|
|
934
938
|
}
|
|
939
|
+
accounts = accounts.map((account)=>ethers.utils.getAddress(account));
|
|
935
940
|
this.connectedAccounts = accounts;
|
|
936
941
|
this.connectedChainId = await this.connector.getChainId();
|
|
937
942
|
return accounts[0]
|
|
@@ -990,7 +995,7 @@ class WalletLink {
|
|
|
990
995
|
let internalCallback;
|
|
991
996
|
switch (event) {
|
|
992
997
|
case 'account':
|
|
993
|
-
internalCallback = (accounts) => callback(accounts[0]);
|
|
998
|
+
internalCallback = (accounts) => callback(ethers.utils.getAddress(accounts[0]));
|
|
994
999
|
this.connector.on('accountsChanged', internalCallback);
|
|
995
1000
|
break
|
|
996
1001
|
}
|
|
@@ -1050,6 +1055,19 @@ const getWallets = ()=>{
|
|
|
1050
1055
|
return availableWallets
|
|
1051
1056
|
};
|
|
1052
1057
|
|
|
1058
|
+
const getConnectedWallets = async()=>{
|
|
1059
|
+
|
|
1060
|
+
let connectedWallets = (await Promise.all(
|
|
1061
|
+
getWallets().map(async(wallet)=>{
|
|
1062
|
+
if(await wallet.account()) {
|
|
1063
|
+
return wallet
|
|
1064
|
+
}
|
|
1065
|
+
})
|
|
1066
|
+
)).filter((value)=>!!value);
|
|
1067
|
+
|
|
1068
|
+
return connectedWallets
|
|
1069
|
+
};
|
|
1070
|
+
|
|
1053
1071
|
const supported = [
|
|
1054
1072
|
wallets.MetaMask,
|
|
1055
1073
|
wallets.Phantom,
|
|
@@ -1058,4 +1076,4 @@ const supported = [
|
|
|
1058
1076
|
wallets.WalletLink
|
|
1059
1077
|
];
|
|
1060
1078
|
|
|
1061
|
-
export { getWallets, supported, wallets };
|
|
1079
|
+
export { getConnectedWallets, getWallets, supported, wallets };
|
package/dist/umd/index.evm.js
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
// required
|
|
13
13
|
this.blockchain = blockchain;
|
|
14
|
-
this.from = from;
|
|
15
|
-
this.to = to;
|
|
14
|
+
this.from = (from && from.match('0x')) ? ethers.ethers.utils.getAddress(from) : from;
|
|
15
|
+
this.to = (to && to.match('0x')) ? ethers.ethers.utils.getAddress(to) : to;
|
|
16
16
|
|
|
17
17
|
// optional
|
|
18
18
|
this.value = _optionalChain$5([Transaction, 'access', _ => _.bigNumberify, 'call', _2 => _2(value, blockchain), 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
|
|
@@ -212,13 +212,13 @@
|
|
|
212
212
|
|
|
213
213
|
async account() {
|
|
214
214
|
if(!_optionalChain$4([window, 'optionalAccess', _15 => _15.ethereum])) { return undefined }
|
|
215
|
-
const accounts = await window.ethereum.request({ method: 'eth_accounts' });
|
|
215
|
+
const accounts = (await window.ethereum.request({ method: 'eth_accounts' })).map((address)=>ethers.ethers.utils.getAddress(address));
|
|
216
216
|
return accounts[0]
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
async connect() {
|
|
220
220
|
if(!_optionalChain$4([window, 'optionalAccess', _16 => _16.ethereum])) { return undefined }
|
|
221
|
-
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
|
|
221
|
+
const accounts = (await window.ethereum.request({ method: 'eth_requestAccounts' })).map((address)=>ethers.ethers.utils.getAddress(address));
|
|
222
222
|
return accounts[0]
|
|
223
223
|
}
|
|
224
224
|
|
|
@@ -226,7 +226,7 @@
|
|
|
226
226
|
let internalCallback;
|
|
227
227
|
switch (event) {
|
|
228
228
|
case 'account':
|
|
229
|
-
internalCallback = (accounts) => callback(accounts[0]);
|
|
229
|
+
internalCallback = (accounts) => callback(ethers.ethers.utils.getAddress(accounts[0]));
|
|
230
230
|
window.ethereum.on('accountsChanged', internalCallback);
|
|
231
231
|
break
|
|
232
232
|
}
|
|
@@ -461,14 +461,14 @@
|
|
|
461
461
|
instance.on("connect", (error, payload) => {
|
|
462
462
|
if (error) { throw error }
|
|
463
463
|
const { accounts, chainId } = payload.params[0];
|
|
464
|
-
this.connectedAccounts = accounts;
|
|
464
|
+
this.connectedAccounts = accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
465
465
|
this.connectedChainId = chainId;
|
|
466
466
|
});
|
|
467
467
|
|
|
468
468
|
instance.on("session_update", (error, payload) => {
|
|
469
469
|
if (error) { throw error }
|
|
470
470
|
const { accounts, chainId } = payload.params[0];
|
|
471
|
-
this.connectedAccounts = accounts;
|
|
471
|
+
this.connectedAccounts = accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
472
472
|
this.connectedChainId = chainId;
|
|
473
473
|
});
|
|
474
474
|
|
|
@@ -504,12 +504,13 @@
|
|
|
504
504
|
this.connector = this.newWalletConnectInstance();
|
|
505
505
|
}
|
|
506
506
|
|
|
507
|
-
|
|
507
|
+
let { accounts, chainId } = await this.connector.connect({ chainId: _optionalChain([options, 'optionalAccess', _ => _.chainId]) });
|
|
508
508
|
|
|
509
509
|
if(accounts instanceof Array && accounts.length) {
|
|
510
510
|
setConnectedInstance$1(this);
|
|
511
511
|
}
|
|
512
512
|
|
|
513
|
+
accounts = accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
513
514
|
this.connectedAccounts = accounts;
|
|
514
515
|
this.connectedChainId = chainId;
|
|
515
516
|
|
|
@@ -532,17 +533,35 @@
|
|
|
532
533
|
|
|
533
534
|
switchTo(blockchainName) {
|
|
534
535
|
return new Promise((resolve, reject)=>{
|
|
536
|
+
let resolved, rejected;
|
|
535
537
|
const blockchain = web3Blockchains.Blockchain.findByName(blockchainName);
|
|
538
|
+
setTimeout(async()=>{
|
|
539
|
+
if(!(await this.connectedTo(blockchainName)) && !resolved && !rejected){
|
|
540
|
+
reject({ code: 'NOT_SUPPORTED' });
|
|
541
|
+
} else {
|
|
542
|
+
resolve();
|
|
543
|
+
}
|
|
544
|
+
}, 3000);
|
|
536
545
|
this.connector.sendCustomRequest({
|
|
537
546
|
method: 'wallet_switchEthereumChain',
|
|
538
547
|
params: [{ chainId: blockchain.id }],
|
|
539
|
-
}).then(
|
|
540
|
-
|
|
548
|
+
}).then(()=>{
|
|
549
|
+
resolved = true;
|
|
550
|
+
resolve();
|
|
551
|
+
}).catch((error)=> {
|
|
552
|
+
if(error && typeof error.message == 'string' && error.message.match('addEthereumChain')){ // chain not yet added
|
|
541
553
|
this.addNetwork(blockchainName)
|
|
542
|
-
.then(()=>this.switchTo(blockchainName).then(
|
|
543
|
-
|
|
554
|
+
.then(()=>this.switchTo(blockchainName).then(()=>{
|
|
555
|
+
resolved = true;
|
|
556
|
+
resolve();
|
|
557
|
+
}))
|
|
558
|
+
.catch(()=>{
|
|
559
|
+
rejected = true;
|
|
560
|
+
reject({ code: 'NOT_SUPPORTED' });
|
|
561
|
+
});
|
|
544
562
|
} else {
|
|
545
|
-
|
|
563
|
+
rejected = true;
|
|
564
|
+
reject({ code: 'NOT_SUPPORTED' });
|
|
546
565
|
}
|
|
547
566
|
});
|
|
548
567
|
})
|
|
@@ -574,8 +593,10 @@
|
|
|
574
593
|
switch (event) {
|
|
575
594
|
case 'account':
|
|
576
595
|
internalCallback = (error, payload) => {
|
|
577
|
-
|
|
578
|
-
|
|
596
|
+
if(payload && payload.params && payload.params[0].accounts && payload.params[0].accounts instanceof Array) {
|
|
597
|
+
const accounts = payload.params[0].accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
598
|
+
callback(accounts[0]);
|
|
599
|
+
}
|
|
579
600
|
};
|
|
580
601
|
this.connector.on("session_update", internalCallback);
|
|
581
602
|
break
|
|
@@ -715,7 +736,7 @@
|
|
|
715
736
|
|
|
716
737
|
async account() {
|
|
717
738
|
if(this.connectedAccounts == undefined) { return }
|
|
718
|
-
return this.connectedAccounts[0]
|
|
739
|
+
return ethers.ethers.utils.getAddress(this.connectedAccounts[0])
|
|
719
740
|
}
|
|
720
741
|
|
|
721
742
|
async connect(options) {
|
|
@@ -725,6 +746,7 @@
|
|
|
725
746
|
if(accounts instanceof Array && accounts.length) {
|
|
726
747
|
setConnectedInstance(this);
|
|
727
748
|
}
|
|
749
|
+
accounts = accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
728
750
|
this.connectedAccounts = accounts;
|
|
729
751
|
this.connectedChainId = await this.connector.getChainId();
|
|
730
752
|
return accounts[0]
|
|
@@ -783,7 +805,7 @@
|
|
|
783
805
|
let internalCallback;
|
|
784
806
|
switch (event) {
|
|
785
807
|
case 'account':
|
|
786
|
-
internalCallback = (accounts) => callback(accounts[0]);
|
|
808
|
+
internalCallback = (accounts) => callback(ethers.ethers.utils.getAddress(accounts[0]));
|
|
787
809
|
this.connector.on('accountsChanged', internalCallback);
|
|
788
810
|
break
|
|
789
811
|
}
|
|
@@ -841,6 +863,19 @@
|
|
|
841
863
|
return availableWallets
|
|
842
864
|
};
|
|
843
865
|
|
|
866
|
+
const getConnectedWallets = async()=>{
|
|
867
|
+
|
|
868
|
+
let connectedWallets = (await Promise.all(
|
|
869
|
+
getWallets().map(async(wallet)=>{
|
|
870
|
+
if(await wallet.account()) {
|
|
871
|
+
return wallet
|
|
872
|
+
}
|
|
873
|
+
})
|
|
874
|
+
)).filter((value)=>!!value);
|
|
875
|
+
|
|
876
|
+
return connectedWallets
|
|
877
|
+
};
|
|
878
|
+
|
|
844
879
|
const supported = [
|
|
845
880
|
wallets.MetaMask,
|
|
846
881
|
wallets.Coinbase,
|
|
@@ -848,6 +883,7 @@
|
|
|
848
883
|
wallets.WalletLink
|
|
849
884
|
];
|
|
850
885
|
|
|
886
|
+
exports.getConnectedWallets = getConnectedWallets;
|
|
851
887
|
exports.getWallets = getWallets;
|
|
852
888
|
exports.supported = supported;
|
|
853
889
|
exports.wallets = wallets;
|
package/dist/umd/index.js
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
// required
|
|
13
13
|
this.blockchain = blockchain;
|
|
14
|
-
this.from = from;
|
|
15
|
-
this.to = to;
|
|
14
|
+
this.from = (from && from.match('0x')) ? ethers.ethers.utils.getAddress(from) : from;
|
|
15
|
+
this.to = (to && to.match('0x')) ? ethers.ethers.utils.getAddress(to) : to;
|
|
16
16
|
|
|
17
17
|
// optional
|
|
18
18
|
this.value = _optionalChain$8([Transaction, 'access', _ => _.bigNumberify, 'call', _2 => _2(value, blockchain), 'optionalAccess', _3 => _3.toString, 'call', _4 => _4()]);
|
|
@@ -212,13 +212,13 @@
|
|
|
212
212
|
|
|
213
213
|
async account() {
|
|
214
214
|
if(!_optionalChain$7([window, 'optionalAccess', _15 => _15.ethereum])) { return undefined }
|
|
215
|
-
const accounts = await window.ethereum.request({ method: 'eth_accounts' });
|
|
215
|
+
const accounts = (await window.ethereum.request({ method: 'eth_accounts' })).map((address)=>ethers.ethers.utils.getAddress(address));
|
|
216
216
|
return accounts[0]
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
async connect() {
|
|
220
220
|
if(!_optionalChain$7([window, 'optionalAccess', _16 => _16.ethereum])) { return undefined }
|
|
221
|
-
const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
|
|
221
|
+
const accounts = (await window.ethereum.request({ method: 'eth_requestAccounts' })).map((address)=>ethers.ethers.utils.getAddress(address));
|
|
222
222
|
return accounts[0]
|
|
223
223
|
}
|
|
224
224
|
|
|
@@ -226,7 +226,7 @@
|
|
|
226
226
|
let internalCallback;
|
|
227
227
|
switch (event) {
|
|
228
228
|
case 'account':
|
|
229
|
-
internalCallback = (accounts) => callback(accounts[0]);
|
|
229
|
+
internalCallback = (accounts) => callback(ethers.ethers.utils.getAddress(accounts[0]));
|
|
230
230
|
window.ethereum.on('accountsChanged', internalCallback);
|
|
231
231
|
break
|
|
232
232
|
}
|
|
@@ -442,9 +442,10 @@
|
|
|
442
442
|
}
|
|
443
443
|
|
|
444
444
|
async account() {
|
|
445
|
-
if(_optionalChain$3([window, 'optionalAccess', _7 => _7.solana
|
|
446
|
-
if(_optionalChain$3([window, 'optionalAccess', _9 => _9.
|
|
447
|
-
let
|
|
445
|
+
if(_optionalChain$3([window, 'optionalAccess', _7 => _7.solana]) == undefined){ return }
|
|
446
|
+
if(_optionalChain$3([window, 'optionalAccess', _8 => _8.solana, 'optionalAccess', _9 => _9.publicKey])) { return window.solana.publicKey.toString() }
|
|
447
|
+
let publicKey;
|
|
448
|
+
try { ({ publicKey } = await window.solana.connect({ onlyIfTrusted: true })); } catch (e) {}
|
|
448
449
|
if(publicKey){ return publicKey.toString() }
|
|
449
450
|
}
|
|
450
451
|
|
|
@@ -648,14 +649,14 @@
|
|
|
648
649
|
instance.on("connect", (error, payload) => {
|
|
649
650
|
if (error) { throw error }
|
|
650
651
|
const { accounts, chainId } = payload.params[0];
|
|
651
|
-
this.connectedAccounts = accounts;
|
|
652
|
+
this.connectedAccounts = accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
652
653
|
this.connectedChainId = chainId;
|
|
653
654
|
});
|
|
654
655
|
|
|
655
656
|
instance.on("session_update", (error, payload) => {
|
|
656
657
|
if (error) { throw error }
|
|
657
658
|
const { accounts, chainId } = payload.params[0];
|
|
658
|
-
this.connectedAccounts = accounts;
|
|
659
|
+
this.connectedAccounts = accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
659
660
|
this.connectedChainId = chainId;
|
|
660
661
|
});
|
|
661
662
|
|
|
@@ -691,12 +692,13 @@
|
|
|
691
692
|
this.connector = this.newWalletConnectInstance();
|
|
692
693
|
}
|
|
693
694
|
|
|
694
|
-
|
|
695
|
+
let { accounts, chainId } = await this.connector.connect({ chainId: _optionalChain([options, 'optionalAccess', _ => _.chainId]) });
|
|
695
696
|
|
|
696
697
|
if(accounts instanceof Array && accounts.length) {
|
|
697
698
|
setConnectedInstance$1(this);
|
|
698
699
|
}
|
|
699
700
|
|
|
701
|
+
accounts = accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
700
702
|
this.connectedAccounts = accounts;
|
|
701
703
|
this.connectedChainId = chainId;
|
|
702
704
|
|
|
@@ -779,8 +781,10 @@
|
|
|
779
781
|
switch (event) {
|
|
780
782
|
case 'account':
|
|
781
783
|
internalCallback = (error, payload) => {
|
|
782
|
-
|
|
783
|
-
|
|
784
|
+
if(payload && payload.params && payload.params[0].accounts && payload.params[0].accounts instanceof Array) {
|
|
785
|
+
const accounts = payload.params[0].accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
786
|
+
callback(accounts[0]);
|
|
787
|
+
}
|
|
784
788
|
};
|
|
785
789
|
this.connector.on("session_update", internalCallback);
|
|
786
790
|
break
|
|
@@ -920,7 +924,7 @@
|
|
|
920
924
|
|
|
921
925
|
async account() {
|
|
922
926
|
if(this.connectedAccounts == undefined) { return }
|
|
923
|
-
return this.connectedAccounts[0]
|
|
927
|
+
return ethers.ethers.utils.getAddress(this.connectedAccounts[0])
|
|
924
928
|
}
|
|
925
929
|
|
|
926
930
|
async connect(options) {
|
|
@@ -930,6 +934,7 @@
|
|
|
930
934
|
if(accounts instanceof Array && accounts.length) {
|
|
931
935
|
setConnectedInstance(this);
|
|
932
936
|
}
|
|
937
|
+
accounts = accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
933
938
|
this.connectedAccounts = accounts;
|
|
934
939
|
this.connectedChainId = await this.connector.getChainId();
|
|
935
940
|
return accounts[0]
|
|
@@ -988,7 +993,7 @@
|
|
|
988
993
|
let internalCallback;
|
|
989
994
|
switch (event) {
|
|
990
995
|
case 'account':
|
|
991
|
-
internalCallback = (accounts) => callback(accounts[0]);
|
|
996
|
+
internalCallback = (accounts) => callback(ethers.ethers.utils.getAddress(accounts[0]));
|
|
992
997
|
this.connector.on('accountsChanged', internalCallback);
|
|
993
998
|
break
|
|
994
999
|
}
|
|
@@ -1048,6 +1053,19 @@
|
|
|
1048
1053
|
return availableWallets
|
|
1049
1054
|
};
|
|
1050
1055
|
|
|
1056
|
+
const getConnectedWallets = async()=>{
|
|
1057
|
+
|
|
1058
|
+
let connectedWallets = (await Promise.all(
|
|
1059
|
+
getWallets().map(async(wallet)=>{
|
|
1060
|
+
if(await wallet.account()) {
|
|
1061
|
+
return wallet
|
|
1062
|
+
}
|
|
1063
|
+
})
|
|
1064
|
+
)).filter((value)=>!!value);
|
|
1065
|
+
|
|
1066
|
+
return connectedWallets
|
|
1067
|
+
};
|
|
1068
|
+
|
|
1051
1069
|
const supported = [
|
|
1052
1070
|
wallets.MetaMask,
|
|
1053
1071
|
wallets.Phantom,
|
|
@@ -1056,6 +1074,7 @@
|
|
|
1056
1074
|
wallets.WalletLink
|
|
1057
1075
|
];
|
|
1058
1076
|
|
|
1077
|
+
exports.getConnectedWallets = getConnectedWallets;
|
|
1059
1078
|
exports.getWallets = getWallets;
|
|
1060
1079
|
exports.supported = supported;
|
|
1061
1080
|
exports.wallets = wallets;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@depay/web3-wallets-evm",
|
|
3
3
|
"moduleName": "Web3Wallets",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "13.1.0",
|
|
5
5
|
"description": "One-Stop-Shop JavaScript library to integrate various web3 crypto wallets and multiple blockchains at once with a single interface.",
|
|
6
6
|
"main": "dist/umd/index.evm.js",
|
|
7
7
|
"module": "dist/esm/index.evm.js",
|