Skip to content

Add Wallet Data Export/Import Functionality#188

Open
sozidatel wants to merge 15 commits into
masterfrom
export_import
Open

Add Wallet Data Export/Import Functionality#188
sozidatel wants to merge 15 commits into
masterfrom
export_import

Conversation

@sozidatel

Copy link
Copy Markdown
Contributor

This PR implements comprehensive wallet data export/import functionality, allowing users to backup and restore their wallet data across devices.

Features Added

Export Functionality:
Export all accounts with names, keys, and token preferences
Export contacts/address book
Support for both regular and encrypted private keys
Support for cosigner accounts
JSON file download with secure data structure

Import Functionality:
Smart conflict resolution for existing accounts
Preserve existing account names while updating token preferences
Import new contacts and update existing ones
Full support for encrypted keys with metadata
Detailed import reports with success/error statistics

User Interface:
New settings menu items for export/import
Dedicated dialogs with clear instructions and warnings
Progress indicators and error handling
File selection with validation

Technical Implementation

Data Structure:
Versioned export format with metadata
Consolidated encrypted key structure (data, nonce, iterations)
Token preference format conversion (ISSUER:CODE ↔ CODE-ISSUER)
Support for cosigner account relationships

Account Management:
Direct localStorage manipulation for encrypted keys
Standard createAccount API for regular keys
refreshKey mechanism for account list updates
Conflict resolution without data loss

Internationalization:
Complete translations for all supported languages (EN, RU, DE, ES, IT, SR-Cyrl, SR-Latn)
Replaced all hardcoded Russian comments with English
Consistent translation patterns

Security Considerations
Private keys are included in exports (user responsibility)
Clear warnings about data confidentiality
Secure file handling and validation
No data transmission - local operations only

Files Changed
New Components: DataExportDialog.tsx, DataImportDialog.tsx
Core Logic: export-data.ts (413 lines of export/import logic)
UI Integration: Settings menu, routing, context updates
Translations: 7 language files with complete localization
Account Management: Enhanced context with refresh mechanisms

- Add data export dialog in settings with security warnings
- Implement export function that collects:
  * Account data (name, publicKey, privateKey/encryptedPrivateKey)
  * Token preferences per account (converted to CODE-ISSUER format)
  * Saved contacts/address book
- Support encrypted private keys for password-protected accounts
- Export as JSON file with version and timestamp
- Add Russian and English translations
- Remove internal account IDs from export (use publicKey as identifier)
- Preserve account order in export for future import sorting
- Add reliable encrypted key export from storage
- Support encrypted private keys in import (base64 decoding)
- Add cross-platform storage access function
- Improve error handling for encrypted key operations
- Add logging for export key types
- Remove dependency on createAccount for import
- Use direct key store operations for better reliability
- Add encryptionMetadata to ExportedAccount interface
- Export nonce and iterations for encrypted keys
- Restore encrypted keys with proper metadata structure
- Use direct localStorage manipulation for encrypted key import
- Preserve original encryption parameters for password compatibility
- Add refreshAccounts function to AccountsContext
- Automatically refresh account list after successful import
- No need to reload app to see imported accounts
- Improves user experience by showing changes immediately
- Merge encryptionMetadata into encryptedPrivateKey object
- Cleaner data structure with data, nonce, and iterations fields
- Simplified export/import logic
- Better encapsulation of encryption-related data
- Use accountID instead of publicKey in export for cosigner accounts
- Properly handle cosignerOf field in import logic
- Fix account lookup to use accountID for both regular and cosigner accounts
- Ensure token preferences are saved with correct accountID
- Support cosigner accounts where private key belongs to different account
- Reset file input value after processing to allow re-selecting same file
- Add clear button to reset dialog state after errors/success
- Better user experience for retrying imports with corrected files
- Prevents stuck state when same file is selected multiple times
- Add automatic redirect to main page after successful import
- Add 'Go to accounts' button for manual navigation
- Ensure imported accounts are visible on main screen
- Better user experience after import completion
- Automatic redirect with 2-second delay to show success message
- Remove 'Go to accounts' button and automatic redirect
- Remove 'Clear' button - auto-clear on new file selection
- Add automatic page reload after successful import to ensure accounts appear
- Simplify dialog interface with better user experience
- Fix issue where imported accounts don't show without manual refresh
- Remove window.location.reload() to avoid confusing user experience
- Add custom 'accountsUpdated' event dispatch after import
- Add event listener in AllAccountsPage to refresh accounts
- Preserve user's view of import results while updating account list
- Better UX without full page reload
- Add refreshKey state to AccountsContext for forced re-rendering
- Update refreshAccounts to increment refreshKey after loading accounts
- Use refreshKey as key prop for AccountList to force re-render
- Remove custom event approach in favor of React key mechanism
- Ensure imported accounts appear immediately without page reload
- Follow same pattern as account creation/deletion for consistency
- Add export/import dialogs in settings
- Support both regular and encrypted private keys
- Handle cosigner accounts correctly
- Export account data, token preferences, and contacts
- Import with conflict resolution for existing data
- Add Russian and English translations
- Use standard createAccount API for better React state management
- Add German, Spanish, Italian, Serbian (Cyrillic and Latin) translations
- Complete localization support for all supported languages
- Maintain consistency with existing translation patterns
- Replace all hardcoded Russian comments with English equivalents
- Maintain code functionality while improving internationalization
- Prepare codebase for international contributors
@sozidatel sozidatel requested a review from troggy September 29, 2025 10:06
@sozidatel sozidatel marked this pull request as ready for review September 29, 2025 16:11
async function getEncryptedKeysFromStorage(): Promise<any> {
// In web environment use localStorage
if (typeof localStorage !== 'undefined') {
const rawKeys = localStorage.getItem("sunce:keys")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это не работает для десктопного приложения. В экспорте не будет ключей.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants