Clear wallet preferences plist file on wallet deletion#1713
Conversation
Summary of ChangesHello @DRadmir, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a bug where wallet preferences persisted on disk even after a wallet was deleted, leading to incorrect behavior upon re-importing the same wallet. The changes introduce a new method to explicitly remove these preferences and integrate this cleanup into the wallet deletion process, ensuring a clean state for re-imported wallets. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request correctly addresses the issue where wallet preferences were persisting after a wallet was deleted. By adding a remove() method to WalletPreferences and calling it during the wallet deletion process, the stale configuration is cleared. However, the current implementation of remove() manually deletes the .plist file from the file system. This is generally discouraged in iOS development because the UserDefaults system (via the cfprefsd daemon) caches these files, and manual deletion can lead to inconsistent states. I have suggested using the official removePersistentDomain(forName:) API instead, which is safer and more reliable. Additionally, I've recommended updating the unit test to verify that the data is cleared rather than checking for the existence of a file on disk.
|
|
||
| public func remove() { | ||
| let plistURL = FileManager.Directory.library(.preferences).url.appendingPathComponent("\(suiteName).plist") | ||
| try? FileManager.default.removeItem(at: plistURL) |
There was a problem hiding this comment.
can we inject FIleManager in init?
public init(walletId: WalletId, manager: FileManager = FileManager.default) {
self.suiteName = Self.suiteName(walletId: walletId.id)
self.defaults = UserDefaults(suiteName: suiteName)!
self.fileManager = manager
}
mb also debugPrint do catch?
0b99f18 to
c1dc685
Compare
| import Preferences | ||
| import Primitives | ||
|
|
||
| public struct WalletPreferencesLocalStore: Sendable { |
There was a problem hiding this comment.
| public struct WalletPreferencesLocalStore: Sendable { | |
| public struct PreferencesLocalStore: Sendable { |
|
|
||
| public func remove(walletId: WalletId) { | ||
| let suiteName = WalletPreferences.suiteName(walletId: walletId.id) | ||
| let plistURL = FileManager.Directory.library(.preferences).url.appendingPathComponent("\(suiteName).plist") |
|
|
||
| public init() {} | ||
|
|
||
| public func remove(walletId: WalletId) { |
When a wallet is deleted, its WalletPreferences (stored in UserDefaults suite) persisted on disk, causing issues when re-importing the same wallet. The completeInitialAddressStatus flag remained true, skipping the Tron multi-sig address check. - Add unit test
c1dc685 to
69a4252
Compare
4700ef4 to
4a3269e
Compare
4a3269e to
d39b6c9
Compare
| if currentWalletId == wallet.walletId { | ||
| walletSessionService.setCurrent(walletId: wallets.first?.walletId) | ||
| } | ||
| if wallets.isEmpty { |
There was a problem hiding this comment.
this should be be under WalletPreferences(walletId: wallet.walletId).clear()
When a wallet is deleted, its WalletPreferences (stored in UserDefaults suite) persisted on disk, causing issues when re-importing the same wallet. The completeInitialAddressStatus flag remained true, skipping the Tron multi-sig address check.
Fix: #1712