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
d7823c4c
Commit
d7823c4c
authored
Apr 03, 2023
by
isstuev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
contract changed
parent
2097b9a3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
types.ts
lib/socket/types.ts
+2
-0
ContractCode.tsx
ui/address/contract/ContractCode.tsx
+24
-2
No files found.
lib/socket/types.ts
View file @
d7823c4c
...
...
@@ -21,6 +21,7 @@ SocketMessage.AddressCoinBalance |
SocketMessage
.
AddressTxs
|
SocketMessage
.
AddressTxsPending
|
SocketMessage
.
AddressTokenTransfer
|
SocketMessage
.
AddressChangedBytecode
|
SocketMessage
.
TokenTransfers
|
SocketMessage
.
TokenTotalSupply
|
SocketMessage
.
ContractVerification
|
...
...
@@ -49,6 +50,7 @@ export namespace SocketMessage {
export
type
AddressTxs
=
SocketMessageParamsGeneric
<
'
transaction
'
,
{
transaction
:
Transaction
}
>
;
export
type
AddressTxsPending
=
SocketMessageParamsGeneric
<
'
pending_transaction
'
,
{
transaction
:
Transaction
}
>
;
export
type
AddressTokenTransfer
=
SocketMessageParamsGeneric
<
'
token_transfer
'
,
{
token_transfer
:
TokenTransfer
}
>
;
export
type
AddressChangedBytecode
=
SocketMessageParamsGeneric
<
'
changed_bytecode
'
,
never
>
;
export
type
TokenTransfers
=
SocketMessageParamsGeneric
<
'
token_transfer
'
,
{
token_transfer
:
number
}
>
;
export
type
TokenTotalSupply
=
SocketMessageParamsGeneric
<
'
total_supply
'
,
{
total_supply
:
number
}
>
;
export
type
ContractVerification
=
SocketMessageParamsGeneric
<
'
verification_result
'
,
SmartContractVerificationResponse
>
;
...
...
ui/address/contract/ContractCode.tsx
View file @
d7823c4c
...
...
@@ -2,8 +2,12 @@ import { Flex, Skeleton, Button, Grid, GridItem, Text, Alert, Link, chakra, Box
import
{
route
}
from
'
nextjs-routes
'
;
import
React
from
'
react
'
;
import
type
{
SocketMessage
}
from
'
lib/socket/types
'
;
import
useApiQuery
from
'
lib/api/useApiQuery
'
;
import
dayjs
from
'
lib/date/dayjs
'
;
import
useSocketChannel
from
'
lib/socket/useSocketChannel
'
;
import
useSocketMessage
from
'
lib/socket/useSocketMessage
'
;
import
Address
from
'
ui/shared/address/Address
'
;
import
AddressIcon
from
'
ui/shared/address/AddressIcon
'
;
import
AddressLink
from
'
ui/shared/address/AddressLink
'
;
...
...
@@ -26,14 +30,32 @@ const InfoItem = chakra(({ label, value, className }: { label: string; value: st
));
const
ContractCode
=
({
addressHash
}:
Props
)
=>
{
const
[
isSocketOpen
,
setIsSocketOpen
]
=
React
.
useState
(
false
);
const
[
isChangedBytecodeSocket
,
setIsChangedBytecodeSocket
]
=
React
.
useState
<
boolean
>
();
const
{
data
,
isLoading
,
isError
}
=
useApiQuery
(
'
contract
'
,
{
pathParams
:
{
hash
:
addressHash
},
queryOptions
:
{
enabled
:
Boolean
(
addressHash
),
enabled
:
Boolean
(
addressHash
)
&&
isSocketOpen
,
refetchOnMount
:
false
,
},
});
const
handleChangedBytecodeMessage
:
SocketMessage
.
AddressChangedBytecode
[
'
handler
'
]
=
React
.
useCallback
(()
=>
{
setIsChangedBytecodeSocket
(
true
);
},
[
]);
const
channel
=
useSocketChannel
({
topic
:
`addresses:
${
addressHash
?.
toLowerCase
()
}
`,
isDisabled: !addressHash,
onJoin: () => setIsSocketOpen(true),
});
useSocketMessage({
channel,
event: 'changed_bytecode',
handler: handleChangedBytecodeMessage,
});
if (isError) {
return <DataFetchAlert/>;
}
...
...
@@ -117,7 +139,7 @@ const ContractCode = ({ addressHash }: Props) => {
{ data.sourcify_repo_url && <LinkExternal href={ data.sourcify_repo_url } fontSize="md">View contract in Sourcify repository</LinkExternal> }
</Alert>
) }
{
data
.
is_changed_bytecode
&&
(
{
(data.is_changed_bytecode || isChangedBytecodeSocket)
&& (
<Alert status="warning">
Warning! Contract bytecode has been changed and does not match the verified one. Therefore, interaction with this smart contract may be risky.
</Alert>
...
...
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