Skip to content

Commit

Permalink
fix: allow deleting last wallet (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya authored Sep 17, 2024
1 parent 8f9a136 commit 4f05700
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
23 changes: 18 additions & 5 deletions lib/state/appStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,15 @@ export const useAppStore = create<AppState>()((set, get) => {
const removeCurrentWallet = () => {
const wallets = [...get().wallets];
if (wallets.length <= 1) {
// cannot delete last wallet
// set to initial wallet status
secureStorage.removeItem(hasOnboardedKey);
secureStorage.setItem(selectedWalletIdKey, "0");
secureStorage.setItem(getWalletKey(0), JSON.stringify({}));
set({
nwcClient: undefined,
selectedWalletId: 0,
wallets: [{}],
});
return;
}
const selectedWalletId = get().selectedWalletId;
Expand Down Expand Up @@ -191,17 +199,22 @@ export const useAppStore = create<AppState>()((set, get) => {
for (let i = 0; i < get().addressBookEntries.length; i++) {
secureStorage.removeItem(getAddressBookEntryKey(i));
}
// clear selected wallet ID
secureStorage.removeItem(selectedWalletIdKey);

// clear fiat currency
secureStorage.removeItem(fiatCurrencyKey);

// clear onboarding status
secureStorage.removeItem(hasOnboardedKey);

// set to initial wallet status
secureStorage.setItem(selectedWalletIdKey, "0");
secureStorage.setItem(getWalletKey(0), JSON.stringify({}));

set({
nwcClient: undefined,
fiatCurrency: undefined,
selectedWalletId: undefined,
wallets: [],
selectedWalletId: 0,
wallets: [{}],
addressBookEntries: [],
});
},
Expand Down
7 changes: 6 additions & 1 deletion pages/settings/wallets/EditWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ export function EditWallet() {
{
text: "Confirm",
onPress: () => {
router.back();
if (useAppStore.getState().wallets.length == 1) {
router.dismissAll();
router.replace("/onboarding");
} else {
router.back();
}
useAppStore.getState().removeCurrentWallet();
},
},
Expand Down

0 comments on commit 4f05700

Please sign in to comment.