Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
xavier506 committed Oct 8, 2021
2 parents 09d25f8 + 1d3ed3d commit a44451a
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 84 deletions.
27 changes: 20 additions & 7 deletions hapi/src/libs/sync-user-rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,29 @@ const updateUserRatings = async (
community: blockProducer.community || 0
}

const result = await (
const exist = await (
await massiveDB
).user_ratings.save({
).user_ratings.findOne({
user: blockProducer.user,
bp: blockProducer.bp,
ratings: ratings,
tx_data: transaction
bp: blockProducer.bp
})

if (!result) {
if (exist) {
const saveResult = await (
await massiveDB
).user_ratings.save({
id: exist.id,
user: blockProducer.user,
bp: blockProducer.bp,
ratings: ratings,
tx_data: transaction
})

if (!saveResult)
throw new Error(
`Could not save ${blockProducer.user}-${blockProducer.bp}`
)
} else {
const insertResult = await (
await massiveDB
).user_ratings.insert({
Expand All @@ -74,7 +87,7 @@ const updateUserRatings = async (

if (!insertResult)
throw new Error(
`Could not save or insert ${blockProducer.user}-${blockProducer.bp}`
`Could not insert ${blockProducer.user}-${blockProducer.bp}`
)
}

Expand Down
158 changes: 85 additions & 73 deletions webapp/src/context/models/producers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export const getProducers = async (limit, orderBy) => {
return getBpDataModeled({
...producer,
edenRate: {
average: producer.eden_average,
ratings_cntr: producer.eden_ratings_cntr,
community: producer.eden_community,
development: producer.eden_development,
infrastructure: producer.eden_infrastructure,
transparency: producer.eden_transparency,
trustiness: producer.eden_trustiness
average: producer?.eden_average || 0,
ratings_cntr: producer?.eden_ratings_cntr || 0,
community: producer?.eden_community || 0,
development: producer?.eden_development || 0,
infrastructure: producer?.eden_infrastructure || 0,
transparency: producer?.eden_transparency || 0,
trustiness: producer?.eden_trustiness || 0
}
})
})
Expand All @@ -56,25 +56,31 @@ export const getBlockProducerRatingByOwner = async (
}
}

export const mutationInsertUserRating = async (
{ ual, user, bp, result, transaction, blockProducers, ...ratings },
state
) => {
export const mutationInsertUserRating = async ({
ual,
user,
bp,
transaction,
blockProducers,
isEden
}) => {
try {
const {
data: { rateProducer }
} = await client.mutate({
variables: {
ratingInput: {
producer: bp,
isEden: state?.user?.userData?.edenMember,
isEden,
user,
transaction: transaction
transaction
}
},
mutation: MUTATION_UPDATE_RATING
})

let producerUpdatedList = []
let currentBP
const rpc = getRpc(ual)

const { rows: rateStat } = await rpc.get_table_rows({
Expand All @@ -88,36 +94,41 @@ export const mutationInsertUserRating = async (
show_payer: false
})

const producerUpdatedList = blockProducers.data.map(producer => {
if (rateStat.length && producer.owner === rateStat[0].bp) {
const parameters = {
community: rateStat[0].community,
development: rateStat[0].development,
infrastructure: rateStat[0].infrastructure,
transparency: rateStat[0].transparency,
trustiness: rateStat[0].trustiness
}
const graphData = Object.values(parameters)

return {
...producer,
average: rateStat[0].average,
ratings_cntr: rateStat[0].ratings_cntr,
system: {
...producer.system,
parameters
},
data: {
...producer.data,
data: graphData
if (blockProducers.data.length) {
producerUpdatedList = blockProducers.data.map(producer => {
if (rateStat.length && producer.owner === rateStat[0].bp) {
const parameters = {
community: rateStat[0].community,
development: rateStat[0].development,
infrastructure: rateStat[0].infrastructure,
transparency: rateStat[0].transparency,
trustiness: rateStat[0].trustiness
}
const graphData = Object.values(parameters)

return {
...producer,
average: rateStat[0].average,
ratings_cntr: rateStat[0].ratings_cntr,
system: {
...producer.system,
parameters
},
data: {
...producer.data,
data: graphData
}
}
}
}

return producer
})
let currentBP = producerUpdatedList.find(producer => producer.owner === bp)
currentBP = { ...currentBP, ...rateProducer.resultEden }
return producer
})
currentBP = producerUpdatedList.find(producer => producer.owner === bp)
currentBP = { ...currentBP, edenRate: rateProducer.resultEden }
} else {
currentBP = await getProducer(bp)
}

const userRate = await getBlockProducerRatingByOwner({
bp,
userAccount: user
Expand Down Expand Up @@ -155,56 +166,57 @@ export const getTotalStats = ({
oneStat
}) => {
const average = calculateTotalStats({
firstAverage: producerData.average,
secondAverage: edenStats.average,
firstCounter: producerData.ratings_cntr,
secondCounter: edenStats.ratings_cntr,
firstAverage: producerData?.average || 0,
secondAverage: edenStats?.average || 0,
firstCounter: producerData?.ratings_cntr || 0,
secondCounter: edenStats?.ratings_cntr || 0,
fieldsAmount: statsAmount
})

const community = calculateTotalStats({
firstAverage: producerData.community,
secondAverage: edenStats.community,
firstCounter: producerData.ratings_cntr,
secondCounter: edenStats.ratings_cntr,
firstAverage: producerData?.community || 0,
secondAverage: edenStats?.community || 0,
firstCounter: producerData?.ratings_cntr || 0,
secondCounter: edenStats?.ratings_cntr || 0,
fieldsAmount: oneStat
})

const development = calculateTotalStats({
firstAverage: producerData.development,
secondAverage: edenStats.development,
firstCounter: producerData.ratings_cntr,
secondCounter: edenStats.ratings_cntr,
firstAverage: producerData?.development || 0,
secondAverage: edenStats?.development || 0,
firstCounter: producerData?.ratings_cntr || 0,
secondCounter: edenStats?.ratings_cntr || 0,
fieldsAmount: oneStat
})

const infrastructure = calculateTotalStats({
firstAverage: producerData.infrastructure,
secondAverage: edenStats.infrastructure,
firstCounter: producerData.ratings_cntr,
secondCounter: edenStats.ratings_cntr,
firstAverage: producerData?.infrastructure || 0,
secondAverage: edenStats?.infrastructure || 0,
firstCounter: producerData?.ratings_cntr || 0,
secondCounter: edenStats?.ratings_cntr || 0,
fieldsAmount: oneStat
})

const trustiness = calculateTotalStats({
firstAverage: producerData.trustiness,
secondAverage: edenStats.trustiness,
firstCounter: producerData.ratings_cntr,
secondCounter: edenStats.ratings_cntr,
firstAverage: producerData?.trustiness || 0,
secondAverage: edenStats?.trustiness || 0,
firstCounter: producerData?.ratings_cntr || 0,
secondCounter: edenStats?.ratings_cntr || 0,
fieldsAmount: oneStat
})

const transparency = calculateTotalStats({
firstAverage: producerData.trustiness,
secondAverage: edenStats.trustiness,
firstCounter: producerData.ratings_cntr,
secondCounter: edenStats.ratings_cntr,
fieldsAmount: oneStat
firstAverage: producerData?.trustiness || 0,
secondAverage: edenStats?.trustiness || 0,
firstCounter: producerData?.ratings_cntr || 0,
secondCounter: edenStats?.ratings_cntr || 0,
fieldsAmount: oneStat || 0
})

return {
average,
ratings_cntr: producerData.ratings_cntr + edenStats.ratings_cntr,
ratings_cntr:
producerData?.ratings_cntr || 0 + edenStats?.ratings_cntr || 0,
community,
development,
infrastructure,
Expand All @@ -229,13 +241,13 @@ export const getProducer = async owner => {
return getBpDataModeled({
...producerData,
edenRate: {
average: producerData.eden_average,
ratings_cntr: producerData.eden_ratings_cntr,
community: producerData.eden_community,
development: producerData.eden_development,
infrastructure: producerData.eden_infrastructure,
transparency: producerData.eden_transparency,
trustiness: producerData.eden_trustiness
average: producerData?.eden_average || 0,
ratings_cntr: producerData?.eden_ratings_cntr || 0,
community: producerData?.eden_community || 0,
development: producerData?.eden_development || 0,
infrastructure: producerData?.eden_infrastructure || 0,
transparency: producerData?.eden_transparency || 0,
trustiness: producerData?.eden_trustiness || 0
}
})
}
4 changes: 3 additions & 1 deletion webapp/src/context/state.context.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,17 @@ export const useSharedState = () => {
user,
bp,
result,
transaction,
...ratings
}) => {
const ratingData = await mutationInsertUserRating({
ual,
user,
bp,
result,
transaction: state.transaction,
transaction,
blockProducers: state.blockProducers,
isEden: state?.user?.userData?.edenMember,
...ratings
})

Expand Down
4 changes: 2 additions & 2 deletions webapp/src/routes/Account/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ const Account = () => {
rel='noopener'
target='_blank'
className={classes.link}
href={`${mainConfig.blockExplorer}/transaction/${rate.tx_data.transaction.transactionId}`}
href={`${mainConfig.blockExplorer}/transaction/${rate.tx_data?.transaction?.transactionId}`}
>
{rate.tx_data.transaction.transactionId}
{rate.tx_data?.transaction?.transactionId}
</Link>
)}
</Box>
Expand Down
14 changes: 13 additions & 1 deletion webapp/src/routes/BlockProducers/BlockProducerRate.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ const BlockProducerRate = () => {
ual: state.ual,
user: state.user.accountName,
bp: account,
transaction: {
transaction: {
transactionId: result.transaction.transaction_id,
transactionDate: result.transaction.processed.block_time
}
},
...getRatingData(false),
result
})
Expand Down Expand Up @@ -298,7 +304,13 @@ const BlockProducerRate = () => {
({ owner }) => owner === account
)
setProducer(bp, true)
setProfileData(bp, {})
setProfileData(
bp,
getBPRadarData({
name: t('myRate'),
parameters: getSavedRatingData({})
})
)

return
}
Expand Down

0 comments on commit a44451a

Please sign in to comment.