@depay/web3-wallets-evm 12.4.1 → 13.0.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/dist/esm/index.evm.js +49 -18
- package/dist/esm/index.js +26 -13
- package/dist/umd/index.evm.js +49 -18
- package/dist/umd/index.js +26 -13
- package/package.json +1 -1
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()]);
|
|
@@ -108,6 +108,9 @@ const sendTransaction$2 = async ({ transaction, wallet })=> {
|
|
|
108
108
|
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
109
109
|
await wallet.switchTo(transaction.blockchain);
|
|
110
110
|
}
|
|
111
|
+
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
112
|
+
throw({ code: 'WRONG_NETWORK' })
|
|
113
|
+
}
|
|
111
114
|
await transaction.prepare({ wallet });
|
|
112
115
|
let provider = new ethers.providers.Web3Provider(window.ethereum, 'any');
|
|
113
116
|
let signer = provider.getSigner(0);
|
|
@@ -210,13 +213,13 @@ class WindowEthereum {
|
|
|
210
213
|
|
|
211
214
|
async account() {
|
|
212
215
|
if(!_optionalChain$4([window, 'optionalAccess', _15 => _15.ethereum])) { return undefined }
|
|
213
|
-
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));
|
|
214
217
|
return accounts[0]
|
|
215
218
|
}
|
|
216
219
|
|
|
217
220
|
async connect() {
|
|
218
221
|
if(!_optionalChain$4([window, 'optionalAccess', _16 => _16.ethereum])) { return undefined }
|
|
219
|
-
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));
|
|
220
223
|
return accounts[0]
|
|
221
224
|
}
|
|
222
225
|
|
|
@@ -224,7 +227,7 @@ class WindowEthereum {
|
|
|
224
227
|
let internalCallback;
|
|
225
228
|
switch (event) {
|
|
226
229
|
case 'account':
|
|
227
|
-
internalCallback = (accounts) => callback(accounts[0]);
|
|
230
|
+
internalCallback = (accounts) => callback(ethers.utils.getAddress(accounts[0]));
|
|
228
231
|
window.ethereum.on('accountsChanged', internalCallback);
|
|
229
232
|
break
|
|
230
233
|
}
|
|
@@ -324,10 +327,13 @@ class MetaMask extends WindowEthereum {
|
|
|
324
327
|
function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
325
328
|
const sendTransaction$1 = async ({ transaction, wallet })=> {
|
|
326
329
|
transaction = new Transaction(transaction);
|
|
327
|
-
await transaction.
|
|
330
|
+
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
331
|
+
await wallet.switchTo(transaction.blockchain);
|
|
332
|
+
}
|
|
328
333
|
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
329
334
|
throw({ code: 'WRONG_NETWORK' })
|
|
330
335
|
}
|
|
336
|
+
await transaction.prepare({ wallet });
|
|
331
337
|
await submit$1({ transaction, wallet }).then(async (tx)=>{
|
|
332
338
|
if (tx) {
|
|
333
339
|
let blockchain = Blockchain.findByName(transaction.blockchain);
|
|
@@ -456,14 +462,14 @@ class WalletConnect {
|
|
|
456
462
|
instance.on("connect", (error, payload) => {
|
|
457
463
|
if (error) { throw error }
|
|
458
464
|
const { accounts, chainId } = payload.params[0];
|
|
459
|
-
this.connectedAccounts = accounts;
|
|
465
|
+
this.connectedAccounts = accounts.map((account)=>ethers.utils.getAddress(account));
|
|
460
466
|
this.connectedChainId = chainId;
|
|
461
467
|
});
|
|
462
468
|
|
|
463
469
|
instance.on("session_update", (error, payload) => {
|
|
464
470
|
if (error) { throw error }
|
|
465
471
|
const { accounts, chainId } = payload.params[0];
|
|
466
|
-
this.connectedAccounts = accounts;
|
|
472
|
+
this.connectedAccounts = accounts.map((account)=>ethers.utils.getAddress(account));
|
|
467
473
|
this.connectedChainId = chainId;
|
|
468
474
|
});
|
|
469
475
|
|
|
@@ -499,12 +505,13 @@ class WalletConnect {
|
|
|
499
505
|
this.connector = this.newWalletConnectInstance();
|
|
500
506
|
}
|
|
501
507
|
|
|
502
|
-
|
|
508
|
+
let { accounts, chainId } = await this.connector.connect({ chainId: _optionalChain([options, 'optionalAccess', _ => _.chainId]) });
|
|
503
509
|
|
|
504
510
|
if(accounts instanceof Array && accounts.length) {
|
|
505
511
|
setConnectedInstance$1(this);
|
|
506
512
|
}
|
|
507
513
|
|
|
514
|
+
accounts = accounts.map((account)=>ethers.utils.getAddress(account));
|
|
508
515
|
this.connectedAccounts = accounts;
|
|
509
516
|
this.connectedChainId = chainId;
|
|
510
517
|
|
|
@@ -527,17 +534,35 @@ class WalletConnect {
|
|
|
527
534
|
|
|
528
535
|
switchTo(blockchainName) {
|
|
529
536
|
return new Promise((resolve, reject)=>{
|
|
537
|
+
let resolved, rejected;
|
|
530
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);
|
|
531
546
|
this.connector.sendCustomRequest({
|
|
532
547
|
method: 'wallet_switchEthereumChain',
|
|
533
548
|
params: [{ chainId: blockchain.id }],
|
|
534
|
-
}).then(
|
|
535
|
-
|
|
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
|
|
536
554
|
this.addNetwork(blockchainName)
|
|
537
|
-
.then(()=>this.switchTo(blockchainName).then(
|
|
538
|
-
|
|
555
|
+
.then(()=>this.switchTo(blockchainName).then(()=>{
|
|
556
|
+
resolved = true;
|
|
557
|
+
resolve();
|
|
558
|
+
}))
|
|
559
|
+
.catch(()=>{
|
|
560
|
+
rejected = true;
|
|
561
|
+
reject({ code: 'NOT_SUPPORTED' });
|
|
562
|
+
});
|
|
539
563
|
} else {
|
|
540
|
-
|
|
564
|
+
rejected = true;
|
|
565
|
+
reject({ code: 'NOT_SUPPORTED' });
|
|
541
566
|
}
|
|
542
567
|
});
|
|
543
568
|
})
|
|
@@ -569,8 +594,10 @@ class WalletConnect {
|
|
|
569
594
|
switch (event) {
|
|
570
595
|
case 'account':
|
|
571
596
|
internalCallback = (error, payload) => {
|
|
572
|
-
|
|
573
|
-
|
|
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
|
+
}
|
|
574
601
|
};
|
|
575
602
|
this.connector.on("session_update", internalCallback);
|
|
576
603
|
break
|
|
@@ -602,6 +629,9 @@ const sendTransaction = async ({ transaction, wallet })=> {
|
|
|
602
629
|
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
603
630
|
await wallet.switchTo(transaction.blockchain);
|
|
604
631
|
}
|
|
632
|
+
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
633
|
+
throw({ code: 'WRONG_NETWORK' })
|
|
634
|
+
}
|
|
605
635
|
await transaction.prepare({ wallet });
|
|
606
636
|
let provider = new ethers.providers.Web3Provider(wallet.connector, 'any');
|
|
607
637
|
let signer = provider.getSigner(0);
|
|
@@ -707,7 +737,7 @@ class WalletLink {
|
|
|
707
737
|
|
|
708
738
|
async account() {
|
|
709
739
|
if(this.connectedAccounts == undefined) { return }
|
|
710
|
-
return this.connectedAccounts[0]
|
|
740
|
+
return ethers.utils.getAddress(this.connectedAccounts[0])
|
|
711
741
|
}
|
|
712
742
|
|
|
713
743
|
async connect(options) {
|
|
@@ -717,6 +747,7 @@ class WalletLink {
|
|
|
717
747
|
if(accounts instanceof Array && accounts.length) {
|
|
718
748
|
setConnectedInstance(this);
|
|
719
749
|
}
|
|
750
|
+
accounts = accounts.map((account)=>ethers.utils.getAddress(account));
|
|
720
751
|
this.connectedAccounts = accounts;
|
|
721
752
|
this.connectedChainId = await this.connector.getChainId();
|
|
722
753
|
return accounts[0]
|
|
@@ -775,7 +806,7 @@ class WalletLink {
|
|
|
775
806
|
let internalCallback;
|
|
776
807
|
switch (event) {
|
|
777
808
|
case 'account':
|
|
778
|
-
internalCallback = (accounts) => callback(accounts[0]);
|
|
809
|
+
internalCallback = (accounts) => callback(ethers.utils.getAddress(accounts[0]));
|
|
779
810
|
this.connector.on('accountsChanged', internalCallback);
|
|
780
811
|
break
|
|
781
812
|
}
|
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()]);
|
|
@@ -109,6 +109,9 @@ const sendTransaction$3 = async ({ transaction, wallet })=> {
|
|
|
109
109
|
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
110
110
|
await wallet.switchTo(transaction.blockchain);
|
|
111
111
|
}
|
|
112
|
+
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
113
|
+
throw({ code: 'WRONG_NETWORK' })
|
|
114
|
+
}
|
|
112
115
|
await transaction.prepare({ wallet });
|
|
113
116
|
let provider = new ethers.providers.Web3Provider(window.ethereum, 'any');
|
|
114
117
|
let signer = provider.getSigner(0);
|
|
@@ -211,13 +214,13 @@ class WindowEthereum {
|
|
|
211
214
|
|
|
212
215
|
async account() {
|
|
213
216
|
if(!_optionalChain$7([window, 'optionalAccess', _15 => _15.ethereum])) { return undefined }
|
|
214
|
-
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));
|
|
215
218
|
return accounts[0]
|
|
216
219
|
}
|
|
217
220
|
|
|
218
221
|
async connect() {
|
|
219
222
|
if(!_optionalChain$7([window, 'optionalAccess', _16 => _16.ethereum])) { return undefined }
|
|
220
|
-
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));
|
|
221
224
|
return accounts[0]
|
|
222
225
|
}
|
|
223
226
|
|
|
@@ -225,7 +228,7 @@ class WindowEthereum {
|
|
|
225
228
|
let internalCallback;
|
|
226
229
|
switch (event) {
|
|
227
230
|
case 'account':
|
|
228
|
-
internalCallback = (accounts) => callback(accounts[0]);
|
|
231
|
+
internalCallback = (accounts) => callback(ethers.utils.getAddress(accounts[0]));
|
|
229
232
|
window.ethereum.on('accountsChanged', internalCallback);
|
|
230
233
|
break
|
|
231
234
|
}
|
|
@@ -512,10 +515,13 @@ class Phantom extends WindowSolana {
|
|
|
512
515
|
function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
513
516
|
const sendTransaction$1 = async ({ transaction, wallet })=> {
|
|
514
517
|
transaction = new Transaction(transaction);
|
|
515
|
-
await transaction.
|
|
518
|
+
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
519
|
+
await wallet.switchTo(transaction.blockchain);
|
|
520
|
+
}
|
|
516
521
|
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
517
522
|
throw({ code: 'WRONG_NETWORK' })
|
|
518
523
|
}
|
|
524
|
+
await transaction.prepare({ wallet });
|
|
519
525
|
await submit$1({ transaction, wallet }).then(async (tx)=>{
|
|
520
526
|
if (tx) {
|
|
521
527
|
let blockchain = Blockchain.findByName(transaction.blockchain);
|
|
@@ -644,14 +650,14 @@ class WalletConnect {
|
|
|
644
650
|
instance.on("connect", (error, payload) => {
|
|
645
651
|
if (error) { throw error }
|
|
646
652
|
const { accounts, chainId } = payload.params[0];
|
|
647
|
-
this.connectedAccounts = accounts;
|
|
653
|
+
this.connectedAccounts = accounts.map((account)=>ethers.utils.getAddress(account));
|
|
648
654
|
this.connectedChainId = chainId;
|
|
649
655
|
});
|
|
650
656
|
|
|
651
657
|
instance.on("session_update", (error, payload) => {
|
|
652
658
|
if (error) { throw error }
|
|
653
659
|
const { accounts, chainId } = payload.params[0];
|
|
654
|
-
this.connectedAccounts = accounts;
|
|
660
|
+
this.connectedAccounts = accounts.map((account)=>ethers.utils.getAddress(account));
|
|
655
661
|
this.connectedChainId = chainId;
|
|
656
662
|
});
|
|
657
663
|
|
|
@@ -687,12 +693,13 @@ class WalletConnect {
|
|
|
687
693
|
this.connector = this.newWalletConnectInstance();
|
|
688
694
|
}
|
|
689
695
|
|
|
690
|
-
|
|
696
|
+
let { accounts, chainId } = await this.connector.connect({ chainId: _optionalChain([options, 'optionalAccess', _ => _.chainId]) });
|
|
691
697
|
|
|
692
698
|
if(accounts instanceof Array && accounts.length) {
|
|
693
699
|
setConnectedInstance$1(this);
|
|
694
700
|
}
|
|
695
701
|
|
|
702
|
+
accounts = accounts.map((account)=>ethers.utils.getAddress(account));
|
|
696
703
|
this.connectedAccounts = accounts;
|
|
697
704
|
this.connectedChainId = chainId;
|
|
698
705
|
|
|
@@ -775,8 +782,10 @@ class WalletConnect {
|
|
|
775
782
|
switch (event) {
|
|
776
783
|
case 'account':
|
|
777
784
|
internalCallback = (error, payload) => {
|
|
778
|
-
|
|
779
|
-
|
|
785
|
+
if(payload && payload.params && payload.params[0].accounts && payload.params[0].accounts instanceof Array) {
|
|
786
|
+
const accounts = payload.params[0].accounts.map((account)=>ethers.utils.getAddress(account));
|
|
787
|
+
callback(accounts[0]);
|
|
788
|
+
}
|
|
780
789
|
};
|
|
781
790
|
this.connector.on("session_update", internalCallback);
|
|
782
791
|
break
|
|
@@ -808,6 +817,9 @@ const sendTransaction = async ({ transaction, wallet })=> {
|
|
|
808
817
|
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
809
818
|
await wallet.switchTo(transaction.blockchain);
|
|
810
819
|
}
|
|
820
|
+
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
821
|
+
throw({ code: 'WRONG_NETWORK' })
|
|
822
|
+
}
|
|
811
823
|
await transaction.prepare({ wallet });
|
|
812
824
|
let provider = new ethers.providers.Web3Provider(wallet.connector, 'any');
|
|
813
825
|
let signer = provider.getSigner(0);
|
|
@@ -913,7 +925,7 @@ class WalletLink {
|
|
|
913
925
|
|
|
914
926
|
async account() {
|
|
915
927
|
if(this.connectedAccounts == undefined) { return }
|
|
916
|
-
return this.connectedAccounts[0]
|
|
928
|
+
return ethers.utils.getAddress(this.connectedAccounts[0])
|
|
917
929
|
}
|
|
918
930
|
|
|
919
931
|
async connect(options) {
|
|
@@ -923,6 +935,7 @@ class WalletLink {
|
|
|
923
935
|
if(accounts instanceof Array && accounts.length) {
|
|
924
936
|
setConnectedInstance(this);
|
|
925
937
|
}
|
|
938
|
+
accounts = accounts.map((account)=>ethers.utils.getAddress(account));
|
|
926
939
|
this.connectedAccounts = accounts;
|
|
927
940
|
this.connectedChainId = await this.connector.getChainId();
|
|
928
941
|
return accounts[0]
|
|
@@ -981,7 +994,7 @@ class WalletLink {
|
|
|
981
994
|
let internalCallback;
|
|
982
995
|
switch (event) {
|
|
983
996
|
case 'account':
|
|
984
|
-
internalCallback = (accounts) => callback(accounts[0]);
|
|
997
|
+
internalCallback = (accounts) => callback(ethers.utils.getAddress(accounts[0]));
|
|
985
998
|
this.connector.on('accountsChanged', internalCallback);
|
|
986
999
|
break
|
|
987
1000
|
}
|
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()]);
|
|
@@ -107,6 +107,9 @@
|
|
|
107
107
|
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
108
108
|
await wallet.switchTo(transaction.blockchain);
|
|
109
109
|
}
|
|
110
|
+
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
111
|
+
throw({ code: 'WRONG_NETWORK' })
|
|
112
|
+
}
|
|
110
113
|
await transaction.prepare({ wallet });
|
|
111
114
|
let provider = new ethers.ethers.providers.Web3Provider(window.ethereum, 'any');
|
|
112
115
|
let signer = provider.getSigner(0);
|
|
@@ -209,13 +212,13 @@
|
|
|
209
212
|
|
|
210
213
|
async account() {
|
|
211
214
|
if(!_optionalChain$4([window, 'optionalAccess', _15 => _15.ethereum])) { return undefined }
|
|
212
|
-
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));
|
|
213
216
|
return accounts[0]
|
|
214
217
|
}
|
|
215
218
|
|
|
216
219
|
async connect() {
|
|
217
220
|
if(!_optionalChain$4([window, 'optionalAccess', _16 => _16.ethereum])) { return undefined }
|
|
218
|
-
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));
|
|
219
222
|
return accounts[0]
|
|
220
223
|
}
|
|
221
224
|
|
|
@@ -223,7 +226,7 @@
|
|
|
223
226
|
let internalCallback;
|
|
224
227
|
switch (event) {
|
|
225
228
|
case 'account':
|
|
226
|
-
internalCallback = (accounts) => callback(accounts[0]);
|
|
229
|
+
internalCallback = (accounts) => callback(ethers.ethers.utils.getAddress(accounts[0]));
|
|
227
230
|
window.ethereum.on('accountsChanged', internalCallback);
|
|
228
231
|
break
|
|
229
232
|
}
|
|
@@ -323,10 +326,13 @@
|
|
|
323
326
|
function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
324
327
|
const sendTransaction$1 = async ({ transaction, wallet })=> {
|
|
325
328
|
transaction = new Transaction(transaction);
|
|
326
|
-
await transaction.
|
|
329
|
+
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
330
|
+
await wallet.switchTo(transaction.blockchain);
|
|
331
|
+
}
|
|
327
332
|
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
328
333
|
throw({ code: 'WRONG_NETWORK' })
|
|
329
334
|
}
|
|
335
|
+
await transaction.prepare({ wallet });
|
|
330
336
|
await submit$1({ transaction, wallet }).then(async (tx)=>{
|
|
331
337
|
if (tx) {
|
|
332
338
|
let blockchain = web3Blockchains.Blockchain.findByName(transaction.blockchain);
|
|
@@ -455,14 +461,14 @@
|
|
|
455
461
|
instance.on("connect", (error, payload) => {
|
|
456
462
|
if (error) { throw error }
|
|
457
463
|
const { accounts, chainId } = payload.params[0];
|
|
458
|
-
this.connectedAccounts = accounts;
|
|
464
|
+
this.connectedAccounts = accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
459
465
|
this.connectedChainId = chainId;
|
|
460
466
|
});
|
|
461
467
|
|
|
462
468
|
instance.on("session_update", (error, payload) => {
|
|
463
469
|
if (error) { throw error }
|
|
464
470
|
const { accounts, chainId } = payload.params[0];
|
|
465
|
-
this.connectedAccounts = accounts;
|
|
471
|
+
this.connectedAccounts = accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
466
472
|
this.connectedChainId = chainId;
|
|
467
473
|
});
|
|
468
474
|
|
|
@@ -498,12 +504,13 @@
|
|
|
498
504
|
this.connector = this.newWalletConnectInstance();
|
|
499
505
|
}
|
|
500
506
|
|
|
501
|
-
|
|
507
|
+
let { accounts, chainId } = await this.connector.connect({ chainId: _optionalChain([options, 'optionalAccess', _ => _.chainId]) });
|
|
502
508
|
|
|
503
509
|
if(accounts instanceof Array && accounts.length) {
|
|
504
510
|
setConnectedInstance$1(this);
|
|
505
511
|
}
|
|
506
512
|
|
|
513
|
+
accounts = accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
507
514
|
this.connectedAccounts = accounts;
|
|
508
515
|
this.connectedChainId = chainId;
|
|
509
516
|
|
|
@@ -526,17 +533,35 @@
|
|
|
526
533
|
|
|
527
534
|
switchTo(blockchainName) {
|
|
528
535
|
return new Promise((resolve, reject)=>{
|
|
536
|
+
let resolved, rejected;
|
|
529
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);
|
|
530
545
|
this.connector.sendCustomRequest({
|
|
531
546
|
method: 'wallet_switchEthereumChain',
|
|
532
547
|
params: [{ chainId: blockchain.id }],
|
|
533
|
-
}).then(
|
|
534
|
-
|
|
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
|
|
535
553
|
this.addNetwork(blockchainName)
|
|
536
|
-
.then(()=>this.switchTo(blockchainName).then(
|
|
537
|
-
|
|
554
|
+
.then(()=>this.switchTo(blockchainName).then(()=>{
|
|
555
|
+
resolved = true;
|
|
556
|
+
resolve();
|
|
557
|
+
}))
|
|
558
|
+
.catch(()=>{
|
|
559
|
+
rejected = true;
|
|
560
|
+
reject({ code: 'NOT_SUPPORTED' });
|
|
561
|
+
});
|
|
538
562
|
} else {
|
|
539
|
-
|
|
563
|
+
rejected = true;
|
|
564
|
+
reject({ code: 'NOT_SUPPORTED' });
|
|
540
565
|
}
|
|
541
566
|
});
|
|
542
567
|
})
|
|
@@ -568,8 +593,10 @@
|
|
|
568
593
|
switch (event) {
|
|
569
594
|
case 'account':
|
|
570
595
|
internalCallback = (error, payload) => {
|
|
571
|
-
|
|
572
|
-
|
|
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
|
+
}
|
|
573
600
|
};
|
|
574
601
|
this.connector.on("session_update", internalCallback);
|
|
575
602
|
break
|
|
@@ -601,6 +628,9 @@
|
|
|
601
628
|
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
602
629
|
await wallet.switchTo(transaction.blockchain);
|
|
603
630
|
}
|
|
631
|
+
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
632
|
+
throw({ code: 'WRONG_NETWORK' })
|
|
633
|
+
}
|
|
604
634
|
await transaction.prepare({ wallet });
|
|
605
635
|
let provider = new ethers.ethers.providers.Web3Provider(wallet.connector, 'any');
|
|
606
636
|
let signer = provider.getSigner(0);
|
|
@@ -706,7 +736,7 @@
|
|
|
706
736
|
|
|
707
737
|
async account() {
|
|
708
738
|
if(this.connectedAccounts == undefined) { return }
|
|
709
|
-
return this.connectedAccounts[0]
|
|
739
|
+
return ethers.ethers.utils.getAddress(this.connectedAccounts[0])
|
|
710
740
|
}
|
|
711
741
|
|
|
712
742
|
async connect(options) {
|
|
@@ -716,6 +746,7 @@
|
|
|
716
746
|
if(accounts instanceof Array && accounts.length) {
|
|
717
747
|
setConnectedInstance(this);
|
|
718
748
|
}
|
|
749
|
+
accounts = accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
719
750
|
this.connectedAccounts = accounts;
|
|
720
751
|
this.connectedChainId = await this.connector.getChainId();
|
|
721
752
|
return accounts[0]
|
|
@@ -774,7 +805,7 @@
|
|
|
774
805
|
let internalCallback;
|
|
775
806
|
switch (event) {
|
|
776
807
|
case 'account':
|
|
777
|
-
internalCallback = (accounts) => callback(accounts[0]);
|
|
808
|
+
internalCallback = (accounts) => callback(ethers.ethers.utils.getAddress(accounts[0]));
|
|
778
809
|
this.connector.on('accountsChanged', internalCallback);
|
|
779
810
|
break
|
|
780
811
|
}
|
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()]);
|
|
@@ -107,6 +107,9 @@
|
|
|
107
107
|
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
108
108
|
await wallet.switchTo(transaction.blockchain);
|
|
109
109
|
}
|
|
110
|
+
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
111
|
+
throw({ code: 'WRONG_NETWORK' })
|
|
112
|
+
}
|
|
110
113
|
await transaction.prepare({ wallet });
|
|
111
114
|
let provider = new ethers.ethers.providers.Web3Provider(window.ethereum, 'any');
|
|
112
115
|
let signer = provider.getSigner(0);
|
|
@@ -209,13 +212,13 @@
|
|
|
209
212
|
|
|
210
213
|
async account() {
|
|
211
214
|
if(!_optionalChain$7([window, 'optionalAccess', _15 => _15.ethereum])) { return undefined }
|
|
212
|
-
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));
|
|
213
216
|
return accounts[0]
|
|
214
217
|
}
|
|
215
218
|
|
|
216
219
|
async connect() {
|
|
217
220
|
if(!_optionalChain$7([window, 'optionalAccess', _16 => _16.ethereum])) { return undefined }
|
|
218
|
-
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));
|
|
219
222
|
return accounts[0]
|
|
220
223
|
}
|
|
221
224
|
|
|
@@ -223,7 +226,7 @@
|
|
|
223
226
|
let internalCallback;
|
|
224
227
|
switch (event) {
|
|
225
228
|
case 'account':
|
|
226
|
-
internalCallback = (accounts) => callback(accounts[0]);
|
|
229
|
+
internalCallback = (accounts) => callback(ethers.ethers.utils.getAddress(accounts[0]));
|
|
227
230
|
window.ethereum.on('accountsChanged', internalCallback);
|
|
228
231
|
break
|
|
229
232
|
}
|
|
@@ -510,10 +513,13 @@
|
|
|
510
513
|
function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
511
514
|
const sendTransaction$1 = async ({ transaction, wallet })=> {
|
|
512
515
|
transaction = new Transaction(transaction);
|
|
513
|
-
await transaction.
|
|
516
|
+
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
517
|
+
await wallet.switchTo(transaction.blockchain);
|
|
518
|
+
}
|
|
514
519
|
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
515
520
|
throw({ code: 'WRONG_NETWORK' })
|
|
516
521
|
}
|
|
522
|
+
await transaction.prepare({ wallet });
|
|
517
523
|
await submit$1({ transaction, wallet }).then(async (tx)=>{
|
|
518
524
|
if (tx) {
|
|
519
525
|
let blockchain = web3Blockchains.Blockchain.findByName(transaction.blockchain);
|
|
@@ -642,14 +648,14 @@
|
|
|
642
648
|
instance.on("connect", (error, payload) => {
|
|
643
649
|
if (error) { throw error }
|
|
644
650
|
const { accounts, chainId } = payload.params[0];
|
|
645
|
-
this.connectedAccounts = accounts;
|
|
651
|
+
this.connectedAccounts = accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
646
652
|
this.connectedChainId = chainId;
|
|
647
653
|
});
|
|
648
654
|
|
|
649
655
|
instance.on("session_update", (error, payload) => {
|
|
650
656
|
if (error) { throw error }
|
|
651
657
|
const { accounts, chainId } = payload.params[0];
|
|
652
|
-
this.connectedAccounts = accounts;
|
|
658
|
+
this.connectedAccounts = accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
653
659
|
this.connectedChainId = chainId;
|
|
654
660
|
});
|
|
655
661
|
|
|
@@ -685,12 +691,13 @@
|
|
|
685
691
|
this.connector = this.newWalletConnectInstance();
|
|
686
692
|
}
|
|
687
693
|
|
|
688
|
-
|
|
694
|
+
let { accounts, chainId } = await this.connector.connect({ chainId: _optionalChain([options, 'optionalAccess', _ => _.chainId]) });
|
|
689
695
|
|
|
690
696
|
if(accounts instanceof Array && accounts.length) {
|
|
691
697
|
setConnectedInstance$1(this);
|
|
692
698
|
}
|
|
693
699
|
|
|
700
|
+
accounts = accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
694
701
|
this.connectedAccounts = accounts;
|
|
695
702
|
this.connectedChainId = chainId;
|
|
696
703
|
|
|
@@ -773,8 +780,10 @@
|
|
|
773
780
|
switch (event) {
|
|
774
781
|
case 'account':
|
|
775
782
|
internalCallback = (error, payload) => {
|
|
776
|
-
|
|
777
|
-
|
|
783
|
+
if(payload && payload.params && payload.params[0].accounts && payload.params[0].accounts instanceof Array) {
|
|
784
|
+
const accounts = payload.params[0].accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
785
|
+
callback(accounts[0]);
|
|
786
|
+
}
|
|
778
787
|
};
|
|
779
788
|
this.connector.on("session_update", internalCallback);
|
|
780
789
|
break
|
|
@@ -806,6 +815,9 @@
|
|
|
806
815
|
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
807
816
|
await wallet.switchTo(transaction.blockchain);
|
|
808
817
|
}
|
|
818
|
+
if((await wallet.connectedTo(transaction.blockchain)) == false) {
|
|
819
|
+
throw({ code: 'WRONG_NETWORK' })
|
|
820
|
+
}
|
|
809
821
|
await transaction.prepare({ wallet });
|
|
810
822
|
let provider = new ethers.ethers.providers.Web3Provider(wallet.connector, 'any');
|
|
811
823
|
let signer = provider.getSigner(0);
|
|
@@ -911,7 +923,7 @@
|
|
|
911
923
|
|
|
912
924
|
async account() {
|
|
913
925
|
if(this.connectedAccounts == undefined) { return }
|
|
914
|
-
return this.connectedAccounts[0]
|
|
926
|
+
return ethers.ethers.utils.getAddress(this.connectedAccounts[0])
|
|
915
927
|
}
|
|
916
928
|
|
|
917
929
|
async connect(options) {
|
|
@@ -921,6 +933,7 @@
|
|
|
921
933
|
if(accounts instanceof Array && accounts.length) {
|
|
922
934
|
setConnectedInstance(this);
|
|
923
935
|
}
|
|
936
|
+
accounts = accounts.map((account)=>ethers.ethers.utils.getAddress(account));
|
|
924
937
|
this.connectedAccounts = accounts;
|
|
925
938
|
this.connectedChainId = await this.connector.getChainId();
|
|
926
939
|
return accounts[0]
|
|
@@ -979,7 +992,7 @@
|
|
|
979
992
|
let internalCallback;
|
|
980
993
|
switch (event) {
|
|
981
994
|
case 'account':
|
|
982
|
-
internalCallback = (accounts) => callback(accounts[0]);
|
|
995
|
+
internalCallback = (accounts) => callback(ethers.ethers.utils.getAddress(accounts[0]));
|
|
983
996
|
this.connector.on('accountsChanged', internalCallback);
|
|
984
997
|
break
|
|
985
998
|
}
|
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.0.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",
|