Skip to content

Commit eb7dbe6

Browse files
committed
feat: Make the asset clickable link without issuer name
1 parent 5ef03e7 commit eb7dbe6

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

src/containers/Vault/VaultHeader/index.tsx

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,20 @@ import SocketContext from '../../shared/SocketContext'
1111
import { getMPTIssuance } from '../../../rippled/lib/rippled'
1212
import { parseVaultWebsite } from '../utils'
1313
import {
14-
shortenMPTID,
1514
shortenVaultID,
1615
shortenAccount,
17-
getCurrencySymbol,
1816
} from '../../shared/utils'
1917
import './styles.scss'
2018
import { useAnalytics } from '../../shared/analytics'
2119
import { parseAmount } from '../../shared/NumberFormattingUtils'
2220
import { convertHexToString } from '../../../rippled/lib/utils'
2321
import { Metadata } from '../../Token/MPT/Header/Metadata'
22+
import Currency from '../../shared/components/Currency'
2423

2524
interface VaultData {
2625
Owner?: string
2726
Asset?: {
28-
currency: string
27+
currency?: string
2928
issuer?: string
3029
mpt_issuance_id?: string
3130
}
@@ -57,19 +56,6 @@ const WITHDRAWAL_POLICIES: { [key: number]: string } = {
5756
1: 'first_come_first_served',
5857
}
5958

60-
const formatAsset = (asset: VaultData['Asset']): string | React.ReactNode => {
61-
if (!asset) return '-'
62-
if (asset.currency === 'XRP') return getCurrencySymbol('XRP')
63-
if (asset.mpt_issuance_id) {
64-
return (
65-
<RouteLink to={MPT_ROUTE} params={{ id: asset.mpt_issuance_id }}>
66-
{shortenMPTID(asset.mpt_issuance_id, 8, 6)}
67-
</RouteLink>
68-
)
69-
}
70-
return asset.currency
71-
}
72-
7359
const getAssetCurrency = (asset: VaultData['Asset']): string =>
7460
asset?.currency === 'XRP' ? '\uE900' : asset?.currency || ''
7561

@@ -252,7 +238,27 @@ export const VaultHeader = ({ data, vaultId, displayCurrency }: Props) => {
252238
<div className="details-column">
253239
<table className="token-table">
254240
<tbody>
255-
<TokenTableRow label={t('asset')} value={formatAsset(asset)} />
241+
<TokenTableRow
242+
label={t('asset')}
243+
value={
244+
asset?.currency === 'XRP' ? (
245+
getAssetCurrency(asset)
246+
) : (
247+
<Currency
248+
currency={
249+
asset?.currency ??
250+
asset?.mpt_issuance_id ??
251+
'Unknown Currency Error'
252+
}
253+
link
254+
issuer={asset?.issuer}
255+
isMPT={asset?.mpt_issuance_id !== undefined}
256+
shortenIssuer
257+
hideIssuer
258+
/>
259+
)
260+
}
261+
/>
256262
<TokenTableRow
257263
label={t('total_value_locked')}
258264
value={(() => {

src/containers/Vault/VaultHeader/test/VaultHeader.test.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,10 @@ describe('VaultHeader Component', () => {
375375
</TestWrapper>,
376376
)
377377

378-
// Verify the exact currency code is displayed
379-
expect(screen.getByText('USD')).toBeInTheDocument()
378+
// Verify the exact currency code is displayed and issuer is hidden
379+
const currencyEl = screen.getByTestId('currency')
380+
expect(currencyEl).toHaveTextContent('USD')
381+
expect(currencyEl).not.toHaveTextContent('rIssuerAccount123')
380382
})
381383

382384
it('displays truncated MPT ID as a link for MPT vaults', () => {
@@ -385,7 +387,6 @@ describe('VaultHeader Component', () => {
385387
const vaultData = {
386388
Owner: 'rTestOwner',
387389
Asset: {
388-
currency: 'MPT',
389390
mpt_issuance_id: mptId,
390391
},
391392
}
@@ -400,12 +401,8 @@ describe('VaultHeader Component', () => {
400401
</TestWrapper>,
401402
)
402403

403-
// MPT ID should be truncated: first 8 chars + "..." + last 6 chars
404-
const expectedTruncated = `${mptId.substring(0, 8)}...${mptId.substring(mptId.length - 6)}`
405-
// expectedTruncated = "00001234...ABCDEF"
406-
407404
// Should be a link to the MPT page with exact truncated text
408-
const mptLink = screen.getByRole('link', { name: expectedTruncated })
405+
const mptLink = screen.getByRole('link', { name: 'MPT (' + mptId + ')' })
409406
expect(mptLink.getAttribute('href')).toBe(`/mpt/${mptId}`)
410407
})
411408

@@ -427,7 +424,7 @@ describe('VaultHeader Component', () => {
427424

428425
// Should display "-" as fallback
429426
const assetRow = screen.getByText('Asset').closest('tr')
430-
expect(assetRow).toHaveTextContent('-')
427+
expect(assetRow).toHaveTextContent('AssetUnknown Currency Error')
431428
})
432429
})
433430

src/containers/shared/components/Currency.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface Props {
1414
shortenIssuer?: boolean
1515
displaySymbol?: boolean
1616
isMPT?: boolean
17+
hideIssuer?: boolean
1718
}
1819

1920
/*
@@ -28,6 +29,7 @@ const Currency = (props: Props) => {
2829
shortenIssuer = false,
2930
displaySymbol = true,
3031
isMPT = false,
32+
hideIssuer = false,
3133
} = props
3234
let content: string
3335

@@ -65,7 +67,7 @@ const Currency = (props: Props) => {
6567
display = `\uE900 ${display}`
6668
}
6769

68-
if (issuer) {
70+
if (issuer && !hideIssuer) {
6971
display += '.'
7072
display += shortenIssuer ? issuer.substring(0, 4) : issuer
7173
}

0 commit comments

Comments
 (0)