-
Notifications
You must be signed in to change notification settings - Fork 105
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
feat(IT Wallet): [SIW-1824] Show alert if wallet instance is revoked #6547
base: master
Are you sure you want to change the base?
Changes from 13 commits
f1fc15b
50ec519
4e3857f
c7694d0
19d9176
7071c48
8582fb7
40bb43c
efee04b
cdb4447
dd2346a
e20bee2
0d1a844
06939b7
260a57a
e37c2fc
1728866
54168ff
9a2fefc
2c2b0c3
72bf28c
c788250
e03ed75
0c6fc9b
bfb16f4
24e0e5f
b6fa8d4
8ddd9ed
70ec8cb
545a54f
fe44716
2ee86b0
dfa16d8
bb5fcfa
d92a539
1261408
84ce577
fe8f6bc
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 | ||
---|---|---|---|---|
@@ -0,0 +1,110 @@ | ||||
import { Alert, AlertButton, Linking } from "react-native"; | ||||
import React from "react"; | ||||
import { IOToast } from "@pagopa/io-app-design-system"; | ||||
import I18n from "../../../../i18n"; | ||||
import { WalletInstanceRevocationReason } from "../../common/utils/itwTypesUtils"; | ||||
|
||||
const closeButtonText = I18n.t( | ||||
"features.itWallet.walletInstanceRevoked.alert.closeButton" | ||||
); | ||||
const alertCtaText = I18n.t( | ||||
"features.itWallet.walletInstanceRevoked.alert.cta" | ||||
); | ||||
|
||||
const itwMinIntergityReqUrl = "https://io.italia.it/documenti-su-io/faq/#n1_12"; | ||||
|
||||
/** | ||||
* Hook to monitor wallet instance status and display alerts if revoked. | ||||
* @param walletInstanceStatus - The status of the wallet instance, including whether it is revoked and the reason for revocation. | ||||
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.
Suggested change
|
||||
*/ | ||||
export const useItwWalletInstanceRevocationAlert = (walletInstanceStatus: { | ||||
isRevoked: boolean; | ||||
revocationReason?: WalletInstanceRevocationReason; | ||||
}) => { | ||||
React.useEffect(() => { | ||||
if (walletInstanceStatus.isRevoked) { | ||||
showWalletRevocationAlert(walletInstanceStatus.revocationReason); | ||||
} | ||||
}, [walletInstanceStatus]); | ||||
}; | ||||
|
||||
/** | ||||
* Displays an alert based on the revocation reason. | ||||
*/ | ||||
const showWalletRevocationAlert = ( | ||||
revocationReason?: WalletInstanceRevocationReason | ||||
) => { | ||||
switch (revocationReason) { | ||||
case "CERTIFICATE_REVOKED_BY_ISSUER": | ||||
showAlert( | ||||
I18n.t( | ||||
"features.itWallet.walletInstanceRevoked.alert.revokedByWalletProvider.title" | ||||
), | ||||
I18n.t( | ||||
"features.itWallet.walletInstanceRevoked.alert.revokedByWalletProvider.content" | ||||
), | ||||
[ | ||||
{ text: closeButtonText }, | ||||
{ | ||||
text: alertCtaText, | ||||
onPress: () => { | ||||
Linking.openURL(itwMinIntergityReqUrl).catch(() => { | ||||
IOToast.error(I18n.t("global.genericError")); | ||||
}); | ||||
} | ||||
} | ||||
] | ||||
); | ||||
break; | ||||
|
||||
case "NEW_WALLET_INSTANCE_CREATED": | ||||
showAlert( | ||||
I18n.t( | ||||
"features.itWallet.walletInstanceRevoked.alert.newWalletInstanceCreated.title" | ||||
), | ||||
I18n.t( | ||||
"features.itWallet.walletInstanceRevoked.alert.newWalletInstanceCreated.content" | ||||
), | ||||
[ | ||||
{ text: closeButtonText }, | ||||
{ | ||||
text: alertCtaText, | ||||
onPress: () => { | ||||
// TODO: Add the correct URL | ||||
Linking.openURL("").catch(() => { | ||||
IOToast.error(I18n.t("global.genericError")); | ||||
}); | ||||
} | ||||
} | ||||
] | ||||
); | ||||
break; | ||||
case "REVOKED_BY_USER": | ||||
showAlert( | ||||
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; | ||||
} | ||||
}; | ||||
|
||||
const showAlert = ( | ||||
title: string, | ||||
message: string, | ||||
buttons: Array<AlertButton> = [{ text: closeButtonText }] | ||||
) => { | ||||
Alert.alert(title, message, buttons); | ||||
}; | ||||
Comment on lines
+103
to
+109
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. Do we really need this? Why not using directly |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,21 +1,24 @@ | ||||
import * as O from "fp-ts/lib/Option"; | ||||
import { flow } from "fp-ts/lib/function"; | ||||
import { PersistConfig, persistReducer } from "redux-persist"; | ||||
import { createSelector } from "reselect"; | ||||
import { getType } from "typesafe-actions"; | ||||
import { Action } from "../../../../../store/actions/types"; | ||||
import { GlobalState } from "../../../../../store/reducers/types"; | ||||
import itwCreateSecureStorage from "../../../common/store/storages/itwSecureStorage"; | ||||
import { isWalletInstanceAttestationValid } from "../../../common/utils/itwAttestationUtils"; | ||||
import { itwLifecycleStoresReset } from "../../../lifecycle/store/actions"; | ||||
import { itwWalletInstanceAttestationStore } from "../actions"; | ||||
import { | ||||
itwWalletInstanceAttestationStore, | ||||
itwUpdateWalletInstanceStatus | ||||
} from "../actions"; | ||||
import { WalletInstanceRevocationReason } from "../../../common/utils/itwTypesUtils"; | ||||
|
||||
export type ItwWalletInstanceState = { | ||||
attestation: string | undefined; | ||||
isRevoked: boolean; | ||||
revocationReason?: WalletInstanceRevocationReason; | ||||
}; | ||||
|
||||
export const itwWalletInstanceInitialState: ItwWalletInstanceState = { | ||||
attestation: undefined | ||||
attestation: undefined, | ||||
isRevoked: false, | ||||
revocationReason: undefined | ||||
}; | ||||
|
||||
const CURRENT_REDUX_ITW_WALLET_INSTANCE_STORE_VERSION = -1; | ||||
|
@@ -27,10 +30,19 @@ const reducer = ( | |||
switch (action.type) { | ||||
case getType(itwWalletInstanceAttestationStore): { | ||||
return { | ||||
...state, | ||||
attestation: action.payload | ||||
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.
Suggested change
I think it's correct to reset the state when we save a new WI: if there is already a 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. Absolutely! Thanks for the suggestion |
||||
}; | ||||
} | ||||
|
||||
case getType(itwUpdateWalletInstanceStatus): { | ||||
return { | ||||
...state, | ||||
isRevoked: action.payload.is_revoked, | ||||
revocationReason: action.payload.revocation_reason | ||||
}; | ||||
} | ||||
|
||||
case getType(itwLifecycleStoresReset): | ||||
return { ...itwWalletInstanceInitialState }; | ||||
|
||||
|
@@ -50,16 +62,4 @@ const persistedReducer = persistReducer( | |||
reducer | ||||
); | ||||
|
||||
export const itwWalletInstanceAttestationSelector = (state: GlobalState) => | ||||
state.features.itWallet.walletInstance.attestation; | ||||
|
||||
export const itwIsWalletInstanceAttestationValidSelector = createSelector( | ||||
itwWalletInstanceAttestationSelector, | ||||
flow( | ||||
O.fromNullable, | ||||
O.map(isWalletInstanceAttestationValid), | ||||
O.getOrElse(() => false) | ||||
) | ||||
); | ||||
|
||||
export default persistedReducer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo:
Intergity
.