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
5c8c26fb
Commit
5c8c26fb
authored
Mar 29, 2023
by
isstuev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new sockets start
parent
407dedf6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
2 deletions
+46
-2
types.ts
lib/socket/types.ts
+2
-0
Token.tsx
ui/pages/Token.tsx
+44
-2
No files found.
lib/socket/types.ts
View file @
5c8c26fb
...
@@ -20,6 +20,7 @@ SocketMessage.AddressTxs |
...
@@ -20,6 +20,7 @@ SocketMessage.AddressTxs |
SocketMessage
.
AddressTxsPending
|
SocketMessage
.
AddressTxsPending
|
SocketMessage
.
AddressTokenTransfer
|
SocketMessage
.
AddressTokenTransfer
|
SocketMessage
.
TokenTransfers
|
SocketMessage
.
TokenTransfers
|
SocketMessage
.
TokenTotalSupply
|
SocketMessage
.
ContractVerification
|
SocketMessage
.
ContractVerification
|
SocketMessage
.
Unknown
;
SocketMessage
.
Unknown
;
...
@@ -46,6 +47,7 @@ export namespace SocketMessage {
...
@@ -46,6 +47,7 @@ export namespace SocketMessage {
export
type
AddressTxsPending
=
SocketMessageParamsGeneric
<
'
pending_transaction
'
,
{
transaction
:
Transaction
}
>
;
export
type
AddressTxsPending
=
SocketMessageParamsGeneric
<
'
pending_transaction
'
,
{
transaction
:
Transaction
}
>
;
export
type
AddressTokenTransfer
=
SocketMessageParamsGeneric
<
'
token_transfer
'
,
{
token_transfer
:
TokenTransfer
}
>
;
export
type
AddressTokenTransfer
=
SocketMessageParamsGeneric
<
'
token_transfer
'
,
{
token_transfer
:
TokenTransfer
}
>
;
export
type
TokenTransfers
=
SocketMessageParamsGeneric
<
'
token_transfer
'
,
{
token_transfer
:
number
}
>
;
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
>
;
export
type
ContractVerification
=
SocketMessageParamsGeneric
<
'
verification_result
'
,
SmartContractVerificationResponse
>
;
export
type
Unknown
=
SocketMessageParamsGeneric
<
undefined
,
unknown
>
;
export
type
Unknown
=
SocketMessageParamsGeneric
<
undefined
,
unknown
>
;
}
}
ui/pages/Token.tsx
View file @
5c8c26fb
import
{
Skeleton
,
Box
,
Flex
,
SkeletonCircle
,
Icon
,
Tag
}
from
'
@chakra-ui/react
'
;
import
{
Skeleton
,
Box
,
Flex
,
SkeletonCircle
,
Icon
,
Tag
}
from
'
@chakra-ui/react
'
;
import
{
useQueryClient
}
from
'
@tanstack/react-query
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
{
useRouter
}
from
'
next/router
'
;
import
React
,
{
useEffect
}
from
'
react
'
;
import
React
,
{
useEffect
}
from
'
react
'
;
import
type
{
SocketMessage
}
from
'
lib/socket/types
'
;
import
type
{
TokenInfo
}
from
'
types/api/token
'
;
import
type
{
RoutedTab
}
from
'
ui/shared/RoutedTabs/types
'
;
import
type
{
RoutedTab
}
from
'
ui/shared/RoutedTabs/types
'
;
import
iconSuccess
from
'
icons/status/success.svg
'
;
import
iconSuccess
from
'
icons/status/success.svg
'
;
import
useApiQuery
from
'
lib/api/useApiQuery
'
;
import
useApiQuery
,
{
getResourceKey
}
from
'
lib/api/useApiQuery
'
;
import
{
useAppContext
}
from
'
lib/appContext
'
;
import
{
useAppContext
}
from
'
lib/appContext
'
;
import
useContractTabs
from
'
lib/hooks/useContractTabs
'
;
import
useContractTabs
from
'
lib/hooks/useContractTabs
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
useIsMobile
from
'
lib/hooks/useIsMobile
'
;
import
useQueryWithPages
from
'
lib/hooks/useQueryWithPages
'
;
import
useQueryWithPages
from
'
lib/hooks/useQueryWithPages
'
;
import
useSocketChannel
from
'
lib/socket/useSocketChannel
'
;
import
useSocketMessage
from
'
lib/socket/useSocketMessage
'
;
import
trimTokenSymbol
from
'
lib/token/trimTokenSymbol
'
;
import
trimTokenSymbol
from
'
lib/token/trimTokenSymbol
'
;
import
AddressContract
from
'
ui/address/AddressContract
'
;
import
AddressContract
from
'
ui/address/AddressContract
'
;
import
TextAd
from
'
ui/shared/ad/TextAd
'
;
import
TextAd
from
'
ui/shared/ad/TextAd
'
;
...
@@ -29,6 +34,8 @@ import TokenTransfer from 'ui/token/TokenTransfer/TokenTransfer';
...
@@ -29,6 +34,8 @@ import TokenTransfer from 'ui/token/TokenTransfer/TokenTransfer';
export
type
TokenTabs
=
'
token_transfers
'
|
'
holders
'
|
'
inventory
'
;
export
type
TokenTabs
=
'
token_transfers
'
|
'
holders
'
|
'
inventory
'
;
const
TokenPageContent
=
()
=>
{
const
TokenPageContent
=
()
=>
{
const
[
isSocketOpen
,
setIsSocketOpen
]
=
React
.
useState
(
false
);
const
[
totalSupplySocket
,
setTotalSupplySocket
]
=
React
.
useState
<
number
>
();
const
router
=
useRouter
();
const
router
=
useRouter
();
const
isMobile
=
useIsMobile
();
const
isMobile
=
useIsMobile
();
...
@@ -40,9 +47,44 @@ const TokenPageContent = () => {
...
@@ -40,9 +47,44 @@ const TokenPageContent = () => {
const
hashString
=
router
.
query
.
hash
?.
toString
();
const
hashString
=
router
.
query
.
hash
?.
toString
();
const
queryClient
=
useQueryClient
();
const
tokenQuery
=
useApiQuery
(
'
token
'
,
{
const
tokenQuery
=
useApiQuery
(
'
token
'
,
{
pathParams
:
{
hash
:
hashString
},
pathParams
:
{
hash
:
hashString
},
queryOptions
:
{
enabled
:
Boolean
(
router
.
query
.
hash
)
},
queryOptions
:
{
enabled
:
isSocketOpen
&&
Boolean
(
router
.
query
.
hash
)
},
});
React
.
useEffect
(()
=>
{
if
(
tokenQuery
.
data
&&
totalSupplySocket
)
{
queryClient
.
setQueryData
(
getResourceKey
(
'
token
'
,
{
pathParams
:
{
hash
:
hashString
}
}),
(
prevData
:
TokenInfo
|
undefined
)
=>
{
if
(
prevData
)
{
return
{
...
prevData
,
total_supply
:
totalSupplySocket
.
toString
()
};
}
});
}
},
[
tokenQuery
.
data
,
totalSupplySocket
,
hashString
,
queryClient
]);
const
handleTotalSupplyMessage
:
SocketMessage
.
TokenTotalSupply
[
'
handler
'
]
=
React
.
useCallback
((
payload
)
=>
{
const
prevData
=
queryClient
.
getQueryData
(
getResourceKey
(
'
token
'
,
{
pathParams
:
{
hash
:
hashString
}
}));
if
(
!
prevData
)
{
setTotalSupplySocket
(
payload
.
total_supply
);
}
queryClient
.
setQueryData
(
getResourceKey
(
'
token
'
,
{
pathParams
:
{
hash
:
hashString
}
}),
(
prevData
:
TokenInfo
|
undefined
)
=>
{
if
(
prevData
)
{
return
{
...
prevData
,
total_supply
:
payload
.
total_supply
.
toString
()
};
}
});
},
[
queryClient
,
hashString
]);
const
channel
=
useSocketChannel
({
topic
:
`tokens:
${
hashString
?.
toLowerCase
()
}
`,
isDisabled: !hashString,
onJoin: () => setIsSocketOpen(true),
});
useSocketMessage({
channel,
event: 'total_supply',
handler: handleTotalSupplyMessage,
});
});
useEffect(() => {
useEffect(() => {
...
...
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