@@ -10,31 +10,26 @@ public partial class Credentials : ComponentBase
10
10
{
11
11
public const string ManageCredentialFormName = "manage-credential-form" ;
12
12
13
- public required IReadOnlyCollection < Credential > Items { get ; set ; }
14
-
15
- public IReadOnlyCollection < CredentialModel > GetItems ( )
16
- {
17
- return Items . Select ( x =>
18
- {
19
- var viewModel = new CredentialModel (
20
- x . Descriptor . Id ,
21
- x . PublicKey ,
22
- x . SignatureCounter ,
23
- x . AttestationFmt ,
24
- x . CreatedAt ,
25
- x . AaGuid ,
26
- x . LastUsedAt ,
27
- x . RpId ,
28
- x . Origin ,
29
- x . Device ,
30
- x . Nickname ,
31
- x . BackupState ,
32
- x . IsBackupEligible ,
33
- x . IsDiscoverable ,
34
- AuthenticatorDataProvider . GetName ( x . AaGuid ) ) ;
35
- return viewModel ;
36
- } ) . ToList ( ) ;
37
- }
13
+ public required IReadOnlyCollection < Credential > ? Items { get ; set ; }
14
+
15
+ public IReadOnlyCollection < CredentialModel > GetItems ( ) =>
16
+ Items ? . Select ( x => new CredentialModel (
17
+ x . Descriptor . Id ,
18
+ x . PublicKey ,
19
+ x . SignatureCounter ,
20
+ x . AttestationFmt ,
21
+ x . CreatedAt ,
22
+ x . AaGuid ,
23
+ x . LastUsedAt ,
24
+ x . RpId ,
25
+ x . Origin ,
26
+ x . Device ,
27
+ x . Nickname ,
28
+ x . BackupState ,
29
+ x . IsBackupEligible ,
30
+ x . IsDiscoverable ,
31
+ x . AuthenticatorDisplayName ?? AuthenticatorDataProvider . GetName ( x . AaGuid ) )
32
+ ) . ToArray ( ) ?? [ ] ;
38
33
39
34
/// <summary>
40
35
/// Determines whether the details of the credentials should be hidden.
@@ -102,7 +97,7 @@ public record CredentialModel
102
97
103
98
public bool ? IsDiscoverable { get ; }
104
99
105
- public string AuthenticatorName { get ; set ; }
100
+ public string ? AuthenticatorName { get ; set ; }
106
101
107
102
public bool IsNew ( )
108
103
{
@@ -112,54 +107,18 @@ public bool IsNew()
112
107
/// <summary>
113
108
/// The title of the credential card.
114
109
/// </summary>
115
- public string Title
116
- {
117
- get
118
- {
119
- if ( IsAuthenticatorKnown )
120
- {
121
- return AuthenticatorName ;
122
- }
123
- return string . IsNullOrEmpty ( Device ) ? "Passkey" : Device ;
124
- }
125
- }
110
+ public string Title => AuthenticatorName ? . NullIfEmpty ( ) ?? Device . NullIfEmpty ( ) ?? "Passkey" ;
126
111
127
112
private string ? _subtitle ;
128
113
129
114
/// <summary>
130
- /// The sub title of the credential card.
115
+ /// The subtitle of the credential card.
131
116
/// </summary>
132
- public string ? SubTitle
117
+ public string SubTitle => _subtitle ??= AuthenticatorName switch
133
118
{
134
- get
135
- {
136
- if ( _subtitle != null )
137
- {
138
- return _subtitle ;
139
- }
140
-
141
- if ( IsAuthenticatorKnown )
142
- {
143
- if ( string . IsNullOrEmpty ( Nickname ) )
144
- {
145
- _subtitle = Device ;
146
- }
147
- else
148
- {
149
- var nickname = string . IsNullOrEmpty ( Nickname ) ? "No nickname" : Nickname ;
150
- _subtitle = $ "{ nickname } on { Device } ";
151
- }
152
- }
153
- else
154
- {
155
- _subtitle = Nickname ;
156
- }
157
-
158
- return _subtitle ;
159
- }
160
- }
161
-
162
- public bool IsAuthenticatorKnown => AaGuid != Guid . Empty ;
119
+ null => Nickname ,
120
+ _ => ! string . IsNullOrEmpty ( Nickname ) ? $ "{ Nickname } on { Device } " : Device
121
+ } ;
163
122
164
123
public CredentialModel (
165
124
byte [ ] descriptorId ,
@@ -176,7 +135,7 @@ public CredentialModel(
176
135
bool ? backupState ,
177
136
bool ? isBackupEligible ,
178
137
bool ? isDiscoverable ,
179
- string authenticatorName )
138
+ string ? authenticatorName )
180
139
{
181
140
DescriptorId = descriptorId . ToBase64Url ( ) ;
182
141
PublicKey = publicKey ;
0 commit comments