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

Hotfix 2.33.1 #4817

Merged
merged 14 commits into from
Oct 4, 2024
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "givethdapp",
"version": "2.33.0",
"version": "2.33.1",
"private": true,
"scripts": {
"build": "next build",
Expand Down
2 changes: 1 addition & 1 deletion pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
const defaultLocale = process.env.defaultLocale;

// Check that PostHog is client-side (used to handle Next.js SSR)
if (typeof window !== 'undefined') {
if (typeof window !== 'undefined' && isProduction) {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY || '', {
api_host:
process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://us.i.posthog.com',
Expand Down Expand Up @@ -125,7 +125,7 @@
!isBypassingMaintenance;

useEffect(() => {
const handleStart = (url: string) => {

Check warning on line 128 in pages/_app.tsx

View workflow job for this annotation

GitHub Actions / build

'url' is defined but never used. Allowed unused args must match /^_/u
NProgress.start();
};
const handleChangeComplete = (url: string) => {
Expand Down Expand Up @@ -182,7 +182,7 @@
}
};
asyncFunc();
}, []);

Check warning on line 185 in pages/_app.tsx

View workflow job for this annotation

GitHub Actions / build

React Hook useEffect has missing dependencies: 'asPath', 'pathname', 'query', and 'router'. Either include them or remove the dependency array

return (
<>
Expand Down
10 changes: 9 additions & 1 deletion src/components/modals/SearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,15 @@ export const SearchModal: FC<IModal> = ({ setShowModal }) => {

useEffect(() => {
if (term) {
router.push(`${Routes.AllProjects}?searchTerm=${term}`);
const updatedQuery = {
...router.query,
searchTerm: term,
sort: EProjectsSortBy.BestMatch,
};
router.push({
pathname: Routes.AllProjects,
query: updatedQuery,
});
closeModal();
}
}, [closeModal, router, term]);
Expand Down
1 change: 0 additions & 1 deletion src/components/project-card/ProjectCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ const ProjectCard = (props: IProjectCard) => {
);
setRecurringDonationSumInQF(totalAmountStreamed);
}
console.log(id, totalAmountStreamed);
}
};

Expand Down
38 changes: 0 additions & 38 deletions src/components/views/donate/DonateIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
Flex,
B,
Button,
H4,
} from '@giveth/ui-design-system';
import { useIntl } from 'react-intl';
import { useRouter } from 'next/router';
Expand Down Expand Up @@ -459,41 +458,4 @@ const ButtonStyled = styled(Button)`
text-transform: capitalize;
`;

const ProjectImage = styled.img`
border-radius: 16px;
width: 100%;
object-fit: cover; // Ensures the image covers the entire container
height: 380px;
position: relative;
`;

const GradientOverlay = styled.div`
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 380px;
background: linear-gradient(
to top,
rgba(1, 1, 27, 0.6),
transparent
); /* Dark navy to transparent gradient */
border-radius: 16px;
`;

const Title = styled(H4)`
position: absolute;
bottom: 40px;
left: 40px;
color: #ffffff;
font-weight: bold;
text-align: left;
z-index: 1;
max-width: 90%; // Set max-width to a suitable percentage value based on your preference
white-space: pre-wrap; // Allows the text to wrap to the next line
> div:first-child {
margin-bottom: 4px;
}
`;

export default DonateIndex;
7 changes: 0 additions & 7 deletions src/components/views/donate/DonatePageProjectDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
P,
IconChevronRight16,
brandColors,
mediaQueries,
Flex,
H5,
semanticColors,
Expand Down Expand Up @@ -230,12 +229,6 @@ const DescriptionSummary = styled(P)`
const DonationSectionWrapper = styled(Flex)`
justify-content: space-between;
flex-direction: column;
${mediaQueries.tablet} {
flex-direction: row;
}
${mediaQueries.laptopS} {
flex-direction: column;
}
`;

const DonateDescription = styled(Flex)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import { useGeneralWallet } from '@/providers/generalWalletProvider';
import { wagmiConfig } from '@/wagmiConfigs';
import { ChainType } from '@/types/config';
import { getBalanceForToken } from './services';
import { fetchTokenBalances } from '@/services/token';
import { Spinner } from '@/components/Spinner';
import { fetchEVMTokenBalances } from '@/services/token';
import { WrappedSpinner } from '@/components/Spinner';

export interface ISelectTokenModalProps extends IModal {
tokens?: IProjectAcceptedToken[];
Expand Down Expand Up @@ -181,7 +181,7 @@ const SelectTokenInnerModal: FC<ISelectTokenModalProps> = ({
try {
setBalanceIsLoading(true);
const balances = isOnEVM
? await fetchTokenBalances(filteredTokens, walletAddress)
? await fetchEVMTokenBalances(filteredTokens, walletAddress)
: await Promise.all(
filteredTokens.map(async token => {
return {
Expand All @@ -195,7 +195,7 @@ const SelectTokenInnerModal: FC<ISelectTokenModalProps> = ({
}),
);
setTokenBalances(balances);
setBalanceIsLoading(true);
setBalanceIsLoading(false);
} catch (error) {
console.error('error on fetchTokenBalances', { error });
}
Expand Down Expand Up @@ -264,7 +264,7 @@ const SelectTokenInnerModal: FC<ISelectTokenModalProps> = ({
/>
))
) : balanceIsLoading ? (
<Spinner />
<WrappedSpinner size={300} />
) : (
<div>No token supported on this chain</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Modal } from '@/components/modals/Modal';
import { useModalAnimation } from '@/hooks/useModalAnimation';
import config from '@/configuration';
import { TokenInfo } from './TokenInfo';
import { fetchBalance } from '@/services/token';
import { fetchEVMTokenBalances } from '@/services/token';
import { ISuperToken, IToken } from '@/types/superFluid';
import { StreamInfo } from './StreamInfo';
import { useDonateData } from '@/context/donate.context';
Expand Down Expand Up @@ -65,20 +65,6 @@ const SelectTokenInnerModal: FC<ISelectTokenModalProps> = ({
return;
}

// A helper function to fetch balance for a single token
const fetchTokenBalance = async (token: IToken) => {
try {
const balance = await fetchBalance(token.id, address);
return { symbol: token.symbol, balance };
} catch (error) {
console.error(
`Error fetching balance for ${token.symbol}:`,
error,
);
return { symbol: token.symbol, balance: undefined };
}
};

// Initiate all balance fetches concurrently
const fetchAllBalances = async () => {
const _allTokens = superTokens.reduce((acc, token) => {
Expand All @@ -87,18 +73,13 @@ const SelectTokenInnerModal: FC<ISelectTokenModalProps> = ({
return acc;
}, [] as IToken[]);

// Create an array of promises for each token balance fetch
const balancePromises = _allTokens.map(token =>
fetchTokenBalance(token),
);

// Wait for all promises to settle
const results = await Promise.all(balancePromises);
const results = await fetchEVMTokenBalances(_allTokens, address);

// Process results into a new balances object
const newBalances = results.reduce((acc, { symbol, balance }) => {
const newBalances = results.reduce((acc, { token, balance }) => {
if (balance !== undefined) {
acc[symbol] = balance;
acc[token.symbol] = balance;
}
return acc;
}, {} as IBalances);
Expand Down Expand Up @@ -148,7 +129,7 @@ const SelectTokenInnerModal: FC<ISelectTokenModalProps> = ({
const token = superTokens.find(
token => token.id === tokenId,
) as IToken;
return (
return token ? (
<StreamInfo
key={tokenId}
stream={tokenStreams[tokenId]}
Expand All @@ -166,7 +147,7 @@ const SelectTokenInnerModal: FC<ISelectTokenModalProps> = ({
}}
isSuperToken={!!token.isSuperToken}
/>
);
) : null;
})}
{superTokens.map(token =>
tokenStreams[token.id] ||
Expand Down
15 changes: 15 additions & 0 deletions src/config/production.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,21 @@ const config: EnvConfig = {
isSuperToken: true,
coingeckoId: 'usd-coin',
},
{
underlyingToken: {
decimals: 18,
id: '0x4F604735c1cF31399C6E711D5962b2B3E0225AD3',
name: 'Glo Dollar',
symbol: 'USDGLO',
coingeckoId: 'glo-dollar',
},
decimals: 18,
id: '0x9F41d0AA24E599fd8D0c180Ee3C0F609dc41c622',
name: 'Super Glo Dollar',
symbol: 'USDGLOx',
isSuperToken: true,
coingeckoId: 'glo-dollar',
},
],
},

Expand Down
3 changes: 2 additions & 1 deletion src/services/givpower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export const getGIVpowerBalanceByAddress = async (users: string[]) => {
console.log('unipool balances res', res);
const unipoolBalancesObj: { [key: string]: string } = {};
for (let i = 0; i < res.length; i++) {
const unipoolBalances = res[i].data.unipoolBalances;
const unipoolBalances = res[i].data?.unipoolBalances;
if (!unipoolBalances) continue;
for (let i = 0; i < unipoolBalances.length; i++) {
const unipoolBalance = unipoolBalances[i];
let currentBalance = unipoolBalancesObj[unipoolBalance.user.id];
Expand Down
46 changes: 31 additions & 15 deletions src/services/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
FETCH_MAINNET_TOKEN_PRICES,
} from '@/apollo/gql/gqlPrice';
import { IProjectAcceptedToken } from '@/apollo/types/gqlTypes';
import { IToken } from '@/types/superFluid';

export const fetchPrice = async (
chainId: number | ChainType,
Expand Down Expand Up @@ -56,27 +57,42 @@ export const fetchBalance = async (
}
};

export const fetchTokenBalances = async (
tokens: IProjectAcceptedToken[],
export const fetchEVMTokenBalances = async <
T extends IProjectAcceptedToken | IToken,
>(
tokens: T[], // Generic type constrained to IProjectAcceptedToken or IToken
walletAddress: string | null,
) => {
): Promise<{ token: T; balance: bigint | undefined }[]> => {
if (!walletAddress || !tokens || tokens.length === 0) return [];

// Filter out native tokens
const erc20Tokens: IProjectAcceptedToken[] = [];
const nativeTokens: IProjectAcceptedToken[] = [];
const erc20Tokens: T[] = [];
const nativeTokens: T[] = [];

// Use the correct property name based on the generic token type
const addressLabel = 'address' in tokens[0] ? 'address' : 'id';

tokens.forEach(token => {
token.address !== AddressZero
? erc20Tokens.push(token)
: nativeTokens.push(token);
const tokenAddress = token[addressLabel as keyof T] as string;

if (tokenAddress !== AddressZero) {
erc20Tokens.push(token);
} else {
nativeTokens.push(token);
}
});

const erc20Calls = erc20Tokens.map(token => ({
address: token.address,
abi: erc20Abi,
functionName: 'balanceOf',
args: [walletAddress],
}));
const erc20Calls = erc20Tokens.map(token => {
const tokenAddress = token[addressLabel as keyof T] as string;

// Ensure the tokenAddress is cast as Address (format starting with 0x)
return {
address: tokenAddress as Address, // Cast to wagmi Address type
abi: erc20Abi,
functionName: 'balanceOf',
args: [walletAddress],
};
});

try {
// Fetch balances for ERC20 tokens via multicall
Expand Down Expand Up @@ -107,7 +123,7 @@ export const fetchTokenBalances = async (
// Combine ERC20 and native token balances
return [...erc20Balances, ...nativeTokenBalances];
} catch (error) {
console.error('Error fetching token balances:', error);
console.error('Error fetching EVM token balances:', error);

// Return undefined balances in case of failure
return tokens.map(token => ({ token, balance: undefined }));
Expand Down
Loading