@depay/web3-wallets-evm 12.3.10 → 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.
@@ -55,8 +55,6 @@ class Transaction {
55
55
  return fragment.inputs.map((input) => {
56
56
  return this.params[input.name]
57
57
  })
58
- } else {
59
- throw 'Contract params have wrong type!'
60
58
  }
61
59
  }
62
60
 
@@ -65,9 +63,16 @@ class Transaction {
65
63
  }
66
64
 
67
65
  async getData() {
68
- let populatedTransaction = await this.getContract().populateTransaction[this.method].apply(
69
- null, this.getContractArguments()
70
- );
66
+ let contractArguments = this.getContractArguments();
67
+ let populatedTransaction;
68
+ if(contractArguments) {
69
+ populatedTransaction = await this.getContract().populateTransaction[this.method].apply(
70
+ null, contractArguments
71
+ );
72
+ } else {
73
+ populatedTransaction = await this.getContract().populateTransaction[this.method].apply(null);
74
+ }
75
+
71
76
  return populatedTransaction.data
72
77
  }
73
78
 
@@ -150,11 +155,17 @@ const submit$2 = ({ transaction, provider, signer }) => {
150
155
 
151
156
  const submitContractInteraction$2 = ({ transaction, signer, provider })=>{
152
157
  let contract = new ethers.Contract(transaction.to, transaction.api, provider);
153
- return contract
154
- .connect(signer)
155
- [transaction.method](...transaction.getContractArguments({ contract }), {
158
+ let contractArguments = transaction.getContractArguments({ contract });
159
+ let method = contract.connect(signer)[transaction.method];
160
+ if(contractArguments) {
161
+ return method(...contractArguments, {
162
+ value: Transaction.bigNumberify(transaction.value, transaction.blockchain)
163
+ })
164
+ } else {
165
+ return method({
156
166
  value: Transaction.bigNumberify(transaction.value, transaction.blockchain)
157
167
  })
168
+ }
158
169
  };
159
170
 
160
171
  const submitSimpleTransfer$2 = ({ transaction, signer })=>{
@@ -516,13 +527,40 @@ class WalletConnect {
516
527
 
517
528
  switchTo(blockchainName) {
518
529
  return new Promise((resolve, reject)=>{
519
- 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
+ });
520
543
  })
521
544
  }
522
545
 
523
546
  addNetwork(blockchainName) {
524
547
  return new Promise((resolve, reject)=>{
525
- 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);
526
564
  })
527
565
  }
528
566
 
@@ -611,11 +649,17 @@ const submit = ({ transaction, provider, signer }) => {
611
649
 
612
650
  const submitContractInteraction = ({ transaction, signer, provider })=>{
613
651
  let contract = new ethers.Contract(transaction.to, transaction.api, provider);
614
- return contract
615
- .connect(signer)
616
- [transaction.method](...transaction.getContractArguments({ contract }), {
652
+ let contractArguments = transaction.getContractArguments({ contract });
653
+ let method = contract.connect(signer)[transaction.method];
654
+ if(contractArguments) {
655
+ return method(...contractArguments, {
617
656
  value: Transaction.bigNumberify(transaction.value, transaction.blockchain)
618
657
  })
658
+ } else {
659
+ return method({
660
+ value: Transaction.bigNumberify(transaction.value, transaction.blockchain)
661
+ })
662
+ }
619
663
  };
620
664
 
621
665
  const submitSimpleTransfer = ({ transaction, signer })=>{
package/dist/esm/index.js CHANGED
@@ -56,8 +56,6 @@ class Transaction {
56
56
  return fragment.inputs.map((input) => {
57
57
  return this.params[input.name]
58
58
  })
59
- } else {
60
- throw 'Contract params have wrong type!'
61
59
  }
62
60
  }
63
61
 
@@ -66,9 +64,16 @@ class Transaction {
66
64
  }
67
65
 
68
66
  async getData() {
69
- let populatedTransaction = await this.getContract().populateTransaction[this.method].apply(
70
- null, this.getContractArguments()
71
- );
67
+ let contractArguments = this.getContractArguments();
68
+ let populatedTransaction;
69
+ if(contractArguments) {
70
+ populatedTransaction = await this.getContract().populateTransaction[this.method].apply(
71
+ null, contractArguments
72
+ );
73
+ } else {
74
+ populatedTransaction = await this.getContract().populateTransaction[this.method].apply(null);
75
+ }
76
+
72
77
  return populatedTransaction.data
73
78
  }
74
79
 
@@ -151,11 +156,17 @@ const submit$3 = ({ transaction, provider, signer }) => {
151
156
 
152
157
  const submitContractInteraction$2 = ({ transaction, signer, provider })=>{
153
158
  let contract = new ethers.Contract(transaction.to, transaction.api, provider);
154
- return contract
155
- .connect(signer)
156
- [transaction.method](...transaction.getContractArguments({ contract }), {
159
+ let contractArguments = transaction.getContractArguments({ contract });
160
+ let method = contract.connect(signer)[transaction.method];
161
+ if(contractArguments) {
162
+ return method(...contractArguments, {
163
+ value: Transaction.bigNumberify(transaction.value, transaction.blockchain)
164
+ })
165
+ } else {
166
+ return method({
157
167
  value: Transaction.bigNumberify(transaction.value, transaction.blockchain)
158
168
  })
169
+ }
159
170
  };
160
171
 
161
172
  const submitSimpleTransfer$3 = ({ transaction, signer })=>{
@@ -704,13 +715,40 @@ class WalletConnect {
704
715
 
705
716
  switchTo(blockchainName) {
706
717
  return new Promise((resolve, reject)=>{
707
- 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
+ });
708
731
  })
709
732
  }
710
733
 
711
734
  addNetwork(blockchainName) {
712
735
  return new Promise((resolve, reject)=>{
713
- 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);
714
752
  })
715
753
  }
716
754
 
@@ -799,11 +837,17 @@ const submit = ({ transaction, provider, signer }) => {
799
837
 
800
838
  const submitContractInteraction = ({ transaction, signer, provider })=>{
801
839
  let contract = new ethers.Contract(transaction.to, transaction.api, provider);
802
- return contract
803
- .connect(signer)
804
- [transaction.method](...transaction.getContractArguments({ contract }), {
840
+ let contractArguments = transaction.getContractArguments({ contract });
841
+ let method = contract.connect(signer)[transaction.method];
842
+ if(contractArguments) {
843
+ return method(...contractArguments, {
805
844
  value: Transaction.bigNumberify(transaction.value, transaction.blockchain)
806
845
  })
846
+ } else {
847
+ return method({
848
+ value: Transaction.bigNumberify(transaction.value, transaction.blockchain)
849
+ })
850
+ }
807
851
  };
808
852
 
809
853
  const submitSimpleTransfer = ({ transaction, signer })=>{
@@ -54,8 +54,6 @@
54
54
  return fragment.inputs.map((input) => {
55
55
  return this.params[input.name]
56
56
  })
57
- } else {
58
- throw 'Contract params have wrong type!'
59
57
  }
60
58
  }
61
59
 
@@ -64,9 +62,16 @@
64
62
  }
65
63
 
66
64
  async getData() {
67
- let populatedTransaction = await this.getContract().populateTransaction[this.method].apply(
68
- null, this.getContractArguments()
69
- );
65
+ let contractArguments = this.getContractArguments();
66
+ let populatedTransaction;
67
+ if(contractArguments) {
68
+ populatedTransaction = await this.getContract().populateTransaction[this.method].apply(
69
+ null, contractArguments
70
+ );
71
+ } else {
72
+ populatedTransaction = await this.getContract().populateTransaction[this.method].apply(null);
73
+ }
74
+
70
75
  return populatedTransaction.data
71
76
  }
72
77
 
@@ -149,11 +154,17 @@
149
154
 
150
155
  const submitContractInteraction$2 = ({ transaction, signer, provider })=>{
151
156
  let contract = new ethers.ethers.Contract(transaction.to, transaction.api, provider);
152
- return contract
153
- .connect(signer)
154
- [transaction.method](...transaction.getContractArguments({ contract }), {
157
+ let contractArguments = transaction.getContractArguments({ contract });
158
+ let method = contract.connect(signer)[transaction.method];
159
+ if(contractArguments) {
160
+ return method(...contractArguments, {
161
+ value: Transaction.bigNumberify(transaction.value, transaction.blockchain)
162
+ })
163
+ } else {
164
+ return method({
155
165
  value: Transaction.bigNumberify(transaction.value, transaction.blockchain)
156
166
  })
167
+ }
157
168
  };
158
169
 
159
170
  const submitSimpleTransfer$2 = ({ transaction, signer })=>{
@@ -515,13 +526,40 @@
515
526
 
516
527
  switchTo(blockchainName) {
517
528
  return new Promise((resolve, reject)=>{
518
- 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
+ });
519
542
  })
520
543
  }
521
544
 
522
545
  addNetwork(blockchainName) {
523
546
  return new Promise((resolve, reject)=>{
524
- 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);
525
563
  })
526
564
  }
527
565
 
@@ -610,11 +648,17 @@
610
648
 
611
649
  const submitContractInteraction = ({ transaction, signer, provider })=>{
612
650
  let contract = new ethers.ethers.Contract(transaction.to, transaction.api, provider);
613
- return contract
614
- .connect(signer)
615
- [transaction.method](...transaction.getContractArguments({ contract }), {
651
+ let contractArguments = transaction.getContractArguments({ contract });
652
+ let method = contract.connect(signer)[transaction.method];
653
+ if(contractArguments) {
654
+ return method(...contractArguments, {
616
655
  value: Transaction.bigNumberify(transaction.value, transaction.blockchain)
617
656
  })
657
+ } else {
658
+ return method({
659
+ value: Transaction.bigNumberify(transaction.value, transaction.blockchain)
660
+ })
661
+ }
618
662
  };
619
663
 
620
664
  const submitSimpleTransfer = ({ transaction, signer })=>{
package/dist/umd/index.js CHANGED
@@ -54,8 +54,6 @@
54
54
  return fragment.inputs.map((input) => {
55
55
  return this.params[input.name]
56
56
  })
57
- } else {
58
- throw 'Contract params have wrong type!'
59
57
  }
60
58
  }
61
59
 
@@ -64,9 +62,16 @@
64
62
  }
65
63
 
66
64
  async getData() {
67
- let populatedTransaction = await this.getContract().populateTransaction[this.method].apply(
68
- null, this.getContractArguments()
69
- );
65
+ let contractArguments = this.getContractArguments();
66
+ let populatedTransaction;
67
+ if(contractArguments) {
68
+ populatedTransaction = await this.getContract().populateTransaction[this.method].apply(
69
+ null, contractArguments
70
+ );
71
+ } else {
72
+ populatedTransaction = await this.getContract().populateTransaction[this.method].apply(null);
73
+ }
74
+
70
75
  return populatedTransaction.data
71
76
  }
72
77
 
@@ -149,11 +154,17 @@
149
154
 
150
155
  const submitContractInteraction$2 = ({ transaction, signer, provider })=>{
151
156
  let contract = new ethers.ethers.Contract(transaction.to, transaction.api, provider);
152
- return contract
153
- .connect(signer)
154
- [transaction.method](...transaction.getContractArguments({ contract }), {
157
+ let contractArguments = transaction.getContractArguments({ contract });
158
+ let method = contract.connect(signer)[transaction.method];
159
+ if(contractArguments) {
160
+ return method(...contractArguments, {
161
+ value: Transaction.bigNumberify(transaction.value, transaction.blockchain)
162
+ })
163
+ } else {
164
+ return method({
155
165
  value: Transaction.bigNumberify(transaction.value, transaction.blockchain)
156
166
  })
167
+ }
157
168
  };
158
169
 
159
170
  const submitSimpleTransfer$3 = ({ transaction, signer })=>{
@@ -702,13 +713,40 @@
702
713
 
703
714
  switchTo(blockchainName) {
704
715
  return new Promise((resolve, reject)=>{
705
- 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
+ });
706
729
  })
707
730
  }
708
731
 
709
732
  addNetwork(blockchainName) {
710
733
  return new Promise((resolve, reject)=>{
711
- 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);
712
750
  })
713
751
  }
714
752
 
@@ -797,11 +835,17 @@
797
835
 
798
836
  const submitContractInteraction = ({ transaction, signer, provider })=>{
799
837
  let contract = new ethers.ethers.Contract(transaction.to, transaction.api, provider);
800
- return contract
801
- .connect(signer)
802
- [transaction.method](...transaction.getContractArguments({ contract }), {
838
+ let contractArguments = transaction.getContractArguments({ contract });
839
+ let method = contract.connect(signer)[transaction.method];
840
+ if(contractArguments) {
841
+ return method(...contractArguments, {
803
842
  value: Transaction.bigNumberify(transaction.value, transaction.blockchain)
804
843
  })
844
+ } else {
845
+ return method({
846
+ value: Transaction.bigNumberify(transaction.value, transaction.blockchain)
847
+ })
848
+ }
805
849
  };
806
850
 
807
851
  const submitSimpleTransfer = ({ transaction, signer })=>{
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.10",
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",
@@ -28,7 +28,7 @@
28
28
  "@depay/coinbase-wallet-sdk": "^1.1.0",
29
29
  "@depay/walletconnect-v1": "^1.7.10",
30
30
  "@depay/web3-blockchains": "^6.2.3",
31
- "@depay/web3-client-evm": "^10.1.23",
31
+ "@depay/web3-client-evm": "^10.2.1",
32
32
  "@depay/web3-constants": "^6.3.2",
33
33
  "ethers": "^5.7.1"
34
34
  },