-
Notifications
You must be signed in to change notification settings - Fork 181
introduce usePrepareDocumentProof in mobile SDK #1176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,11 +2,12 @@ | |||||||||||||||||||||||||||||||||||||||
| // SPDX-License-Identifier: BUSL-1.1 | ||||||||||||||||||||||||||||||||||||||||
| // NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| import { createContext, type PropsWithChildren, useContext, useMemo } from 'react'; | ||||||||||||||||||||||||||||||||||||||||
| import { createContext, type PropsWithChildren, useContext, useEffect, useMemo } from 'react'; | ||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 5 in packages/mobile-sdk-alpha/src/context.tsx
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| import { createSelfClient } from './client'; | ||||||||||||||||||||||||||||||||||||||||
| import { SdkEvents } from './types/events'; | ||||||||||||||||||||||||||||||||||||||||
| import type { Adapters, Config, SelfClient } from './types/public'; | ||||||||||||||||||||||||||||||||||||||||
| import { loadSelectedDocument } from './documents/utils'; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * React context holding a {@link SelfClient} instance. | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -66,3 +67,32 @@ | |||||||||||||||||||||||||||||||||||||||
| if (!client) throw new Error('useSelfClient must be used within a SelfClientProvider'); | ||||||||||||||||||||||||||||||||||||||||
| return client; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| export function usePrepareDocumentProof() { | ||||||||||||||||||||||||||||||||||||||||
|
Check failure on line 71 in packages/mobile-sdk-alpha/src/context.tsx
|
||||||||||||||||||||||||||||||||||||||||
| const selfClient = useSelfClient(); | ||||||||||||||||||||||||||||||||||||||||
| const { useProvingStore } = selfClient; | ||||||||||||||||||||||||||||||||||||||||
| const currentState = useProvingStore(state => state.currentState); | ||||||||||||||||||||||||||||||||||||||||
| const init = useProvingStore(state => state.init); | ||||||||||||||||||||||||||||||||||||||||
| const setUserConfirmed = useProvingStore(state => state.setUserConfirmed); | ||||||||||||||||||||||||||||||||||||||||
| const isReadyToProve = currentState === 'ready_to_prove'; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||
| const initializeProving = async () => { | ||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||
| const selectedDocument = await loadSelectedDocument(selfClient); | ||||||||||||||||||||||||||||||||||||||||
| if (selectedDocument?.data?.documentCategory === 'aadhaar') { | ||||||||||||||||||||||||||||||||||||||||
| init(selfClient, 'register'); | ||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||
| init(selfClient, 'dsc'); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||
| console.error('Error loading selected document:', error); | ||||||||||||||||||||||||||||||||||||||||
| init(selfClient, 'dsc'); | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+77
to
+79
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid logging PII - console.error('Error loading selected document:', error);
+ console.error('Error loading selected document');📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this code has only been moved, can be tackled separately
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shazarre, understood—I'll defer this for now since it's pre-existing code. Would you like me to open a follow-up issue to track the PII logging cleanup separately? |
||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+73
to
+80
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Await init call - init(selfClient, 'register');
+ await init(selfClient, 'register');
} else {
- init(selfClient, 'dsc');
+ await init(selfClient, 'dsc');
}
} catch (error) {
- console.error('Error loading selected document:', error);
- init(selfClient, 'dsc');
+ console.error('Error loading selected document:', error instanceof Error ? error.message : 'unknown');
+ await init(selfClient, 'dsc');📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this code has only been moved, can be tackled separately (if needed)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shazarre, understood! Since this is moved code, it makes sense to keep the refactoring focused and address the async handling in a follow-up if needed. Thanks for clarifying! 👍 |
||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| initializeProving(); | ||||||||||||||||||||||||||||||||||||||||
| }, [init, selfClient]); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| return { setUserConfirmed, isReadyToProve }; | ||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Stale Closures and Missing DependenciesThe
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you trippin. |
||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.