@depay/web3-wallets-evm 12.3.11 → 12.4.1

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.
@@ -527,13 +527,40 @@ class WalletConnect {
527
527
 
528
528
  switchTo(blockchainName) {
529
529
  return new Promise((resolve, reject)=>{
530
- reject({ code: 'NOT_SUPPORTED' });
530
+ const blockchain = Blockchain.findByName(blockchainName);
531
+ this.connector.sendCustomRequest({
532
+ method: 'wallet_switchEthereumChain',
533
+ params: [{ chainId: blockchain.id }],
534
+ }).then(resolve).catch((error)=> {
535
+ if(error && typeof error.message == 'string' && error.message.match('wallet_addEthereumChain')){ // chain not yet added
536
+ this.addNetwork(blockchainName)
537
+ .then(()=>this.switchTo(blockchainName).then(resolve))
538
+ .catch(reject);
539
+ } else {
540
+ reject(error);
541
+ }
542
+ });
531
543
  })
532
544
  }
533
545
 
534
546
  addNetwork(blockchainName) {
535
547
  return new Promise((resolve, reject)=>{
536
- reject({ code: 'NOT_SUPPORTED' });
548
+ const blockchain = Blockchain.findByName(blockchainName);
549
+ this.connector.sendCustomRequest({
550
+ method: 'wallet_addEthereumChain',
551
+ params: [{
552
+ chainId: blockchain.id,
553
+ chainName: blockchain.fullName,
554
+ nativeCurrency: {
555
+ name: blockchain.currency.name,
556
+ symbol: blockchain.currency.symbol,
557
+ decimals: blockchain.currency.decimals
558
+ },
559
+ rpcUrls: [blockchain.rpc],
560
+ blockExplorerUrls: [blockchain.explorer],
561
+ iconUrls: [blockchain.logo]
562
+ }],
563
+ }).then(resolve).catch(reject);
537
564
  })
538
565
  }
539
566
 
package/dist/esm/index.js CHANGED
@@ -715,13 +715,58 @@ class WalletConnect {
715
715
 
716
716
  switchTo(blockchainName) {
717
717
  return new Promise((resolve, reject)=>{
718
- reject({ code: 'NOT_SUPPORTED' });
718
+ let resolved, rejected;
719
+ const blockchain = Blockchain.findByName(blockchainName);
720
+ setTimeout(async()=>{
721
+ if(!(await this.connectedTo(blockchainName)) && !resolved && !rejected){
722
+ reject({ code: 'NOT_SUPPORTED' });
723
+ } else {
724
+ resolve();
725
+ }
726
+ }, 3000);
727
+ this.connector.sendCustomRequest({
728
+ method: 'wallet_switchEthereumChain',
729
+ params: [{ chainId: blockchain.id }],
730
+ }).then(()=>{
731
+ resolved = true;
732
+ resolve();
733
+ }).catch((error)=> {
734
+ if(error && typeof error.message == 'string' && error.message.match('addEthereumChain')){ // chain not yet added
735
+ this.addNetwork(blockchainName)
736
+ .then(()=>this.switchTo(blockchainName).then(()=>{
737
+ resolved = true;
738
+ resolve();
739
+ }))
740
+ .catch(()=>{
741
+ rejected = true;
742
+ reject({ code: 'NOT_SUPPORTED' });
743
+ });
744
+ } else {
745
+ rejected = true;
746
+ reject({ code: 'NOT_SUPPORTED' });
747
+ }
748
+ });
719
749
  })
720
750
  }
721
751
 
722
752
  addNetwork(blockchainName) {
723
753
  return new Promise((resolve, reject)=>{
724
- reject({ code: 'NOT_SUPPORTED' });
754
+ const blockchain = Blockchain.findByName(blockchainName);
755
+ this.connector.sendCustomRequest({
756
+ method: 'wallet_addEthereumChain',
757
+ params: [{
758
+ chainId: blockchain.id,
759
+ chainName: blockchain.fullName,
760
+ nativeCurrency: {
761
+ name: blockchain.currency.name,
762
+ symbol: blockchain.currency.symbol,
763
+ decimals: blockchain.currency.decimals
764
+ },
765
+ rpcUrls: [blockchain.rpc],
766
+ blockExplorerUrls: [blockchain.explorer],
767
+ iconUrls: [blockchain.logo]
768
+ }],
769
+ }).then(resolve).catch(reject);
725
770
  })
726
771
  }
727
772
 
@@ -526,13 +526,40 @@
526
526
 
527
527
  switchTo(blockchainName) {
528
528
  return new Promise((resolve, reject)=>{
529
- reject({ code: 'NOT_SUPPORTED' });
529
+ const blockchain = web3Blockchains.Blockchain.findByName(blockchainName);
530
+ this.connector.sendCustomRequest({
531
+ method: 'wallet_switchEthereumChain',
532
+ params: [{ chainId: blockchain.id }],
533
+ }).then(resolve).catch((error)=> {
534
+ if(error && typeof error.message == 'string' && error.message.match('wallet_addEthereumChain')){ // chain not yet added
535
+ this.addNetwork(blockchainName)
536
+ .then(()=>this.switchTo(blockchainName).then(resolve))
537
+ .catch(reject);
538
+ } else {
539
+ reject(error);
540
+ }
541
+ });
530
542
  })
531
543
  }
532
544
 
533
545
  addNetwork(blockchainName) {
534
546
  return new Promise((resolve, reject)=>{
535
- reject({ code: 'NOT_SUPPORTED' });
547
+ const blockchain = web3Blockchains.Blockchain.findByName(blockchainName);
548
+ this.connector.sendCustomRequest({
549
+ method: 'wallet_addEthereumChain',
550
+ params: [{
551
+ chainId: blockchain.id,
552
+ chainName: blockchain.fullName,
553
+ nativeCurrency: {
554
+ name: blockchain.currency.name,
555
+ symbol: blockchain.currency.symbol,
556
+ decimals: blockchain.currency.decimals
557
+ },
558
+ rpcUrls: [blockchain.rpc],
559
+ blockExplorerUrls: [blockchain.explorer],
560
+ iconUrls: [blockchain.logo]
561
+ }],
562
+ }).then(resolve).catch(reject);
536
563
  })
537
564
  }
538
565
 
package/dist/umd/index.js CHANGED
@@ -713,13 +713,58 @@
713
713
 
714
714
  switchTo(blockchainName) {
715
715
  return new Promise((resolve, reject)=>{
716
- reject({ code: 'NOT_SUPPORTED' });
716
+ let resolved, rejected;
717
+ const blockchain = web3Blockchains.Blockchain.findByName(blockchainName);
718
+ setTimeout(async()=>{
719
+ if(!(await this.connectedTo(blockchainName)) && !resolved && !rejected){
720
+ reject({ code: 'NOT_SUPPORTED' });
721
+ } else {
722
+ resolve();
723
+ }
724
+ }, 3000);
725
+ this.connector.sendCustomRequest({
726
+ method: 'wallet_switchEthereumChain',
727
+ params: [{ chainId: blockchain.id }],
728
+ }).then(()=>{
729
+ resolved = true;
730
+ resolve();
731
+ }).catch((error)=> {
732
+ if(error && typeof error.message == 'string' && error.message.match('addEthereumChain')){ // chain not yet added
733
+ this.addNetwork(blockchainName)
734
+ .then(()=>this.switchTo(blockchainName).then(()=>{
735
+ resolved = true;
736
+ resolve();
737
+ }))
738
+ .catch(()=>{
739
+ rejected = true;
740
+ reject({ code: 'NOT_SUPPORTED' });
741
+ });
742
+ } else {
743
+ rejected = true;
744
+ reject({ code: 'NOT_SUPPORTED' });
745
+ }
746
+ });
717
747
  })
718
748
  }
719
749
 
720
750
  addNetwork(blockchainName) {
721
751
  return new Promise((resolve, reject)=>{
722
- reject({ code: 'NOT_SUPPORTED' });
752
+ const blockchain = web3Blockchains.Blockchain.findByName(blockchainName);
753
+ this.connector.sendCustomRequest({
754
+ method: 'wallet_addEthereumChain',
755
+ params: [{
756
+ chainId: blockchain.id,
757
+ chainName: blockchain.fullName,
758
+ nativeCurrency: {
759
+ name: blockchain.currency.name,
760
+ symbol: blockchain.currency.symbol,
761
+ decimals: blockchain.currency.decimals
762
+ },
763
+ rpcUrls: [blockchain.rpc],
764
+ blockExplorerUrls: [blockchain.explorer],
765
+ iconUrls: [blockchain.logo]
766
+ }],
767
+ }).then(resolve).catch(reject);
723
768
  })
724
769
  }
725
770
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@depay/web3-wallets-evm",
3
3
  "moduleName": "Web3Wallets",
4
- "version": "12.3.11",
4
+ "version": "12.4.1",
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",
@@ -27,7 +27,7 @@
27
27
  "peerDependencies": {
28
28
  "@depay/coinbase-wallet-sdk": "^1.1.0",
29
29
  "@depay/walletconnect-v1": "^1.7.10",
30
- "@depay/web3-blockchains": "^6.2.3",
30
+ "@depay/web3-blockchains": "^6.3.1",
31
31
  "@depay/web3-client-evm": "^10.2.1",
32
32
  "@depay/web3-constants": "^6.3.2",
33
33
  "ethers": "^5.7.1"