diff --git a/screens/Home/MyVcsTab.tsx b/screens/Home/MyVcsTab.tsx index 4d62ce2db4..cbe39575c8 100644 --- a/screens/Home/MyVcsTab.tsx +++ b/screens/Home/MyVcsTab.tsx @@ -12,7 +12,6 @@ import { ErrorMessageOverlay, MessageOverlay, } from '../../components/MessageOverlay'; -import {groupBy} from '../../shared/javascript'; import {VcItemContainer} from '../../components/VC/VcItemContainer'; import {BannerNotification} from '../../components/BannerNotification'; import { @@ -23,16 +22,15 @@ import {TelemetryConstants} from '../../shared/telemetry/TelemetryConstants'; import {Error} from '../../components/ui/Error'; import {useIsFocused} from '@react-navigation/native'; +import {getVCsOrderedByPinStatus} from '../../shared/Utils'; export const MyVcsTab: React.FC = props => { const {t} = useTranslation('MyVcsTab'); const controller = useMyVcsTab(props); const storeErrorTranslationPath = 'errors.savingFailed'; - const [pinned, unpinned] = groupBy( + const vcMetadataOrderedByPinStatus = getVCsOrderedByPinStatus( controller.vcMetadatas, - vcMetadata => vcMetadata.isPinned, ); - const vcMetadataOrderedByPinStatus = pinned.concat(unpinned); const getId = () => { controller.DISMISS(); diff --git a/screens/QrLogin/MyBindedVcs.tsx b/screens/QrLogin/MyBindedVcs.tsx index b5df9b4637..7b5bceaa65 100644 --- a/screens/QrLogin/MyBindedVcs.tsx +++ b/screens/QrLogin/MyBindedVcs.tsx @@ -7,16 +7,14 @@ import {QrLoginRef} from '../../machines/QrLoginMachine'; import {Icon} from 'react-native-elements'; import {Modal} from '../../components/ui/Modal'; import {VcItemContainer} from '../../components/VC/VcItemContainer'; -import {groupBy} from '../../shared/javascript'; +import {getVCsOrderedByPinStatus} from '../../shared/Utils'; export const MyBindedVcs: React.FC = props => { const controller = useQrLogin(props); const {t} = useTranslation('QrLogin'); - const [pinned, unpinned] = groupBy( + const shareableVcsMetadataOrderedByPinStatus = getVCsOrderedByPinStatus( controller.shareableVcsMetadata, - vcMetadata => vcMetadata.isPinned, ); - const shareableVcsMetadataOrderedByPinStatus = pinned.concat(unpinned); return ( { const {t} = useTranslation('SendVcScreen'); const {appService} = useContext(GlobalContext); const controller = useSendVcScreen(); - const [pinned, unpinned] = groupBy( + const shareableVcsMetadataOrderedByPinStatus = getVCsOrderedByPinStatus( controller.shareableVcsMetadata, - vcMetadata => vcMetadata.isPinned, ); - const shareableVcsMetadataOrderedByPinStatus = pinned.concat(unpinned); let service; if (shareableVcsMetadataOrderedByPinStatus?.length > 0) { diff --git a/shared/Utils.ts b/shared/Utils.ts new file mode 100644 index 0000000000..c98872ceaf --- /dev/null +++ b/shared/Utils.ts @@ -0,0 +1,10 @@ +import {VCMetadata} from './VCMetadata'; +import {groupBy} from './javascript'; + +export const getVCsOrderedByPinStatus = (vcMetadatas: VCMetadata[]) => { + const [pinned, unpinned] = groupBy( + vcMetadatas, + (vcMetadata: VCMetadata) => vcMetadata.isPinned, + ); + return pinned.concat(unpinned); +};