Skip to content

Commit 670a0ba

Browse files
Fix cairo hyperlinks (#386)
Co-authored-by: Eric Lau <[email protected]>
1 parent 0532980 commit 670a0ba

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

packages/ui/src/cairo/inject-hyperlinks.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ export function injectHyperlinks(code: string) {
77
while (match != null) {
88
const [line, libraryPrefix, libraryPath] = match;
99
if (line !== undefined && libraryPrefix !== undefined && libraryPath !== undefined) {
10-
const githubPrefix = `https://github.com/OpenZeppelin/cairo-contracts/blob/${contractsVersionTag}/src/`;
10+
const githubPrefix = `https://github.com/OpenZeppelin/cairo-contracts/blob/${contractsVersionTag}/packages/`;
1111

1212
let libraryPathSegments = libraryPath.split('::');
13+
libraryPathSegments.splice(1, 0, 'src');
1314

14-
// Remove the component name
15-
if (libraryPathSegments.length > 0 && libraryPathSegments[libraryPathSegments.length - 1] !== 'interface') {
16-
libraryPathSegments.pop();
17-
}
15+
removeComponentName(libraryPathSegments);
1816

1917
if (libraryPathSegments !== undefined && libraryPathSegments.length > 0) {
2018
const replacedImportLine = `use<\/span> <a class="import-link" href='${githubPrefix}${libraryPathSegments.join('/')}.cairo' target='_blank' rel='noopener noreferrer'>${libraryPrefix}::${libraryPath}</a>;`;
@@ -24,4 +22,14 @@ export function injectHyperlinks(code: string) {
2422
match = importRegex.exec(code);
2523
}
2624
return result;
27-
}
25+
}
26+
27+
function removeComponentName(libraryPathSegments: Array<string>) {
28+
const lastItem = libraryPathSegments[libraryPathSegments.length - 1];
29+
if (lastItem === 'UpgradeableComponent') {
30+
// Replace component name with 'upgradeable'
31+
libraryPathSegments.splice(-1, 1, 'upgradeable');
32+
} else {
33+
libraryPathSegments.pop();
34+
}
35+
}

0 commit comments

Comments
 (0)