From b7b4dd006643cb563fa054c7550bdb46517f048f Mon Sep 17 00:00:00 2001 From: kvtodev Date: Mon, 13 Jul 2026 13:52:40 +0800 Subject: [PATCH] extract mud point wallet entry component for reuse in tauri app --- .../PlatformMudPointWalletEntry.test.tsx | 5 +++-- .../src/components}/PlatformMudPointWalletEntry.tsx | 7 +++---- .../shared/src/icons}/topbar-wallet.png | Bin .../common/platformMudPointWalletModel.ts | 10 ---------- .../image-editor/ImageCanvasTopbarView.test.tsx | 3 --- .../image-editor/ImageCanvasTopbarView.tsx | 2 +- .../platform-entry/PlatformProfileRechargeModal.tsx | 2 +- .../rpg-entry/RpgEntryHomeView.recharge.test.tsx | 3 --- src/components/rpg-entry/RpgEntryHomeView.tsx | 2 +- 9 files changed, 9 insertions(+), 25 deletions(-) rename {src/components/common => packages/shared/src/components}/PlatformMudPointWalletEntry.test.tsx (97%) rename {src/components/common => packages/shared/src/components}/PlatformMudPointWalletEntry.tsx (97%) rename {public/creation-home => packages/shared/src/icons}/topbar-wallet.png (100%) delete mode 100644 src/components/common/platformMudPointWalletModel.ts diff --git a/src/components/common/PlatformMudPointWalletEntry.test.tsx b/packages/shared/src/components/PlatformMudPointWalletEntry.test.tsx similarity index 97% rename from src/components/common/PlatformMudPointWalletEntry.test.tsx rename to packages/shared/src/components/PlatformMudPointWalletEntry.test.tsx index 1156a20d4..08d3011d9 100644 --- a/src/components/common/PlatformMudPointWalletEntry.test.tsx +++ b/packages/shared/src/components/PlatformMudPointWalletEntry.test.tsx @@ -4,8 +4,9 @@ import { act, fireEvent, render, screen, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { expect, test, vi } from 'vitest'; -import { PlatformMudPointWalletEntry } from './PlatformMudPointWalletEntry'; -import { formatMudPointCount } from './platformMudPointWalletModel'; +import { PlatformMudPointWalletEntry } from './PlatformMudPointWalletEntry.tsx'; + +import { formatMudPointCount } from '@/packages/shared/src/utils/format.ts'; const breakdown = { totalPoints: 207, diff --git a/src/components/common/PlatformMudPointWalletEntry.tsx b/packages/shared/src/components/PlatformMudPointWalletEntry.tsx similarity index 97% rename from src/components/common/PlatformMudPointWalletEntry.tsx rename to packages/shared/src/components/PlatformMudPointWalletEntry.tsx index 6f2b0f218..d4aec9a44 100644 --- a/src/components/common/PlatformMudPointWalletEntry.tsx +++ b/packages/shared/src/components/PlatformMudPointWalletEntry.tsx @@ -8,10 +8,9 @@ import { useState, } from 'react'; -import type { ProfileMudPointBalance } from '../../../packages/shared/src/contracts/runtime'; -import { formatMudPointCount } from './platformMudPointWalletModel'; - -const MUD_POINT_ICON_SRC = '/creation-home/topbar-wallet.png'; +import type { ProfileMudPointBalance } from '@/packages/shared/src'; +import MUD_POINT_ICON_SRC from '@/packages/shared/src/icons/topbar-wallet.png'; +import { formatMudPointCount } from '@/packages/shared/src/utils/format.ts'; export type PlatformMudPointWalletEntryProps = { balance: number | null; diff --git a/public/creation-home/topbar-wallet.png b/packages/shared/src/icons/topbar-wallet.png similarity index 100% rename from public/creation-home/topbar-wallet.png rename to packages/shared/src/icons/topbar-wallet.png diff --git a/src/components/common/platformMudPointWalletModel.ts b/src/components/common/platformMudPointWalletModel.ts deleted file mode 100644 index 0236383c0..000000000 --- a/src/components/common/platformMudPointWalletModel.ts +++ /dev/null @@ -1,10 +0,0 @@ -export function formatMudPointCount(value: number, compact = false) { - const normalizedValue = Math.max(0, Math.round(value)); - if (compact && normalizedValue >= 100_000_000) { - return `${(normalizedValue / 100_000_000).toFixed(1)}亿`; - } - if (compact && normalizedValue >= 10_000) { - return `${(normalizedValue / 10_000).toFixed(1)}万`; - } - return normalizedValue.toLocaleString('zh-CN'); -} diff --git a/src/components/image-editor/ImageCanvasTopbarView.test.tsx b/src/components/image-editor/ImageCanvasTopbarView.test.tsx index 1bbf80ec6..c9eb10d4b 100644 --- a/src/components/image-editor/ImageCanvasTopbarView.test.tsx +++ b/src/components/image-editor/ImageCanvasTopbarView.test.tsx @@ -108,9 +108,6 @@ describe('ImageCanvasTopbarView', () => { }); expect(walletChip.textContent).toBe('泥点 1.2万'); - expect(walletChip.querySelector('img')?.getAttribute('src')).toBe( - '/creation-home/topbar-wallet.png', - ); await user.hover(walletChip); const details = screen.getByRole('dialog', { name: '泥点账户详情' }); diff --git a/src/components/image-editor/ImageCanvasTopbarView.tsx b/src/components/image-editor/ImageCanvasTopbarView.tsx index 72fa0e4ab..49607699a 100644 --- a/src/components/image-editor/ImageCanvasTopbarView.tsx +++ b/src/components/image-editor/ImageCanvasTopbarView.tsx @@ -8,7 +8,7 @@ import { } from 'lucide-react'; import type { ProfileMudPointBalance } from '../../../packages/shared/src/contracts/runtime'; -import { PlatformMudPointWalletEntry } from '../common/PlatformMudPointWalletEntry'; +import { PlatformMudPointWalletEntry } from '../../../packages/shared/src/components/PlatformMudPointWalletEntry.tsx'; import { PlatformStatusMessage } from '../common/PlatformStatusMessage'; import { PlatformTextField } from '../common/PlatformTextField'; import { EditorIconButton } from './ImageCanvasEditorPrimitives'; diff --git a/src/components/platform-entry/PlatformProfileRechargeModal.tsx b/src/components/platform-entry/PlatformProfileRechargeModal.tsx index 26964cc30..329dc3a0f 100644 --- a/src/components/platform-entry/PlatformProfileRechargeModal.tsx +++ b/src/components/platform-entry/PlatformProfileRechargeModal.tsx @@ -8,7 +8,6 @@ import type { import { PlatformActionButton } from '../common/PlatformActionButton'; import { PlatformAsyncStatePanel } from '../common/PlatformAsyncStatePanel'; import { PlatformEmptyState } from '../common/PlatformEmptyState'; -import { formatMudPointCount } from '../common/platformMudPointWalletModel'; import { PlatformPillBadge } from '../common/PlatformPillBadge'; import { PlatformProfileSkeletonList } from '../common/PlatformProfileSkeletonList'; import { PlatformStatusMessage } from '../common/PlatformStatusMessage'; @@ -16,6 +15,7 @@ import { PlatformSubpanel } from '../common/PlatformSubpanel'; import { formatRechargePrice } from '../rpg-entry/rpgEntryProfileFundsViewModel'; import { PlatformProfileModalShell } from './PlatformProfileModalShell'; import type { NativeWechatPaymentState } from './usePlatformProfileCenterController'; +import { formatMudPointCount } from '@/packages/shared/src/utils/format.ts'; const WECHAT_NATIVE_PAY_QR_IMAGE_SIZE = 180; export type PlatformProfileRechargeModalProps = { diff --git a/src/components/rpg-entry/RpgEntryHomeView.recharge.test.tsx b/src/components/rpg-entry/RpgEntryHomeView.recharge.test.tsx index d0298e996..789e0e466 100644 --- a/src/components/rpg-entry/RpgEntryHomeView.recharge.test.tsx +++ b/src/components/rpg-entry/RpgEntryHomeView.recharge.test.tsx @@ -4235,9 +4235,6 @@ test('logged in create tab shows real wallet balance beside the brand', () => { expect(walletEntry?.className).toContain( 'platform-mobile-create-wallet-chip', ); - expect(walletButton.querySelector('img')?.getAttribute('src')).toBe( - '/creation-home/topbar-wallet.png', - ); expect( within(topbar as HTMLElement).getByRole('button', { name: '充值' }), ).toBeTruthy(); diff --git a/src/components/rpg-entry/RpgEntryHomeView.tsx b/src/components/rpg-entry/RpgEntryHomeView.tsx index 78b66671a..2a662dfe7 100644 --- a/src/components/rpg-entry/RpgEntryHomeView.tsx +++ b/src/components/rpg-entry/RpgEntryHomeView.tsx @@ -89,7 +89,7 @@ import { PlatformAsyncStatePanel } from '../common/PlatformAsyncStatePanel'; import { PlatformEmptyState } from '../common/PlatformEmptyState'; import { PlatformFilterToolbar } from '../common/PlatformFilterToolbar'; import { PlatformIconButton } from '../common/PlatformIconButton'; -import { PlatformMudPointWalletEntry } from '../common/PlatformMudPointWalletEntry'; +import { PlatformMudPointWalletEntry } from '../../../packages/shared/src/components/PlatformMudPointWalletEntry.tsx'; import { PlatformNavigableListItem } from '../common/PlatformNavigableListItem'; import { PlatformPillBadge } from '../common/PlatformPillBadge'; import {