@@ -10,26 +10,31 @@ 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
- 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 ( ) ?? [ ] ;
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
+ }
33
38
34
39
/// <summary>
35
40
/// Determines whether the details of the credentials should be hidden.
@@ -97,7 +102,7 @@ public record CredentialModel
97
102
98
103
public bool ? IsDiscoverable { get ; }
99
104
100
- public string ? AuthenticatorName { get ; set ; }
105
+ public string AuthenticatorName { get ; set ; }
101
106
102
107
public bool IsNew ( )
103
108
{
@@ -107,18 +112,54 @@ public bool IsNew()
107
112
/// <summary>
108
113
/// The title of the credential card.
109
114
/// </summary>
110
- public string Title => AuthenticatorName ? . NullIfEmpty ( ) ?? Device . NullIfEmpty ( ) ?? "Passkey" ;
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
+ }
111
126
112
127
private string ? _subtitle ;
113
128
114
129
/// <summary>
115
- /// The subtitle of the credential card.
130
+ /// The sub title of the credential card.
116
131
/// </summary>
117
- public string SubTitle => _subtitle ??= AuthenticatorName switch
132
+ public string ? SubTitle
118
133
{
119
- null => Nickname ,
120
- _ => ! string . IsNullOrEmpty ( Nickname ) ? $ "{ Nickname } on { Device } " : Device
121
- } ;
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 ;
122
163
123
164
public CredentialModel (
124
165
byte [ ] descriptorId ,
@@ -135,7 +176,7 @@ public CredentialModel(
135
176
bool ? backupState ,
136
177
bool ? isBackupEligible ,
137
178
bool ? isDiscoverable ,
138
- string ? authenticatorName )
179
+ string authenticatorName )
139
180
{
140
181
DescriptorId = descriptorId . ToBase64Url ( ) ;
141
182
PublicKey = publicKey ;
0 commit comments