Skip to content

Commit

Permalink
fix(components): add remove saved account function
Browse files Browse the repository at this point in the history
  • Loading branch information
jennieramida committed Nov 8, 2023
1 parent 2ced7d7 commit 89315cc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lib/components/modal/account/RemoveSavedAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useCallback } from "react";

import { ActionModal } from "../ActionModal";
import { CustomIcon } from "lib/components/icon";
import { useAccountStore } from "lib/providers/store";
import type { AccountLocalInfo } from "lib/stores/account";
import { truncate } from "lib/utils";

Expand All @@ -35,8 +36,9 @@ export function RemoveSavedAccountModal({
),
}: RemoveSavedAccountModalProps) {
const toast = useToast();
const { removeSavedAccount } = useAccountStore();
const handleRemove = useCallback(() => {
// removeSavedCode(codeId);
removeSavedAccount(account.address);

toast({
title: `Removed \u2018${account.name}\u2019 from Saved Codes`,
Expand All @@ -46,7 +48,7 @@ export function RemoveSavedAccountModal({
position: "bottom-right",
icon: <CustomIcon name="check-circle-solid" color="success.main" />,
});
}, [account.name, toast]);
}, [removeSavedAccount, account.address, account.name, toast]);
return (
<ActionModal
title={
Expand Down
6 changes: 6 additions & 0 deletions src/lib/stores/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ export class AccountStore {
return this.savedAccounts[this.userKey]?.includes(address) ?? false;
}

removeSavedAccount(address: Addr): void {
this.savedAccounts[this.userKey] = this.savedAccounts[this.userKey]?.filter(
(each) => each !== address
);
}

getSavedAccounts(): AccountLocalInfo[] {
const savedAccountsByUserKey = this.savedAccounts[this.userKey] ?? [];
return savedAccountsByUserKey
Expand Down

0 comments on commit 89315cc

Please sign in to comment.