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

Syncing of milestone votes with chain and brief delete feature #268

Merged
merged 17 commits into from
Dec 20, 2023
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
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
Loading