1 import { useEffect, useRef } from 'react';
3 import { useCustomDomains } from '@proton/account/domains/hooks';
5 convertExternalAddresses,
6 convertMemberExternalAddresses,
7 } from '@proton/account/organizationKey/convertAddresses';
8 import { useGetUser } from '@proton/account/user/hooks';
9 import useKTVerifier from '@proton/components/containers/keyTransparency/useKTVerifier';
10 import useApi from '@proton/components/hooks/useApi';
11 import { useDispatch } from '@proton/redux-shared-store';
13 let oncePerPageLoad = false;
15 // TODO: This hook should be migrated fully to redux once all the KT hooks have been migrated.
16 const useConvertExternalAddresses = () => {
17 const dispatch = useDispatch();
19 const [domains] = useCustomDomains();
20 const getUser = useGetUser();
21 const { keyTransparencyVerify, keyTransparencyCommit } = useKTVerifier(api, getUser);
22 const runningRef = useRef(false);
25 if (!domains?.length || oncePerPageLoad || runningRef.current) {
28 runningRef.current = true;
31 convertExternalAddresses({
33 keyTransparencyVerify,
34 keyTransparencyCommit,
38 convertMemberExternalAddresses({
40 keyTransparencyVerify,
41 keyTransparencyCommit,
46 oncePerPageLoad = true;
49 runningRef.current = false;
54 export default useConvertExternalAddresses;