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
058575d9
Commit
058575d9
authored
Jun 07, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor and remove context usage
parent
464c15f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
32 deletions
+60
-32
ContractCode.tsx
ui/address/contract/ContractCode.tsx
+6
-4
ContractSourceCode.tsx
ui/address/contract/ContractSourceCode.tsx
+54
-28
No files found.
ui/address/contract/ContractCode.tsx
View file @
058575d9
...
@@ -212,10 +212,12 @@ const ContractCode = ({ addressHash, noSocket }: Props) => {
...
@@ -212,10 +212,12 @@ const ContractCode = ({ addressHash, noSocket }: Props) => {
isLoading={ isPlaceholderData }
isLoading={ isPlaceholderData }
/>
/>
) }
) }
<ContractSourceCode
{ data?.is_verified && (
address={ addressHash }
<ContractSourceCode
isLoading={ isPlaceholderData }
address={ addressHash }
/>
implementationAddress={ addressInfo?.implementation_address ?? undefined }
/>
) }
{ data?.compiler_settings ? (
{ data?.compiler_settings ? (
<RawDataSnippet
<RawDataSnippet
data={ JSON.stringify(data.compiler_settings, undefined, 4) }
data={ JSON.stringify(data.compiler_settings, undefined, 4) }
...
...
ui/address/contract/ContractSourceCode.tsx
View file @
058575d9
...
@@ -5,13 +5,13 @@ import React from 'react';
...
@@ -5,13 +5,13 @@ import React from 'react';
import
type
{
SmartContract
}
from
'
types/api/contract
'
;
import
type
{
SmartContract
}
from
'
types/api/contract
'
;
import
type
{
ArrayElement
}
from
'
types/utils
'
;
import
type
{
ArrayElement
}
from
'
types/utils
'
;
import
useApiQuery
from
'
lib/api/useApiQuery
'
;
import
*
as
stubs
from
'
stubs/contract
'
;
import
CopyToClipboard
from
'
ui/shared/CopyToClipboard
'
;
import
CopyToClipboard
from
'
ui/shared/CopyToClipboard
'
;
import
LinkInternal
from
'
ui/shared/LinkInternal
'
;
import
LinkInternal
from
'
ui/shared/LinkInternal
'
;
import
CodeEditor
from
'
ui/shared/monaco/CodeEditor
'
;
import
CodeEditor
from
'
ui/shared/monaco/CodeEditor
'
;
import
formatFilePath
from
'
ui/shared/monaco/utils/formatFilePath
'
;
import
formatFilePath
from
'
ui/shared/monaco/utils/formatFilePath
'
;
import
{
useContractContext
}
from
'
./context
'
;
const
SOURCE_CODE_OPTIONS
=
[
const
SOURCE_CODE_OPTIONS
=
[
{
id
:
'
primary
'
,
label
:
'
Proxy
'
}
as
const
,
{
id
:
'
primary
'
,
label
:
'
Proxy
'
}
as
const
,
{
id
:
'
secondary
'
,
label
:
'
Implementation
'
}
as
const
,
{
id
:
'
secondary
'
,
label
:
'
Implementation
'
}
as
const
,
...
@@ -31,26 +31,45 @@ function getEditorData(contractInfo: SmartContract | undefined) {
...
@@ -31,26 +31,45 @@ function getEditorData(contractInfo: SmartContract | undefined) {
}
}
interface
Props
{
interface
Props
{
address
?:
string
;
// todo_tom need address of proxy contract
address
?:
string
;
i
sLoading
?:
boolean
;
// todo_tom should be true if proxyInfo is not loaded
i
mplementationAddress
?:
string
;
}
}
// todo_tom fix mobile layout
const
ContractSourceCode
=
({
address
,
implementationAddress
}:
Props
)
=>
{
const
ContractSourceCode
=
({
address
,
isLoading
}:
Props
)
=>
{
const
[
sourceType
,
setSourceType
]
=
React
.
useState
<
SourceCodeType
>
(
'
primary
'
);
const
[
sourceType
,
setSourceType
]
=
React
.
useState
<
SourceCodeType
>
(
'
primary
'
);
const
{
contractInfo
:
primaryContract
,
proxyInfo
:
secondaryContract
}
=
useContractContext
();
const
primaryContractQuery
=
useApiQuery
(
'
contract
'
,
{
pathParams
:
{
hash
:
address
},
const
editorDataPrimary
=
React
.
useMemo
(()
=>
{
queryOptions
:
{
return
getEditorData
(
primaryContract
);
enabled
:
Boolean
(
address
),
},
[
primaryContract
]);
refetchOnMount
:
false
,
placeholderData
:
stubs
.
CONTRACT_CODE_VERIFIED
,
const
editorDataSecondary
=
React
.
useMemo
(()
=>
{
},
return
getEditorData
(
secondaryContract
);
});
},
[
secondaryContract
]);
const
secondaryContractQuery
=
useApiQuery
(
'
contract
'
,
{
const
activeContract
=
sourceType
===
'
secondary
'
?
secondaryContract
:
primaryContract
;
pathParams
:
{
hash
:
implementationAddress
},
const
activeContractData
=
sourceType
===
'
secondary
'
?
editorDataSecondary
:
editorDataPrimary
;
queryOptions
:
{
enabled
:
Boolean
(
implementationAddress
),
refetchOnMount
:
false
,
placeholderData
:
stubs
.
CONTRACT_CODE_VERIFIED
,
},
});
const
isLoading
=
implementationAddress
?
primaryContractQuery
.
isPlaceholderData
||
secondaryContractQuery
.
isPlaceholderData
:
primaryContractQuery
.
isPlaceholderData
;
const
primaryEditorData
=
React
.
useMemo
(()
=>
{
return
getEditorData
(
primaryContractQuery
.
data
);
},
[
primaryContractQuery
.
data
]);
const
secondaryEditorData
=
React
.
useMemo
(()
=>
{
return
getEditorData
(
secondaryContractQuery
.
data
);
},
[
secondaryContractQuery
.
data
]);
const
activeContract
=
sourceType
===
'
secondary
'
?
secondaryContractQuery
.
data
:
primaryContractQuery
.
data
;
const
activeContractData
=
sourceType
===
'
secondary
'
?
secondaryEditorData
:
primaryEditorData
;
const
heading
=
(
const
heading
=
(
<
Skeleton
isLoaded=
{
!
isLoading
}
fontWeight=
{
500
}
>
<
Skeleton
isLoaded=
{
!
isLoading
}
fontWeight=
{
500
}
>
...
@@ -59,10 +78,17 @@ const ContractSourceCode = ({ address, isLoading }: Props) => {
...
@@ -59,10 +78,17 @@ const ContractSourceCode = ({ address, isLoading }: Props) => {
</
Skeleton
>
</
Skeleton
>
);
);
const
diagramLink
=
activeContract
?.
can_be_visualized_via_sol2uml
&&
address
?
(
const
diagramLinkAddress
=
(()
=>
{
if
(
!
activeContract
?.
can_be_visualized_via_sol2uml
)
{
return
;
}
return
sourceType
===
'
secondary
'
?
implementationAddress
:
address
;
})();
const
diagramLink
=
diagramLinkAddress
?
(
<
Tooltip
label=
"Visualize contract code using Sol2Uml JS library"
>
<
Tooltip
label=
"Visualize contract code using Sol2Uml JS library"
>
<
LinkInternal
<
LinkInternal
href=
{
route
({
pathname
:
'
/visualize/sol2uml
'
,
query
:
{
address
}
})
}
href=
{
route
({
pathname
:
'
/visualize/sol2uml
'
,
query
:
{
address
:
diagramLinkAddress
}
})
}
ml=
"auto"
ml=
"auto"
>
>
<
Skeleton
isLoaded=
{
!
isLoading
}
>
<
Skeleton
isLoaded=
{
!
isLoading
}
>
...
@@ -70,7 +96,7 @@ const ContractSourceCode = ({ address, isLoading }: Props) => {
...
@@ -70,7 +96,7 @@ const ContractSourceCode = ({ address, isLoading }: Props) => {
</
Skeleton
>
</
Skeleton
>
</
LinkInternal
>
</
LinkInternal
>
</
Tooltip
>
</
Tooltip
>
)
:
null
;
)
:
<
Box
ml=
"auto"
/>
;
const
copyToClipboard
=
activeContractData
?.
length
===
1
?
const
copyToClipboard
=
activeContractData
?.
length
===
1
?
<
CopyToClipboard
text=
{
activeContractData
[
0
].
source_code
}
isLoading=
{
isLoading
}
ml=
{
3
}
/>
:
<
CopyToClipboard
text=
{
activeContractData
[
0
].
source_code
}
isLoading=
{
isLoading
}
ml=
{
3
}
/>
:
...
@@ -80,15 +106,15 @@ const ContractSourceCode = ({ address, isLoading }: Props) => {
...
@@ -80,15 +106,15 @@ const ContractSourceCode = ({ address, isLoading }: Props) => {
setSourceType
(
event
.
target
.
value
as
SourceCodeType
);
setSourceType
(
event
.
target
.
value
as
SourceCodeType
);
},
[]);
},
[]);
const
editorSourceTypeSelector
=
secondaryContract
?.
source_code
?
(
const
editorSourceTypeSelector
=
!
secondaryContractQuery
.
isPlaceholderData
&&
secondaryContractQuery
.
data
?.
source_code
?
(
<
Select
<
Select
size=
"xs"
size=
"xs"
borderRadius=
"base"
value=
{
sourceType
}
value=
{
sourceType
}
onChange=
{
handleSelectChange
}
onChange=
{
handleSelectChange
}
focusBorderColor=
"none"
focusBorderColor=
"none"
w=
"auto"
w=
"auto"
ml=
{
3
}
ml=
{
3
}
borderRadius=
"base"
>
>
{
SOURCE_CODE_OPTIONS
.
map
((
option
)
=>
<
option
key=
{
option
.
id
}
value=
{
option
.
id
}
>
{
option
.
label
}
</
option
>)
}
{
SOURCE_CODE_OPTIONS
.
map
((
option
)
=>
<
option
key=
{
option
.
id
}
value=
{
option
.
id
}
>
{
option
.
label
}
</
option
>)
}
</
Select
>
</
Select
>
...
@@ -99,25 +125,25 @@ const ContractSourceCode = ({ address, isLoading }: Props) => {
...
@@ -99,25 +125,25 @@ const ContractSourceCode = ({ address, isLoading }: Props) => {
return
<
Skeleton
h=
"557px"
w=
"100%"
/>;
return
<
Skeleton
h=
"557px"
w=
"100%"
/>;
}
}
if
(
!
editorDataPrimary
)
{
if
(
!
primaryEditorData
)
{
return
null
;
return
null
;
}
}
return
(
return
(
<>
<>
<
Box
display=
{
sourceType
===
'
primary
'
?
'
block
'
:
'
none
'
}
>
<
Box
display=
{
sourceType
===
'
primary
'
?
'
block
'
:
'
none
'
}
>
<
CodeEditor
data=
{
editorDataPrimary
}
remappings=
{
primaryContract
?.
compiler_settings
?.
remappings
}
/>
<
CodeEditor
data=
{
primaryEditorData
}
remappings=
{
primaryContractQuery
.
data
?.
compiler_settings
?.
remappings
}
/>
</
Box
>
</
Box
>
{
editorDataSecondary
&&
(
{
secondaryEditorData
&&
(
<
Box
display=
{
sourceType
===
'
secondary
'
?
'
block
'
:
'
none
'
}
>
<
Box
display=
{
sourceType
===
'
secondary
'
?
'
block
'
:
'
none
'
}
>
<
CodeEditor
data=
{
editorDataSecondary
}
remappings=
{
secondaryContract
?.
compiler_settings
?.
remappings
}
/>
<
CodeEditor
data=
{
secondaryEditorData
}
remappings=
{
secondaryContractQuery
.
data
?.
compiler_settings
?.
remappings
}
/>
</
Box
>
</
Box
>
)
}
)
}
</>
</>
);
);
})();
})();
if
(
!
editorDataPrimary
)
{
if
(
!
primaryEditorData
)
{
return
null
;
return
null
;
}
}
...
...
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