Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
xavier506 committed Sep 7, 2021
2 parents ac9acfa + dc2d77b commit cd6885e
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 54 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ HASURA_GRAPHQL_ACTION_BASE_URL=http://hapi:9090

# WEBAPP
REACT_APP_RATING_CONTRACT=rateproducer
REACT_APP_EDEN_CONTRACT=genesis.eden // si es jungle genesisdeden
REACT_APP_GRAPHQL_HTTP_URL=http://localhost:8080/v1/graphql
REACT_APP_API_URL=https://jungle.eosio.cr
REACT_APP_GRAPHQL_WS_URL=ws://localhost:8080/v1/graphql
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/push-master-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
NAMESPACE: mainnet-eosrate
# webapp
REACT_APP_RATING_CONTRACT: rateproducer
REACT_APP_EDEN_CONTRACT: ${{ secrets.REACT_APP_EDEN_CONTRACT }}
REACT_APP_PROXY_CONTRACT: regproxyinfo
REACT_APP_GRAPHQL_HTTP_URL: https://graphql.eosrate.io/v1/graphql
REACT_APP_GRAPHQL_WS_URL: wss://graphql.eosrate.io/v1/graphql
Expand All @@ -69,6 +70,7 @@ jobs:
INGRESS_GRAPHQL_HOST: graphql.eosrate.io
# webapp
REACT_APP_RATING_CONTRACT: rateproducer
REACT_APP_EDEN_CONTRACT: ${{ secrets.REACT_APP_EDEN_CONTRACT }}
REACT_APP_GRAPHQL_HTTP_URL: https://graphql.eosrate.io/v1/graphql
REACT_APP_GRAPHQL_WS_URL: wss://graphql.eosrate.io/v1/graphql
REACT_APP_EOS_API_URL: https://api.main.alohaeos.com
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/push-staging-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
NAMESPACE: jungle-eosrate
# webapp
REACT_APP_RATING_CONTRACT: rateproducer
REACT_APP_EDEN_CONTRACT: ${{ secrets.REACT_APP_EDEN_CONTRACT }}
REACT_APP_PROXY_CONTRACT: regproxyinfo
REACT_APP_GRAPHQL_HTTP_URL: https://graphql-jungle.eosrate.io/v1/graphql
REACT_APP_GRAPHQL_WS_URL: wss://graphql-jungle.eosrate.io/v1/graphql
Expand All @@ -69,6 +70,7 @@ jobs:
INGRESS_GRAPHQL_HOST: graphql-jungle.eosrate.io
# webapp
REACT_APP_RATING_CONTRACT: rateproducer
REACT_APP_EDEN_CONTRACT: ${{ secrets.REACT_APP_EDEN_CONTRACT }}
REACT_APP_PROXY_CONTRACT: regproxyinfo
REACT_APP_GRAPHQL_HTTP_URL: https://graphql-jungle.eosrate.io/v1/graphql
REACT_APP_GRAPHQL_WS_URL: wss://graphql-jungle.eosrate.io/v1/graphql
Expand Down
51 changes: 40 additions & 11 deletions contracts/rateproducer/include/rateproducer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,55 @@ namespace eosio {
in_election = 1
};

