Skip to content

Commit

Permalink
Fix reactions (#3564)
Browse files Browse the repository at this point in the history
* Fix tips

* To lower

* Fix lint

* Update comment

Co-authored-by: Raymond Jacobson <ray@audius.co>
  • Loading branch information
piazzatron and raymondjacobson authored Jul 28, 2022
1 parent 8cb266e commit 6876cb8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions identity-service/src/routes/reactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,37 @@ const { handleResponse, errorResponseBadRequest, errorResponseServerError, succe
const authMiddleware = require('../authMiddleware')
const models = require('../models')
const { logger } = require('../logging')
const { default: Axios } = require('axios')

const MAX_REACTIONS_PER_FETCH = 100

const handleReaction = async ({ senderWallet, reactionType, reactedTo, libs, reactionValue }) => {
const { solanaWeb3Manager } = libs
const currentSlot = await solanaWeb3Manager.getSlot()

// Get tips on DN to ensure reactions only to received tips
const { discoveryProviderEndpoint } = libs.discoveryProvider
const url = `${discoveryProviderEndpoint}/v1/full/tips`
const resp = await Axios({
method: 'get',
url,
params: {
tx_signatures: reactedTo
}
})

const tips = resp.data.data

if (tips.length !== 1) {
// Can't react to something that doesn't exist
throw new Error(`No tip for tx_id ${reactedTo}`)
}

const { erc_wallet: tipReceiverWallet } = tips[0].receiver
if (tipReceiverWallet.toLowerCase() !== senderWallet.toLowerCase()) {
throw new Error(`Can't react unless user was the tip recipient`)
}

const now = Date.now()
await models.Reactions.create({
slot: currentSlot,
Expand Down

0 comments on commit 6876cb8

Please sign in to comment.