From 1d3ed3de107fc734a7c4030f6acce254a12498a9 Mon Sep 17 00:00:00 2001 From: AngeloCG97 <51149817+AngeloCG97@users.noreply.github.com> Date: Fri, 8 Oct 2021 13:01:50 -0600 Subject: [PATCH] fix(webapp): fix eden rating function (#821) * 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 Co-authored-by: JustinCast * 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 <5632966+xavier506@users.noreply.github.com> Co-authored-by: Andres Gomez * 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 Co-authored-by: JustinCast * 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 <5632966+xavier506@users.noreply.github.com> Co-authored-by: Andres Gomez * 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 Co-authored-by: JustinCast * Update push-master-environment.yaml (#576) * fix(cron): update config values (#579) * Revert "fix(cron): update config values (#579)" (#580) This reverts commit 13ecf78f0cec5c1a938a1ee0aee646828995d940. * 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 <5632966+xavier506@users.noreply.github.com> Co-authored-by: Andres Gomez Co-authored-by: JustinCast Co-authored-by: Xavier Fernandez Co-authored-by: Leister Francisco Alvarez Campos --- hapi/src/libs/sync-user-rating.js | 27 ++- webapp/src/context/models/producers.js | 158 ++++++++++-------- webapp/src/context/state.context.js | 4 +- webapp/src/routes/Account/index.js | 4 +- .../BlockProducers/BlockProducerRate.js | 14 +- 5 files changed, 123 insertions(+), 84 deletions(-) diff --git a/hapi/src/libs/sync-user-rating.js b/hapi/src/libs/sync-user-rating.js index f11c5765..0867f773 100644 --- a/hapi/src/libs/sync-user-rating.js +++ b/hapi/src/libs/sync-user-rating.js @@ -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({ @@ -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}` ) } diff --git a/webapp/src/context/models/producers.js b/webapp/src/context/models/producers.js index baec8f30..4992cb26 100644 --- a/webapp/src/context/models/producers.js +++ b/webapp/src/context/models/producers.js @@ -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 } }) }) @@ -56,10 +56,14 @@ 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 } @@ -67,14 +71,16 @@ export const mutationInsertUserRating = async ( 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({ @@ -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 @@ -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, @@ -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 } }) } diff --git a/webapp/src/context/state.context.js b/webapp/src/context/state.context.js index f487f576..4bf122ee 100644 --- a/webapp/src/context/state.context.js +++ b/webapp/src/context/state.context.js @@ -271,6 +271,7 @@ export const useSharedState = () => { user, bp, result, + transaction, ...ratings }) => { const ratingData = await mutationInsertUserRating({ @@ -278,8 +279,9 @@ export const useSharedState = () => { user, bp, result, - transaction: state.transaction, + transaction, blockProducers: state.blockProducers, + isEden: state?.user?.userData?.edenMember, ...ratings }) diff --git a/webapp/src/routes/Account/index.js b/webapp/src/routes/Account/index.js index 7ad180dd..fdded944 100644 --- a/webapp/src/routes/Account/index.js +++ b/webapp/src/routes/Account/index.js @@ -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} )} diff --git a/webapp/src/routes/BlockProducers/BlockProducerRate.js b/webapp/src/routes/BlockProducers/BlockProducerRate.js index 81fc00c8..b0a808ff 100644 --- a/webapp/src/routes/BlockProducers/BlockProducerRate.js +++ b/webapp/src/routes/BlockProducers/BlockProducerRate.js @@ -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 }) @@ -298,7 +304,13 @@ const BlockProducerRate = () => { ({ owner }) => owner === account ) setProducer(bp, true) - setProfileData(bp, {}) + setProfileData( + bp, + getBPRadarData({ + name: t('myRate'), + parameters: getSavedRatingData({}) + }) + ) return }