-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor hooks related to removing accounts
- Loading branch information
1 parent
48ac19f
commit 61677df
Showing
8 changed files
with
97 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useRemoveAccount } from "./removeAccountDataHooks"; | ||
import { mockSecretKeyAccount } from "../../mocks/factories"; | ||
import { renderHook } from "../../mocks/testUtils"; | ||
import { accountsSlice } from "../redux/slices/accountsSlice"; | ||
import { store } from "../redux/store"; | ||
|
||
describe("useRemoveAccount", () => { | ||
test("deletes relevant data from accounts slice", () => { | ||
const account = mockSecretKeyAccount(0); | ||
store.dispatch(accountsSlice.actions.addAccount(account)); | ||
store.dispatch( | ||
accountsSlice.actions.addSecretKey({ | ||
pkh: account.address.pkh, | ||
encryptedSecretKey: "encryptedSecretKey" as any, | ||
}) | ||
); | ||
|
||
const { | ||
result: { current: removeAccount }, | ||
} = renderHook(() => useRemoveAccount()); | ||
removeAccount(account); | ||
|
||
expect(store.getState().accounts.items).toEqual([]); | ||
expect(store.getState().accounts.secretKeys).toEqual({}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { AccountType, LedgerAccount, SecretKeyAccount, SocialAccount } from "../../types/Account"; | ||
import { useAppDispatch } from "../redux/hooks"; | ||
import { accountsSlice } from "../redux/slices/accountsSlice"; | ||
|
||
const { removeMnemonicAndAccounts, removeNonMnemonicAccounts } = accountsSlice.actions; | ||
|
||
/** | ||
* Hook for removing all accounts from mnemonic group by a given fingerprint. | ||
*/ | ||
export const useRemoveMnemonic = () => { | ||
const dispatch = useAppDispatch(); | ||
return (fingerPrint: string) => { | ||
dispatch( | ||
removeMnemonicAndAccounts({ | ||
fingerPrint, | ||
}) | ||
); | ||
}; | ||
}; | ||
|
||
/** | ||
* Hook for removing all accounts of a given type. | ||
*/ | ||
export const useRemoveNonMnemonic = () => { | ||
const dispatch = useAppDispatch(); | ||
return (accountType: AccountType) => { | ||
dispatch( | ||
removeNonMnemonicAccounts({ | ||
accountType, | ||
}) | ||
); | ||
}; | ||
}; | ||
|
||
/** | ||
* Hook for removing single account. | ||
*/ | ||
export const useRemoveAccount = () => { | ||
const dispatch = useAppDispatch(); | ||
return (account: SocialAccount | LedgerAccount | SecretKeyAccount) => { | ||
if (account.type === "secret_key") { | ||
dispatch(accountsSlice.actions.removeSecretKey(account)); | ||
} | ||
dispatch(accountsSlice.actions.removeAccount(account)); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61677df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage report
Test suite run success
1182 tests passing in 163 suites.
Report generated by 🧪jest coverage report action from 61677df