@@ -82,7 +82,7 @@ class Nf3 {
82
82
@returns {Promise }
83
83
*/
84
84
async init ( mnemonic ) {
85
- this . setWeb3Provider ( ) ;
85
+ await this . setWeb3Provider ( ) ;
86
86
this . shieldContractAddress = await this . getContractAddress ( 'Shield' ) ;
87
87
this . proposersContractAddress = await this . getContractAddress ( 'Proposers' ) ;
88
88
this . challengesContractAddress = await this . getContractAddress ( 'Challenges' ) ;
@@ -279,11 +279,14 @@ class Nf3 {
279
279
tokenType ,
280
280
value ,
281
281
this . web3 ,
282
+ ! ! this . ethereumSigningKey ,
282
283
) ;
283
284
} catch ( err ) {
284
285
throw new Error ( err ) ;
285
286
}
286
- if ( txDataToSign ) await this . submitTransaction ( txDataToSign , ercAddress , 0 ) ;
287
+ if ( txDataToSign ) {
288
+ await this . submitTransaction ( txDataToSign , ercAddress , 0 ) ;
289
+ }
287
290
const res = await axios . post ( `${ this . clientBaseUrl } /deposit` , {
288
291
ercAddress,
289
292
tokenId,
@@ -728,12 +731,20 @@ class Nf3 {
728
731
Returns the balance of tokens held in layer 2
729
732
@method
730
733
@async
734
+ @param {Array } ercList - list of erc contract addresses to filter.
735
+ @param {Boolean } filterByCompressedPkd - flag to indicate if request is filtered
736
+ ones compressed pkd
731
737
@returns {Promise } This promise resolves into an object whose properties are the
732
738
addresses of the ERC contracts of the tokens held by this account in Layer 2. The
733
739
value of each propery is the number of tokens originating from that contract.
734
740
*/
735
- async getLayer2Balances ( ) {
736
- const res = await axios . get ( `${ this . clientBaseUrl } /commitment/balance` ) ;
741
+ async getLayer2Balances ( ercList , filterByCompressedPkd ) {
742
+ const res = await axios . get ( `${ this . clientBaseUrl } /commitment/balance` , {
743
+ params : {
744
+ compressedPkd : filterByCompressedPkd === true ? this . zkpKeys . compressedPkd : null ,
745
+ ercList,
746
+ } ,
747
+ } ) ;
737
748
return res . data . balance ;
738
749
}
739
750
@@ -747,9 +758,11 @@ class Nf3 {
747
758
value of each propery is the number of tokens originating from that contract.
748
759
*/
749
760
async getLayer2BalancesDetails ( ercList ) {
750
- const res = await axios . post ( `${ this . clientBaseUrl } /commitment/balance-details` , {
751
- compressedPkd : this . zkpKeys . compressedPkd ,
752
- ercList,
761
+ const res = await axios . get ( `${ this . clientBaseUrl } /commitment/balance-details` , {
762
+ params : {
763
+ compressedPkd : this . zkpKeys . compressedPkd ,
764
+ ercList,
765
+ } ,
753
766
} ) ;
754
767
return res . data . balance ;
755
768
}
@@ -758,26 +771,42 @@ class Nf3 {
758
771
Returns the balance of tokens held in layer 2
759
772
@method
760
773
@async
774
+ @param {Array } ercList - list of erc contract addresses to filter.
775
+ @param {Boolean } filterByCompressedPkd - flag to indicate if request is filtered
776
+ ones compressed pkd
761
777
@returns {Promise } This promise resolves into an object whose properties are the
762
778
addresses of the ERC contracts of the tokens held by this account in Layer 2. The
763
779
value of each propery is the number of tokens pending deposit from that contract.
764
780
*/
765
- async getLayer2PendingDepositBalances ( ) {
766
- const res = await axios . get ( `${ this . clientBaseUrl } /commitment/pending-deposit` ) ;
781
+ async getLayer2PendingDepositBalances ( ercList , filterByCompressedPkd ) {
782
+ const res = await axios . get ( `${ this . clientBaseUrl } /commitment/pending-deposit` , {
783
+ params : {
784
+ compressedPkd : filterByCompressedPkd === true ? this . zkpKeys . compressedPkd : null ,
785
+ ercList,
786
+ } ,
787
+ } ) ;
767
788
return res . data . balance ;
768
789
}
769
790
770
791
/**
771
792
Returns the balance of tokens held in layer 2
772
793
@method
773
794
@async
795
+ @param {Array } ercList - list of erc contract addresses to filter.
796
+ @param {Boolean } filterByCompressedPkd - flag to indicate if request is filtered
797
+ ones compressed pkd
774
798
@returns {Promise } This promise resolves into an object whose properties are the
775
799
addresses of the ERC contracts of the tokens held by this account in Layer 2. The
776
800
value of each propery is the number of tokens pending spent (transfer & withdraw)
777
801
from that contract.
778
802
*/
779
- async getLayer2PendingSpentBalances ( ) {
780
- const res = await axios . get ( `${ this . clientBaseUrl } /commitment/pending-spent` ) ;
803
+ async getLayer2PendingSpentBalances ( ercList , filterByCompressedPkd ) {
804
+ const res = await axios . get ( `${ this . clientBaseUrl } /commitment/pending-spent` , {
805
+ params : {
806
+ compressedPkd : filterByCompressedPkd === true ? this . zkpKeys . compressedPkd : null ,
807
+ ercList,
808
+ } ,
809
+ } ) ;
781
810
return res . data . balance ;
782
811
}
783
812
@@ -810,14 +839,14 @@ class Nf3 {
810
839
/**
811
840
Set a Web3 Provider URL
812
841
*/
813
- setWeb3Provider ( ) {
842
+ async setWeb3Provider ( ) {
814
843
this . web3 = new Web3 ( this . web3WsUrl ) ;
815
844
this . web3 . eth . transactionBlockTimeout = 200 ;
816
845
this . web3 . eth . transactionConfirmationBlocks = 12 ;
817
846
if ( typeof window !== 'undefined' ) {
818
847
if ( window . ethereum && this . ethereumSigningKey === '' ) {
819
848
this . web3 = new Web3 ( window . ethereum ) ;
820
- window . ethereum . request ( { method : 'eth_accounts ' } ) ;
849
+ await window . ethereum . request ( { method : 'eth_requestAccounts ' } ) ;
821
850
} else {
822
851
// Metamask not available
823
852
throw new Error ( 'No Web3 provider found' ) ;
0 commit comments