struct member_v0 {
eosio::name account;
std::string name;
member_status_type status;
uint64_t nft_template_id;

uint64_t primary_key() const { return account.value; }
struct member_v0
{
eosio::name account;
std::string name;
member_status_type status;
uint64_t nft_template_id;
// Only reflected in v1
election_participation_status_type election_participation_status = not_in_election;
uint8_t election_rank = 0;
eosio::name representative{uint64_t(-1)};
std::optional<eosio::public_key> encryption_key;

uint64_t primary_key() const { return account.value; }
uint128_t by_representative() const
{
return (static_cast<uint128_t>(election_rank) << 64) | representative.value;
}
};
EOSIO_REFLECT(member_v0, account, name, status, nft_template_id)

using member_variant = std::variant<member_v0>;
// - A member can donate at any time after the end of a scheduled election and before
// the start of the next scheduled election.
// - A member who does not make a donation before the election starts will be deactivated.
//
struct member_v1 : member_v0
{
};
EOSIO_REFLECT(member_v1,
base member_v0,
election_participation_status,
election_rank,
representative,
encryption_key);

using member_variant = std::variant<member_v0, member_v1>;

struct member {
struct member
{
member_variant value;
EDEN_FORWARD_MEMBERS(value,
account,
name,
status,
nft_template_id);
EDEN_FORWARD_FUNCTIONS(value, primary_key);
nft_template_id,
election_participation_status,
election_rank,
representative,
encryption_key);
EDEN_FORWARD_FUNCTIONS(value, primary_key, by_representative)
};
EOSIO_REFLECT(member, value)
using member_table_type = eosio::multi_index<"member"_n, member>;
Expand Down
Binary file modified contracts/rateproducer/rateproducer.wasm
Binary file not shown.
58 changes: 28 additions & 30 deletions contracts/rateproducer/src/rateproducer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,44 +454,42 @@ namespace eoscostarica {
auto uniq_rating_index = _ratings.get_index<name("uniqrating")>();
auto existing_rating = uniq_rating_index.find(uniq_rating);

if( existing_rating != uniq_rating_index.end() ) {

//delete rate info
auto itr = uniq_rating_index.erase(existing_rating);

//update bp stats
float bp_transparency = 0;
float bp_infrastructure = 0;
float bp_trustiness = 0;
float bp_community = 0;
float bp_development = 0;
uint32_t bp_ratings_cntr = 0;
float bp_average = 0;
check( existing_rating != uniq_rating_index.end(), "Rating does not exist" );

//re-calculate stats for the bp
calculate_bp_stats (scope,
bp,
&bp_transparency,
&bp_infrastructure,
&bp_trustiness,
&bp_community,
&bp_development,
&bp_ratings_cntr,
&bp_average);
//save the re-calcualtes stats
update_bp_stats (scope,
&user,
&bp,
//delete rate info
auto itr = uniq_rating_index.erase(existing_rating);

//update bp stats
float bp_transparency = 0;
float bp_infrastructure = 0;
float bp_trustiness = 0;
float bp_community = 0;
float bp_development = 0;
uint32_t bp_ratings_cntr = 0;
float bp_average = 0;

//re-calculate stats for the bp
calculate_bp_stats (scope,
bp,
&bp_transparency,
&bp_infrastructure,
&bp_trustiness,
&bp_community,
&bp_development,
&bp_ratings_cntr,
&bp_average);

}

//save the re-calcualtes stats
update_bp_stats (scope,
&user,
&bp,
&bp_transparency,
&bp_infrastructure,
&bp_trustiness,
&bp_community,
&bp_development,
&bp_ratings_cntr,
&bp_average);
}

void rateproducer::loadedens() {
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ services:
restart: always
environment:
REACT_APP_RATING_CONTRACT: "${REACT_APP_RATING_CONTRACT}"
REACT_APP_EDEN_CONTRACT: "${REACT_APP_EDEN_CONTRACT}"
HASURA_GRAPHQL_DATABASE_URL: "${HASURA_GRAPHQL_DATABASE_URL}"
HASURA_GRAPHQL_MIGRATIONS_DIR: /migrations
HASURA_GRAPHQL_METADATA_DIR: /metadata
Expand Down
1 change: 1 addition & 0 deletions webapp/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ build-docker: ./Dockerfile
-t $(DOCKER_REGISTRY)/$(IMAGE_NAME_WEBAPP):$(VERSION) --target server \
-t $(DOCKER_REGISTRY)/$(IMAGE_NAME_WEBAPP):$(LATEST_TAG) --target server \
--build-arg REACT_APP_RATING_CONTRACT="$(REACT_APP_RATING_CONTRACT)" \
--build-arg REACT_APP_EDEN_CONTRACT="$(REACT_APP_EDEN_CONTRACT)" \
--build-arg REACT_APP_GRAPHQL_HTTP_URL="$(REACT_APP_GRAPHQL_HTTP_URL)" \
--build-arg REACT_APP_GRAPHQL_WS_URL="$(REACT_APP_GRAPHQL_WS_URL)" \
--build-arg REACT_APP_EOS_API_URL="$(REACT_APP_EOS_API_URL)" \
Expand Down
3 changes: 3 additions & 0 deletions webapp/public/edenos.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 29 additions & 11 deletions webapp/src/components/app-bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ const MainTopBar = ({
useEffect(async () => {
if (!user) setMayVote(false)
else if (
user.voter_info.producers.length > 20 ||
user.voter_info.proxy.length > 0
user.voter_info &&
(user.voter_info.producers.length > 20 ||
user.voter_info.proxy.length > 0)
)
setMayVote(true)
}, [user])
Expand Down Expand Up @@ -111,15 +112,32 @@ const MainTopBar = ({
<SearchIcon />
</IconButton>
<Box style={{ marginRight: '10px', marginTop: '5px' }}>
{mayVote && (
<SpecialTooltip title={t('unlockedRating')}>
<LockOpenOutlinedIcon />
</SpecialTooltip>
)}
{!mayVote && (
<SpecialTooltip title={t('lockedRating')}>
<LockOutlinedIcon />
</SpecialTooltip>
{user && (
<>
{!user.edenMember && (
<>
{mayVote && (
<SpecialTooltip title={t('unlockedRating')}>
<LockOpenOutlinedIcon />
</SpecialTooltip>
)}
{!mayVote && (
<SpecialTooltip title={t('lockedRating')}>
<LockOutlinedIcon />
</SpecialTooltip>
)}
</>
)}
{user.edenMember && (
<SpecialTooltip title={t('edenMemberMessage')}>
<img
src='/edenos.svg'
alt='eden icon'
style={{ width: '28px' }}
/>
</SpecialTooltip>
)}
</>
)}
</Box>
<LanguageSelect />
Expand Down
2 changes: 2 additions & 0 deletions webapp/src/config/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export const appName = 'EOSRate'
export const contract = process.env.REACT_APP_RATING_CONTRACT || 'rateproducer'
export const contractEden =
process.env.REACT_APP_EDEN_CONTRACT || 'genesis.eden'
export const eosApiHost = process.env.REACT_APP_EOS_API_HOST
export const eosApiPort = process.env.REACT_APP_EOS_API_PORT
export const eosApiProtocol = process.env.REACT_APP_EOS_API_PROTOCOL
Expand Down
1 change: 1 addition & 0 deletions webapp/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"drawerLinkRicardianContract": "Ricardian Contract",
"drawerLinkHelp": "Help",
"lockedRating": "You must vote for at least 21 block producers or a proxy to unlock ratings",
"edenMemberMessage": "Eden member. Ratings unlocked.",
"unlockedRating": "You have voted for 21 bps or a proxy and have unlocked ratings",
"success" : "Success!",
"appBarSignIn": "Sign In",
Expand Down
1 change: 1 addition & 0 deletions webapp/src/language/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"drawerLinkRicardianContract": "Contratos Ricardianos",
"drawerLinkHelp": "Ayuda",
"lockedRating": "Debes votar por al menos 21 productores de bloques o un proxy para desbloquear calificaciones",
"edenMemberMessage": "Miembro de Eden. Calificaciones desbloqueadas.",
"unlockedRating": "Ha votado por 21 bps o un proxy y ha desbloqueado calificaciones",
"success": "¡Éxito!",
"appBarSignIn": "Iniciar Sesión",
Expand Down
21 changes: 20 additions & 1 deletion webapp/src/models/User/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import _get from 'lodash.get'
import apolloClient from 'services/graphql'
import { getRpc, getAccountName } from 'utils/eosjsUtils'

import { contractEden } from '../../config'
import QUERY_GET_RATES from './query_get_rates'
import MUTATION_DELETE_USER_RATE from './mutation_delete_user_rate'

Expand Down Expand Up @@ -36,9 +37,26 @@ const user = {

let account = null
let userRates = []
let edenMember = false
const rpc = getRpc(ual)
if (accountName.length) {
account = await rpc.get_account(accountName)

const { rows: edenMenbers } = await rpc.get_table_rows({
json: true,
code: contractEden,
scope: 0,
table: 'member',
reverse: false,
show_payer: false
})

for (const member of edenMenbers) {
if (accountName === member[1].account) {
edenMember = true
break
}
}
}

const {
Expand Down Expand Up @@ -67,7 +85,8 @@ const user = {
...account,
hasProxy: Boolean(proxy.length),
producersCount: producers.length,
userRates
userRates,
edenMember
})
: this.setUser(null)

Expand Down
4 changes: 3 additions & 1 deletion webapp/src/routes/block-producers/block-producer-rate.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ const BlockProducerRate = ({ account, ual }) => {
}, [])

useEffect(() => {
if (user && (user.hasProxy || user.producersCount >= 21)) {
if (user && user.edenMember) {
setShowAlert(false)
} else if (user && (user.hasProxy || user.producersCount >= 21)) {
setShowAlert(false)
} else {
user && setShowAlert(true)
Expand Down

0 comments on commit cd6885e

Please sign in to comment.