1
1
import { useAppAgent } from '@easypid/agent'
2
2
import { setWalletServiceProviderPin } from '@easypid/crypto/WalletServiceProviderClient'
3
3
import { InvalidPinError } from '@easypid/crypto/error'
4
+ import { useDevelopmentMode } from '@easypid/hooks'
4
5
import { type FormattedSubmission , getSubmissionForMdocDocumentRequest } from '@package/agent'
5
6
import { usePushToWallet } from '@package/app/src/hooks/usePushToWallet'
6
7
import { useToastController } from '@package/ui'
7
- import { useEffect , useState } from 'react'
8
+ import { useCallback , useEffect , useState } from 'react'
8
9
import { type ActivityStatus , addSharedActivityForCredentialsForRequest } from '../activity/activityRecord'
9
10
import { shareDeviceResponse , shutdownDataTransfer } from '../proximity'
10
11
import { FunkeOfflineSharingScreen } from './FunkeOfflineSharingScreen'
@@ -23,6 +24,7 @@ export function FunkeMdocOfflineSharingScreen({
23
24
const toast = useToastController ( )
24
25
const pushToWallet = usePushToWallet ( )
25
26
const { agent } = useAppAgent ( )
27
+ const [ isDevelopmentModeEnabled ] = useDevelopmentMode ( )
26
28
27
29
const [ submission , setSubmission ] = useState < FormattedSubmission > ( )
28
30
const [ isProcessing , setIsProcessing ] = useState ( false )
@@ -32,6 +34,8 @@ export function FunkeMdocOfflineSharingScreen({
32
34
. then ( setSubmission )
33
35
. catch ( ( error ) => {
34
36
toast . show ( 'Presentation information could not be extracted.' , {
37
+ message :
38
+ error instanceof Error && isDevelopmentModeEnabled ? `Development mode error: ${ error . message } ` : undefined ,
35
39
customData : { preset : 'danger' } ,
36
40
} )
37
41
agent . config . logger . error ( 'Error getting credentials for mdoc device request' , {
@@ -40,7 +44,16 @@ export function FunkeMdocOfflineSharingScreen({
40
44
41
45
pushToWallet ( )
42
46
} )
43
- } , [ agent , deviceRequest , toast . show , pushToWallet ] )
47
+ } , [ agent , deviceRequest , toast . show , pushToWallet , isDevelopmentModeEnabled ] )
48
+
49
+ const handleError = useCallback (
50
+ ( { reason, description, redirect = true } : { reason : string ; description ?: string ; redirect ?: boolean } ) => {
51
+ toast . show ( reason , { message : description , customData : { preset : 'danger' } } )
52
+ if ( redirect ) pushToWallet ( )
53
+ return
54
+ } ,
55
+ [ toast , pushToWallet ]
56
+ )
44
57
45
58
const onProofAccept = async ( { pin, onPinComplete, onPinError } : onPinSubmitProps ) => {
46
59
// Already checked for submission in the useEffect
@@ -59,6 +72,13 @@ export function FunkeMdocOfflineSharingScreen({
59
72
if ( e instanceof InvalidPinError ) {
60
73
onPinError ?.( )
61
74
}
75
+
76
+ handleError ( {
77
+ reason : 'Authentication Error' ,
78
+ redirect : true ,
79
+ description :
80
+ e instanceof Error && isDevelopmentModeEnabled ? `Development mode error: ${ e . message } ` : undefined ,
81
+ } )
62
82
}
63
83
64
84
// Once this returns we just assume it's successful
@@ -69,10 +89,14 @@ export function FunkeMdocOfflineSharingScreen({
69
89
sessionTranscript,
70
90
submission,
71
91
} )
72
- } catch ( error ) {
73
- agent . config . logger . error ( 'Could not share device response' , { error } )
92
+ } catch ( e ) {
74
93
await addActivity ( 'failed' )
75
- pushToWallet ( )
94
+ handleError ( {
95
+ reason : 'Could not share device response' ,
96
+ redirect : true ,
97
+ description :
98
+ e instanceof Error && isDevelopmentModeEnabled ? `Development mode error: ${ e . message } ` : undefined ,
99
+ } )
76
100
}
77
101
78
102
await addActivity ( 'success' )
@@ -89,8 +113,7 @@ export function FunkeMdocOfflineSharingScreen({
89
113
setIsProcessing ( false )
90
114
91
115
shutdownDataTransfer ( )
92
- pushToWallet ( )
93
- toast . show ( 'Proof has been declined.' , { customData : { preset : 'danger' } } )
116
+ handleError ( { reason : 'Proof has been declined' , redirect : true } )
94
117
}
95
118
96
119
const onProofComplete = ( ) => {
0 commit comments