Skip to content

Comments

Clear wallet preferences plist file on wallet deletion#1713

Merged
DRadmir merged 3 commits intomainfrom
clear-wallet-preferences-on-delete
Feb 19, 2026
Merged

Clear wallet preferences plist file on wallet deletion#1713
DRadmir merged 3 commits intomainfrom
clear-wallet-preferences-on-delete

Conversation

@DRadmir
Copy link
Contributor

@DRadmir DRadmir commented Feb 18, 2026

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 remove() method to WalletPreferences that deletes the plist file
  • Call remove() in WalletService.delete() to clean up preferences
  • Add unit test for remove() functionality

Fix: #1712

@DRadmir DRadmir self-assigned this Feb 18, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • Wallet Preferences Cleanup: Implemented a mechanism to clear wallet preferences (stored in UserDefaults) from disk when a wallet is deleted, resolving issues with re-importing wallets.
  • New remove() method: Added a remove() method to the WalletPreferences class, responsible for deleting the associated .plist file.
  • Integration with Wallet Deletion: Integrated the new remove() method into WalletService.delete(), ensuring preferences are cleaned up automatically upon wallet removal.
  • Unit Testing: Included a dedicated unit test to verify the correct functionality of the WalletPreferences.remove() method.

🧠 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
  • Packages/FeatureServices/WalletService/WalletService.swift
    • Added a call to WalletPreferences(walletId: wallet.walletId).remove() within the delete method to ensure associated preferences are cleared when a wallet is removed.
  • Packages/Preferences/Sources/WalletPreferences.swift
    • Introduced a new private property suiteName to store the UserDefaults suite identifier.
    • Modified the init method to use the new suiteName property when initializing UserDefaults.
    • Added a public remove() method that locates and deletes the preferences .plist file associated with the wallet's suiteName.
    • Refactored the static suite method into suiteName to return just the string identifier, which is then used for UserDefaults initialization and file path construction.
  • Packages/Preferences/Tests/WalletPreferencesTests.swift
    • Added a new test case testRemove() to verify that calling remove() on WalletPreferences successfully deletes the corresponding .plist file from the file system.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

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)
Copy link
Contributor

@gemdev111 gemdev111 Feb 18, 2026

Choose a reason for hiding this comment

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

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?

@DRadmir DRadmir marked this pull request as draft February 18, 2026 17:25
@DRadmir DRadmir force-pushed the clear-wallet-preferences-on-delete branch from 0b99f18 to c1dc685 Compare February 18, 2026 17:48
import Preferences
import Primitives

public struct WalletPreferencesLocalStore: Sendable {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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")
Copy link
Contributor

Choose a reason for hiding this comment

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

reuse


public init() {}

public func remove(walletId: WalletId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

make it throwable

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
@DRadmir DRadmir force-pushed the clear-wallet-preferences-on-delete branch from c1dc685 to 69a4252 Compare February 19, 2026 06:41
@DRadmir DRadmir marked this pull request as ready for review February 19, 2026 06:43
@DRadmir DRadmir force-pushed the clear-wallet-preferences-on-delete branch from 4700ef4 to 4a3269e Compare February 19, 2026 07:19
@DRadmir DRadmir force-pushed the clear-wallet-preferences-on-delete branch from 4a3269e to d39b6c9 Compare February 19, 2026 08:04
@DRadmir DRadmir merged commit 80d4c27 into main Feb 19, 2026
1 check passed
@DRadmir DRadmir deleted the clear-wallet-preferences-on-delete branch February 19, 2026 08:09
if currentWalletId == wallet.walletId {
walletSessionService.setCurrent(walletId: wallets.first?.walletId)
}
if wallets.isEmpty {
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be be under WalletPreferences(walletId: wallet.walletId).clear()

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.

Remove WalletPreferences from file system after removing the wallet

3 participants