Skip to content

Commit

Permalink
Added no vote list (#256)
Browse files Browse the repository at this point in the history
* moved global css files to _app.tsx

* latest fixes

* reviewed changes

* no confidence vote for both votes added

* removed old project page

* blocked unauthorized users fron applications and projects

* reviewed changes

* fixed no confidence vote list

* build fixes

* removed briefs/id/applications page

* refund flow optimization

* blocked unauthorized brief owners from applications
  • Loading branch information
ssani7 authored Nov 13, 2023
1 parent 96606f9 commit f852a17
Show file tree
Hide file tree
Showing 24 changed files with 303 additions and 1,774 deletions.
10 changes: 6 additions & 4 deletions src/components/Application/BriefOwnerHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ const BriefOwnerHeader = (props: BriefOwnerHeaderProps) => {
user,
} = props;

const [balance, setBalance] = useState<string>();
const [imbueBalance, setImbueBalance] = useState<string>();
const [balance, setBalance] = useState<number | undefined>();
const [imbueBalance, setImbueBalance] = useState<number | undefined>();
const [loadingWallet, setLoadingWallet] = useState<string>('loading');
const [error, setError] = useState<any>();

Expand Down Expand Up @@ -129,13 +129,15 @@ const BriefOwnerHeader = (props: BriefOwnerHeaderProps) => {
user?.web3_address,
application.id
);

const imbueBalance = await getBalance(
Currency.IMBU,
user,
user?.web3_address
);
setBalance(balance.toLocaleString());
setImbueBalance(imbueBalance.toLocaleString());

setBalance(Number(balance) || 0);
setImbueBalance(Number(imbueBalance) || 0);
} catch (error) {
setError({ message: error });
} finally {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ClientView/ClientView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function ClientView({
onClick={() => setSwitcher('projects')}
className='text-2xl text-black py-5 border-r text-center w-full'
>
Projects({briefs?.acceptedBriefs.length})
Projects({briefs?.acceptedBriefs?.length})
</p>
<p
onClick={() => setSwitcher('grants')}
Expand Down
43 changes: 43 additions & 0 deletions src/components/CopyToClipboardToast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Alert } from '@mui/material';
import React, { ReactNode, useState } from 'react';


interface CopyToClipboardProps {
link: string;
title: string;
children: ReactNode;
extraClass?: string;
}

const CopyToClipboardToast = (props: CopyToClipboardProps) => {
const { link, title, children, extraClass } = props;
const [copied, setCopied] = useState<string>('');

const copyToClipboard = () => {
const textToCopy = link || '';

navigator.clipboard.writeText(textToCopy);
setCopied(title);

setTimeout(() => {
setCopied('');
}, 3000);
};

return (
<div className='inline'>
<div
className={`fixed ${extraClass || "top-5"} z-10 transform duration-300 transition-all ${copied ? 'right-5' : '-right-full'
}`}
>
<Alert severity='success'>{`${copied} Copied to clipboard`}</Alert>
</div>

<div className='inline cursor-pointer' onClick={copyToClipboard}>
{children}
</div>
</div>
);
};

export default CopyToClipboardToast;
41 changes: 29 additions & 12 deletions src/components/Dashboard/MyClientBriefsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
//import ArrowBackIcon from '@mui/icons-material/ArrowBack';
import { useRouter } from 'next/router';
import React, { useEffect, useState } from 'react';
import { useSelector } from 'react-redux';

import { Freelancer, Project } from '@/model';
import {
getBriefApplications,
getUserBriefs,
} from '@/redux/services/briefService';
import { getUsersOngoingGrants } from '@/redux/services/projectServices';
import { RootState } from '@/redux/store/store';

// import OngoingProject from './FreelacerView/OngoingProject/OngoingProject';
// import { ApplicationContainer } from '../Briefs/ApplicationContainer';
Expand All @@ -20,12 +22,13 @@ type ClientViewProps = {
briefId: string | string[] | undefined;
handleMessageBoxClick: (_userId: number, _freelander: Freelancer) => void;
redirectToBriefApplications: (_applicationId: string) => void;
user: any;
};

const MyClientBriefsView = (props: ClientViewProps) => {
const { user, briefId, handleMessageBoxClick, redirectToBriefApplications } =
props;
const { briefId, handleMessageBoxClick, redirectToBriefApplications } = props;

const { user, loading } = useSelector((state: RootState) => state.userState);


const [briefs, _setBriefs] = useState<any>();
const [briefApplications, setBriefApplications] = useState<Project[]>([]);
Expand All @@ -35,25 +38,39 @@ const MyClientBriefsView = (props: ClientViewProps) => {

useEffect(() => {
const setUserBriefs = async () => {
if (user?.id) _setBriefs(await getUserBriefs(user?.id));
setOngoingGrants(await getUsersOngoingGrants(user?.web3_address));
if (!user.id) return router.push('/auth/sign-in')

_setBriefs(await getUserBriefs(user?.id));

if (user?.web3_address)
setOngoingGrants(await getUsersOngoingGrants(user?.web3_address));
};
setUserBriefs();
}, [user?.id, user?.web3_address]);
!loading && setUserBriefs();

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [user.id, user?.web3_address, loading]);

useEffect(() => {
const getApplications = async (id: string | number) => {
const getApplications = async () => {
if (!briefId) return

try {
setLoadingApplications(true);
setBriefApplications(await getBriefApplications(id));
const resp = await getBriefApplications(String(briefId));

if (resp.status === 501)
return router.push('/dashboard');

setBriefApplications(resp);
setLoadingApplications(false);
} catch (error) {
console.log(error);
} finally {
setLoadingApplications(false);
}
};
briefId && getApplications(briefId.toString());
}, [briefId, user?.id]);

briefId && getApplications();
}, [briefId, loading, router]);

const goBack = () => {
router.query.briefId = [];
Expand Down
31 changes: 23 additions & 8 deletions src/components/HirePopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { getOffchainEscrowAddress, getOffchainEscrowBalance, mintTokens } from '
import { RootState } from '@/redux/store/store';

import AccountChoice from './AccountChoice';
import CopyToClipboardToast from './CopyToClipboardToast';
import ErrorScreen from './ErrorScreen';
import SuccessScreen from './SuccessScreen';
import styles from '../styles/modules/hire-modal.module.css';
Expand Down Expand Up @@ -74,12 +75,19 @@ export const HirePopup = ({


const updateEscrowInfo = async () => {
const escrowAddress = await getOffchainEscrowAddress(application.id);
setEscrowAddress(escrowAddress);
const allBalances = await getOffchainEscrowBalance(application.id);
const currency = Currency[application.currency_id].toString().toLowerCase();
const escrowBalance = Number(allBalances[currency]) ?? 0;
setEscrowBalance(escrowBalance);
try {
const escrowAddress = await getOffchainEscrowAddress(application.id);

if (escrowAddress?.status !== "Failed")
setEscrowAddress(escrowAddress);

const allBalances = await getOffchainEscrowBalance(application.id);
const currency = Currency[application.currency_id].toString().toLowerCase();
const escrowBalance = Number(allBalances[currency]) || 0;
setEscrowBalance(escrowBalance);
} catch (error) {
setError({ message: "Failed to load payment info" })
}
};

useEffect(() => {
Expand Down Expand Up @@ -379,8 +387,15 @@ export const HirePopup = ({
</p>
<p className='mb-10'>
<span>Escrow Address:</span>
<span className='text-lg lg:text-xl text-imbue-lemon mr-1'>
{escrowAddress}
<span
className='text-lg lg:text-xl text-imbue-lemon ml-1 font-mono'
>
<CopyToClipboardToast
title='Payment address'
link={escrowAddress}
>
{escrowAddress}
</CopyToClipboardToast>
</span>
</p>
<p className='mb-10'>
Expand Down
Loading

0 comments on commit f852a17

Please sign in to comment.