Skip to content

Commit c91b1aa

Browse files
Copilotmvadari
andcommitted
Fix parser to handle both nested and flat credential structures, use SimpleGroup for better UI
Co-authored-by: mvadari <8029314+mvadari@users.noreply.github.com>
1 parent e29670a commit c91b1aa

File tree

2 files changed

+54
-41
lines changed

2 files changed

+54
-41
lines changed

src/containers/shared/components/Transaction/DepositPreauth/Simple.tsx

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,10 @@
11
import { useTranslation } from 'react-i18next'
22
import { SimpleRow } from '../SimpleRow'
3+
import { SimpleGroup } from '../SimpleGroup'
34
import { TransactionSimpleProps } from '../types'
45
import { DepositPreauth, CredentialAuth } from './types'
56
import { convertHexToString } from '../../../../../rippled/lib/utils'
67

7-
const renderCredentials = (credentials: CredentialAuth[], t: any) => {
8-
return (
9-
<>
10-
{credentials.map((cred, index) => (
11-
<div key={`${cred.Issuer}-${cred.CredentialType}`}>
12-
<SimpleRow
13-
label={index === 0 ? t('credential_issuer') : ''}
14-
data-testid={`credential-issuer-${index}`}
15-
>
16-
{cred.Issuer}
17-
</SimpleRow>
18-
<SimpleRow
19-
label={index === 0 ? t('credential_type') : ''}
20-
data-testid={`credential-type-${index}`}
21-
>
22-
{convertHexToString(cred.CredentialType)}
23-
</SimpleRow>
24-
</div>
25-
))}
26-
</>
27-
)
28-
}
29-
308
export const Simple = ({ data }: TransactionSimpleProps<DepositPreauth>) => {
319
const { t } = useTranslation()
3210
const { Authorize, Unauthorize, AuthorizeCredentials, UnauthorizeCredentials } = data.instructions
@@ -49,23 +27,47 @@ export const Simple = ({ data }: TransactionSimpleProps<DepositPreauth>) => {
4927

5028
if (AuthorizeCredentials && AuthorizeCredentials.length > 0) {
5129
return (
52-
<>
53-
<SimpleRow label={t('authorize')} data-testid="authorize-credentials-label">
54-
{t('accepted_credentials')}
55-
</SimpleRow>
56-
{renderCredentials(AuthorizeCredentials, t)}
57-
</>
30+
<SimpleGroup title={`${t('authorize')} ${t('accepted_credentials')}`}>
31+
{AuthorizeCredentials.map((cred, index) => (
32+
<div key={`${cred.Issuer}-${cred.CredentialType}`}>
33+
<SimpleRow
34+
label={t('credential_issuer')}
35+
data-testid={`credential-issuer-${index}`}
36+
>
37+
{cred.Issuer}
38+
</SimpleRow>
39+
<SimpleRow
40+
label={t('credential_type')}
41+
data-testid={`credential-type-${index}`}
42+
>
43+
{convertHexToString(cred.CredentialType)}
44+
</SimpleRow>
45+
</div>
46+
))}
47+
</SimpleGroup>
5848
)
5949
}
6050

6151
if (UnauthorizeCredentials && UnauthorizeCredentials.length > 0) {
6252
return (
63-
<>
64-
<SimpleRow label={t('unauthorize')} data-testid="unauthorize-credentials-label">
65-
{t('accepted_credentials')}
66-
</SimpleRow>
67-
{renderCredentials(UnauthorizeCredentials, t)}
68-
</>
53+
<SimpleGroup title={`${t('unauthorize')} ${t('accepted_credentials')}`}>
54+
{UnauthorizeCredentials.map((cred, index) => (
55+
<div key={`${cred.Issuer}-${cred.CredentialType}`}>
56+
<SimpleRow
57+
label={t('credential_issuer')}
58+
data-testid={`credential-issuer-${index}`}
59+
>
60+
{cred.Issuer}
61+
</SimpleRow>
62+
<SimpleRow
63+
label={t('credential_type')}
64+
data-testid={`credential-type-${index}`}
65+
>
66+
{convertHexToString(cred.CredentialType)}
67+
</SimpleRow>
68+
</div>
69+
))}
70+
</SimpleGroup>
6971
)
7072
}
7173

src/containers/shared/components/Transaction/DepositPreauth/parser.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,33 @@ import { CredentialAuth, DepositPreauth } from './types'
22

33
// Transform the nested XRPL credential structure to flat CredentialAuth objects
44
const transformCredentials = (credentials: any[]): CredentialAuth[] => {
5-
return credentials.map((item) => ({
6-
Issuer: item.Credential.Issuer,
7-
CredentialType: item.Credential.CredentialType,
8-
}))
5+
return credentials.map((item) => {
6+
// Check if it's nested (has Credential wrapper) or already flat
7+
if (item.Credential) {
8+
return {
9+
Issuer: item.Credential.Issuer,
10+
CredentialType: item.Credential.CredentialType,
11+
}
12+
} else {
13+
// Already flat, return as-is
14+
return {
15+
Issuer: item.Issuer,
16+
CredentialType: item.CredentialType,
17+
}
18+
}
19+
})
920
}
1021

1122
export const parser = (tx: any): DepositPreauth => {
12-
// Handle AuthorizeCredentials with nested structure
23+
// Handle AuthorizeCredentials (both nested and flat structures)
1324
if (tx.AuthorizeCredentials) {
1425
return {
1526
...tx,
1627
AuthorizeCredentials: transformCredentials(tx.AuthorizeCredentials),
1728
} as DepositPreauth
1829
}
1930

20-
// Handle UnauthorizeCredentials with nested structure
31+
// Handle UnauthorizeCredentials (both nested and flat structures)
2132
if (tx.UnauthorizeCredentials) {
2233
return {
2334
...tx,

0 commit comments

Comments
 (0)