-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(IT Wallet): [SIW-1824] Show alert if wallet instance is revoked (#…
…6547) ## Short description This PR adds functionality to display an alert in the wallet section when the Wallet Instance has been revoked. The alerts are displayed based on the revocation reason. ## List of changes proposed in this pull request - add `itwUpdateWalletInstanceStatus` in `getStatusOrResetWalletInstance` to update the wallet instance status - update the global state of Wallet Instance including revocation details - add `itwWalletInstanceStatusSelector` to retrieve WI status - add `useItwWalletInstanceRevocationAlert` to display `Alert` in based on the revocation reason ## How to test Simulate or revoked via Web the wallet instance revocation and navigate to wallet section CERTIFICATE_REVOKED_BY_ISSUER https://github.com/user-attachments/assets/9aa867fb-f690-4da4-8e19-a1e53298e6de REVOKED_BY_USER https://github.com/user-attachments/assets/24899e8b-0110-4228-8edc-8f2b6da3e7e3
- Loading branch information
1 parent
323996f
commit fbe9e87
Showing
19 changed files
with
322 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
ts/features/itwallet/walletInstance/hook/useItwWalletInstanceRevocationAlert.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { Alert } from "react-native"; | ||
import { useCallback } from "react"; | ||
import I18n from "../../../../i18n"; | ||
import { WalletInstanceRevocationReason } from "../../common/utils/itwTypesUtils"; | ||
import { useIODispatch, useIOSelector } from "../../../../store/hooks"; | ||
import { itwWalletInstanceStatusSelector } from "../store/selectors"; | ||
import { useOnFirstRender } from "../../../../utils/hooks/useOnFirstRender"; | ||
import { itwUpdateWalletInstanceStatus } from "../store/actions"; | ||
import { openWebUrl } from "../../../../utils/url"; | ||
|
||
const closeButtonText = I18n.t( | ||
"features.itWallet.walletInstanceRevoked.alert.closeButton" | ||
); | ||
const alertCtaText = I18n.t( | ||
"features.itWallet.walletInstanceRevoked.alert.cta" | ||
); | ||
|
||
const itwMinIntegrityReqUrl = "https://io.italia.it/documenti-su-io/faq/#n1_12"; | ||
const itwDocsOnIOMultipleDevicesUrl = | ||
"https://io.italia.it/documenti-su-io/faq/#n1_14"; | ||
|
||
/** | ||
* Hook to monitor wallet instance status and display alerts if revoked. | ||
*/ | ||
export const useItwWalletInstanceRevocationAlert = () => { | ||
const walletInstanceStatus = useIOSelector(itwWalletInstanceStatusSelector); | ||
const dispatch = useIODispatch(); | ||
|
||
useOnFirstRender( | ||
useCallback(() => { | ||
if (walletInstanceStatus?.is_revoked) { | ||
showWalletRevocationAlert(walletInstanceStatus.revocation_reason); | ||
dispatch(itwUpdateWalletInstanceStatus(undefined)); | ||
} | ||
}, [walletInstanceStatus, dispatch]) | ||
); | ||
}; | ||
|
||
/** | ||
* Displays an alert based on the revocation reason. | ||
*/ | ||
const showWalletRevocationAlert = ( | ||
revocationReason?: WalletInstanceRevocationReason | ||
) => { | ||
switch (revocationReason) { | ||
case "CERTIFICATE_REVOKED_BY_ISSUER": | ||
Alert.alert( | ||
I18n.t( | ||
"features.itWallet.walletInstanceRevoked.alert.revokedByWalletProvider.title" | ||
), | ||
I18n.t( | ||
"features.itWallet.walletInstanceRevoked.alert.revokedByWalletProvider.content" | ||
), | ||
[ | ||
{ text: closeButtonText }, | ||
{ | ||
text: alertCtaText, | ||
onPress: () => openWebUrl(itwMinIntegrityReqUrl) | ||
} | ||
] | ||
); | ||
break; | ||
|
||
case "NEW_WALLET_INSTANCE_CREATED": | ||
Alert.alert( | ||
I18n.t( | ||
"features.itWallet.walletInstanceRevoked.alert.newWalletInstanceCreated.title" | ||
), | ||
I18n.t( | ||
"features.itWallet.walletInstanceRevoked.alert.newWalletInstanceCreated.content" | ||
), | ||
[ | ||
{ text: closeButtonText }, | ||
{ | ||
text: alertCtaText, | ||
onPress: () => openWebUrl(itwDocsOnIOMultipleDevicesUrl) | ||
} | ||
] | ||
); | ||
break; | ||
case "REVOKED_BY_USER": | ||
Alert.alert( | ||
I18n.t( | ||
"features.itWallet.walletInstanceRevoked.alert.revokedByUser.title" | ||
), | ||
I18n.t( | ||
"features.itWallet.walletInstanceRevoked.alert.revokedByUser.content" | ||
), | ||
[ | ||
{ | ||
text: I18n.t( | ||
"features.itWallet.walletInstanceRevoked.alert.closeButtonAlt" | ||
) | ||
} | ||
] | ||
); | ||
break; | ||
default: | ||
break; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
ts/features/itwallet/walletInstance/store/selectors/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as O from "fp-ts/lib/Option"; | ||
import { flow } from "fp-ts/lib/function"; | ||
import { createSelector } from "reselect"; | ||
import { GlobalState } from "../../../../../store/reducers/types"; | ||
import { isWalletInstanceAttestationValid } from "../../../common/utils/itwAttestationUtils"; | ||
|
||
/* Selector to get the wallet instance attestation */ | ||
export const itwWalletInstanceAttestationSelector = (state: GlobalState) => | ||
state.features.itWallet.walletInstance.attestation; | ||
|
||
/* Selector to check if the attestation is valid */ | ||
export const itwIsWalletInstanceAttestationValidSelector = createSelector( | ||
itwWalletInstanceAttestationSelector, | ||
flow( | ||
O.fromNullable, | ||
O.map(isWalletInstanceAttestationValid), | ||
O.getOrElse(() => false) | ||
) | ||
); | ||
|
||
/* Selector to get the wallet instance status */ | ||
export const itwWalletInstanceStatusSelector = (state: GlobalState) => | ||
state.features.itWallet.walletInstance.status; |
Oops, something went wrong.