Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
74f4be16
Commit
74f4be16
authored
Apr 07, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
handle aliased imports
parent
6f1128a1
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
45 additions
and
18 deletions
+45
-18
contract.ts
types/api/contract.ts
+4
-1
ContractCode.tsx
ui/address/contract/ContractCode.tsx
+1
-0
ContractSourceCode.tsx
ui/address/contract/ContractSourceCode.tsx
+3
-2
CodeEditor.tsx
ui/shared/monaco/CodeEditor.tsx
+4
-3
getFullPathOfImportedFile.test.ts
ui/shared/monaco/utils/getFullPathOfImportedFile.test.ts
+22
-10
getFullPathOfImportedFile.ts
ui/shared/monaco/utils/getFullPathOfImportedFile.ts
+11
-2
No files found.
types/api/contract.ts
View file @
74f4be16
...
...
@@ -30,7 +30,10 @@ export interface SmartContract {
file_path
:
string
;
additional_sources
:
Array
<
{
file_path
:
string
;
source_code
:
string
}
>
;
external_libraries
:
Array
<
SmartContractExternalLibrary
>
|
null
;
compiler_settings
:
unknown
;
compiler_settings
?:
{
evmVersion
?:
string
;
remappings
?:
Array
<
string
>
;
};
verified_twin_address_hash
:
string
|
null
;
minimal_proxy_address_hash
:
string
|
null
;
}
...
...
ui/address/contract/ContractCode.tsx
View file @
74f4be16
...
...
@@ -177,6 +177,7 @@ const ContractCode = ({ addressHash }: Props) => {
isViper=
{
Boolean
(
data
.
is_vyper_contract
)
}
filePath=
{
data
.
file_path
}
additionalSource=
{
data
.
additional_sources
}
remappings=
{
data
.
compiler_settings
?.
remappings
}
/>
)
}
{
Boolean
(
data
.
compiler_settings
)
&&
(
...
...
ui/address/contract/ContractSourceCode.tsx
View file @
74f4be16
...
...
@@ -16,9 +16,10 @@ interface Props {
isViper
:
boolean
;
filePath
?:
string
;
additionalSource
?:
SmartContract
[
'
additional_sources
'
];
remappings
?:
Array
<
string
>
;
}
const
ContractSourceCode
=
({
data
,
hasSol2Yml
,
address
,
isViper
,
filePath
,
additionalSource
}:
Props
)
=>
{
const
ContractSourceCode
=
({
data
,
hasSol2Yml
,
address
,
isViper
,
filePath
,
additionalSource
,
remappings
}:
Props
)
=>
{
const
heading
=
(
<
Text
fontWeight=
{
500
}
>
<
span
>
Contract source code
</
span
>
...
...
@@ -56,7 +57,7 @@ const ContractSourceCode = ({ data, hasSol2Yml, address, isViper, filePath, addi
{
diagramLink
}
{
copyToClipboard
}
</
Flex
>
<
CodeEditor
data=
{
editorData
}
/>
<
CodeEditor
data=
{
editorData
}
remappings=
{
remappings
}
/>
</
section
>
);
};
...
...
ui/shared/monaco/CodeEditor.tsx
View file @
74f4be16
...
...
@@ -35,9 +35,10 @@ const EDITOR_HEIGHT = 500;
interface
Props
{
data
:
Array
<
File
>
;
remappings
?:
Array
<
string
>
;
}
const
CodeEditor
=
({
data
}:
Props
)
=>
{
const
CodeEditor
=
({
data
,
remappings
}:
Props
)
=>
{
const
[
instance
,
setInstance
]
=
React
.
useState
<
Monaco
|
undefined
>
();
const
[
editor
,
setEditor
]
=
React
.
useState
<
monaco
.
editor
.
IStandaloneCodeEditor
|
undefined
>
();
const
[
index
,
setIndex
]
=
React
.
useState
(
0
);
...
...
@@ -145,14 +146,14 @@ const CodeEditor = ({ data }: Props) => {
.
map
((
element
:
HTMLSpanElement
)
=>
element
.
innerText
)
.
join
(
''
);
const
fullPath
=
getFullPathOfImportedFile
(
data
[
index
].
file_path
,
path
);
const
fullPath
=
getFullPathOfImportedFile
(
data
[
index
].
file_path
,
path
,
remappings
);
const
fileIndex
=
data
.
findIndex
((
file
)
=>
file
.
file_path
===
fullPath
);
if
(
fileIndex
>
-
1
)
{
event
.
stopPropagation
();
handleSelectFile
(
fileIndex
);
}
}
},
[
data
,
handleSelectFile
,
index
,
isMetaPressed
,
isMobile
]);
},
[
data
,
handleSelectFile
,
index
,
isMetaPressed
,
isMobile
,
remappings
]);
const
handleKeyDown
=
React
.
useCallback
((
event
:
React
.
KeyboardEvent
)
=>
{
isMetaKey
(
event
)
&&
setIsMetaPressed
(
true
);
...
...
ui/shared/monaco/utils/getFullPathOfImportedFile.test.ts
View file @
74f4be16
...
...
@@ -18,20 +18,32 @@ it('returns undefined if imported file is outside the base file folder', () => {
expect
(
result
).
toBeUndefined
();
});
it
(
'
returns unmodified path if it is already absolute
'
,
()
=>
{
const
result
=
getFullPathOfImportedFile
(
'
/index.sol
'
,
'
/abc/contract.sol
'
,
);
expect
(
result
).
toBe
(
'
/abc/contract.sol
'
);
describe
(
'
returns unmodified path if it is already absolute
'
,
()
=>
{
it
(
'
with prefix
'
,
()
=>
{
const
result
=
getFullPathOfImportedFile
(
'
/index.sol
'
,
'
/abc/contract.sol
'
,
);
expect
(
result
).
toBe
(
'
/abc/contract.sol
'
);
});
it
(
'
without prefix
'
,
()
=>
{
const
result
=
getFullPathOfImportedFile
(
'
/index.sol
'
,
'
abc/contract.sol
'
,
);
expect
(
result
).
toBe
(
'
/abc/contract.sol
'
);
});
});
it
(
'
returns undefined for external path
'
,
()
=>
{
it
(
'
correctly manages remappings
'
,
()
=>
{
const
result
=
getFullPathOfImportedFile
(
'
/index.sol
'
,
'
https://github.com/ethereum/dapp/contract.sol
'
,
'
node_modules/@openzeppelin/contracts/access/AccessControl.sol
'
,
[
'
@ensdomains/=node_modules/@ensdomains/
'
,
'
@openzeppelin/=node_modules/@openzeppelin/
'
],
);
expect
(
result
).
toBe
Undefined
(
);
expect
(
result
).
toBe
(
'
/node_modules/@openzeppelin/contracts/access/AccessControl.sol
'
);
});
ui/shared/monaco/utils/getFullPathOfImportedFile.ts
View file @
74f4be16
import
stripLeadingSlash
from
'
lib/stripLeadingSlash
'
;
export
default
function
getFullPathOfImportedFile
(
baseFilePath
:
string
,
importedFilePath
:
string
)
{
export
default
function
getFullPathOfImportedFile
(
baseFilePath
:
string
,
importedFilePath
:
string
,
remappings
?:
Array
<
string
>
)
{
if
(
importedFilePath
[
0
]
!==
'
.
'
)
{
return
importedFilePath
[
0
]
===
'
/
'
?
importedFilePath
:
'
/
'
+
importedFilePath
;
let
result
=
importedFilePath
;
if
(
remappings
&&
remappings
.
length
>
0
)
{
const
[
alias
,
target
]
=
remappings
.
map
((
item
)
=>
item
.
split
(
'
=
'
)).
find
(([
key
])
=>
importedFilePath
.
startsWith
(
key
))
||
[];
if
(
alias
)
{
result
=
importedFilePath
.
replace
(
alias
,
target
);
}
}
return
result
[
0
]
===
'
/
'
?
result
:
'
/
'
+
result
;
}
const
baseFileChunks
=
stripLeadingSlash
(
baseFilePath
).
split
(
'
/
'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment