Aidar/com 6385 re build wallet demo with v2#78
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull Request Overview
This PR upgrades the wallet-earn demo from Compass API SDK v1 to v2, introducing significant architectural changes in how vault and position data are fetched and managed.
- Updated
@compass-labs/api-sdkfrom v1.0.23 to v2.0.1 - Separated vault listing and user positions into distinct API endpoints
- Replaced transaction bundler pattern with simplified
earnManageAPI - Introduced
COMPASS_WALLET_ADDRESSenvironment variable for wallet address management
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| wallet-earn/package.json | Updated Compass API SDK dependency to v2.0.1 |
| wallet-earn/utils/utils.ts | Added getWalletAddress() helper and updated type references to v2 models |
| wallet-earn/components/WalletScreen.tsx | Simplified to show only wallet balances, removed vault position calculations |
| wallet-earn/components/TokenScreen.tsx | Added position merging logic and introduced EnrichedVaultData type |
| wallet-earn/components/Screens.tsx | Refactored data fetching to use separate vaults and positions endpoints |
| wallet-earn/components/EarnItem.tsx | Updated to use v2 vault metrics (CAGR, lifetime returns) and simplified form logic |
| wallet-earn/app/page.tsx | Replaced private key derivation with getWalletAddress() helper |
| wallet-earn/app/api/vaults/route.ts | New endpoint for fetching vault list with USDC filtering |
| wallet-earn/app/api/positions/route.ts | New endpoint for fetching user earn positions |
| wallet-earn/app/api/vault/[address]/route.ts | Updated to use getWalletAddress() helper |
| wallet-earn/app/api/token/[token]/route.ts | Updated to use getWalletAddress() helper |
| wallet-earn/app/api/deposit/route.ts | Simplified to use earnManage API instead of manual allowance + deposit |
| wallet-earn/app/api/withdraw/route.ts | Simplified to use earnManage API instead of transaction bundler |
| wallet-earn/README.md | Added COMPASS_WALLET_ADDRESS to environment variables list |
| wallet-earn/.env.example | Added COMPASS_WALLET_ADDRESS placeholder |
Comments suppressed due to low confidence (2)
wallet-earn/utils/utils.ts:70
- The
addTotalBalancefunction is still exported but is no longer used after the refactoring. It was replaced with inline calculations inWalletScreen.tsx. Consider removing this unused export to keep the codebase clean.
export const addTotalBalance = (
tokenData: TokenData[],
vaultData: EnrichedVaultData[]
) =>
tokenData.reduce((sum, token) => {
const tokenSingle = tokenData?.find(
(tD) => tD.tokenSymbol == token.tokenSymbol
) as TokenData;
const tokenTotal = addTokenTotal(tokenSingle, vaultData);
return sum + tokenTotal * Number(token.price);
}, 0);
wallet-earn/utils/utils.ts:57
- The
addTokenTotalfunction is still exported but appears to no longer be used anywhere in the codebase after the refactoring. This function was previously used inWalletScreen.tsxandTokenScreen.tsxbut has been replaced with inline calculations. Consider removing this unused export to keep the codebase clean.
export const addTokenTotal = (tokenData: TokenData, vaultData: EnrichedVaultData[]) =>
vaultData
.filter((vD) => vD.denomination === tokenData.tokenSymbol)
.reduce(
(sum, vD) => sum + Number(vD?.userPosition?.amountInUnderlyingToken) || 0,
0
) + Number(tokenData.amount);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <Slider | ||
| value={[amount]} | ||
| max={ | ||
| Number(token.amount) + | ||
| Number(vaultData.userPosition?.amountInUnderlyingToken) | ||
| } | ||
| step={ | ||
| (Number(token.amount) + | ||
| Number(vaultData.userPosition?.amountInUnderlyingToken)) / | ||
| 400 | ||
| } | ||
| max={Number(token.amount)} | ||
| step={Number(token.amount) / 400} |
There was a problem hiding this comment.
The slider allows users to select amounts between 0 and their wallet balance (Number(token.amount)), but the current position might already exceed the wallet balance if funds are staked. This means users cannot increase positions beyond their wallet balance, which is correct, but they also cannot see or adjust to positions higher than their current wallet balance if they have existing stakes. The UX is confusing because the slider max doesn't represent the user's total manageable position. Consider using Number(token.amount) + Number(vaultData.userPosition?.amountInUnderlyingToken || 0) as the max to allow full position management.
No description provided.