@@ -11,7 +11,8 @@ import {
1111 type InstalledExtensionData ,
1212 type AnyExtensionData ,
1313} from '~types/extensions.ts' ;
14- import { type Colony } from '~types/graphql.ts' ;
14+ import { type ColonyRole } from '~types/graphql.ts' ;
15+ import { extractColonyRoles } from '~utils/colonyRoles.ts' ;
1516import { getMappedExtensionData } from '~utils/extensions.ts' ;
1617
1718export enum ExtensionMethods {
@@ -42,6 +43,11 @@ interface UseExtensionDataReturn {
4243const useExtensionData = ( extensionId : string ) : UseExtensionDataReturn => {
4344 const { colony, refetchColony } = useColonyContext ( ) ;
4445
46+ const colonyRoles = useMemo (
47+ ( ) => extractColonyRoles ( colony . roles ) ,
48+ [ colony . roles ] ,
49+ ) ;
50+
4551 const extensionHash = getExtensionHash ( extensionId as Extension ) ;
4652
4753 const {
@@ -66,19 +72,20 @@ const useExtensionData = (extensionId: string): UseExtensionDataReturn => {
6672 } ) ;
6773 const { version } = versionData ?. getCurrentVersionByKey ?. items ?. [ 0 ] || { } ;
6874
69- const extensionConfig = supportedExtensionsConfig . find (
70- ( e ) => e . extensionId === extensionId ,
75+ const extensionConfig = useMemo (
76+ ( ) => supportedExtensionsConfig . find ( ( e ) => e . extensionId === extensionId ) ,
77+ [ extensionId ] ,
7178 ) ;
7279
7380 const extensionData = useMemo < AnyExtensionData | null > (
7481 ( ) =>
7582 getMappedExtensionData ( {
76- colony ,
83+ colonyRoles ,
7784 colonyExtension : rawExtensionData ,
7885 version,
7986 extensionConfig,
8087 } ) ,
81- [ colony , rawExtensionData , version , extensionConfig ] ,
88+ [ colonyRoles , rawExtensionData , version , extensionConfig ] ,
8289 ) ;
8390
8491 const handleRefetch = useCallback (
@@ -88,16 +95,17 @@ const useExtensionData = (extensionId: string): UseExtensionDataReturn => {
8895 refetchResponse . data . getExtensionByColonyAndHash ?. items [ 0 ] ;
8996
9097 if ( updatedColonyExtension ) {
91- let updatedColony : Colony | null = null ;
98+ let updatedColonyRoles : ColonyRole [ ] | null = null ;
9299 if ( shouldRefetchPermissions ) {
93100 const colonyRefetchResponse = await refetchColony ( ) ;
94- updatedColony =
95- colonyRefetchResponse ?. data . getColonyByName ?. items ?. [ 0 ] ?? null ;
101+ const updatedColony =
102+ colonyRefetchResponse ?. data . getColonyByName ?. items ?. [ 0 ] ;
103+ updatedColonyRoles = extractColonyRoles ( updatedColony ?. roles ) ;
96104 }
97105
98106 // Extension is guaranteed to be installed if returned by the query
99107 return getMappedExtensionData ( {
100- colony : updatedColony ?? colony ,
108+ colonyRoles : updatedColonyRoles ?? colonyRoles ,
101109 colonyExtension : updatedColonyExtension ,
102110 version,
103111 extensionConfig,
@@ -106,7 +114,7 @@ const useExtensionData = (extensionId: string): UseExtensionDataReturn => {
106114
107115 return null ;
108116 } ,
109- [ colony , extensionConfig , refetch , refetchColony , version ] ,
117+ [ colonyRoles , extensionConfig , refetch , refetchColony , version ] ,
110118 ) ;
111119
112120 return {
0 commit comments