@@ -19,9 +19,16 @@ import Toggle from '../Toggle'
1919import Modal , { Props as ModalProps } from './Modal'
2020import { useWalletAccount , useWalletClient } from '$/features/wallet/hooks'
2121import { Flag } from '$/features/flag/types'
22- import useTokenMetadata from '$/hooks/useTokenMetadata'
2322import TextField from '$/components/TextField'
2423import i18n from '$/utils/i18n'
24+ import useRoomEntryRequirements from '$/hooks/useRoomEntryRequirements'
25+ import TokenLogo from '$/components/TokenLogo'
26+ import TokenStandardLabel from '$/components/TokenStandardLabel'
27+ import { RoomId } from '$/features/room/types'
28+ import useCachedTokenGate from '$/hooks/useCachedTokenGate'
29+ import trunc from '$/utils/trunc'
30+ import TokenLabel from '$/components/TokenLabel'
31+ import useFetchingTokenMetadataForAnyTokenId from '$/hooks/useFetchingTokenMetadataForAnyTokenId'
2532
2633export default function RoomPropertiesModal ( {
2734 title = i18n ( 'roomPropertiesModal.title' ) ,
@@ -31,14 +38,7 @@ export default function RoomPropertiesModal({
3138} : ModalProps ) {
3239 const selectedRoomId = useSelectedRoomId ( )
3340
34- const {
35- name : roomName = '' ,
36- tokenAddress,
37- minRequiredBalance,
38- tokenType,
39- tokenIds = [ ] ,
40- stakingEnabled = false ,
41- } = useSelectedRoom ( ) || { }
41+ const { name : roomName = '' } = useSelectedRoom ( ) || { }
4242
4343 const isStorageEnabled = useStorageNodeState ( selectedRoomId , STREAMR_STORAGE_NODE_GERMANY )
4444
@@ -91,84 +91,16 @@ export default function RoomPropertiesModal({
9191 )
9292 } , [ open , selectedRoomId ] )
9393
94- const tokenMetadata = useTokenMetadata ( tokenAddress , tokenIds )
95-
9694 return (
9795 < Modal { ...props } onAbort = { onAbort } title = { title } subtitle = { roomName || subtitle } >
98- { tokenMetadata ? (
99- < >
100- { tokenType && (
101- < Label >
102- < b > Token Standard:</ b >
103- { tokenType . standard }
104- </ Label >
105- ) }
106- { tokenAddress && (
107- < Label >
108- < b > Address:</ b >
109- { tokenAddress }
110- </ Label >
111- ) }
112- { 'name' in tokenMetadata && tokenMetadata . name && (
113- < Label >
114- < b > Token Name:</ b >
115- { tokenMetadata . name }
116- </ Label >
117- ) }
118- { 'symbol' in tokenMetadata && tokenMetadata . symbol && (
119- < Label >
120- < b > Symbol:</ b >
121- { tokenMetadata . symbol }
122- </ Label >
123- ) }
124- { 'decimals' in tokenMetadata && tokenMetadata . decimals && (
125- < Label >
126- < b > Decimals:</ b >
127- { tokenMetadata . decimals }
128- </ Label >
129- ) }
130- { 'granularity' in tokenMetadata && tokenMetadata . granularity && (
131- < Label >
132- < b > Granularity:</ b >
133- { tokenMetadata . granularity }
134- </ Label >
135- ) }
136- { 'uris' in tokenMetadata && tokenMetadata . uris && (
137- < >
138- { Object . entries ( tokenMetadata . uris ) . map ( ( [ tokenId , uri ] ) => (
139- < Label key = { tokenId } >
140- < b > URI:</ b >
141- { uri }
142- </ Label >
143- ) ) }
144- </ >
145- ) }
146- { minRequiredBalance !== undefined && (
147- < Label >
148- < b > Min Token Amount:</ b >
149- { minRequiredBalance . toString ( ) }
150- </ Label >
151- ) }
152- < Label > { i18n ( 'roomPropertiesModal.stakingLabel' ) } </ Label >
153- < div css = { tw `flex` } >
154- < div css = { tw `grow` } >
155- < Hint css = { tw `pr-16` } >
156- < Text > { i18n ( 'addTokenGatedRoomModal.stakingDesc' ) } </ Text >
157- </ Hint >
158- </ div >
159- < div css = { tw `mt-2` } >
160- < Toggle value = { stakingEnabled } />
161- </ div >
162- </ div >
163- </ >
164- ) : null }
16596 < Form onSubmit = { ( ) => void onAbort ?.( ) } >
16697 { ! ! selectedRoomId && (
16798 < >
16899 < Label > { i18n ( 'roomPropertiesModal.roomIdLabel' ) } </ Label >
169100 < TextField defaultValue = { selectedRoomId } readOnly />
170101 </ >
171102 ) }
103+ < TokenGateSummary roomId = { selectedRoomId } />
172104 < >
173105 < Label > { i18n ( 'addRoomModal.storageFieldLabel' ) } </ Label >
174106 < div css = { tw `flex` } >
@@ -195,3 +127,76 @@ export default function RoomPropertiesModal({
195127}
196128
197129RoomPropertiesModal . displayName = 'RoomPropertiesModal'
130+
131+ function TokenGateSummary ( { roomId } : { roomId : RoomId | undefined } ) {
132+ const tokenGate = useCachedTokenGate ( roomId )
133+
134+ const entryReq = useRoomEntryRequirements ( roomId )
135+
136+ const isFetching = useFetchingTokenMetadataForAnyTokenId ( tokenGate ?. tokenAddress )
137+
138+ if ( ! tokenGate ) {
139+ return null
140+ }
141+
142+ const { tokenAddress, stakingEnabled } = tokenGate
143+
144+ return (
145+ < >
146+ < Label > { i18n ( 'roomPropertiesModal.tokenGateLabel' ) } </ Label >
147+ < div
148+ css = { tw `
149+ [img]:mr-3
150+ border
151+ border-[#F1F4F7]
152+ flex
153+ h-[64px]
154+ items-center
155+ px-4
156+ rounded-lg
157+ text-[#36404E]
158+ text-[14px]
159+ ` }
160+ >
161+ < TokenLogo tokenAddress = { tokenAddress } />
162+ < div css = { tw `mr-6 grow` } >
163+ < div css = { tw `font-semibold` } >
164+ < Text
165+ truncate
166+ css = { [
167+ tw `leading-normal` ,
168+ isFetching &&
169+ tw `
170+ animate-pulse
171+ [animation-duration: 0.5s]
172+ ` ,
173+ ] }
174+ >
175+ { isFetching ? (
176+ i18n ( 'common.load' , true )
177+ ) : ! entryReq ? (
178+ < > Failed to load</ >
179+ ) : (
180+ < >
181+ { typeof entryReq . quantity === 'string' && (
182+ < > { entryReq . quantity } </ >
183+ ) }
184+ { entryReq . unit }
185+ </ >
186+ ) }
187+ </ Text >
188+ </ div >
189+ < div css = { tw `text-[#59799C]` } >
190+ < Text > { trunc ( tokenAddress ) } </ Text >
191+ </ div >
192+ </ div >
193+ < TokenStandardLabel tokenAddress = { tokenAddress } css = { tw `mr-1.5` } />
194+ { stakingEnabled && (
195+ < TokenLabel as = "div" css = { tw `uppercase` } >
196+ < Text > { i18n ( 'roomPropertiesModal.stakingLabel' ) } </ Text >
197+ </ TokenLabel >
198+ ) }
199+ </ div >
200+ </ >
201+ )
202+ }
0 commit comments