@depay/web3-wallets-evm 12.3.11 → 12.4.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.
@@ -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,40 @@ class WalletConnect {
715
715
 
716
716
  switchTo(blockchainName) {
717
717
  return new Promise((resolve, reject)=>{
718
- reject({ code: 'NOT_SUPPORTED' });
718
+ const blockchain = Blockchain.findByName(blockchainName);
719
+ this.connector.sendCustomRequest({
720
+ method: 'wallet_switchEthereumChain',
721
+ params: [{ chainId: blockchain.id }],
722
+ }).then(resolve).catch((error)=> {
723
+ if(error && typeof error.message == 'string' && error.message.match('wallet_addEthereumChain')){ // chain not yet added
724
+ this.addNetwork(blockchainName)
725
+ .then(()=>this.switchTo(blockchainName).then(resolve))
726
+ .catch(reject);
727
+ } else {
728
+ reject(error);
729
+ }
730
+ });
719
731
  })
720
732
  }
721
733
 
722
734
  addNetwork(blockchainName) {
723
735
  return new Promise((resolve, reject)=>{
724
- reject({ code: 'NOT_SUPPORTED' });
736
+ const blockchain = Blockchain.findByName(blockchainName);
737
+ this.connector.sendCustomRequest({
738
+ method: 'wallet_addEthereumChain',
739
+ params: [{
740
+ chainId: blockchain.id,
741
+ chainName: blockchain.fullName,
742
+ nativeCurrency: {
743
+ name: blockchain.currency.name,
744
+ symbol: blockchain.currency.symbol,
745
+ decimals: blockchain.currency.decimals
746
+ },
747
+ rpcUrls: [blockchain.rpc],
748
+ blockExplorerUrls: [blockchain.explorer],
749
+ iconUrls: [blockchain.logo]
750
+ }],
751
+ }).then(resolve).catch(reject);
725
752
  })
726
753
  }
727
754
 
@@ -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,40 @@
713
713
 
714
714
  switchTo(blockchainName) {
715
715
  return new Promise((resolve, reject)=>{
716
- reject({ code: 'NOT_SUPPORTED' });
716
+ const blockchain = web3Blockchains.Blockchain.findByName(blockchainName);
717
+ this.connector.sendCustomRequest({
718
+ method: 'wallet_switchEthereumChain',
719
+ params: [{ chainId: blockchain.id }],
720
+ }).then(resolve).catch((error)=> {
721
+ if(error && typeof error.message == 'string' && error.message.match('wallet_addEthereumChain')){ // chain not yet added
722
+ this.addNetwork(blockchainName)
723
+ .then(()=>this.switchTo(blockchainName).then(resolve))
724
+ .catch(reject);
725
+ } else {
726
+ reject(error);
727
+ }
728
+ });
717
729
  })
718
730
  }
719
731
 
720
732
  addNetwork(blockchainName) {
721
733
  return new Promise((resolve, reject)=>{
722
- reject({ code: 'NOT_SUPPORTED' });
734
+ const blockchain = web3Blockchains.Blockchain.findByName(blockchainName);
735
+ this.connector.sendCustomRequest({
736
+ method: 'wallet_addEthereumChain',
737
+ params: [{
738
+ chainId: blockchain.id,
739
+ chainName: blockchain.fullName,
740
+ nativeCurrency: {
741
+ name: blockchain.currency.name,
742
+ symbol: blockchain.currency.symbol,
743
+ decimals: blockchain.currency.decimals
744
+ },
745
+ rpcUrls: [blockchain.rpc],
746
+ blockExplorerUrls: [blockchain.explorer],
747
+ iconUrls: [blockchain.logo]
748
+ }],
749
+ }).then(resolve).catch(reject);
723
750
  })
724
751
  }
725
752
 
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.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",