Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,31 @@ export default function ClaimCredential() {
retrieved.error.message || "Failed to retrieve credentials.",
);
} else {
Alert.alert(
"Success",
`Retrieved ${retrieved.value.length} credential(s) successfully!`,
);
// A credential offer can contain more than one credential, and each one is
// retrieved independently. Narrow each item on isSuccess so that a credential
// that failed to retrieve is not reported as a success.
let successCount = 0;
const failureMessages: string[] = [];

for (const item of retrieved.value) {
if (item.isSuccess) {
successCount++;
} else {
failureMessages.push(`${item.docType}: ${item.error.message}`);
}
}

if (failureMessages.length === 0) {
Alert.alert(
"Success",
`Retrieved ${successCount} credential(s) successfully!`,
);
} else {
Alert.alert(
"Partial Success",
`Retrieved ${successCount} credential(s). Failed to retrieve ${failureMessages.length}:\n${failureMessages.join("\n")}`,
);
}
}
// Refresh the list of mobile credentials in the holder application
await getMobileCredentials();
Expand Down Expand Up @@ -155,11 +176,12 @@ export default function ClaimCredential() {
<ScrollView style={{ flex: 1 }}>
{credentialOffer.credentials.map(
(cred: OfferedCredential, index: number) => (
<View key={`${cred.doctype}-${index}`} style={styles.card}>
<View key={`${cred.docType}-${index}`} style={styles.card}>
<Text style={styles.cardTitle}>{cred.name}</Text>
<Text style={styles.text}>Document Type: {cred.doctype}</Text>
<Text style={styles.text}>Document Type: {cred.docType}</Text>
{/* An offer only includes claims when it contains claim data */}
<Text style={styles.text}>
Number of Claims: {cred.claims?.length}
Number of Claims: {cred.claims?.length ?? 0}
</Text>
</View>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"ios": "expo run:ios"
},
"dependencies": {
"@mattrglobal/mobile-credential-holder-react-native": "^8.1.1",
"@mattrglobal/mobile-credential-holder-react-native": "^10.0.0",
"expo": "^55",
"expo-build-properties": "~55.0.13",
"expo-constants": "~55.0.15",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function HolderProvider({ children }: { children: React.ReactNode }) {
const result = await initialize({
userAuthenticationConfiguration: {
userAuthenticationBehavior: UserAuthenticationBehavior.OnInitialize,
userAuthenticationType: UserAuthenticationType.BiometricOrPasscode,
userAuthenticationType: UserAuthenticationType.UserPresence,
},
credentialIssuanceConfiguration: {
autoTrustMobileCredentialIaca: true,
Expand Down Expand Up @@ -87,8 +87,23 @@ export function HolderProvider({ children }: { children: React.ReactNode }) {

const getMobileCredentials = useCallback(async () => {
if (!isHolderInitialized) return;
const credentials = await getCredentials();
setMobileCredentials(credentials);

try {
const result = await getCredentials();

if (result.isErr()) {
setError(result.error.message || "Failed to get credentials.");
return;
}

setMobileCredentials(result.value);
} catch (err) {
setError(
err instanceof Error
? err.message
: "Unknown error while getting credentials",
);
}
}, [isHolderInitialized]);

// When the holder is initialized, get the mobile credentials to display in the app
Expand All @@ -113,7 +128,18 @@ export function HolderProvider({ children }: { children: React.ReactNode }) {
style: "destructive",
onPress: async () => {
try {
await deleteCredential(credentialId);
const result = await deleteCredential(credentialId);

// Expected failures are returned as an error result rather
// than thrown, so handle them before reporting success
if (result.isErr()) {
Alert.alert(
"Error",
result.error.message || "Failed to delete credential.",
);
return;
}

Alert.alert("Success", "Credential deleted successfully.");
await getMobileCredentials();
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"ios": "expo run:ios"
},
"dependencies": {
"@mattrglobal/mobile-credential-holder-react-native": "^8.1.1",
"@mattrglobal/mobile-credential-holder-react-native": "^10.0.0",
"expo": "^55",
"expo-build-properties": "~55.0.13",
"expo-constants": "~55.0.15",
Expand Down
Loading