Skip to content

Commit aab6a4d

Browse files
committed
refactor: enhance transaction display logic with new helper functions
1 parent 50ab0be commit aab6a4d

1 file changed

Lines changed: 47 additions & 9 deletions

File tree

  • src/layouts/SecondaryKeys/components/SecondaryKeyItem

src/layouts/SecondaryKeys/components/SecondaryKeyItem/index.tsx

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import { Button } from '~/components/UiKit';
1010
import { AccountContext } from '~/context/AccountContext';
1111
import { AssetContext } from '~/context/AssetContext';
1212
import { PortfolioContext } from '~/context/PortfolioContext';
13-
import { formatBalance, formatDid } from '~/helpers/formatters';
13+
import {
14+
capitalizeFirstLetter,
15+
formatBalance,
16+
formatDid,
17+
} from '~/helpers/formatters';
1418
import { PermissionScopeType } from '../../types';
1519
import { deduplicateAssetsByID, formatAssetDisplay } from '../../utils';
1620
import {
@@ -333,6 +337,41 @@ export const SecondaryKeyItem = ({
333337
return detailsExpanded ? 'Hide details' : 'Show details';
334338
};
335339

340+
const getTransactionType = (
341+
extrinsics: string[] | undefined,
342+
): { hasSpecific: boolean; isAll: boolean; isNone: boolean } => {
343+
return {
344+
hasSpecific: !!(extrinsics && extrinsics.length > 0),
345+
isAll: extrinsics === undefined,
346+
isNone: extrinsics !== undefined && extrinsics.length === 0,
347+
};
348+
};
349+
350+
const renderTransactionDisplay = (
351+
pallet: string,
352+
extrinsics: string[] | undefined,
353+
): React.ReactNode => {
354+
const type = getTransactionType(extrinsics);
355+
const extrinsicsText = extrinsics?.join(', ') || '';
356+
const shouldBreak = type.hasSpecific && extrinsicsText.length > 25;
357+
358+
if (type.hasSpecific) {
359+
return (
360+
<>
361+
{capitalizeFirstLetter(pallet)} - {shouldBreak && <br />}
362+
{extrinsicsText}
363+
</>
364+
);
365+
}
366+
if (type.isAll) {
367+
return `${capitalizeFirstLetter(pallet)} (all)`;
368+
}
369+
if (type.isNone) {
370+
return `${capitalizeFirstLetter(pallet)} (none)`;
371+
}
372+
return null;
373+
};
374+
336375
return (
337376
<StyledSecondaryKeyItem>
338377
<StyledInfoWrapper>
@@ -401,16 +440,15 @@ export const SecondaryKeyItem = ({
401440
<PermissionDetailLabel>Included Functions:</PermissionDetailLabel>
402441
<PermissionDetailList>
403442
{transactionsPermission.values.map((tx) => {
404-
const extrinsicsText = tx.extrinsics?.join(', ') || '';
405-
const fullText = `${tx.pallet}.${extrinsicsText}`;
406-
const shouldBreak = fullText.length > 35;
407-
const txKey = `${tx.pallet}-${
408-
tx.extrinsics?.join('-') || 'all'
409-
}`;
443+
const txKey = `${tx.pallet}-${tx.extrinsics?.join('-') || 'all'}`;
444+
const displayContent = renderTransactionDisplay(
445+
tx.pallet,
446+
tx.extrinsics,
447+
);
448+
410449
return (
411450
<PermissionDetailValue key={txKey}>
412-
{tx.pallet}.{extrinsicsText && shouldBreak && <br />}
413-
{extrinsicsText}
451+
{displayContent}
414452
</PermissionDetailValue>
415453
);
416454
})}

0 commit comments

Comments
 (0)