diff --git a/data/networks.json b/data/networks.json index 7c6cf4fb62..04a0e965aa 100644 --- a/data/networks.json +++ b/data/networks.json @@ -77,9 +77,9 @@ "terra-testnet": { "id": "terra-testnet", "title": "Terra", - "chain_id": "soju-0012", - "api_url": "http://terra-soju-0012.lunie.io/", - "rpc_url": "wss://terra-soju-0012.lunie.io/websocket", + "chain_id": "soju-0013", + "api_url": "http://terra-testnet.lunie.io/", + "rpc_url": "wss://terra-testnet.lunie.io/websocket", "bech32_prefix": "terra", "testnet": true, "feature_session": false, diff --git a/lib/cosmosV0-source.js b/lib/cosmosV0-source.js index 5fd77c870f..0e02099ad0 100644 --- a/lib/cosmosV0-source.js +++ b/lib/cosmosV0-source.js @@ -365,12 +365,21 @@ class CosmosV0API extends PerBlockCacheDataSource { } async getOverview(delegatorAddress, validatorsDictionary) { - const [balances, delegations, stakingDenom] = await Promise.all([ + const [ + balances, + delegations, + undelegations, + stakingDenom + ] = await Promise.all([ this.getBalancesFromAddress(delegatorAddress), this.getDelegationsForDelegatorAddress( delegatorAddress, validatorsDictionary ), + this.getUndelegationsForDelegatorAddress( + delegatorAddress, + validatorsDictionary + ), this.getStakinDenom() ]) const rewards = await this.getRewards( @@ -381,6 +390,7 @@ class CosmosV0API extends PerBlockCacheDataSource { return this.reducers.overviewReducer( balances, delegations, + undelegations, rewards, stakingDenom ) diff --git a/lib/reducers/cosmosV0-reducers.js b/lib/reducers/cosmosV0-reducers.js index f420ac1d7c..c89ec6f18c 100644 --- a/lib/reducers/cosmosV0-reducers.js +++ b/lib/reducers/cosmosV0-reducers.js @@ -18,7 +18,7 @@ function proposalBeginTime(proposal) { function proposalEndTime(proposal) { switch (proposal.proposal_status.toLowerCase()) { case 'depositperiod': - return proposal.voting_start_time + return proposal.deposit_end_time case 'votingperiod': // the end time lives in the past already if the proposal is finalized // eslint-disable-next-line no-fallthrough @@ -299,7 +299,13 @@ function rewardReducer(reward, validator) { } } -function overviewReducer(balances, delegations, rewards, stakingDenom) { +function overviewReducer( + balances, + delegations, + undelegations, + rewards, + stakingDenom +) { stakingDenom = denomLookup(stakingDenom) const totalRewards = _.flatten(rewards) @@ -316,12 +322,16 @@ function overviewReducer(balances, delegations, rewards, stakingDenom) { (sum, { amount }) => BigNumber(sum).plus(amount), 0 ) + const undelegatingStake = undelegations.reduce( + (sum, { amount }) => BigNumber(sum).plus(amount), + 0 + ) return { // rewards, totalRewards: totalRewards, liquidStake: liquidStake, - totalStake: liquidStake.plus(delegatedStake) + totalStake: liquidStake.plus(delegatedStake).plus(undelegatingStake) } } diff --git a/lib/reducers/cosmosV2-reducers.js b/lib/reducers/cosmosV2-reducers.js index c6933bde56..5de6c28e71 100644 --- a/lib/reducers/cosmosV2-reducers.js +++ b/lib/reducers/cosmosV2-reducers.js @@ -93,12 +93,17 @@ function validatorReducer( } function undelegationEndTimeReducer(transaction) { - if ( - transaction.events[1].attributes.find(tx => tx.key === `completion_time`) - ) { - return transaction.events[1].attributes.filter( - tx => tx.key === `completion_time` - )[0].value + if (transaction.events) { + let completionTimeAttribute + transaction.events.find(({ attributes }) => { + if (attributes) { + completionTimeAttribute = attributes.find( + tx => tx.key === `completion_time` + ) + } + return !!completionTimeAttribute + }) + return completionTimeAttribute ? completionTimeAttribute.value : undefined } else { return null } diff --git a/lib/reducers/terraV3-reducers.js b/lib/reducers/terraV3-reducers.js index c34d77dddc..9095485948 100644 --- a/lib/reducers/terraV3-reducers.js +++ b/lib/reducers/terraV3-reducers.js @@ -2,19 +2,24 @@ const cosmosV2Reducers = require('./cosmosV2-reducers') // Terra has a slightly different structure and needs its own undelegationEndTimeReducer function undelegationEndTimeReducer(transaction) { - if (transaction.logs[0].events.length > 2) { - let endTime - const attributes = Object.values(transaction.logs[0].events).map( - event => event.attributes - ) - attributes.forEach(attribute => - attribute.map(tx => { - if (tx.key === `completion_time`) { - endTime = tx.value - } - }) - ) - return endTime ? endTime : null + if (transaction.logs) { + let completionTimeAttribute + transaction.logs.find(({ events }) => { + if (events) { + events.find(({ attributes }) => { + if (attributes) { + completionTimeAttribute = attributes.find( + tx => tx.key === `completion_time` + ) + } + return !!completionTimeAttribute + }) + } + return !!completionTimeAttribute + }) + return completionTimeAttribute ? completionTimeAttribute.value : undefined + } else { + return null } } diff --git a/lib/regenV0-source.js b/lib/regenV0-source.js index 3cc3813bb5..42dc5fecf7 100644 --- a/lib/regenV0-source.js +++ b/lib/regenV0-source.js @@ -16,7 +16,9 @@ class RegenV0API extends CosmosV0API { async getTransactionsByHeight(height) { const { txs } = await this.get(`txs?tx.height=${height}`) return Array.isArray(txs) - ? txs.map(transaction => this.reducers.transactionReducer(transaction)) + ? txs.map(transaction => + this.reducers.transactionReducer(transaction, this.reducers) + ) : [] } @@ -31,7 +33,9 @@ class RegenV0API extends CosmosV0API { const dupFreeTxs = uniqWith(txs, (a, b) => a.txhash === b.txhash) const sortedTxs = sortBy(dupFreeTxs, ['timestamp']) const reversedTxs = reverse(sortedTxs) - return reversedTxs.map(transactionReducer) + return reversedTxs.map(transaction => + transactionReducer(transaction, this.reducers) + ) } }