mirror of
https://github.com/selfxyz/self.git
synced 2026-04-27 03:01:15 -04:00
* save wip demo app nfc scanning * save wip * fix types * Fix Android NFC scanning in demo app (#1241) * fix tests * fix pipelines * fix linting * WIP move to flows/onboarding/scan-nfc * prettier and fix test * fix test * update lock * update deps * Feat/android prebuilt modules (#1292) * move entire screen * remove redundancy in components and utils * fixes * lint * ignore * remove unneeded * fix imports * remove unused * Update packages/mobile-sdk-alpha/src/types/events.ts Co-authored-by: Aaron DeRuvo <aaron.deruvo@clabs.co> * uuid not needed for demo app * android: update ci check * timeout fix, image temp fix * prettier fix * try rebuild deps every time * Temporarily disable cache check in CI * Revert "try rebuild deps every time" This reverts commita5c97210a5. * ignore false positive * Revert "Revert "try rebuild deps every time"" This reverts commit4f44615fd6. * fix? * sanitize error message first * remove TODO that has been taken care of * MSDK: add ios prebuilts (#1308) * add ios prebuilt * remove outdate readme * remove duplicates * comment out unused * add prettier ignore * Update .gitguardian.yml to ignore iOS frameworks and build artifacts * update gitguardian ignore paths * migrate config version * add ignored-matches --------- Co-authored-by: Justin Hernandez <justin.hernandez@self.xyz> * remove duplicated code * exclude mobile-sdk native modules when `E2E_TESTING` flag is set * app: disable ios msdk auto-linking * add E2E_TESTING flag --------- Co-authored-by: Leszek Stachowski <leszek.stachowski@self.xyz> Co-authored-by: seshanthS <seshanth@protonmail.com> Co-authored-by: Seshanth.S <35675963+seshanthS@users.noreply.github.com> Co-authored-by: Aaron DeRuvo <aaron.deruvo@clabs.co>
115 lines
3.2 KiB
TypeScript
115 lines
3.2 KiB
TypeScript
// SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
|
|
|
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
|
|
import type { DocumentCatalog, DocumentMetadata, IDDocument } from '@selfxyz/common/utils/types';
|
|
import { loadSelectedDocument, useSelfClient } from '@selfxyz/mobile-sdk-alpha';
|
|
|
|
import HomeScreen from './src/screens/HomeScreen';
|
|
import type { ScreenContext, ScreenId, ScreenRoute } from './src/screens';
|
|
import { screenMap } from './src/screens';
|
|
import SelfClientProvider from './src/providers/SelfClientProvider';
|
|
import { NavigationProvider, useNavigation, type ScreenName } from './src/navigation/NavigationProvider';
|
|
|
|
type SelectedDocumentState = {
|
|
data: IDDocument;
|
|
metadata: DocumentMetadata;
|
|
};
|
|
|
|
const routeMap: Record<ScreenId, ScreenName> = {
|
|
generate: 'Generate',
|
|
register: 'Register',
|
|
mrz: 'MRZ',
|
|
home: 'Home',
|
|
nfc: 'NFC',
|
|
documents: 'Documents',
|
|
'country-selection': 'CountrySelection',
|
|
'id-selection': 'IDSelection',
|
|
success: 'Success',
|
|
};
|
|
|
|
const screenToRoute = Object.entries(routeMap).reduce(
|
|
(acc, [key, value]) => {
|
|
acc[value as unknown as ScreenName] = key as unknown as ScreenId;
|
|
return acc;
|
|
},
|
|
{} as Record<ScreenName, ScreenId>,
|
|
);
|
|
|
|
function DemoApp() {
|
|
const selfClient = useSelfClient();
|
|
const navigation = useNavigation();
|
|
|
|
const [catalog, setCatalog] = useState<DocumentCatalog>({ documents: [] });
|
|
const [selectedDocument, setSelectedDocument] = useState<SelectedDocumentState | null>(null);
|
|
|
|
const refreshDocuments = useCallback(async () => {
|
|
try {
|
|
const selected = await loadSelectedDocument(selfClient);
|
|
const nextCatalog = await selfClient.loadDocumentCatalog();
|
|
setCatalog(nextCatalog);
|
|
setSelectedDocument(selected);
|
|
} catch (error) {
|
|
console.warn('Failed to refresh documents', error);
|
|
setCatalog({ documents: [] });
|
|
setSelectedDocument(null);
|
|
}
|
|
}, [selfClient]);
|
|
|
|
const navigate = useCallback(
|
|
(next: ScreenRoute) => {
|
|
const routeName = routeMap[next];
|
|
if (routeName) {
|
|
navigation.navigate(routeName);
|
|
}
|
|
},
|
|
[navigation],
|
|
);
|
|
|
|
const screenContext: ScreenContext = {
|
|
navigate,
|
|
goHome: () => navigation.navigate('Home'),
|
|
documentCatalog: catalog,
|
|
selectedDocument,
|
|
refreshDocuments,
|
|
};
|
|
|
|
useEffect(() => {
|
|
refreshDocuments();
|
|
}, [refreshDocuments]);
|
|
|
|
const renderCurrentScreen = () => {
|
|
const { currentScreen } = navigation;
|
|
|
|
if (currentScreen === 'Home') {
|
|
return <HomeScreen screenContext={screenContext} />;
|
|
}
|
|
|
|
const screenRoute = screenToRoute[currentScreen];
|
|
if (screenRoute && screenMap[screenRoute]) {
|
|
const descriptor = screenMap[screenRoute];
|
|
const ScreenComponent = descriptor.load();
|
|
const props = descriptor.getProps?.(screenContext) ?? {};
|
|
return <ScreenComponent {...props} />;
|
|
}
|
|
|
|
return <HomeScreen screenContext={screenContext} />;
|
|
};
|
|
|
|
return renderCurrentScreen();
|
|
}
|
|
|
|
function App() {
|
|
return (
|
|
<NavigationProvider>
|
|
<SelfClientProvider>
|
|
<DemoApp />
|
|
</SelfClientProvider>
|
|
</NavigationProvider>
|
|
);
|
|
}
|
|
|
|
export default App;
|