-
Notifications
You must be signed in to change notification settings - Fork 54
feat(account-abstraction): add xdr encode decode utils #126
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
David-patrick-chuks
wants to merge
12
commits into
ancore-org:main
Choose a base branch
from
David-patrick-chuks:feat/113-account-abstraction-xdr-utils
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.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
25739ac
feat(account-abstraction): add xdr encode decode utils
David-patrick-chuks ed1821d
chore(ci): fix repo-wide lint and build checks
David-patrick-chuks 1e8fa9e
style: apply prettier formatting
David-patrick-chuks fc2c6c4
Merge remote-tracking branch 'origin/main' into feat/113-account-abst…
David-patrick-chuks fa9d507
fix(ci): repair monorepo checks on xdr utils branch
David-patrick-chuks 1ac4b9e
style: format files required by ci
David-patrick-chuks aff860b
test(contract): match invalid nonce panic
David-patrick-chuks c60d0ab
Merge upstream/main into feat/113-account-abstraction-xdr-utils
David-patrick-chuks cc3b996
fix(crypto): use node webcrypto types
David-patrick-chuks e158e07
fix(extension-wallet): restore build after merge
David-patrick-chuks 3804098
fix(extension-wallet): repair flat eslint config
David-patrick-chuks 0831d28
fix(core-sdk): declare buffersource global for lint
David-patrick-chuks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,293 +1,5 @@ | ||
| /** | ||
| * App Component Example | ||
| * | ||
| * Demonstrates how to use ErrorBoundary and error-handler in a React application. | ||
| * This example shows: | ||
| * 1. Wrapping the app with ErrorBoundary | ||
| * 2. Using error-handler in async functions | ||
| * 3. Implementing retry functionality | ||
| * 4. Handling different error categories | ||
| */ | ||
| import { SettingsScreen } from './screens/Settings/SettingsScreen'; | ||
|
|
||
| import { useState, useEffect, useCallback } from 'react'; | ||
| import { | ||
| ErrorBoundary, | ||
| useErrorHandler, | ||
| handleError, | ||
| withErrorHandling, | ||
| createRetryable, | ||
| } from './errors'; | ||
|
|
||
| /** | ||
| * Sample data type | ||
| */ | ||
| interface UserData { | ||
| id: string; | ||
| name: string; | ||
| balance: string; | ||
| } | ||
|
|
||
| /** | ||
| * Example component that fetches data - demonstrates async error handling | ||
| * Uses the error-handler to classify and log errors | ||
| */ | ||
| function DataFetcher(): JSX.Element { | ||
| const [data, setData] = useState<UserData | null>(null); | ||
| const [loading, setLoading] = useState(false); | ||
| const [error, setError] = useState<Error | null>(null); | ||
|
|
||
| // Use the error handler hook for manual error dispatching | ||
| const { reset } = useErrorHandler(); | ||
|
|
||
| const fetchData = useCallback(async () => { | ||
| setLoading(true); | ||
| setError(null); | ||
|
|
||
| try { | ||
| // Simulate a network request that might fail | ||
| const response = await fetch('/api/user'); | ||
|
|
||
| if (!response.ok) { | ||
| // Use the global error handler to classify the error | ||
| const errorInfo = handleError( | ||
| new Error(`HTTP ${response.status}: ${response.statusText}`), | ||
| 'fetchUserData' | ||
| ); | ||
| throw new Error(errorInfo.message); | ||
| } | ||
|
|
||
| const userData = await response.json(); | ||
| setData(userData); | ||
| } catch (err) { | ||
| const handledError = handleError(err, 'fetchUserData'); | ||
|
|
||
| // Log the error (handled by error-handler internally) | ||
| console.log('Error category:', handledError.category); | ||
| console.log('Recoverable:', handledError.recoverable); | ||
|
|
||
| setError(handledError.originalError as Error); | ||
| } finally { | ||
| setLoading(false); | ||
| } | ||
| }, []); | ||
|
|
||
| // Initial fetch on mount | ||
| useEffect(() => { | ||
| fetchData(); | ||
| }, [fetchData]); | ||
|
|
||
| if (error) { | ||
| return ( | ||
| <div className="p-4 border border-red-300 rounded-lg bg-red-50"> | ||
| <p className="text-red-800 mb-2">Error: {error.message}</p> | ||
| <div className="flex gap-2"> | ||
| <button | ||
| onClick={fetchData} | ||
| className="px-3 py-1 bg-red-600 text-white rounded hover:bg-red-700" | ||
| > | ||
| Retry | ||
| </button> | ||
| <button | ||
| onClick={reset} | ||
| className="px-3 py-1 border border-red-600 text-red-600 rounded hover:bg-red-50" | ||
| > | ||
| Reset | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| if (loading) { | ||
| return <div className="p-4">Loading...</div>; | ||
| } | ||
|
|
||
| return ( | ||
| <div className="p-4"> | ||
| <h3 className="font-bold">User Data</h3> | ||
| {data && ( | ||
| <ul> | ||
| <li>ID: {data.id}</li> | ||
| <li>Name: {data.name}</li> | ||
| <li>Balance: {data.balance}</li> | ||
| </ul> | ||
| )} | ||
| <button onClick={fetchData} className="mt-2 px-3 py-1 bg-blue-600 text-white rounded"> | ||
| Refresh | ||
| </button> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Example component using withErrorHandling HOC | ||
| * Wraps an async function with automatic error handling | ||
| */ | ||
| async function fetchUserBalance(userId: string): Promise<string> { | ||
| // Simulate network call | ||
| const response = await fetch(`/api/balance/${userId}`); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error('Failed to fetch balance'); | ||
| } | ||
|
|
||
| const data = await response.json(); | ||
| return data.balance; | ||
| } | ||
|
|
||
| // Wrap function with error handling (example utility export usage) | ||
| void withErrorHandling(fetchUserBalance as any, 'fetchUserBalance'); | ||
|
|
||
| /** | ||
| * Example component using createRetryable | ||
| * Creates a function that automatically retries on failure | ||
| */ | ||
| async function submitTransaction(txData: object): Promise<{ txHash: string }> { | ||
| // Simulate transaction submission | ||
| const response = await fetch('/api/submit', { | ||
| method: 'POST', | ||
| body: JSON.stringify(txData), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error('Transaction failed'); | ||
| } | ||
|
|
||
| return response.json(); | ||
| export function App() { | ||
| return <SettingsScreen />; | ||
| } | ||
|
|
||
| // Create a retryable version that retries up to 3 times | ||
| const submitTransactionWithRetry = createRetryable(submitTransaction as any, 3, 1000); | ||
|
|
||
| /** | ||
| * Transaction component - demonstrates retry functionality | ||
| */ | ||
| function TransactionComponent(): JSX.Element { | ||
| const [status, setStatus] = useState<string>('idle'); | ||
| const [txHash, setTxHash] = useState<string | null>(null); | ||
|
|
||
| const handleSubmit = async () => { | ||
| setStatus('submitting'); | ||
|
|
||
| const result = (await submitTransactionWithRetry({ amount: 100 })) as { txHash: string }; | ||
|
|
||
| if ('txHash' in result) { | ||
| setTxHash(result.txHash); | ||
| setStatus('success'); | ||
| } else { | ||
| setStatus('failed'); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="p-4 border rounded-lg"> | ||
| <h3 className="font-bold mb-2">Transaction</h3> | ||
| <p className="mb-2">Status: {status}</p> | ||
| {txHash && <p className="mb-2">Tx Hash: {txHash}</p>} | ||
| <button | ||
| onClick={handleSubmit} | ||
| disabled={status === 'submitting'} | ||
| className="px-3 py-1 bg-green-600 text-white rounded" | ||
| > | ||
| {status === 'submitting' ? 'Submitting...' : 'Submit Transaction'} | ||
| </button> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Main App component - wrapped with ErrorBoundary | ||
| * The ErrorBoundary will catch any rendering errors in children | ||
| */ | ||
| export function App(): JSX.Element { | ||
| // Callback for handling errors that escape component boundaries | ||
| const handleAppError = (error: Error, errorInfo: React.ErrorInfo) => { | ||
| console.error('App-level error:', error, errorInfo.componentStack); | ||
| }; | ||
|
|
||
| // Callback for resetting app state | ||
| const handleReset = () => { | ||
| console.log('App reset requested'); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="min-h-screen bg-gray-100 p-8"> | ||
| <h1 className="text-3xl font-bold mb-8">Extension Wallet</h1> | ||
|
|
||
| {/* Wrap the entire app with ErrorBoundary */} | ||
| <ErrorBoundary onError={handleAppError} onReset={handleReset}> | ||
| <div className="space-y-8"> | ||
| {/* Example 1: Data fetching with manual error handling */} | ||
| <section className="bg-white p-4 rounded-lg shadow"> | ||
| <h2 className="text-xl font-semibold mb-4">Data Fetcher Example</h2> | ||
| <DataFetcher /> | ||
| </section> | ||
|
|
||
| {/* Example 2: Transaction with retry */} | ||
| <section className="bg-white p-4 rounded-lg shadow"> | ||
| <h2 className="text-xl font-semibold mb-4">Transaction Example (with retry)</h2> | ||
| <TransactionComponent /> | ||
| </section> | ||
|
|
||
| {/* Example 3: Direct error handler usage */} | ||
| <section className="bg-white p-4 rounded-lg shadow"> | ||
| <h2 className="text-xl font-semibold mb-4">Direct Error Handler Example</h2> | ||
| <DirectErrorExample /> | ||
| </section> | ||
| </div> | ||
| </ErrorBoundary> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Component demonstrating direct use of error-handler | ||
| */ | ||
| function DirectErrorExample(): JSX.Element { | ||
| const [result, setResult] = useState<string | null>(null); | ||
|
|
||
| const testNetworkError = () => { | ||
| const errorInfo = handleError(new Error('ECONNREFUSED: Connection refused'), 'networkTest'); | ||
| setResult(`Category: ${errorInfo.category}, Recoverable: ${errorInfo.recoverable}`); | ||
| }; | ||
|
|
||
| const testValidationError = () => { | ||
| const errorInfo = handleError( | ||
| new Error('validation failed: invalid address'), | ||
| 'validationTest' | ||
| ); | ||
| setResult(`Category: ${errorInfo.category}, Recoverable: ${errorInfo.recoverable}`); | ||
| }; | ||
|
|
||
| const testContractError = () => { | ||
| const errorInfo = handleError(new Error('Contract: execution reverted'), 'contractTest'); | ||
| setResult(`Category: ${errorInfo.category}, Recoverable: ${errorInfo.recoverable}`); | ||
| }; | ||
|
|
||
| const testUnknownError = () => { | ||
| const errorInfo = handleError(new Error('Something unexpected'), 'unknownTest'); | ||
| setResult(`Category: ${errorInfo.category}, Recoverable: ${errorInfo.recoverable}`); | ||
| }; | ||
|
|
||
| return ( | ||
| <div> | ||
| <div className="flex gap-2 mb-4"> | ||
| <button onClick={testNetworkError} className="px-2 py-1 bg-gray-200 rounded text-sm"> | ||
| Test Network Error | ||
| </button> | ||
| <button onClick={testValidationError} className="px-2 py-1 bg-gray-200 rounded text-sm"> | ||
| Test Validation Error | ||
| </button> | ||
| <button onClick={testContractError} className="px-2 py-1 bg-gray-200 rounded text-sm"> | ||
| Test Contract Error | ||
| </button> | ||
| <button onClick={testUnknownError} className="px-2 py-1 bg-gray-200 rounded text-sm"> | ||
| Test Unknown Error | ||
| </button> | ||
| </div> | ||
| {result && <p className="p-2 bg-blue-50 rounded text-sm">{result}</p>} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export default App; | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: ancore-org/ancore
Length of output: 88
🏁 Script executed:
Repository: ancore-org/ancore
Length of output: 11113
🏁 Script executed:
Repository: ancore-org/ancore
Length of output: 2248
🏁 Script executed:
Repository: ancore-org/ancore
Length of output: 362
Add ErrorBoundary at the app entry point.
The app has no error boundary protection at any level. While
ErrorBoundarycomponents exist in the codebase (apps/extension-wallet/src/errors/), neitherApp.tsxnor the actual entry point (main.tsx) uses them. Unhandled errors inSettingsScreenwill crash the app without a user-friendly fallback UI.Wrap the app with
ErrorBoundaryinmain.tsx(around<SettingsScreen />):Example fix for main.tsx
Additionally, this change (simplifying
App.tsx) appears unrelated to the PR's stated objectives (XDR encoding/decoding utils). Consider splitting into a separate PR for clarity.🤖 Prompt for AI Agents