@@ -7,13 +7,17 @@ const LiquidityPool = require('./LiquidityPool')
77const InputDataDecoder = require ( 'ethereum-input-data-decoder' )
88
99class MasterChef {
10- constructor ( web3 , chefABI , address , pendingMethodName , pendingSymbol = '' ) {
10+ constructor ( web3 , chefABI , address , pendingMethodName = 'pendingCake' , pendingSymbol = '' ) {
1111 this . web3 = web3
1212 this . address = address
1313 this . contract = new web3 . eth . Contract ( chefABI , address )
1414 this . decoder = new InputDataDecoder ( chefABI )
1515 this . pendingMethodName = pendingMethodName
16+
1617 this . pendingSymbol = pendingSymbol
18+ if ( this . pendingSymbol === '' ) {
19+ this . pendingSymbol = this . pendingMethodName . replace ( 'pending' , '' ) . toUpperCase ( )
20+ }
1721 }
1822
1923 lpTransactions ( walletTx , poolID ) {
@@ -52,14 +56,8 @@ class MasterChef {
5256
5357 async getPendingReward ( poolID , walletAddress ) {
5458 const pendingReward = await this . contract . methods [ this . pendingMethodName ] ( poolID , walletAddress ) . call ( )
55-
56- let tokenName = this . pendingSymbol
57- if ( tokenName === '' ) {
58- tokenName = this . pendingMethodName . replace ( 'pending' , '' ) . toUpperCase ( )
59- }
60-
6159 const rewards = { }
62- rewards [ tokenName ] = parseFloat ( Web3 . utils . fromWei ( pendingReward ) )
60+ rewards [ this . pendingSymbol ] = parseFloat ( Web3 . utils . fromWei ( pendingReward ) )
6361 return rewards
6462 }
6563
@@ -86,7 +84,8 @@ class MasterChef {
8684
8785 const poolRewardPerBlock = Web3 . utils . fromWei ( BigNumber ( allocPoint ) . dividedBy ( this . totalAllocPoint ) . multipliedBy ( this . rewardPerBlock ) . integerValue ( ) . toFixed ( ) )
8886 const userPoolRewardPerBlock = poolRewardPerBlock * pool . share ( lpTokenAmount )
89- const rewardPerYear = userPoolRewardPerBlock * 3600 * 24 * 365 / 3
87+ const rewardPerYear = { }
88+ rewardPerYear [ this . pendingSymbol ] = userPoolRewardPerBlock * 3600 * 24 * 365 / 3
9089
9190 return {
9291 poolID, lpTokenAmount, totalDeposited, pendingReward, tokens, rewardPerYear, lpAddress, lpTransactions
@@ -102,9 +101,18 @@ class MasterChef {
102101 this . totalAllocPoint = await this . contract . methods . totalAllocPoint ( ) . call ( )
103102
104103 try {
105- this . rewardPerBlock = await this . contract . methods . cakePerBlock ( ) . call ( ) // TODO change reward per block
104+ this . rewardPerBlock = await this . contract . methods [ this . pendingSymbol . toLowerCase ( ) + 'PerBlock' ] ( ) . call ( )
106105 } catch ( e ) {
107- this . rewardPerBlock = 0
106+ try {
107+ this . rewardPerBlock = await this . contract . methods [ this . pendingSymbol + 'PerBlock' ] ( ) . call ( )
108+ } catch ( e ) {
109+ try {
110+ const ABISymbol = this . pendingMethodName . replace ( 'pending' , '' ) . toLowerCase ( )
111+ this . rewardPerBlock = await this . contract . methods [ ABISymbol + 'PerBlock' ] ( ) . call ( )
112+ } catch ( e ) {
113+ this . rewardPerBlock = 0
114+ }
115+ }
108116 }
109117
110118 let pools = [ ]
0 commit comments