Skip to content

Commit

Permalink
feat: add timer and text (#1891)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason C. Leach <[email protected]>
  • Loading branch information
jleach authored Mar 28, 2024
1 parent 8a71739 commit 96bb0a0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/src/localization/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ const translation = {
"AppOnOtherDevice": "I have it on another device",
"CreatePersonCred": "Step 2: Create your Person credential",
"StartProcess": "Start the process",
"PageTitle": "Person Credential"
"PageTitle": "Person Credential",
"PleaseWait": "Please wait as we get things ready for you",
},
"NetInfo": {
"NoInternetConnectionTitle": "No internet connection",
Expand Down
3 changes: 2 additions & 1 deletion app/src/localization/fr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ const translation = {
"AppOnOtherDevice": "I have it on another device (FR)",
"CreatePersonCred": "Step 2: Create your Person credential (FR)",
"StartProcess": "Start the process (FR)",
"PageTitle": "Person Credential (FR)"
"PageTitle": "Person Credential (FR)",
"PleaseWait": "Please wait as we get things ready for you (FR)",
},
"NetInfo": {
"NoInternetConnectionTitle": "No internet connection (FR)",
Expand Down
3 changes: 2 additions & 1 deletion app/src/localization/pt-br/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ const translation = {
"AppOnOtherDevice": "I have it on another device (PT-BR)",
"CreatePersonCred": "Step 2: Create your Person credential (PT-BR)",
"StartProcess": "Start the process (PT-BR)",
"PageTitle": "Person Credential (PT-BR)"
"PageTitle": "Person Credential (PT-BR)",
"PleaseWait": "Please wait as we get things ready for you (PT-BR)",
},
"NetInfo": {
"NoInternetConnectionTitle": "No internet connection (PT-BR)",
Expand Down
33 changes: 30 additions & 3 deletions app/src/screens/PersonCredential.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import {
BifoldAgent,
Screens,
Stacks,
InfoTextBox,
} from '@hyperledger/aries-bifold-core'
import { useNavigation } from '@react-navigation/native'
import React, { useState, useCallback, useEffect } from 'react'
import React, { useState, useCallback, useEffect, useRef } from 'react'
import { useTranslation } from 'react-i18next'
import { StyleSheet, Text, View, TouchableOpacity, Linking, Platform, ScrollView } from 'react-native'
import { SafeAreaView } from 'react-native-safe-area-context'
Expand All @@ -25,6 +26,8 @@ import { getAvailableAttestationCredentials } from '../helpers/Attestation'
import { connectToIASAgent, authenticateWithServiceCard, WellKnownAgentDetails } from '../helpers/BCIDHelper'
import { BCState } from '../store'

const attestationProofRequestWaitTimeout = 10000

export default function PersonCredential() {
const { agent } = useAgent()
const [store] = useStore<BCState>()
Expand All @@ -39,6 +42,7 @@ export default function PersonCredential() {
const [remoteAgentDetails, setRemoteAgentDetails] = useState<WellKnownAgentDetails | undefined>()
const { loading: attestationLoading } = useAttestation ? useAttestation() : { loading: false }
const [didCompleteAttestationProofRequest, sedDidCompleteAttestationProofRequest] = useState<boolean>(false)
const timer = useRef<NodeJS.Timeout>()

const styles = StyleSheet.create({
pageContainer: {
Expand Down Expand Up @@ -143,6 +147,24 @@ export default function PersonCredential() {
.then((remoteAgentDetails: WellKnownAgentDetails) => {
setRemoteAgentDetails(remoteAgentDetails)

timer.current = setTimeout(() => {
if (!remoteAgentDetails || !remoteAgentDetails.connectionId) {
return
}

const proofRequest = receivedProofRequests.find(
(proof) => proof.connectionId === remoteAgentDetails.connectionId
)
if (!proofRequest) {
// No proof from our IAS Agent to respond to, do nothing.
agent.config.logger.info(
`Waited ${attestationProofRequestWaitTimeout / 1000}sec on attestation proof request, continuing`
)

sedDidCompleteAttestationProofRequest(true)
}
}, attestationProofRequestWaitTimeout)

agent.config.logger.error(`Connected to IAS agent, connectionId: ${remoteAgentDetails?.connectionId}`)
})
.catch((error) => {
Expand All @@ -158,8 +180,6 @@ export default function PersonCredential() {
return
}

// TODO:(jl) We need to set a 10 second timeout.

// We have an attestation credential and can respond to an
// attestation proof request.
const proofRequest = receivedProofRequests.find((proof) => proof.connectionId === remoteAgentDetails.connectionId)
Expand All @@ -168,6 +188,8 @@ export default function PersonCredential() {
return
}

timer.current && clearTimeout(timer.current)

acceptAttestationProofRequest(agent, proofRequest)
.then((status: boolean) => {
// We can unblock the workflow and proceed with
Expand Down Expand Up @@ -294,6 +316,11 @@ export default function PersonCredential() {
{t('PersonCredential.CreatePersonCred')}
</Text>
</View>
{workflowInProgress ? (
<View style={{ marginBottom: 10 }}>
<InfoTextBox>{t('PersonCredential.PleaseWait')}</InfoTextBox>
</View>
) : null}
{appInstalled ? (
<Button
buttonType={ButtonType.Primary}
Expand Down

0 comments on commit 96bb0a0

Please sign in to comment.