Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCT-1833: Websockets don't work (project_donors, project_rewards) #371

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions backend/app/infrastructure/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ def handle_connect():
project_rewards = get_estimated_project_rewards().rewards
emit("project_rewards", _serialize_project_rewards(project_rewards))

for project in project_rewards:
donors = controller.get_all_donations_by_project(project.address)
emit(
"project_donors",
{"project": project.address, "donors": _serialize_donors(donors)},
)


@socketio.on("disconnect")
def handle_disconnect():
Expand Down
14 changes: 7 additions & 7 deletions ci/argocd/contracts/uat.env
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
BLOCK_NUMBER=6372841
BLOCK_NUMBER=6440834
GLM_CONTRACT_ADDRESS=0x71432DD1ae7DB41706ee6a22148446087BdD0906
AUTH_CONTRACT_ADDRESS=0xC0Dbb4117f48199C41784ACDdF534613435A633a
DEPOSITS_CONTRACT_ADDRESS=0x6462cC5dE29E1dd238f489a7bFfbb1C0E2A7543B
EPOCHS_CONTRACT_ADDRESS=0xD7c16938d22f111C7725a9f02abdbC282f7a4701
PROPOSALS_CONTRACT_ADDRESS=0x95ECcB9f1b036718fCb6d35b28c0D7c0CB69b768
WITHDRAWALS_TARGET_CONTRACT_ADDRESS=0x88a89528b7C1FaadCB4A83765206cfbDFafCa077
VAULT_CONTRACT_ADDRESS=0x5833e8e7d4d90d3B1b872186DEB62faE97DA6634
AUTH_CONTRACT_ADDRESS=0xab594179cD009616fD183259F3b9d68270faA053
DEPOSITS_CONTRACT_ADDRESS=0xe6E9332995F0469D33fa6296D0A432bD9fe8Db60
EPOCHS_CONTRACT_ADDRESS=0x323F991FC3659507Ef5eA9385D72bF31cb468033
PROPOSALS_CONTRACT_ADDRESS=0xead93af66E5C2228Cd047Cd70891405111fA3548
WITHDRAWALS_TARGET_CONTRACT_ADDRESS=0x077265B94EeF6c40B725c0426331bcc8DBFC7Ee0
VAULT_CONTRACT_ADDRESS=0x0c6c38FB0e5222727389E6efe0E654bD5b9D4484
8 changes: 2 additions & 6 deletions client/src/api/queryKeys/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const ROOTS: Root = {
individualReward: 'individualReward',
matchedProjectRewards: 'matchedProjectRewards',
patronMode: 'patronMode',
projectDonors: 'projectDonors',
projectRewardsThreshold: 'projectRewardsThreshold',
projectsDonors: 'projectsDonors',
projectsEpoch: 'projectsEpoch',
projectsIpfsResults: 'projectsIpfsResults',
upcomingBudget: 'upcomingBudget',
Expand Down Expand Up @@ -56,12 +56,8 @@ export const QUERY_KEYS: QueryKeys = {
lockedSummarySnapshots: ['lockedSummarySnapshots'],
matchedProjectRewards: epochNumber => [ROOTS.matchedProjectRewards, epochNumber.toString()],
patronMode: userAddress => [ROOTS.patronMode, userAddress],
projectDonors: (projectAddress, epochNumber) => [
ROOTS.projectDonors,
projectAddress,
epochNumber.toString(),
],
projectRewardsThreshold: epochNumber => [ROOTS.projectRewardsThreshold, epochNumber.toString()],
projectsDonors: epochNumber => [ROOTS.projectsDonors, epochNumber.toString()],
projectsEpoch: epochNumber => [ROOTS.projectsEpoch, epochNumber.toString()],
projectsIpfsResults: (projectAddress, epochNumber) => [
ROOTS.projectsIpfsResults,
Expand Down
7 changes: 2 additions & 5 deletions client/src/api/queryKeys/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export type Root = {
individualReward: 'individualReward';
matchedProjectRewards: 'matchedProjectRewards';
patronMode: 'patronMode';
projectDonors: 'projectDonors';
projectRewardsThreshold: 'projectRewardsThreshold';
projectsDonors: 'projectsDonors';
projectsEpoch: 'projectsEpoch';
projectsIpfsResults: 'projectsIpfsResults';
upcomingBudget: 'upcomingBudget';
Expand Down Expand Up @@ -58,11 +58,8 @@ export type QueryKeys = {
lockedSummarySnapshots: ['lockedSummarySnapshots'];
matchedProjectRewards: (epochNumber: number) => [Root['matchedProjectRewards'], string];
patronMode: (userAddress: string) => [Root['patronMode'], string];
projectDonors: (
projectAddress: string,
epochNumber: number,
) => [Root['projectDonors'], string, string];
projectRewardsThreshold: (epochNumber: number) => [Root['projectRewardsThreshold'], string];
projectsDonors: (epochNumber: number) => [Root['projectsDonors'], string];
projectsEpoch: (epochNumber: number) => [Root['projectsEpoch'], string];
projectsIpfsResults: (
projectAddress: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';

import Svg from 'components/ui/Svg';
import useGetValuesToDisplay from 'hooks/helpers/useGetValuesToDisplay';
import useProjectDonors from 'hooks/queries/donors/useProjectDonors';
import useProjectsDonors from 'hooks/queries/donors/useProjectsDonors';
import useCurrentEpoch from 'hooks/queries/useCurrentEpoch';
import useIsDecisionWindowOpen from 'hooks/queries/useIsDecisionWindowOpen';
import useMatchedProjectRewards from 'hooks/queries/useMatchedProjectRewards';
Expand Down Expand Up @@ -107,7 +107,8 @@ const AllocationItemRewards: FC<AllocationItemRewardsProps> = ({
const { data: matchedProjectRewards } = useMatchedProjectRewards();
const { data: uqScore } = useUqScore(currentEpoch!);

const { data: projectDonors } = useProjectDonors(address);
const { data: projectsDonors } = useProjectsDonors();
const projectDonors = projectsDonors?.[address];

// value can an empty string, which crashes parseUnits. Hence the alternative.
const valueToUse = value || '0';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const MetricsEpoch = (): ReactElement => {
useEpochUnusedRewards(epoch);

const ethBelowThreshold =
projectRewardsThreshold === undefined
projectRewardsThreshold === undefined || projectsDonors === undefined
? BigInt(0)
: Object.values(projectsDonors).reduce((acc, curr) => {
const projectSumOfDonations = curr.reduce((acc2, curr2) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ProjectDonorsHeader from 'components/Project/ProjectDonorsHeader';
import ProjectDonorsList from 'components/Project/ProjectDonorsList';
import Button from 'components/ui/Button';
import { DONORS_SHORT_LIST_LENGTH } from 'constants/donors';
import useProjectDonors from 'hooks/queries/donors/useProjectDonors';
import useProjectsDonors from 'hooks/queries/donors/useProjectsDonors';
import useCurrentEpoch from 'hooks/queries/useCurrentEpoch';

import styles from './ProjectDonors.module.scss';
Expand All @@ -23,12 +23,11 @@ const ProjectDonors: FC<ProjectDonorsProps> = ({
const { data: currentEpoch } = useCurrentEpoch();

const epochNumber = parseInt(epoch!, 10);

const { t } = useTranslation('translation', { keyPrefix: 'components.dedicated.donors' });
const { data: projectDonors, isFetching } = useProjectDonors(
projectAddress,
const { data: projectsDonors, isFetching } = useProjectsDonors(
epochNumber === currentEpoch ? undefined : epochNumber,
);
const projectDonors = projectsDonors?.[projectAddress];

const [isFullDonorsListModalOpen, setIsFullDonorsListModalOpen] = useState(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { FC, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useParams } from 'react-router-dom';

import useProjectDonors from 'hooks/queries/donors/useProjectDonors';
import useProjectsDonors from 'hooks/queries/donors/useProjectsDonors';
import useCurrentEpoch from 'hooks/queries/useCurrentEpoch';

import styles from './ProjectDonorsHeader.module.scss';
Expand All @@ -20,16 +20,19 @@ const ProjectDonorsHeader: FC<ProjectDonorsListProps> = ({

const epochNumber = parseInt(epoch!, 10);

const { data: projectDonors, isFetching } = useProjectDonors(
projectAddress,
const { data: projectsDonors, isFetching } = useProjectsDonors(
epochNumber === currentEpoch ? undefined : epochNumber,
);
const projectDonors = projectsDonors?.[projectAddress];

const numberOfDonors = useMemo(() => {
if (epochNumber === currentEpoch) {
return 0;
}
return isFetching ? '--' : projectDonors?.length;
if (isFetching) {
return '---';
}
return projectDonors?.length || '0';
}, [isFetching, projectDonors, epochNumber, currentEpoch]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ProjectDonorsListItem from 'components/Project/ProjectDonorsListItem';
import ProjectDonorsListSkeletonItem from 'components/Project/ProjectDonorsListSkeletonItem';
import ProjectDonorsListTotalDonated from 'components/Project/ProjectDonorsListTotalDonated';
import { DONORS_SHORT_LIST_LENGTH } from 'constants/donors';
import useProjectDonors from 'hooks/queries/donors/useProjectDonors';
import useProjectsDonors from 'hooks/queries/donors/useProjectsDonors';
import useCurrentEpoch from 'hooks/queries/useCurrentEpoch';

import styles from './ProjectDonorsList.module.scss';
Expand All @@ -23,10 +23,10 @@ const ProjectDonorsList: FC<ProjectDonorsListProps> = ({

const epochNumber = parseInt(epoch!, 10);

const { data: projectDonors, isFetching } = useProjectDonors(
projectAddress,
const { data: projectsDonors, isFetching } = useProjectsDonors(
epochNumber === currentEpoch ? undefined : epochNumber,
);
const projectDonors = projectsDonors?.[projectAddress];

return (
<div className={cx(styles.root, className)} data-test={dataTest}>
Expand Down
39 changes: 12 additions & 27 deletions client/src/components/Project/ProjectList/ProjectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,18 @@ import ProjectListProps from './types';

const ProjectList: FC<ProjectListProps> = ({ projects, epoch }) => (
<>
{projects.map(
(
{
address,
description,
name,
profileImageSmall,
website,
totalValueOfAllocations,
numberOfDonors,
},
index,
) => (
<ProjectListItem
key={address}
address={address}
description={description}
epoch={epoch}
index={index}
name={name}
numberOfDonors={numberOfDonors}
profileImageSmall={profileImageSmall}
totalValueOfAllocations={totalValueOfAllocations}
website={website}
/>
),
)}
{projects.map(({ address, description, name, profileImageSmall, website }, index) => (
<ProjectListItem
key={address}
address={address}
description={description}
epoch={epoch}
index={index}
name={name}
profileImageSmall={profileImageSmall}
website={website}
/>
))}
</>
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { FC, Fragment, memo, useMemo } from 'react';
import React, { FC, Fragment, useMemo } from 'react';

import ProjectDonors from 'components/Project/ProjectDonors';
import ProjectListItemHeader from 'components/Project/ProjectListItemHeader';
import RewardsWithoutThreshold from 'components/shared/RewardsWithoutThreshold';
import RewardsWithThreshold from 'components/shared/RewardsWithThreshold';
import Description from 'components/ui/Description';
import useCurrentEpoch from 'hooks/queries/useCurrentEpoch';
import useProjectsIpfsWithRewards from 'hooks/queries/useProjectsIpfsWithRewards';
import decodeBase64ToUtf8 from 'utils/decodeBase64ToUtf8';

import styles from './ProjectListItem.module.scss';
Expand All @@ -19,9 +20,13 @@ const ProjectListItem: FC<ProjectListItemProps> = ({
website,
index,
epoch,
totalValueOfAllocations,
numberOfDonors,
}) => {
const { data: projectsIpfsWithRewards } = useProjectsIpfsWithRewards(epoch);
const projectIpfsWithRewards = projectsIpfsWithRewards.find(p => p.address === address);
// loadedProjects (ProjectView) aren't updated during changes in open AW
// to provide live updates, the following values are taken directly from projectsIpfsWithRewards
const numberOfDonors = projectIpfsWithRewards?.numberOfDonors || 0;
const totalValueOfAllocations = projectIpfsWithRewards?.totalValueOfAllocations || 0n;
const { data: currentEpoch } = useCurrentEpoch();
const isEpoch1 = currentEpoch === 1;

Expand Down Expand Up @@ -66,4 +71,4 @@ const ProjectListItem: FC<ProjectListItemProps> = ({
);
};

export default memo(ProjectListItem);
export default ProjectListItem;
2 changes: 0 additions & 2 deletions client/src/components/Project/ProjectListItem/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ export default interface ProjectListItemProps {
epoch?: number;
index: number;
name?: string;
numberOfDonors: number;
profileImageSmall?: string;
totalValueOfAllocations?: bigint;
website?: {
label?: string;
url: string;
Expand Down
3 changes: 3 additions & 0 deletions client/src/hooks/helpers/useSubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export default function useSubscription<TData>({
}

websocketService().then(socket => {
if (socket.default.hasListeners(event)) {
return;
}
aziolek marked this conversation as resolved.
Show resolved Hide resolved
socket.default.on(event, data => {
callback(data);
});
Expand Down
60 changes: 0 additions & 60 deletions client/src/hooks/queries/donors/useProjectDonors.ts

This file was deleted.

Loading