Skip to content

Commit

Permalink
fix issues with undelegatio end time (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
faboweb authored Dec 9, 2019
1 parent 1869328 commit 610f855
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
17 changes: 11 additions & 6 deletions lib/reducers/cosmosV2-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
31 changes: 18 additions & 13 deletions lib/reducers/terraV3-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit 610f855

Please sign in to comment.