Skip to content

Commit

Permalink
Merge branch 'main' into feature-create-rhs-cards
Browse files Browse the repository at this point in the history
  • Loading branch information
adetoye-dev authored Dec 4, 2023
2 parents 5a8062f + b1595ce commit d4c4abd
Show file tree
Hide file tree
Showing 124 changed files with 2,320 additions and 1,102 deletions.
4 changes: 2 additions & 2 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useRouter } from 'next/router';
import NextNProgress from 'nextjs-progressbar';
import { useEffect, useState } from 'react';
import AppLayout from 'src/components/AppLayout';
import CMDK from 'src/components/CMDK';
// import CMDK from 'src/components/CMDK';
import { antdTheme } from 'styles/antdTheme';

import { ApiContextProvider } from '~src/context/ApiContext';
Expand Down Expand Up @@ -93,7 +93,7 @@ function App({ Component, pageProps }: AppProps) {
{showSplashScreen && <SplashLoader />}
<main className={`${poppins.variable} ${poppins.className} ${robotoMono.className} ${workSans.className} ${showSplashScreen ? 'hidden' : ''}`}>
<NextNProgress color='#E5007A' />
<CMDK />
{/* <CMDK /> */}
<AppLayout
Component={Component}
pageProps={pageProps}
Expand Down
8 changes: 6 additions & 2 deletions pages/api/v1/auth/actions/addPostReaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import withErrorHandling from '~src/api-middlewares/withErrorHandling';
import { isValidNetwork } from '~src/api-utils';
import { postsByTypeRef } from '~src/api-utils/firestore_refs';
import authServiceInstance from '~src/auth/auth';
import { deleteKeys } from '~src/auth/redis';
import { deleteKeys, redisDel } from '~src/auth/redis';
import { MessageType } from '~src/auth/types';
import getTokenFromReq from '~src/auth/utils/getTokenFromReq';
import messages from '~src/auth/utils/messages';
Expand All @@ -20,7 +20,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse<MessageType>) {
const network = String(req.headers['x-network']);
if (!network || !isValidNetwork(network)) return res.status(400).json({ message: 'Missing network name in request headers' });

const { userId, postId, reaction, postType, trackNumber = null } = req.body;
const { userId, postId, reaction, postType, trackNumber } = req.body;
if (!userId || isNaN(postId) || !reaction || !postType) return res.status(400).json({ message: 'Missing parameters in request body' });

const token = getTokenFromReq(req);
Expand Down Expand Up @@ -65,10 +65,14 @@ async function handler(req: NextApiRequest, res: NextApiResponse<MessageType>) {
// delete referendum v2 redis cache
if (postType == ProposalType.REFERENDUM_V2) {
const trackListingKey = `${network}_${subsquidProposalType}_trackId_${trackNumber}_*`;
const referendumDetailKey = `${network}_OpenGov_${subsquidProposalType}_postId_${postId}`;
await redisDel(referendumDetailKey);
await deleteKeys(trackListingKey);
}
} else if (postType == ProposalType.DISCUSSIONS) {
const discussionListingKey = `${network}_${ProposalType.DISCUSSIONS}_page_*`;
const discussionDetailKey = `${network}_${ProposalType.DISCUSSIONS}_postId_${postId}`;
await redisDel(discussionDetailKey);
await deleteKeys(discussionListingKey);
}
}
Expand Down
5 changes: 4 additions & 1 deletion pages/api/v1/auth/actions/addProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import authServiceInstance from '~src/auth/auth';
import { ISocial, MessageType, TokenType } from '~src/auth/types';
import getTokenFromReq from '~src/auth/utils/getTokenFromReq';
import isValidEmail from '~src/auth/utils/isValidEmail';
import isValidPassowrd from '~src/auth/utils/isValidPassowrd';
import messages from '~src/auth/utils/messages';
import nameBlacklist from '~src/auth/utils/nameBlacklist';
import firebaseAdmin from '~src/services/firebaseInit';
Expand All @@ -17,7 +18,7 @@ import apiErrorWithStatusCode from '~src/util/apiErrorWithStatusCode';
async function handler(req: NextApiRequest, res: NextApiResponse<TokenType | MessageType>) {
const firestore = firebaseAdmin.firestore();
if (req.method !== 'POST') return res.status(405).json({ message: 'Invalid request method, POST required.' });
const { badges: badgesString, bio, image, title, social_links: socialLinksString, username, custom_username = false, email } = req.body;
const { badges: badgesString, bio, image, title, social_links: socialLinksString, username, custom_username = false, email, password } = req.body;
if (!username) return res.status(400).json({ message: 'Missing parameters in request body' });

for (let i = 0; i < nameBlacklist.length; i++) {
Expand Down Expand Up @@ -65,6 +66,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse<TokenType | Mes
}
if (!isValidEmail(email)) throw apiErrorWithStatusCode(messages.INVALID_EMAIL, 400);
await authServiceInstance.SendVerifyEmail(token, email, network);
if (!isValidPassowrd(password)) return res.status(400).json({ message: messages.PASSWORD_LENGTH_ERROR });
await authServiceInstance.ResetPasswordFromAuth(token, password);
}

