Skip to content

Commit 0642db4

Browse files
committed
add new regexp for named-key component
Signed-off-by: Evgeniy Bilov <eugenebelov@users.noreply.github.com>
1 parent f6621a1 commit 0642db4

9 files changed

Lines changed: 926 additions & 920 deletions

dist/cspr-design.es.js

Lines changed: 884 additions & 883 deletions
Large diffs are not rendered by default.

dist/cspr-design.umd.js

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export declare enum NamedKeyPrefix {
1111
ACCOUNT_HASH = "account-hash-",
1212
CONTRACT_PACKAGE = "contract-package-"
1313
}
14+
export declare const hashPrefixRegExpV2: RegExp;
15+
/** @deprecated use hashPrefixRegExpV2 instead */
1416
export declare const hashPrefixRegEx: RegExp;
1517
export declare const hasNamedKeyPrefix: (value: any) => boolean;
1618
export declare const getNamedKeyPrefix: (value: string) => string;

dist/lib/utils/named-key-prefix.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.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.

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@make-software/cspr-design",
3-
"version": "2.0.6",
3+
"version": "2.0.7",
44
"description": "React-based UI component library powering Casper Blockchain applications",
55
"homepage": "https://cspr.design",
66
"repository": "git://github.com/make-software/cspr-design",

src/lib/utils/named-key-prefix.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export enum NamedKeyPrefix {
1212
CONTRACT_PACKAGE = 'contract-package-',
1313
}
1414

15+
export const hashPrefixRegExpV2 = new RegExp(
16+
/^(?:(entity-)?contract(?:-package)?|account-hash|dictionary|withdraw|balance|deploy|uref|hash|era|bid)-[0-9a-f]{64}(?:-\d{3})?$/gi,
17+
);
18+
19+
/** @deprecated use hashPrefixRegExpV2 instead */
1520
export const hashPrefixRegEx = new RegExp(
1621
`(${Object.values(NamedKeyPrefix).join('|')})(?=[0-9a-fA-F])`,
1722
'i',
@@ -26,7 +31,7 @@ export const hasNamedKeyPrefix = (value: any): boolean =>
2631
export const getNamedKeyPrefix = (value: string): string => {
2732
const hasPrefix = hasNamedKeyPrefix(value);
2833

29-
return hasPrefix && value.match(hashPrefixRegEx)
30-
? value.match(hashPrefixRegEx)![0]
34+
return hasPrefix && value.match(hashPrefixRegExpV2)
35+
? value.match(hashPrefixRegExpV2)![0]
3136
: '';
3237
};

src/lib/utils/named-key.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { hashPrefixRegEx } from './named-key-prefix';
1+
import { getNamedKeyPrefix, hashPrefixRegExpV2 } from './named-key-prefix';
22

33
export interface SplitDataType {
44
prefix: string;
@@ -9,12 +9,10 @@ export const deriveSplitDataFromNamedKeyValue = (
99
namedKeyValue: string,
1010
): SplitDataType => {
1111
const [hash, lastDigits] = namedKeyValue
12-
.replace(hashPrefixRegEx, '')
12+
.replace(hashPrefixRegExpV2, '')
1313
.split('-');
1414

15-
const formattedPrefix = namedKeyValue.match(hashPrefixRegEx)
16-
? namedKeyValue.match(hashPrefixRegEx)![0]
17-
: '';
15+
const formattedPrefix = getNamedKeyPrefix(namedKeyValue);
1816
const formattedHash = lastDigits ? `${hash}-${lastDigits}` : `${hash}`;
1917

2018
return {

0 commit comments

Comments
 (0)