@@ -5,14 +5,15 @@ import React, { useContext, useMemo, useState, useEffect } from "react"
55
66import { useIsProposalButtonDisabled } from "../../../../services/contracts/baseDAO/hooks/useCycleInfo"
77import { InfoIcon } from "modules/explorer/components/styled/InfoIcon"
8- import { MainButton } from "modules/common/MainButton "
8+ import { SmallButton } from "modules/common/SmallButton "
99import { useEtherlinkDAOID } from "../router"
1010import { EtherlinkContext } from "services/wagmi/context"
1111import { useEvmProposalOps } from "services/contracts/etherlinkDAO/hooks/useEvmProposalOps"
1212import { useHistory } from "react-router-dom"
1313import { EvmRegistryTable } from "modules/etherlink/components/EvmRegistryTable"
1414import { SearchInput } from "modules/explorer/pages/DAOList/components/Searchbar"
1515import { styled } from "@material-ui/core"
16+ import { useRegistry } from "services/wagmi/etherlink/hooks/useRegistry"
1617
1718const ShellHeroContainer = styled ( ContentContainer ) ( {
1819 background : "inherit !important" ,
@@ -26,13 +27,19 @@ export const EvmRegistryPage: React.FC = () => {
2627 const theme = useTheme ( )
2728 const isMobileSmall = useMediaQuery ( theme . breakpoints . down ( "xs" ) )
2829 const daoId = useEtherlinkDAOID ( )
29- const { daoSelected } = useContext ( EtherlinkContext )
30+ const { daoSelected, provider , network } = useContext ( EtherlinkContext )
3031 const shouldDisable = useIsProposalButtonDisabled ( daoId )
3132 const { setMetadataFieldValue, setCurrentStep, setDaoRegistry } = useEvmProposalOps ( )
3233 const history = useHistory ( )
3334 const [ searchText , setSearchText ] = useState ( "" )
3435 const [ debouncedSearchText , setDebouncedSearchText ] = useState ( "" )
3536
37+ const {
38+ data : rpcRegistryEntries ,
39+ isLoading : isRpcLoading ,
40+ error : rpcError
41+ } = useRegistry ( provider , daoSelected ?. registryAddress , network || "" )
42+
3643 useEffect ( ( ) => {
3744 const timer = setTimeout ( ( ) => {
3845 setDebouncedSearchText ( searchText )
@@ -41,16 +48,59 @@ export const EvmRegistryPage: React.FC = () => {
4148 return ( ) => clearTimeout ( timer )
4249 } , [ searchText ] )
4350
44- const registryList = useMemo ( ( ) => {
51+ const firestoreRegistryList = useMemo ( ( ) => {
4552 if ( ! daoSelected ?. registry ) {
4653 return [ ]
4754 }
4855 return Object . entries ( daoSelected ?. registry ) . map ( ( [ key , value ] ) => ( {
4956 key,
5057 value : value as string ,
51- onClick : ( ) => { }
58+ onClick : ( ) => {
59+ setMetadataFieldValue ( "type" , "edit_registry" )
60+ setDaoRegistry ( "key" , key )
61+ setDaoRegistry ( "value" , value as string )
62+ setCurrentStep ( 1 )
63+ history . push ( `${ window . location . pathname . slice ( 0 , - 8 ) } proposals` )
64+ }
5265 } ) )
53- } , [ daoSelected ?. registry ] )
66+ } , [ daoSelected ?. registry , setMetadataFieldValue , setDaoRegistry , setCurrentStep , history ] )
67+
68+ const registryList = useMemo ( ( ) => {
69+ const rpcEntries = rpcRegistryEntries || [ ]
70+ const firestoreEntries = firestoreRegistryList || [ ]
71+
72+ console . log ( "[Registry Source] RPC entries:" , rpcEntries )
73+ console . log ( "[Registry Source] Firestore entries:" , firestoreEntries )
74+ console . log ( "[Registry Source] RPC loading:" , isRpcLoading )
75+ console . log ( "[Registry Source] RPC error:" , rpcError )
76+
77+ if ( rpcEntries . length > 0 && ! isRpcLoading && ! rpcError ) {
78+ console . log ( "[Registry Source] Using: RPC" )
79+ return rpcEntries . map ( entry => ( {
80+ key : entry . key ,
81+ value : entry . value ,
82+ onClick : ( ) => {
83+ setMetadataFieldValue ( "type" , "edit_registry" )
84+ setDaoRegistry ( "key" , entry . key )
85+ setDaoRegistry ( "value" , entry . value )
86+ setCurrentStep ( 1 )
87+ history . push ( `${ window . location . pathname . slice ( 0 , - 8 ) } proposals` )
88+ }
89+ } ) )
90+ } else {
91+ console . log ( "[Registry Source] Using: Firestore" )
92+ return firestoreEntries
93+ }
94+ } , [
95+ rpcRegistryEntries ,
96+ firestoreRegistryList ,
97+ isRpcLoading ,
98+ rpcError ,
99+ setMetadataFieldValue ,
100+ setDaoRegistry ,
101+ setCurrentStep ,
102+ history
103+ ] )
54104
55105 const filteredRegistryList = useMemo ( ( ) => {
56106 if ( ! debouncedSearchText ) {
@@ -82,7 +132,7 @@ export const EvmRegistryPage: React.FC = () => {
82132 direction = { isMobileSmall ? "column" : "row" }
83133 xs = { isMobileSmall ? undefined : true }
84134 >
85- < MainButton
135+ < SmallButton
86136 variant = "contained"
87137 color = "secondary"
88138 onClick = { ( ) => {
@@ -93,7 +143,7 @@ export const EvmRegistryPage: React.FC = () => {
93143 disabled = { shouldDisable }
94144 >
95145 New Item
96- </ MainButton >
146+ </ SmallButton >
97147 { shouldDisable && (
98148 < Tooltip placement = "bottom" title = "Not on proposal creation period" >
99149 < InfoIcon color = "secondary" />
@@ -105,19 +155,7 @@ export const EvmRegistryPage: React.FC = () => {
105155 </ Grid >
106156 </ ShellHeroContainer >
107157 < Grid item >
108- < EvmRegistryTable
109- data = { filteredRegistryList . map ( rItem => ( {
110- key : rItem . key ,
111- value : rItem . value ,
112- onClick : ( ) => {
113- setMetadataFieldValue ( "type" , "edit_registry" )
114- setDaoRegistry ( "key" , rItem . key )
115- setDaoRegistry ( "value" , rItem . value )
116- setCurrentStep ( 1 )
117- history . push ( `${ window . location . pathname . slice ( 0 , - 8 ) } proposals` )
118- }
119- } ) ) }
120- />
158+ < EvmRegistryTable data = { filteredRegistryList } />
121159 </ Grid >
122160 </ Grid >
123161 </ >
0 commit comments