Skip to content

Commit

Permalink
Syncing of milestone votes with chain and brief delete feature (#268)
Browse files Browse the repository at this point in the history
* milestone votes sync added

* balance fixes

* brief optimization

* made balance fetching once for brief ownder in application

* relete brief added

* fix for hire rate and job posted

* project posted fix

* hire rate formula fix

* only mint tokens when its required

* show error message to user

* reduced balance fetch

* dummy commit to restart the build

* amend the verified freelancer only flag

* round off hire rate

* purge brief application get api authentication for showing brief data to all

* range added for brief applications

---------

Co-authored-by: samelamin <[email protected]>
  • Loading branch information
ssani7 and samelamin committed Dec 20, 2023
1 parent 1c2fc05 commit c64ed62
Show file tree
Hide file tree
Showing 27 changed files with 946 additions and 595 deletions.
24 changes: 17 additions & 7 deletions src/components/Application/ApplicationOwnerHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React, { useEffect, useState } from 'react';

import { Brief } from '@/lib/models';
import { showErrorMessage } from '@/utils/errorMessages';
import { getBalance } from '@/utils/helper';
import { initImbueAPIInfo } from '@/utils/polkadot';

import {
Expand Down Expand Up @@ -37,7 +38,7 @@ type ApplicationOwnerProps = {
_escrow_address?: string
) => Promise<void>;
user: User | any;
imbueBalance: string | any;
// imbueBalance: string;
};

const ApplicationOwnerHeader = (props: ApplicationOwnerProps) => {
Expand All @@ -49,14 +50,15 @@ const ApplicationOwnerHeader = (props: ApplicationOwnerProps) => {
setLoading,
updateProject,
user,
imbueBalance,
// imbueBalance,
} = props;

const [openPopup, setOpenPopup] = useState(false);
const [success, setSuccess] = useState<boolean>(false);
const [error, setError] = useState<any>();
const [loadingWallet, setLoadingWallet] = useState<string>('loading');
const [firstLoad, setFirstLoad] = useState<boolean>(true);
const [imbueBalance, setImbueBalance] = useState<string>();

const router = useRouter();

Expand All @@ -66,6 +68,14 @@ const ApplicationOwnerHeader = (props: ApplicationOwnerProps) => {

try {

const balance = await getBalance(
Currency.IMBU,
user,
user?.web3_address
);

setImbueBalance(balance.toLocaleString());

if (firstLoad)
setLoadingWallet('loading');

Expand All @@ -77,12 +87,12 @@ const ApplicationOwnerHeader = (props: ApplicationOwnerProps) => {
setFirstLoad(false)
}
};
// user?.web3_address && showBalance();
user?.web3_address && showBalance();

const timer = setInterval(() => {
user?.web3_address && showBalance();
}, 5000);
return () => clearInterval(timer);
// const timer = setInterval(() => {
// user?.web3_address && showBalance();
// }, 5000);
// return () => clearInterval(timer);

}, [user?.web3_address, application.currency_id, user, loadingWallet, firstLoad]);

Expand Down
61 changes: 24 additions & 37 deletions src/components/Application/BriefOwnerHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ const BriefOwnerHeader = (props: BriefOwnerHeaderProps) => {
} = props;

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

const [openPopup, setOpenPopup] = useState<boolean>(false);
Expand Down Expand Up @@ -117,11 +116,16 @@ const BriefOwnerHeader = (props: BriefOwnerHeaderProps) => {
useEffect(() => {
const showBalance = async () => {

if (loadingWallet === 'loading' && !firstLoad) return;
// if (loadingWallet === 'loading' && !firstLoad) return;
if (loadingWallet === 'loading' || !user.web3_address || !application.id) return;

setLoadingWallet('loading')

console.log("hit");

try {
if (firstLoad)
setLoadingWallet('loading');
// if (firstLoad)
// setLoadingWallet('loading');

const balance = await getBalance(
application?.currency_id ?? Currency.IMBU,
Expand All @@ -130,14 +134,7 @@ const BriefOwnerHeader = (props: BriefOwnerHeaderProps) => {
application.id
);

const imbueBalance = await getBalance(
Currency.IMBU,
user,
user?.web3_address
);

setBalance(Number(balance) || 0);
setImbueBalance(Number(imbueBalance) || 0);
} catch (error) {
setError({ message: error });
} finally {
Expand All @@ -146,14 +143,15 @@ const BriefOwnerHeader = (props: BriefOwnerHeaderProps) => {
setFirstLoad(false)
}
};
// user?.web3_address && showBalance();

const timer = setInterval(() => {
user?.web3_address && showBalance();
}, 5000);
return () => clearInterval(timer);
user?.web3_address && showBalance();

}, [user?.web3_address, application.currency_id, user, loadingWallet, firstLoad]);
// const timer = setInterval(() => {
// user?.web3_address && showBalance();
// }, 5000);
// return () => clearInterval(timer);

}, [user?.web3_address, application?.currency_id]);

const mobileView = useMediaQuery('(max-width:480px)');

Expand Down Expand Up @@ -339,25 +337,14 @@ const BriefOwnerHeader = (props: BriefOwnerHeaderProps) => {

<div className='flex flex-col gap-1 mt-5 justify-center lg:items-end'>
<p className='text-content'>Escrow Balance</p>
{application?.currency_id !== Currency.IMBU ? (
<p className='text-sm text-imbue-purple'>
{loadingWallet === 'loading' && 'Loading Wallet...'}
{loadingWallet === 'connecting' && 'Connecting Wallet...'}
{loadingWallet !== 'loading' &&
(balance === undefined
? 'No wallet found'
: `$${Currency[application?.currency_id ?? 0]}: ${balance}`)}
</p>
) : (
<p className='text-sm lg:text-base text-imbue-purple'>
{loadingWallet === 'loading' && 'Loading Wallet...'}
{loadingWallet === 'connecting' && 'Connecting Wallet...'}
{!loadingWallet &&
(balance === undefined
? 'No wallet found'
: `$${Currency[Currency.IMBU]}: ${imbueBalance}`)}
</p>
)}
<p className='text-sm text-imbue-purple'>
{loadingWallet === 'loading' && 'Loading Wallet...'}
{loadingWallet === 'connecting' && 'Connecting Wallet...'}
{loadingWallet !== 'loading' &&
(balance === undefined
? 'No wallet found'
: `$${Currency[application?.currency_id ?? 0]}: ${balance}`)}
</p>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/components/BackButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const BackButton = (props: JSX.IntrinsicAttributes & React.ClassAttributes<HTMLD
onClick={() => router.back()}
className='border border-transparent hover:border-content rounded-full flex items-center justify-center cursor-pointer'
>
<ArrowBackIcon className='h-7 w-7 group-hover:text-white' color='secondary' />
<ArrowBackIcon className='h-full w-full max-w-[28px] group-hover:text-white' color='secondary' />
</div>
</Tooltip>
</div>
Expand Down
Loading

0 comments on commit c64ed62

Please sign in to comment.