Skip to content

Commit

Permalink
Fix/remove contact (#160)
Browse files Browse the repository at this point in the history
Co-authored-by: Sai Ranjit Tummalapalli <[email protected]>
fix: close contact modal after deletion (#141)
fix: import wallet failure scenario (#142)
fix: scanning qrcode multiple times (#143)
fix deep link issue (#147)
fix: credential detail modal button container (#155)

Signed-off-by: Sai Ranjit Tummalapalli <[email protected]>
  • Loading branch information
poonam-ghewande authored and sairanjit committed Apr 16, 2024
1 parent ed53f80 commit f73144e
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 6 deletions.
42 changes: 41 additions & 1 deletion app/components/modals/CommonRemoveModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ const CommonRemoveModal: React.FC<CommonRemoveModalProps> = ({ usage, visible, d

const titleForConfirmButton = (): string => {
switch (usage) {
case ModalUsage.ContactRemoveWithCredentialsOffer:
return t('ContactDetails.GoToCredentialsOffer')
case ModalUsage.ContactRemoveWithProofRequest:
return t('ContactDetails.GoToProofRequest')
case ModalUsage.ContactRemove:
return t('ContactDetails.RemoveContact')
case ModalUsage.ContactRemoveWithCredentials:
Expand All @@ -146,6 +150,10 @@ const CommonRemoveModal: React.FC<CommonRemoveModalProps> = ({ usage, visible, d

const labelForConfirmButton = (): string => {
switch (usage) {
case ModalUsage.ContactRemoveWithCredentialsOffer:
return t('ContactDetails.GoToCredentialsOffer')
case ModalUsage.ContactRemoveWithProofRequest:
return t('ContactDetails.GoToProofRequest')
case ModalUsage.ContactRemove:
return t('ContactDetails.RemoveContact')
case ModalUsage.ContactRemoveWithCredentials:
Expand All @@ -160,6 +168,8 @@ const CommonRemoveModal: React.FC<CommonRemoveModalProps> = ({ usage, visible, d
const testIdForConfirmButton = (): string => {
switch (usage) {
case ModalUsage.ContactRemove:
case ModalUsage.ContactRemoveWithCredentialsOffer:
case ModalUsage.ContactRemoveWithProofRequest:
case ModalUsage.CredentialRemove:
return testIdWithKey('ConfirmRemoveButton')
case ModalUsage.ContactRemoveWithCredentials:
Expand All @@ -175,6 +185,8 @@ const CommonRemoveModal: React.FC<CommonRemoveModalProps> = ({ usage, visible, d
const testIdForCancelButton = (): string => {
switch (usage) {
case ModalUsage.ContactRemove:
case ModalUsage.ContactRemoveWithCredentialsOffer:
case ModalUsage.ContactRemoveWithProofRequest:
case ModalUsage.CredentialRemove:
return testIdWithKey('CancelRemoveButton')
case ModalUsage.ContactRemoveWithCredentials:
Expand Down Expand Up @@ -254,6 +266,28 @@ const CommonRemoveModal: React.FC<CommonRemoveModalProps> = ({ usage, visible, d
</View>
</View>
)
case ModalUsage.ContactRemoveWithCredentialsOffer:
return (
<View style={[{ marginBottom: 25 }]}>
<View style={[{ marginBottom: 25 }]}>
<Text style={[TextTheme.modalTitle]}>{t('ContactDetails.UnableToRemoveTitle')}</Text>
</View>
<View>
<Text style={[styles.bodyText]}>{t('ContactDetails.UnableToRemoveCaptionLabel')}</Text>
</View>
</View>
)
case ModalUsage.ContactRemoveWithProofRequest:
return (
<View style={[{ marginBottom: 25 }]}>
<View style={[{ marginBottom: 25 }]}>
<Text style={[TextTheme.modalTitle]}>{t('ContactDetails.UnableToRemoveTitle')}</Text>
</View>
<View>
<Text style={[styles.bodyText]}>{t('ContactDetails.UnableToRemoveCaptionRequestLabel')}</Text>
</View>
</View>
)
case ModalUsage.CredentialOfferDecline:
return (
<View style={[{ marginBottom: 25 }]}>
Expand Down Expand Up @@ -321,7 +355,13 @@ const CommonRemoveModal: React.FC<CommonRemoveModalProps> = ({ usage, visible, d
onPress={onSubmit}
disabled={disabled}
buttonType={
usage === ModalUsage.ContactRemoveWithCredentials ? ButtonType.ModalPrimary : ButtonType.ModalCritical
usage === ModalUsage.ContactRemoveWithCredentials
? ButtonType.ModalPrimary
: ButtonType.ModalCritical && usage === ModalUsage.ContactRemoveWithCredentialsOffer
? ButtonType.ModalPrimary
: ButtonType.ModalCritical && usage === ModalUsage.ContactRemoveWithProofRequest
? ButtonType.ModalPrimary
: ButtonType.ModalCritical
}
/>
</View>
Expand Down
4 changes: 4 additions & 0 deletions app/localization/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ const translation = {
"RemoveCaption": "To add credentials, the issuing organization needs to be a Contact.",
"UnableToRemoveTitle": "Unable to remove Contact",
"UnableToRemoveCaption": "Unable to remove because there are credentials issued by this Contact in your wallet. Remove the credentials first then remove this Contact.",
"UnableToRemoveCaptionLabel": "Unable to remove because there are credential offer issued by this Contact in your wallet. Remove the credentials offer first then remove this Contact.",
"UnableToRemoveCaptionRequestLabel": "Unable to remove because there are proof request issued by this Contact in your wallet. Remove the Proof request first then remove this Contact.",
"GoToCredentials": "Go to Credentials",
"GoToCredentialsOffer": "Go to CredentialsOffer",
"GoToProofRequest": "Go to ProofRequest",
"RemoveContact": "Remove Contact",
"ContactRemoved": "Contact removed",
"RemoveContactMessageTop": "By removing this Contact you'll no longer be able to:",
Expand Down
53 changes: 48 additions & 5 deletions app/screens/ContactDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {
CredentialState,
ProofState,
deleteConnectionRecordById,
deleteOobRecordById,
useConnectionById,
useCredentialByState,
useProofByState,
} from '@adeya/ssi'
import { useNavigation } from '@react-navigation/core'
import { StackNavigationProp, StackScreenProps } from '@react-navigation/stack'
Expand Down Expand Up @@ -34,6 +36,8 @@ const ContactDetails: React.FC<ContactDetailsProps> = ({ route }) => {
const navigation = useNavigation<StackNavigationProp<ContactStackParams>>()
const [isRemoveModalDisplayed, setIsRemoveModalDisplayed] = useState<boolean>(false)
const [isCredentialsRemoveModalDisplayed, setIsCredentialsRemoveModalDisplayed] = useState<boolean>(false)
const [isCredentialsOfferRemoveModalDisplayed, setIsCredentialsOfferRemoveModalDisplayed] = useState<boolean>(false)
const [isProofRequestRemoveModalDisplayed, setIsProofRequestRemoveModalDisplayed] = useState<boolean>(false)
const connection = useConnectionById(connectionId)
// FIXME: This should be exposed via a react hook that allows to filter credentials by connection id
const connectionCredentials = [
Expand All @@ -42,6 +46,12 @@ const ContactDetails: React.FC<ContactDetailsProps> = ({ route }) => {
].filter(credential => credential.connectionId === connection?.id)
const { ColorPallet, TextTheme } = useTheme()

const connectionCredentialsOffer = [...useCredentialByState(CredentialState.OfferReceived)].filter(
credential => credential.connectionId === connection?.id,
)
const connectionProofRequest = [...useProofByState(ProofState.RequestReceived)].filter(
credential => credential.connectionId === connection?.id,
)
const styles = StyleSheet.create({
contentContainer: {
padding: 20,
Expand All @@ -55,10 +65,19 @@ const ContactDetails: React.FC<ContactDetailsProps> = ({ route }) => {
})

const handleOnRemove = () => {
if (connectionCredentials?.length) {
setIsCredentialsRemoveModalDisplayed(true)
} else {
setIsRemoveModalDisplayed(true)
switch (true) {
case Boolean(connectionCredentialsOffer?.length):
setIsCredentialsOfferRemoveModalDisplayed(true)
break
case Boolean(connectionCredentials?.length):
setIsCredentialsRemoveModalDisplayed(true)
break
case Boolean(connectionProofRequest?.length):
setIsProofRequestRemoveModalDisplayed(true)
break
default:
setIsRemoveModalDisplayed(true)
break
}
}

Expand Down Expand Up @@ -97,16 +116,28 @@ const ContactDetails: React.FC<ContactDetailsProps> = ({ route }) => {
const handleGoToCredentials = () => {
navigation.getParent()?.navigate(TabStacks.CredentialStack, { screen: Screens.Credentials })
}

const handleGoToCredentialsOffer = () => {
navigation.getParent()?.navigate(TabStacks.HomeStack, { screen: Screens.Home })
}
const handleCancelUnableRemove = () => {
setIsCredentialsRemoveModalDisplayed(false)
}

const handleOfferCancelUnableRemove = () => {
setIsCredentialsOfferRemoveModalDisplayed(false)
}
const handleProofRequestCancelUnableRemove = () => {
setIsProofRequestRemoveModalDisplayed(false)
}

const callOnRemove = useCallback(() => handleOnRemove(), [])
const callSubmitRemove = useCallback(() => handleSubmitRemove(), [connection])
const callCancelRemove = useCallback(() => handleCancelRemove(), [])
const callGoToCredentials = useCallback(() => handleGoToCredentials(), [])
const callGoToCredentialsOffer = useCallback(() => handleGoToCredentialsOffer(), [])
const callCancelUnableToRemove = useCallback(() => handleCancelUnableRemove(), [])
const callCancelUnableToRemoveOffer = useCallback(() => handleOfferCancelUnableRemove(), [])
const callCancelUnableToRemoveProofRequest = useCallback(() => handleProofRequestCancelUnableRemove(), [])

const contactLabel = useMemo(() => getConnectionName(connection) ?? '', [connection])
const onDismissModalTouched = () => {
Expand Down Expand Up @@ -146,6 +177,18 @@ const ContactDetails: React.FC<ContactDetailsProps> = ({ route }) => {
onSubmit={callGoToCredentials}
onCancel={callCancelUnableToRemove}
/>
<CommonRemoveModal
usage={ModalUsage.ContactRemoveWithCredentialsOffer}
visible={isCredentialsOfferRemoveModalDisplayed}
onSubmit={callGoToCredentialsOffer}
onCancel={callCancelUnableToRemoveOffer}
/>
<CommonRemoveModal
usage={ModalUsage.ContactRemoveWithProofRequest}
visible={isProofRequestRemoveModalDisplayed}
onSubmit={callGoToCredentialsOffer}
onCancel={callCancelUnableToRemoveProofRequest}
/>
</View>
)}
<View style={[styles.controlsContainer]}>
Expand Down
2 changes: 2 additions & 0 deletions app/types/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ export enum ModalUsage {
CredentialOfferDecline,
ProofRequestDecline,
CustomNotificationDecline,
ContactRemoveWithCredentialsOffer,
ContactRemoveWithProofRequest,
}

0 comments on commit f73144e

Please sign in to comment.