Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Fixes active indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
iPaulPro committed Mar 1, 2022
1 parent 4c56f62 commit 1a53d52
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,13 @@ const createActiveIndicatorTooltip = (innerText) => {
return tooltip
}

const addActiveIndicator = (tooltipText, profileDetailsDiv) => {
const tooltip = createActiveIndicatorTooltip(tooltipText)
const activeIndicator = createActiveIndicatorElement(tooltip)
const avatar = profileDetailsDiv.querySelector('.creator-profile__avatar')
avatar.appendChild(activeIndicator)
}

const showIndicatorIfActive = (publicKey, profileDetailsDiv) => getTransactionInfo(publicKey, -1, 100)
.then((transactions) => {
const latestTransaction = transactions.reverse()
Expand All @@ -437,12 +444,19 @@ const showIndicatorIfActive = (publicKey, profileDetailsDiv) => getTransactionIn
if (document.getElementById(activeIndicatorId)) return

const blockHashHex = latestTransaction['BlockHashHex']
if (!blockHashHex || (blockHashHex && blockHashHex.length === 0)) {
// This means the transaction is still in the mempool, which means active within the past 5 min
const tooltipText = `Last active < 5 minutes ago`
addActiveIndicator(tooltipText, profileDetailsDiv)
return
}

getBlock(blockHashHex).then((res) => {
const header = res['Header']
const error = res['Error']
let tooltipText

// This means the transaction is still in the mempool, which means active within the past 5 min
// This also means the transaction is still in the mempool
if (error && error.includes('Key not found')) {
tooltipText = `Last active < 5 minutes ago`
} else {
Expand All @@ -457,10 +471,7 @@ const showIndicatorIfActive = (publicKey, profileDetailsDiv) => getTransactionIn
}

if (tooltipText) {
const tooltip = createActiveIndicatorTooltip(tooltipText)
const activeIndicator = createActiveIndicatorElement(tooltip)
const avatar = profileDetailsDiv.querySelector('.creator-profile__avatar')
avatar.appendChild(activeIndicator)
addActiveIndicator(tooltipText, profileDetailsDiv)
}
})
})
Expand Down Expand Up @@ -518,7 +529,7 @@ const enrichProfileFromApi = (profileDetailsDiv) => {
})
if (loggedInUserIsHodler) addSellButton()

return getUserMetadata(pagePubKey)
return getUserMetadata(pagePubKey).catch(() => {})

}).then(metadata => {
const userDataDiv = getProfileUserDataDiv()
Expand Down

0 comments on commit 1a53d52

Please sign in to comment.