Skip to content

Commit 14ca7c9

Browse files
[CLICK-990] Uref truncating (#55)
* test commit * test commit * test commit * test commit * test commit * test commit * test commit * test commit * fixed deriveSplitDataFromNamedKeyValue * fixed deriveSplitDataFromNamedKeyValue * fixed deriveSplitDataFromNamedKeyValue * fixed deriveSplitDataFromNamedKeyValue * fixed deriveSplitDataFromNamedKeyValue * fixed deriveSplitDataFromNamedKeyValue * fixed deriveSplitDataFromNamedKeyValue * fixed deriveSplitDataFromNamedKeyValue * fixed deriveSplitDataFromNamedKeyValue * fixed deriveSplitDataFromNamedKeyValue * fixed deriveSplitDataFromNamedKeyValue * Fixed truncate issue * Fixed regex * Fixed regex 2
1 parent f15f615 commit 14ca7c9

10 files changed

Lines changed: 4699 additions & 4712 deletions

File tree

dist/cspr-design.es.js

Lines changed: 4595 additions & 4601 deletions
Large diffs are not rendered by default.

dist/cspr-design.umd.js

Lines changed: 38 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lib/components/deploy-actions/deploy-result-row.d.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { default as React } from 'react';
22
import { ActionIdentificationHashesType } from './deploy-action-row';
3-
import { AccountInfoResult, ContractResult, DataResponse, Deploy, DeployContractPackageResult, GetDeployResult } from '../../types/types';
3+
import { DataResponse, Deploy, GetDeployResult, ContractResult, DeployContractPackageResult, AccountInfoResult } from '../../types/types';
44
export declare enum ResultRowVariation {
55
default = "default",
66
gray = "gray"
@@ -9,9 +9,7 @@ export interface DeployResultRowComponentProps {
99
deploy: Deploy;
1010
loading: boolean;
1111
actionIdentificationHashes: ActionIdentificationHashesType;
12-
deployRawData?: DataResponse<GetDeployResult & {
13-
api_version: string;
14-
}> | null;
12+
deployRawData?: DataResponse<GetDeployResult> | null;
1513
actionComponents?: React.ReactElement[] | null;
1614
variation?: ResultRowVariation;
1715
shouldCollapse?: boolean;

dist/lib/components/deploy-actions/deploy-result-row.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lib/components/named-key-value/named-key-value.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lib/utils/named-key.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ export interface SplitDataType {
22
prefix: string;
33
hash: string;
44
}
5+
export declare const prefixOnlyRegExp: RegExp;
56
export declare const deriveSplitDataFromNamedKeyValue: (namedKeyValue: string) => SplitDataType;
67
//# sourceMappingURL=named-key.d.ts.map

dist/lib/utils/named-key.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/components/deploy-actions/deploy-result-row.tsx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,24 @@ import TransferActionRow from './components/TransferActionRow';
88
import { ActionIdentificationHashesType } from './deploy-action-row';
99
import { DeployActionDataProvider } from './services/deploy-action-context';
1010
import {
11-
AccountInfoResult,
12-
ContractResult,
1311
ContractTypeId,
1412
DataResponse,
15-
Deploy, DeployContractPackageResult,
13+
Deploy,
1614
DeployTransferResult,
1715
FTActionsResult,
18-
GetDeployResult,
1916
NftActionsResult,
17+
GetDeployResult, ContractResult, DeployContractPackageResult, AccountInfoResult,
2018
} from '../../types/types';
2119
import FlexRow from '../flex-row/flex-row';
22-
import BodyText from '../body-text/body-text';
2320
import FlexColumn from '../flex-column/flex-column';
2421
import ExpandCollapsedButton from '../expand-collapsed/expand-collapsed-button';
2522
import { getDeployStatus, Status } from '../deploy-status/deploy-status';
2623
import {isTransferDeploy} from "./utils/contract";
2724
import {isNonNullable} from "../../utils/guards";
2825
import {NftTypeToEntryPointMap} from '../../types/NFTToken';
2926
import {FTTransactionResult, FTActionType} from '../../types/FTToken';
27+
import BodyText from "../body-text/body-text.tsx";
28+
3029

3130
const DefaultResultItem = styled(FlexRow)(({ theme }) => ({
3231
padding: '14px 0',
@@ -60,9 +59,9 @@ const GrayResultItem = styled(FlexRow)(({ theme }) => ({
6059

6160
const ResultItemWrapper = ({ variation, ...props }) => {
6261
return variation === ResultRowVariation.default ? (
63-
<DefaultResultItem {...props} />
62+
<DefaultResultItem {...props} />
6463
) : (
65-
<GrayResultItem {...props} />
64+
<GrayResultItem {...props} />
6665
);
6766
};
6867

@@ -85,7 +84,7 @@ export interface DeployResultRowComponentProps {
8584
deploy: Deploy;
8685
loading: boolean;
8786
actionIdentificationHashes: ActionIdentificationHashesType;
88-
deployRawData?: DataResponse< GetDeployResult & {api_version: string}> | null;
87+
deployRawData?: DataResponse<GetDeployResult> | null;
8988
actionComponents?: React.ReactElement[] | null;
9089
variation?: ResultRowVariation;
9190
shouldCollapse?: boolean;
@@ -175,12 +174,11 @@ const getSortedResultComponents = ({
175174
getActionElementToRender(action)
176175
);
177176

178-
const combinedActionComponents = [
177+
return [
179178
associatedKeyComponent,
180179
...sortedActionComponents,
181180
...(actionComponents || []),
182181
].filter(isNonNullable);
183-
return combinedActionComponents;
184182
};
185183

186184
const manageCollapsingResults = ({
@@ -254,6 +252,8 @@ export const DeployResultRowComponent = (
254252
actionComponents,
255253
actionIdentificationHashes,
256254
});
255+
const actionsCount = combinedActionComponents?.length ?? 0;
256+
const isSingleResult = actionsCount <= 1;
257257

258258
const [isCollapsed, setCollapsed] = useState<boolean>(shouldCollapse);
259259

@@ -278,7 +278,7 @@ export const DeployResultRowComponent = (
278278

279279
const collapsedLabel =
280280
combinedActionComponents?.length <= 1 ? `View ${combinedActionComponents?.length} result`
281-
: `View all ${combinedActionComponents?.length} results`;
281+
: `View all ${combinedActionComponents?.length} results`;
282282
const expandedLabel =
283283
combinedActionComponents?.length <= 1
284284
? 'Collapse result'
@@ -314,7 +314,7 @@ export const DeployResultRowComponent = (
314314
type DeployResultRowProps = DeployResultRowComponentProps & {
315315
getAccountInfo: (publicKey: string) => AccountInfoResult | null | undefined;
316316
getContractPackageInfoByHash?: (
317-
contractPackageHash: string,
317+
contractPackageHash: string,
318318
) => DeployContractPackageResult | null | undefined;
319319
getContractInfoByHash?: (
320320
contractHash: string,
@@ -356,14 +356,14 @@ export const DeployResultRow = (props: DeployResultRowProps) => {
356356
return null;
357357
}
358358
return (
359-
<DeployActionDataProvider
360-
getAccountInfo={getAccountInfo}
361-
getContractPackageInfoByHash={getContractPackageInfoByHash}
362-
getContractInfoByHash={getContractInfoByHash}
363-
csprLiveDomainPath={csprLiveDomainPath}
364-
>
365-
<DeployResultRowComponent {...rest} />
366-
</DeployActionDataProvider>
359+
<DeployActionDataProvider
360+
getAccountInfo={getAccountInfo}
361+
getContractPackageInfoByHash={getContractPackageInfoByHash}
362+
getContractInfoByHash={getContractInfoByHash}
363+
csprLiveDomainPath={csprLiveDomainPath}
364+
>
365+
<DeployResultRowComponent {...rest} />
366+
</DeployActionDataProvider>
367367
);
368368
};
369369

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,44 @@
11
import React from 'react';
22
import { formatHash, HashLength } from '../../utils/formatters';
33
import { deriveSplitDataFromNamedKeyValue } from '../../utils/named-key';
4-
import { NamedKeyPrefix } from '../../utils/named-key-prefix';
54
import { useMatchMedia } from '../../utils/match-media';
65
import FlexRow from '../flex-row/flex-row';
76
import Link from '../link/link';
87

98
interface NamedKeyValueProps {
10-
namedKey: string;
11-
noPrefix?: boolean;
12-
hashLength?: HashLength;
13-
csprLiveDomainPath: string;
9+
namedKey: string;
10+
noPrefix?: boolean;
11+
hashLength?: HashLength;
12+
csprLiveDomainPath: string;
1413
}
1514

16-
export const NamedKeyValue = ({
17-
namedKey,
18-
noPrefix,
19-
hashLength,
20-
csprLiveDomainPath,
15+
export const NamedKeyValue = (
16+
{
17+
namedKey,
18+
noPrefix,
19+
hashLength,
20+
csprLiveDomainPath,
2121
}: NamedKeyValueProps) => {
22-
const responsiveHashLength = useMatchMedia(
23-
[HashLength.TINY, HashLength.MEDIUM, HashLength.FULL, HashLength.FULL],
24-
[],
25-
);
26-
const { prefix, hash } = deriveSplitDataFromNamedKeyValue(namedKey);
22+
const { prefix, hash } = deriveSplitDataFromNamedKeyValue(namedKey);
2723

28-
const isURefNamedKey = namedKey.includes(NamedKeyPrefix.UREF);
29-
const redirectHash = isURefNamedKey ? namedKey : hash;
24+
const responsiveHashLength = useMatchMedia(
25+
[HashLength.TINY, HashLength.MEDIUM, HashLength.FULL, HashLength.FULL],
26+
[hashLength],
27+
);
3028

31-
const redirectPath = `${csprLiveDomainPath}/search/${redirectHash}`;
32-
return (
33-
<FlexRow>
34-
{redirectPath ? (
35-
<Link color={'hash'} href={redirectPath}>
36-
{!noPrefix && prefix}
37-
{formatHash(hash, hashLength || responsiveHashLength)}
38-
</Link>
39-
) : (
40-
formatHash(hash, hashLength || responsiveHashLength)
41-
)}
42-
</FlexRow>
43-
);
44-
};
29+
const resolvedHashLength = hashLength ?? responsiveHashLength;
30+
31+
const redirectPath = `${csprLiveDomainPath}/search/${namedKey}`;
4532

46-
export default NamedKeyValue;
33+
const displayValue = formatHash(hash, resolvedHashLength);
34+
35+
return (
36+
<FlexRow>
37+
<Link color="hash" href={redirectPath}>
38+
{!noPrefix && prefix}
39+
{displayValue}
40+
</Link>
41+
</FlexRow>
42+
);
43+
};
44+
export default NamedKeyValue;

src/lib/utils/named-key.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
import { getNamedKeyPrefix, hashPrefixRegExpV2 } from './named-key-prefix';
2-
31
export interface SplitDataType {
42
prefix: string;
53
hash: string;
64
}
75

6+
export const prefixOnlyRegExp = new RegExp(`(?:(entity-)?contract(?:-package)?|account-hash|dictionary|withdraw|balance|deploy|uref|hash|era|bid)-(?=[0-9a-fA-F])`,
7+
'gi'
8+
);
9+
810
export const deriveSplitDataFromNamedKeyValue = (
9-
namedKeyValue: string,
11+
namedKeyValue: string
1012
): SplitDataType => {
11-
const [hash, lastDigits] = namedKeyValue
12-
.replace(hashPrefixRegExpV2, '')
13-
.split('-');
14-
15-
const formattedPrefix = getNamedKeyPrefix(namedKeyValue);
16-
const formattedHash = lastDigits ? `${hash}-${lastDigits}` : `${hash}`;
13+
const match = namedKeyValue.match(prefixOnlyRegExp);
14+
const prefix = match ? match[0] : '';
15+
const hash = prefix ? namedKeyValue.slice(prefix.length) : namedKeyValue;
1716

18-
return {
19-
prefix: formattedPrefix,
20-
hash: formattedHash,
21-
};
22-
};
17+
return { prefix, hash };
18+
};

0 commit comments

Comments
 (0)