Skip to content

Commit

Permalink
small improvements
Browse files Browse the repository at this point in the history
Signed-off-by: kenkosmowski <[email protected]>
  • Loading branch information
kenkosmowski committed Nov 21, 2024
1 parent 1825e3e commit 4dd424d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public async Task<CredentialSetRecord> RefreshCredentialSetState(CredentialSetRe
if (credentialSetRecord.IsDeleted())
return credentialSetRecord;

credentialSetRecord.ExpiresAt.IfSome( expiresAt =>
credentialSetRecord.ExpiresAt.IfSome(expiresAt =>
{
if (expiresAt < DateTime.UtcNow)
credentialSetRecord.State = CredentialState.Expired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,4 @@ public static JObject EncodeToJson(this CredentialDisplay display)

return result;
}

// TODO: Unpure
public static SdJwtDisplay ToSdJwtDisplay(this CredentialDisplay credentialDisplay)
{
var logo = new SdJwtDisplay.SdJwtLogo
{
Uri = credentialDisplay.Logo.ToNullable()?.Uri!,
AltText = credentialDisplay.Logo.ToNullable()?.AltText.ToNullable()
};

return new SdJwtDisplay
{
Logo = logo,
Name = credentialDisplay.Name.ToNullable(),
BackgroundColor = credentialDisplay.BackgroundColor.ToNullable(),
Locale = credentialDisplay.Locale.ToNullable()?.ToString(),
TextColor = credentialDisplay.TextColor.ToNullable()
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public record CredentialLogo
/// </summary>
public Uri Uri { get; }

private CredentialLogo(Option<string> altText, Uri uri)
private CredentialLogo(Uri uri, Option<string> altText)
{
AltText = altText;
Uri = uri;
Expand All @@ -33,17 +33,14 @@ public static Option<CredentialLogo> OptionalCredentialLogo(JToken logo)
var altText = logo.GetByKey(AltTextJsonKey).ToOption().OnSome(text =>
{
var str = text.ToString();
if (string.IsNullOrWhiteSpace(str))
return Option<string>.None;
return str;
return string.IsNullOrWhiteSpace(str) ? Option<string>.None : str;
});

return logo.GetByKey(UriJsonKey).ToOption().Match(
uri => {
try
{
return new CredentialLogo(altText, new Uri(uri.ToString()));
return new CredentialLogo(new Uri(uri.ToString()), altText);
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ public static Dictionary<string, ClaimMetadata> ExtractClaimMetadata(this SdJwtC
{
var claimMetadatas = new Dictionary<string, ClaimMetadata> { { claimMetadata.Key, claimMetadata.Value } };
if (!(claimMetadata.Value.NestedClaims == null || claimMetadata.Value.NestedClaims.Count == 0))
if (claimMetadata.Value.NestedClaims == null || claimMetadata.Value.NestedClaims.Count == 0)
return claimMetadatas;
foreach (var nested in claimMetadata.Value.NestedClaims!)
{
foreach (var nested in claimMetadata.Value.NestedClaims!)
{
claimMetadatas.Add(claimMetadata.Key + "." + nested.Key, nested.Value?.ToObject<ClaimMetadata>()!);
}
claimMetadatas.Add(claimMetadata.Key + "." + nested.Key, nested.Value?.ToObject<ClaimMetadata>()!);
}
return claimMetadatas;
})
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value) ?? new Dictionary<string, ClaimMetadata>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,12 @@ await credential.Value.Match(
},
// ReSharper disable once UnusedParameter.Local
transactionId => throw new NotImplementedException());

await result.OnSuccess(async _ => await _credentialSetService.AddAsync(credentialSet));

await result.OnSuccess(async task =>
{
await task;
await _credentialSetService.AddAsync(credentialSet);
});

return credentialSet;
}
Expand Down

0 comments on commit 4dd424d

Please sign in to comment.