2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2019 Signal Messenger, LLC
|
2021-06-17 17:15:10 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { createSelector } from 'reselect';
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { StateType } from '../reducer';
|
|
|
|
import type { AccountsStateType } from '../ducks/accounts';
|
2022-04-12 00:26:09 +00:00
|
|
|
import type { UUIDStringType } from '../../types/UUID';
|
2021-06-17 17:15:10 +00:00
|
|
|
|
|
|
|
export const getAccounts = (state: StateType): AccountsStateType =>
|
|
|
|
state.accounts;
|
|
|
|
|
2022-04-12 00:26:09 +00:00
|
|
|
export type AccountSelectorType = (
|
|
|
|
identifier?: string
|
|
|
|
) => UUIDStringType | undefined;
|
2021-06-17 17:15:10 +00:00
|
|
|
export const getAccountSelector = createSelector(
|
|
|
|
getAccounts,
|
|
|
|
(accounts: AccountsStateType): AccountSelectorType => {
|
|
|
|
return (identifier?: string) => {
|
|
|
|
if (!identifier) {
|
2022-04-12 00:26:09 +00:00
|
|
|
return undefined;
|
2021-06-17 17:15:10 +00:00
|
|
|
}
|
|
|
|
|
2022-04-12 00:26:09 +00:00
|
|
|
return accounts.accounts[identifier] || undefined;
|
2021-06-17 17:15:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|