feat(web): wallet balance reads mcp-server §4 first

Try getHeicodeBalance() (mcp-server /api/user/balance per product-package §4)
before falling back to local /api/user/self. Aligns Wallet page with the
Heicode product-package contract so balance numbers come from the same source
the desktop sidecar uses.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-12 14:56:47 +08:00
co-authored by Claude Opus 4.7
parent 4c263040c9
commit ddc32466c2
+23 -1
View File
@@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next'
import { getSelf } from '@/lib/api'
import { useStatus } from '@/hooks/use-status'
import { useSystemConfig } from '@/hooks/use-system-config'
import { getHeicodeBalance } from '@/lib/heicode-mcp'
import { SectionPageLayout } from '@/components/layout'
import { AffiliateRewardsCard } from './components/affiliate-rewards-card'
import { BillingHistoryDialog } from './components/dialogs/billing-history-dialog'
@@ -84,10 +85,31 @@ export function Wallet(props: WalletProps) {
const { processing: pancakeProcessing, processWaffoPancakePayment } =
useWaffoPancakePayment()
// Fetch and refresh user data
// Fetch and refresh user data.
// Per docs/product-package/13 §6 "模型与余额" + Heicode-接口契约文档 §4,
// the canonical balance source is mcp-server /api/user/heicode/balance
// (server-side wraps NewAPI admin token, returns the freshest figures).
// Fall back to NewAPI /api/user/self when the user hasn't yet been
// mirrored into NewAPI via from-agnet (HEICODE_USER_NOT_FOUND) so a
// brand-new account still sees something instead of empty stats.
const fetchUser = useCallback(async () => {
try {
setUserLoading(true)
const heicodeBalance = await getHeicodeBalance().catch(() => null)
if (heicodeBalance) {
setUser({
id: heicodeBalance.heicodeUserId,
username: heicodeBalance.username,
email: heicodeBalance.email,
display_name: heicodeBalance.displayName,
group: heicodeBalance.group,
status: heicodeBalance.status,
quota: heicodeBalance.quota,
used_quota: heicodeBalance.usedQuota,
request_count: heicodeBalance.requestCount,
} as UserWalletData)
return
}
const response = await getSelf()
if (response.success && response.data) {
setUser(response.data as UserWalletData)