//update profile field in userRef
Expand Down
26 changes: 13 additions & 13 deletions pages/api/v1/auth/actions/createOpengovTreasuryProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ const handler: NextApiHandler<CreatePostResponseType> = async (req, res) => {

if (isNaN(Number(userId)) || isNaN(Number(postId))) return res.status(400).json({ message: 'Invalid parameters in request body' });

if (discussionId < 0 || isNaN(discussionId)) return res.status(400).json({ message: messages.INVALID_DISCUSSION_ID });

const token = getTokenFromReq(req);
if (!token) return res.status(400).json({ message: 'Invalid token' });

Expand All @@ -40,20 +38,22 @@ const handler: NextApiHandler<CreatePostResponseType> = async (req, res) => {
}

const current_datetime = new Date();
const discussionDoc = postsByTypeRef(network, ProposalType.DISCUSSIONS).doc(String(discussionId));

if (!discussionDoc) {
return res.status(400).json({ message: `No discussion post found with id ${discussionId}.` });
if (Number(discussionId) >= 0 && !isNaN(Number(discussionId))) {
const discussionDoc = postsByTypeRef(network, ProposalType.DISCUSSIONS).doc(String(discussionId));

await discussionDoc.set(
{
last_edited_at: current_datetime,
post_link: {
id: Number(postId),
type: ProposalType.REFERENDUM_V2
}
},
{ merge: true }
);
}

discussionDoc.update({
last_edited_at: current_datetime,
post_link: {
id: Number(postId),
type: ProposalType.REFERENDUM_V2
}
});

const newPost: Post = {
content,
createdOnPolkassembly: true,
Expand Down
8 changes: 7 additions & 1 deletion pages/api/v1/auth/actions/createPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import messages from '~src/auth/utils/messages';
import { ProposalType } from '~src/global/proposalType';
import { firestore_db } from '~src/services/firebaseInit';
import { IPostTag, Post } from '~src/types';
import getSubstrateAddress from '~src/util/getSubstrateAddress';
import isContentBlacklisted from '~src/util/isContentBlacklisted';

async function handler(req: NextApiRequest, res: NextApiResponse<CreatePostResponseType>) {
Expand All @@ -24,7 +25,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse<CreatePostRespo
const network = String(req.headers['x-network']);
if (!network || !isValidNetwork(network)) return res.status(400).json({ message: 'Invalid network in request header' });

const { content, proposalType, title, topicId, userId, gov_type, tags } = req.body;
const { content, proposalType, title, topicId, userId, gov_type, tags, inductee_address } = req.body;
if (!content || !title || !topicId || !userId || !proposalType) return res.status(400).json({ message: 'Missing parameters in request body' });

if (typeof content !== 'string' || typeof title !== 'string' || isContentBlacklisted(title) || isContentBlacklisted(content)) {
Expand All @@ -33,6 +34,10 @@ async function handler(req: NextApiRequest, res: NextApiResponse<CreatePostRespo

if (tags && !Array.isArray(tags)) return res.status(400).json({ message: 'Invalid tags parameter' });

const substrate_inductee_address = getSubstrateAddress(inductee_address);

if (inductee_address && !substrate_inductee_address) return res.status(400).json({ message: 'Invalid inductee_address parameter' });

const strProposalType = String(proposalType);
if (!isOffChainProposalTypeValid(strProposalType)) return res.status(400).json({ message: `The off chain proposal type "${proposalType}" is invalid.` });

Expand Down Expand Up @@ -60,6 +65,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse<CreatePostRespo
gov_type: gov_type,
history: [],
id: newID,
inductee_address: substrate_inductee_address || '',
isDeleted: false,
last_comment_at,
last_edited_at: last_comment_at,
Expand Down
23 changes: 22 additions & 1 deletion pages/api/v1/auth/actions/removePostReaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ import withErrorHandling from '~src/api-middlewares/withErrorHandling';
import { isValidNetwork } from '~src/api-utils';
import { postsByTypeRef } from '~src/api-utils/firestore_refs';
import authServiceInstance from '~src/auth/auth';
import { deleteKeys, redisDel } from '~src/auth/redis';
import { MessageType } from '~src/auth/types';
import getTokenFromReq from '~src/auth/utils/getTokenFromReq';
import messages from '~src/auth/utils/messages';
import { ProposalType, getSubsquidLikeProposalType } from '~src/global/proposalType';

async function handler(req: NextApiRequest, res: NextApiResponse<MessageType>) {
if (req.method !== 'POST') return res.status(405).json({ message: 'Invalid request method, POST required.' });

const network = String(req.headers['x-network']);
if (!network || !isValidNetwork(network)) return res.status(400).json({ message: 'Missing network name in request headers' });

const { userId, postId, reaction, postType } = req.body;
const { userId, postId, reaction, postType, trackNumber } = req.body;
if (!userId || isNaN(postId) || !reaction || !postType) return res.status(400).json({ message: 'Missing parameters in request body' });

const token = getTokenFromReq(req);
Expand All @@ -30,6 +32,25 @@ async function handler(req: NextApiRequest, res: NextApiResponse<MessageType>) {
const postRef = postsByTypeRef(network, postType).doc(String(postId));
const userReactionsSnapshot = await postRef.collection('post_reactions').where('user_id', '==', user.id).limit(1).get();

const subsquidProposalType = getSubsquidLikeProposalType(postType);

if (process.env.IS_CACHING_ALLOWED == '1') {
if (!isNaN(trackNumber)) {
// delete referendum v2 redis cache
if (postType == ProposalType.REFERENDUM_V2) {
const trackListingKey = `${network}_${subsquidProposalType}_trackId_${trackNumber}_*`;
const referendumDetailKey = `${network}_OpenGov_${subsquidProposalType}_postId_${postId}`;
await redisDel(referendumDetailKey);
await deleteKeys(trackListingKey);
}
} else if (postType == ProposalType.DISCUSSIONS) {
const discussionListingKey = `${network}_${ProposalType.DISCUSSIONS}_page_*`;
const discussionDetailKey = `${network}_${ProposalType.DISCUSSIONS}_postId_${postId}`;
await redisDel(discussionDetailKey);
await deleteKeys(discussionListingKey);
}
}

if (!userReactionsSnapshot.empty) {
const reactionDocRef = userReactionsSnapshot.docs[0].ref;
await reactionDocRef
Expand Down
4 changes: 2 additions & 2 deletions pages/api/v1/verification/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const handler: NextApiHandler<IVerificationResponse | MessageType> = async (req,

const twitterData = twitterVerificationDoc.data();

if (twitterData?.twitter_handle !== account) return res.status(400).json({ message: 'Twitter handle does not match' });
if (`${twitterData?.twitter_handle}`.toLowerCase() !== `${account}`.toLowerCase()) return res.status(400).json({ message: 'Twitter handle does not match' });

if (twitterData?.verified && twitterData?.user_id === userId) {
return res.status(200).json({ message: VerificationStatus.ALREADY_VERIFIED });
Expand All @@ -124,7 +124,7 @@ const handler: NextApiHandler<IVerificationResponse | MessageType> = async (req,
} else {
await twitterVerificationDoc.ref.set({
created_at: new Date(),
twitter_handle: account,
twitter_handle: twitterData?.twitter_handle,
user_id: userId,
verified: false
});
Expand Down
3 changes: 1 addition & 2 deletions pages/api/v1/verification/twitter-callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ export const getTwitterCallback = async ({ network, oauthVerifier, oauthRequestT
oauthAccessToken,
oauthAccessTokenSecret
});

if (twitterDocData?.twitter_handle !== twitterUser?.screen_name) throw apiErrorWithStatusCode('Twitter handle does not match', 400);
if (twitterDocData?.twitter_handle.toLowerCase() !== twitterUser?.screen_name.toLowerCase()) throw apiErrorWithStatusCode('Twitter handle does not match', 400);

await twitterDoc.ref.set({
...twitterDocData,
Expand Down
39 changes: 39 additions & 0 deletions pages/api/v1/votes/ayeNayTotalCount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2019-2025 @polkassembly/polkassembly authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.

import type { NextApiHandler } from 'next';
import withErrorHandling from '~src/api-middlewares/withErrorHandling';
import { MessageType } from '~src/auth/types';
import messages from '~src/auth/utils/messages';
import { isProposalTypeValid, isValidNetwork } from '~src/api-utils';
import fetchSubsquid from '~src/util/fetchSubsquid';
import { GET_AYE_NAY_TOTAL_COUNT } from '~src/queries';

interface Props {
proposalType: string;
postId: number;
}

const handler: NextApiHandler<any | MessageType> = async (req, res) => {
const { proposalType, postId } = req.body as unknown as Props;

const network = String(req.headers['x-network']);
if (network === 'undefined' || !isValidNetwork(network)) return res.status(400).json({ message: messages.INVALID_NETWORK });
if (isNaN(Number(postId)) || isProposalTypeValid(proposalType)) return res.status(400).json({ message: messages.INVALID_PARAMS });
const query = GET_AYE_NAY_TOTAL_COUNT;

const variables: any = {
proposalIndex_eq: postId,
type_eq: proposalType
};

const data = await fetchSubsquid({
network,
query,
variables
});
res.json(data['data']);
};

export default withErrorHandling(handler);
3 changes: 3 additions & 0 deletions pages/delegation/[track].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { setNetwork } from '~src/redux/network';
import { ErrorState } from '~src/ui-components/UIStates';
import checkRouteNetworkWithRedirect from '~src/util/checkRouteNetworkWithRedirect';
import getQueryToTrack from '~src/util/getQueryToTrack';
import { useTheme } from 'next-themes';

export const getServerSideProps: GetServerSideProps = async ({ req, query }) => {
const network = getNetworkFromReqHeaders(req.headers);
Expand Down Expand Up @@ -57,6 +58,7 @@ interface ITrackProps {
const DashboardTracks: FC<ITrackProps> = (props) => {
const { data, error, trackDetails } = props;
const dispatch = useDispatch();
const { resolvedTheme: theme } = useTheme();

useEffect(() => {
dispatch(setNetwork(props.network));
Expand All @@ -76,6 +78,7 @@ const DashboardTracks: FC<ITrackProps> = (props) => {
<DashboardTrackListing
posts={posts}
trackDetails={trackDetails}
theme={theme}
/>
</>
);
Expand Down
3 changes: 2 additions & 1 deletion pages/delegation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import { useRouter } from 'next/router';
import checkRouteNetworkWithRedirect from '~src/util/checkRouteNetworkWithRedirect';
import { useDispatch } from 'react-redux';
import { setNetwork } from '~src/redux/network';
import { delegationSupportedNetworks } from '~src/components/DelegationDashboard';

export const getServerSideProps: GetServerSideProps = async ({ req }) => {
const network = getNetworkFromReqHeaders(req.headers);

const networkRedirect = checkRouteNetworkWithRedirect(network);
if (networkRedirect) return networkRedirect;

if (!['kusama', 'polkadot'].includes(network)) {
if (!delegationSupportedNetworks.includes(network)) {
return {
props: {},
redirect: {
Expand Down
8 changes: 7 additions & 1 deletion pages/user/[username].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ const UserProfile: FC<IUserProfileProps> = (props) => {
};
});

const sortTabItemsByCount = (tabItems: any) => {
return tabItems.sort((a: any, b: any) => b?.label?.props?.count - a?.label?.props?.count);
};

const sortedTabItems = sortTabItemsByCount(tabItems);

return (
<>
<SEOHead
Expand Down Expand Up @@ -247,7 +253,7 @@ const UserProfile: FC<IUserProfileProps> = (props) => {
theme={theme}
className='ant-tabs-tab-bg-white font-medium text-sidebarBlue dark:bg-section-dark-overlay'
type='card'
items={tabItems as any}
items={sortedTabItems as any}
/>
</div>
)}
Expand Down
4 changes: 4 additions & 0 deletions public/assets/delegate-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions public/assets/icons/Beneficiary.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d4c4abd

Please sign in to comment.