Skip to content
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
22 changes: 14 additions & 8 deletions lib/portfolio.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { UserDashboardResponse, ZerionAPI } from 'zerion-sdk';
import { Address, isAddress, zeroAddress } from 'viem';
import { kv } from '@vercel/kv';
import { chainIdToName, supportedMainnetChains } from '@/lib/constants';
import { WalletAgentContext, WalletBalanceCache } from '@/lib/types';
Expand All @@ -10,7 +9,7 @@ const GAS_ASSET_THRESHOLD = 0.1;
const MAX_SIGNIFICANT_ASSETS = 20;

export const getWalletAgentContext = async (
address: Address,
address: `0x${string}`,
): Promise<WalletAgentContext> => {
if (!isAddress(address)) {
throw new Error('Invalid Ethereum address format');
Expand All @@ -33,11 +32,7 @@ export const getWalletAgentContext = async (
const zerionData = await getEvmBalances(address);
const tokens = zerionData.tokens;

const nativeTokens = tokens.filter(
(token) =>
!token.meta.contractAddress ||
token.meta.contractAddress === zeroAddress,
);
const nativeTokens = tokens.filter((token) => !token.meta.contractAddress);

const chainsWithGas = nativeTokens
.filter((token) => token.balances.usdBalance >= GAS_ASSET_THRESHOLD)
Expand Down Expand Up @@ -99,7 +94,7 @@ export const getWalletAgentContext = async (
};

export const getEvmBalances = async (
address: Address,
address: `0x${string}`,
): Promise<UserDashboardResponse> => {
if (!isAddress(address)) {
throw new Error('Invalid Ethereum address format');
Expand Down Expand Up @@ -167,3 +162,14 @@ function generateActionableSummary(

return summary;
}

// Instead of using viem, use a simple regex to check if the address is valid.
const addressRegex = /^0x[a-fA-F0-9]{40}$/

function isAddress(address: string): boolean {
// Break early with simple check.
if (!address.startsWith('0x') && address.length === 42) {return false;}

// Then try the regex.
return addressRegex.test(address);
}
6 changes: 0 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
"@bitte-ai/data": " 0.1.0-main-cd0def5",
"@google-cloud/firestore": "^7.11.0",
"@jest/globals": "^29.7.0",
"@mintbase-js/data": "^0.6.6",
"@mintbase-js/rpc": "^0.6.6",
"@mintbase-js/sdk": "^0.6.6",
"@mintbase-js/storage": "^0.6.6",
"@mysten/sui": "^1.27.1",
"@near-wallet-selector/core": "^8.10.1",
"@prisma/client": "6.6.0",
Expand Down Expand Up @@ -55,7 +51,6 @@
"sonner": "^2.0.1",
"tailwind-merge": "^3.0.1",
"tailwindcss-animate": "^1.0.7",
"viem": "^2.27.0",
"zerion-sdk": "^0.1.1",
"zod": "^3.24.2"
},
Expand All @@ -67,7 +62,6 @@
"@types/node-fetch": "^2.6.12",
"@types/react": "^19",
"@types/react-dom": "^19",
"cross-fetch": "^4.1.0",
"eslint": "^9",
"eslint-config-next": "15.1.0",
"jest": "^29.7.0",
Expand Down
Loading