-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Pending Transaction Service for broadcast error handling #231
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
Open
Gaubee
wants to merge
66
commits into
main
Choose a base branch
from
feat/pending-tx-service
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When assetType is specified in URL params (e.g. ?assetType=CPCC), the previous code would immediately fallback to native asset if tokens hadn't loaded yet, then get overwritten again causing a flicker. Now returns null from initialAsset when tokens are still loading, allowing the useEffect to properly set the asset once tokens are available.
- SendPage: use explorer.queryTx to open block explorer, disable button if not configured - TransferWalletLockJob: add onViewExplorer callback to TxStatusDisplay - DestroyPage: same fix as SendPage - TxStatusDisplay: add onViewExplorer prop for explorer link button
…cast error handling - Move BroadcastResultSchema into apis/bnqkl_wallet/bioforest/types.ts - Move pending-tx service into services/transaction/pending-tx.ts - Fix broadcastTransaction to catch ApiError and extract error info - Add E2E tests for broadcast errors (real chain + mock) - Captured real error codes: 001-11028 (asset not enough), 002-41011 (fee not enough)
- Store transactions to pendingTxService before broadcasting - Update status to 'broadcasting' during broadcast - Update status to 'broadcasted' on success with txHash - Update status to 'failed' on BroadcastError with error details
- Create PendingTxList component for displaying pending transactions - Create usePendingTransactions hook for fetching pending tx data - Integrate pending tx list at top of transaction history page - Support delete action for pending transactions
- Create PendingTxDetailPage with full transaction status display - Add PendingTxDetailActivity and register route /pending-tx/:pendingTxId - Support retry broadcast for failed transactions - Support delete for failed/created transactions - Navigate to detail page on pending tx item click - Add retryCount i18n translation
- Create PendingTxManager with auto-retry for failed broadcasts - Add subscription mechanism for UI status updates - Sync broadcasted transactions to check confirmation status - Integrate manager into usePendingTransactions hook - Auto-start manager when pending transactions exist
- Add PendingTxList to WalletTab for visibility - Show pending transactions between quick actions and portfolio - Support retry and delete actions from home page
- Send notifications on broadcast success/failure - Send notification when transaction is confirmed - Include transaction details in notification data
…tions - Add pending tx count badge on wallet tab in TabBar - Add deleteExpired method to PendingTxService for cleanup - Auto-cleanup expired transactions (24h) during sync - Badge shows count or '9+' for many pending transactions
- Add onNavigate callback to NotificationItem for transaction notifications - Navigate to /pending-tx/:pendingTxId when clicking transaction notifications - Add 'View Details' link with chevron icon for actionable notifications - Add viewDetails i18n translations for en/zh-CN
- Add status-specific background colors (blue/amber/red/green) - Add pulse animation for broadcasting and broadcasted states - Improve visual feedback for transaction status
- Test deleteExpired cleanup functionality - Test incrementRetry counter - Test status color consistency - Test notification with pendingTxId for navigation
- Add invalidateBalance method to PendingTxManager - Invalidate balance query cache when transaction is confirmed - Triggers automatic balance refresh in UI
- Add transactionHistoryKeys import - Invalidate transaction history cache along with balance - Ensures UI shows the confirmed transaction immediately
- Remove direct IndexedDB manipulation that caused NotFoundError - Test only verifies method exists and is callable - Full deleteExpired logic is covered in unit tests
- Add pendingTx translations (title, broadcasting, broadcasted, failed, retry, delete, retryCount) - Add broadcast error translations (assetNotEnough, feeNotEnough, rejected, unknown) - Add txStatus.created translations for pending broadcast state
- Add pending-tx-list.stories.tsx with 6 stories (Default, Broadcasting, Broadcasted, Failed, Empty, MultipleStates) - Add storybook-e2e/pending-tx-list.spec.ts for visual regression testing - Generate 5 screenshots for different pending tx states - All storybook tests passing (6 tests)
c75d512 to
acfcf35
Compare
- Fix broadcastTransaction to detect success when API returns transaction object - Fix pattern lock to show error message and allow retry on broadcast failure - Add E2E testing checklist documentation
When broadcast returns error code 001-00034 (transaction already exists), treat it as success since the transaction is already on chain.
fdd0c92 to
bd4ffdc
Compare
- Change broadcastTransaction to return BroadcastResult with alreadyExists flag - When transaction already exists on chain, mark as 'confirmed' instead of 'broadcasted' - Update all callers: use-send, use-burn, pending-tx detail page, pending-tx-manager
- Add tests for BroadcastResult type structure - Add tests for 001-00034 duplicate transaction handling - Add tests for PendingTx marking as confirmed on duplicate broadcast style: use flex-col for pending tx actions layout
- Add errorCode check for 001-00034 in ApiError handling - Return BroadcastResult with alreadyExists=true for duplicate tx - Refactor pending-tx-list to use @biochain/key-ui components (IconCircle, AddressDisplay, Alert) - Remove unreliable message-based fallback checks
- PendingTxList: add onClearAllFailed prop and button (shows when 2+ failed) - usePendingTransactions: add clearAllFailed method - WalletTab: pass clearAllFailed to PendingTxList - i18n: add clearAllFailed translation key
- PendingTx schema: add confirmedBlockHeight and confirmedAt fields - UpdatePendingTxStatusInput: support confirmation info - pending-tx detail page: show confirmed block height and time - i18n: add confirmedBlockHeight and confirmedAt translation keys
- Add error codes: 001-00034, 001-11038, 001-11039, 001-22001, 001-11067 - Add i18n keys: alreadyExists, forbidden, assetNotExist, invalidParams, accountFrozen - Support both zh-CN and en locales
… docs - Replace hardcoded Chinese notification messages with i18n keys in pending-tx-manager.ts - Add pendingTx notification translations to en/zh-CN notification.json - Add PendingTxService documentation to white-book (04-PendingTx.md)
…tailPage - Add TransferWalletLockJob.stories.tsx with 7 stories covering all states: - WalletLockStep, TwoStepSecretStep, BroadcastingState, BroadcastedState - FailedState, ConfirmedState, FullFlow (interactive demo) - Enhance PendingTxDetailPage.stories.tsx with 5 stories: - Broadcasting, Broadcasted, Failed, Confirmed, InteractiveTest - Add data-testid for retry/delete buttons for future e2e testing
…ransitions, and timeout detection - Add subscription mechanism tests (notify, unsubscribe, multiple subscribers) - Add status transition validation tests (state machine compliance) - Add retry count tracking tests (auto-retry limit, manual retry) - Add broadcasting timeout detection tests (30s threshold) - Total: 28 tests for pending-tx-manager
- Add broadcast.timeout and broadcast.failed i18n keys - Replace hardcoded Chinese in pending-tx-manager.ts broadcasting timeout handler
…ast status - Add subscribe/notify mechanism to pendingTxService for real-time updates - Update usePendingTransactions to subscribe to pendingTxService instead of manager - Show broadcasting status immediately when pattern verification starts - Remove duplicate result step from Send page (BottomSheet handles status display)
…iption support - Create key-fetch package with plugin architecture (interval, deps, ttl, dedupe, tag, etag) - Add React hooks (useKeyFetch, useKeyFetchSubscribe) - Add BioChain cache rules configuration - Fix button nesting issue in pending-tx-list (use div with role=button) - Update use-pending-transactions to subscribe to block height changes via keyFetch
…m genesis block - Fix interval plugin to use URL-level timer management - Add dynamic polling interval based on URL (getPollingIntervalByUrl) - Initialize cache rules at app startup in service-main.ts - Fetch forgeInterval from genesis block (block/1) before subscribing - Add console logging for debugging polling and block updates
…a fetching - chain-service: getBlockHeight uses keyFetch for /lastblock - asset-service: getTokenBalances uses keyFetch for /address/asset - transaction-service: getTransactionStatus/getTransaction use keyFetch - pending-tx-manager: checkConfirmation uses keyFetch for tx query All read operations now benefit from keyFetch caching and reactive updates.
- getTransactionHistory now uses keyFetch for /lastblock and /transactions/query - All bioforest read operations now use keyFetch for caching and reactive updates
- useBalanceQuery: now uses keyFetch subscription instead of React Query polling - useTransactionHistoryQuery: defaults to current chain instead of 'all' - useKeyFetch: added enabled option and isFetching state - Removed React Query dependency from these hooks - On-demand subscription: only queries current selected chain
…endency - use-address-balance-query: migrated to keyFetch - use-address-transactions-query: migrated to keyFetch - use-address-portfolio: migrated to keyFetch - pages/history/detail.tsx: use keyFetch instead of useQuery All chain data queries now use keyFetch for reactive subscriptions.
BREAKING CHANGE: Complete API redesign
- Schema-first: Zod schema is now required for type-safe validation
- Factory pattern: keyFetch.create() returns KeyFetchInstance object
- useKeyFetch(kf, params) instead of useKeyFetch(url)
- useKeyFetchSubscribe(kf, params, callback) for subscriptions
- Plugins adapted to new architecture (interval, deps, ttl, tag, etag)
- Removed old cache.ts and core.test.ts (need rewrite)
New usage:
const lastBlock = keyFetch.create({
name: 'bfmeta.lastblock',
schema: LastBlockSchema,
url: 'https://api.example.com/:chainId/lastblock',
use: [interval(15_000)],
})
// React
const { data } = useKeyFetch(lastBlock, { chainId: 'bfmeta' })
- Create bioforest/fetch.ts with Schema definitions and factory functions - Update chain-service to use getChainFetchInstances() - Remove old keyFetch import from asset-service, transaction-service - Update pending-tx-manager to use native fetch (temporary) - Simplify use-pending-transactions hook (remove old keyFetch subscription) - Delete obsolete key-fetch-rules.ts Services now use direct fetch for API calls. React components can use useKeyFetch(instance, params) for reactive data fetching.
Clarify that 'pnpm tsc --noEmit' does NOT check src/ files because root tsconfig.json has 'files: []'. Must use: - pnpm tsc -p tsconfig.app.json --noEmit (for src/) - pnpm typecheck (for all packages via turbo)
- Remove unused variables and parameters (prefix with _ where intentionally unused) - Fix circular type references (use indexed access types instead of Record) - Restore accidentally deleted console.log statements from previous cleanup - Fix test setup fetch mock to include preconnect property - Remove unused type declarations and helper functions - Fix vite plugin server config type compatibility Errors reduced: 323 → 291 (32 fixed) Remaining errors documented in TYPE_ERRORS_PLAN.md for systematic review Changes are conservative - no logic modifications: - Only type annotations and unused code cleanup - Preserved all functional console statements - Used _ prefix for intentionally unused parameters - Commented out instead of deleting potentially useful code See TYPE_ERRORS_PLAN.md for categorized remaining errors and fix strategies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements a comprehensive Pending Transaction Service for systematically managing unconfirmed transactions and proper broadcast error handling.
Core Features
Testing
Screenshots
Generated storybook-e2e screenshots:
pending-tx-list-default.png- 默认多状态列表pending-tx-broadcasting.png- 广播中状态pending-tx-broadcasted.png- 等待上链状态pending-tx-failed.png- 广播失败状态pending-tx-multiple-states.png- 多状态组合Commits (26)
Architecture
New/Modified Files
New Files:
src/services/transaction/pending-tx.ts- PendingTxService (IndexedDB)src/services/transaction/pending-tx-manager.ts- Background managersrc/services/bioforest-sdk/errors.ts- BroadcastError classsrc/components/transaction/pending-tx-list.tsx- UI with animationssrc/components/transaction/pending-tx-list.stories.tsx- Storybook storiessrc/pages/pending-tx/detail.tsx- Detail pagesrc/hooks/use-pending-transactions.ts- React hooke2e/pending-tx-ui.mock.spec.ts- E2E testsstorybook-e2e/pending-tx-list.spec.ts- Visual regression testsModified Files:
src/stackflow/components/TabBar.tsx- Pending tx badgesrc/stackflow/activities/tabs/WalletTab.tsx- Home page integrationsrc/pages/history/index.tsx- History page integrationsrc/pages/notifications/index.tsx- Click navigationsrc/hooks/use-send.bioforest.ts- Service integrationsrc/hooks/use-burn.bioforest.ts- Service integrationsrc/i18n/locales/*/transaction.json- i18n translations (4 languages)