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