-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
1810 usdglo token #4795
1810 usdglo token #4795
Changes from 13 commits
1cd56c0
bbf7ed8
071c3cc
c1b15d4
1a8275a
3fead58
e6c780e
ce1f6b7
5abda0e
b7ecd72
804b9fb
0d261d6
5c2f617
5c9de99
bd0c8e4
a4aa1e6
0270b64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ import { useGeneralWallet } from '@/providers/generalWalletProvider'; | |
import { wagmiConfig } from '@/wagmiConfigs'; | ||
import { ChainType } from '@/types/config'; | ||
import { getBalanceForToken } from './services'; | ||
import { fetchTokenBalances } from '@/services/token'; | ||
import { fetchEVMTokenBalances } from '@/services/token'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Update error logs to use Residual usage of
🔗 Analysis chainVerify impact on non-EVM chains and add explanatory comment. The import statement has been changed from To verify the impact, please run the following script: Consider adding a comment explaining why this change was made, for example: // Import EVM-specific token balance fetching function
import { fetchEVMTokenBalances } from '@/services/token'; 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for any remaining usage of fetchTokenBalances
rg "fetchTokenBalances" --type typescript
# Check if there are any non-EVM chain specific balance fetching functions
rg "fetch.*TokenBalances" --type typescript
Length of output: 245 Script: #!/bin/bash
# Search for any remaining usage of fetchTokenBalances
rg "fetchTokenBalances" --type ts
# Check if there are any non-EVM chain specific balance fetching functions
rg "fetch[A-Za-z]*TokenBalances" --type ts
Length of output: 980 |
||
import { Spinner } from '@/components/Spinner'; | ||
|
||
export interface ISelectTokenModalProps extends IModal { | ||
|
@@ -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 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { fetchBalance, fetchEVMTokenBalances } from '@/services/token'; | ||
import { ISuperToken, IToken } from '@/types/superFluid'; | ||
import { StreamInfo } from './StreamInfo'; | ||
import { useDonateData } from '@/context/donate.context'; | ||
|
@@ -87,18 +87,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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for In the Apply this diff to add error handling: const fetchAllBalances = async () => {
+ try {
const _allTokens = superTokens.reduce((acc, token) => {
acc.push(token);
acc.push(token.underlyingToken);
return acc;
}, [] as IToken[]);
const results = await fetchEVMTokenBalances(_allTokens, address);
// Process results into a new balances object
const newBalances = results.reduce((acc, { token, balance }) => {
if (balance !== undefined) {
acc[token.symbol] = balance;
}
return acc;
}, {} as IBalances);
const filteredTokens = superTokens.filter(
token => !(newBalances[token.symbol] > 0n),
);
setTokens(filteredTokens);
// Update the state with the new balances
setBalances(newBalances);
+ } catch (error) {
+ console.error('Error fetching EVM token balances:', error);
+ // Optionally handle the error, e.g., set an error state or notify the user
+ }
};
|
||
|
@@ -131,6 +126,8 @@ const SelectTokenInnerModal: FC<ISelectTokenModalProps> = ({ | |
}, | ||
); | ||
|
||
console.log('token', tokens); | ||
|
||
return ( | ||
<> | ||
<Wrapper> | ||
|
@@ -148,6 +145,11 @@ const SelectTokenInnerModal: FC<ISelectTokenModalProps> = ({ | |
const token = superTokens.find( | ||
token => token.id === tokenId, | ||
) as IToken; | ||
if (!token?.symbol) { | ||
console.log('token', token); | ||
return; | ||
} | ||
|
||
return ( | ||
<StreamInfo | ||
key={tokenId} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider refactoring to eliminate code duplication. The line Apply this refactor to create a helper function: +const getTokenAddress = (token: T): string => token[addressLabel as keyof T] as string;
// In the token separation loop
-const tokenAddress = token[addressLabel as keyof T] as string;
+const tokenAddress = getTokenAddress(token);
// In the erc20Calls mapping
-const tokenAddress = token[addressLabel as keyof T] as string;
+const tokenAddress = getTokenAddress(token);
|
||
// 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], | ||
}; | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate Casting You can use a regular expression or a utility function to validate the Ethereum address format. For example: // Ensure the tokenAddress is cast as Address (format starting with 0x)
const tokenAddress = getTokenAddress(token);
+// Validate the token address format
+if (!/^0x[a-fA-F0-9]{40}$/.test(tokenAddress)) {
+ throw new Error(`Invalid token address: ${tokenAddress}`);
+}
return {
address: tokenAddress as Address,
abi: erc20Abi,
functionName: 'balanceOf',
args: [walletAddress],
};
|
||
|
||
try { | ||
// Fetch balances for ERC20 tokens via multicall | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Missing
isGivbackEligible
inFETCH_PROJECT_BY_SLUG_DONATION
QueryThe
isGivbackEligible
field is not present in theFETCH_PROJECT_BY_SLUG_DONATION
query as expected. Please ensure that this field is included and correctly handled in the frontend components consuming this query.🔗 Analysis chain
Ensure consistent inclusion of
isGivbackEligible
in queries.The
isGivbackEligible
field has been re-added to theFETCH_PROJECT_BY_SLUG_DONATION
query. Please verify that this field is necessary for the donation flow and that it is correctly handled in the frontend components consuming this query.To confirm consistent usage of
isGivbackEligible
across the codebase, you can run the following script:🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 984
Script:
Length of output: 257