Skip to content

Commit

Permalink
fix(webapp): fix eden rating function (#821)
Browse files Browse the repository at this point in the history
* Publish changes to prod  (#566)

* avoid statefulsets update errors on actions runs refs #535. (#536)

* deprecate demux service. refs #538 (#540)

* add handler url from env var & other minor bug fixes (#542)

* Add missing env var to config map (#543)

* add handler url from env var & other minor bug fixes

* add missing env var

* fix: update some env vars

* fix: update some env vars

* fix: replace .env values with the previous ones

* Feat/add tx link (#545)

* feat: add tx link

* feat: remove secrets

* setup env workflow (#546)

* wip

* wip: add env files & db_data to .gitignore

* fix: remove .env files

* fix: remove .env files

* fix: delete unnecessary code

* refactor: remove unnecessary code

* fix: minimal

* Fix/rate action buttons not showing (#547)

* wip

* wip: add env files & db_data to .gitignore

* fix: remove .env files

* fix: remove .env files

* fix: delete unnecessary code

* refactor: remove unnecessary code

* fix: minimal

* fix: rate buttons not showing in certains densities

* Fix/hasura console config (#556)

* Deploy to mainnet (#544)

* avoid statefulsets update errors on actions runs refs #535. (#536)

* deprecate demux service. refs #538 (#540)

* add handler url from env var & other minor bug fixes (#542)

* Add missing env var to config map (#543)

* add handler url from env var & other minor bug fixes

* add missing env var

* fix: update some env vars

* fix: update some env vars

* fix: replace .env values with the previous ones

Co-authored-by: Andres Gomez <[email protected]>
Co-authored-by: JustinCast <[email protected]>

* wip

* wip: add env files & db_data to .gitignore

* fix: remove .env files

* fix: remove .env files

* fix: delete unnecessary code

* refactor: remove unnecessary code

* fix: minimal

* feat: voting tool revamp

* fix: remove comments

* fix: add i18n entries

* fix: bug fixes

* fix: hasura console config

Co-authored-by: Xavier <[email protected]>
Co-authored-by: Andres Gomez <[email protected]>

* Fix/add missing i18n entries (#554)

* Deploy to mainnet (#544)

* avoid statefulsets update errors on actions runs refs #535. (#536)

* deprecate demux service. refs #538 (#540)

* add handler url from env var & other minor bug fixes (#542)

* Add missing env var to config map (#543)

* add handler url from env var & other minor bug fixes

* add missing env var

* fix: update some env vars

* fix: update some env vars

* fix: replace .env values with the previous ones

Co-authored-by: Andres Gomez <[email protected]>
Co-authored-by: JustinCast <[email protected]>

* wip

* wip: add env files & db_data to .gitignore

* fix: remove .env files

* fix: remove .env files

* fix: delete unnecessary code

* refactor: remove unnecessary code

* fix: minimal

* feat: voting tool revamp

* fix: remove comments

* fix: add i18n entries

* fix: bug fixes

Co-authored-by: Xavier <[email protected]>
Co-authored-by: Andres Gomez <[email protected]>

* docs: add env example (#565)

* fix: not able to sync proxies locally (#564)

* fix: update hasura version

* fix: hasura version && other minor bug fixes

* Fix/update hasura version (#567)

* fix: remove build:staging statement

* latest changes

Co-authored-by: Andres Gomez <[email protected]>
Co-authored-by: JustinCast <[email protected]>

* Update push-master-environment.yaml (#576)

* fix(cron): update config values (#579)

* Revert "fix(cron): update config values (#579)" (#580)

This reverts commit 13ecf78.

* add(link sidebar): Add network Monitor in sidebar

* fix(structure-files): change names to folders and files

* feat(gql): add producers query

* feat(models): add new functions to mdels

* feat(bpProfilePage): model necessary data

* fix(BPRatePage): fix rating process

* feat(bpRate): apply new design

* feat(rating-page): apply new design

* feat(header): add user info component by user type

* fix(header): refactor structure code

* feat(front-end): show total rating data

* fix(scrips): change contract name

* fix(card): load user votes on bp section

* fix(DB): delete unnecessary colums on DB

* fix(front-end): fix eden ratign action

* fix(front-end): fix eden ratign action

* fix(webapp): load eden ratings stats from view

* fix(webapp): style radar on rating page

* fix(webapp): remove comments

* fix(webapp): fix eden rating function

* fix(webapp): save tranaction data

Co-authored-by: Xavier <[email protected]>
Co-authored-by: Andres Gomez <[email protected]>
Co-authored-by: JustinCast <[email protected]>
Co-authored-by: Xavier Fernandez <[email protected]>
Co-authored-by: Leister Francisco Alvarez Campos <[email protected]>
  • Loading branch information
6 people authored Oct 8, 2021
1 parent 808bdc7 commit 1d3ed3d
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 1d3ed3d

Please sign in to comment.