From 610f855a1b7441e4bb77e0ecbefcdf670437bd64 Mon Sep 17 00:00:00 2001 From: Fabian Date: Mon, 9 Dec 2019 19:50:26 +0100 Subject: [PATCH] fix issues with undelegatio end time (#175) --- lib/reducers/cosmosV2-reducers.js | 17 +++++++++++------ lib/reducers/terraV3-reducers.js | 31 ++++++++++++++++++------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/lib/reducers/cosmosV2-reducers.js b/lib/reducers/cosmosV2-reducers.js index c6933bde56..021880aacb 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.value } else { return null } diff --git a/lib/reducers/terraV3-reducers.js b/lib/reducers/terraV3-reducers.js index c34d77dddc..584d5d0c9e 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.value + } else { + return null } }