Skip to content

Commit

Permalink
Merge pull request #189 from kaleido-io/gateway-updates
Browse files Browse the repository at this point in the history
fixes for gateway mode
  • Loading branch information
shorsher authored Aug 15, 2022
2 parents f0a81a5 + 4898119 commit 8c4e718
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 28 deletions.
12 changes: 8 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const App: React.FC = () => {
const [messageType, setMessageType] = useState<SnackbarMessageType>('error');
const [nodeID, setNodeID] = useState('');
const [nodeName, setNodeName] = useState('');
const [multiparty, setMultiparty] = useState(true);
const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws';
const [poolCache, setPoolCache] = useState<Map<string, ITokenPool>>(
new Map()
Expand Down Expand Up @@ -87,8 +88,11 @@ const App: React.FC = () => {
.then(async ([namespaceResponse, statusResponse]) => {
if (namespaceResponse.ok && statusResponse.ok) {
const status: IStatus = await statusResponse.json();
setNodeID(status.node.id);
setNodeName(status.node.name);
setMultiparty(status.multiparty.enabled);
if (status.multiparty.enabled && status.node !== undefined) {
setNodeID(status.node.id);
setNodeName(status.node.name);
}
setSelectedNamespace(status.namespace.name);
const ns: INamespace[] = await namespaceResponse.json();
setNamespaces(ns);
Expand Down Expand Up @@ -163,7 +167,6 @@ const App: React.FC = () => {

if (initialized) {
if (initError) {
// figure out what to display
return (
<>
<StyledEngineProvider injectFirst>
Expand All @@ -177,11 +180,12 @@ const App: React.FC = () => {
return (
<ApplicationContext.Provider
value={{
multiparty,
namespaces,
selectedNamespace,
setSelectedNamespace,
nodeID,
nodeName,
setSelectedNamespace,
newEvents,
clearNewEvents,
lastRefreshTime,
Expand Down
6 changes: 5 additions & 1 deletion src/components/Charts/MyNodeDiagram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,11 @@ export const MyNodeDiagram: React.FC<Props> = ({

useEffect(() => {
const { nodes, edges } = getLayoutedElements(
makeInitialNodes(plugins, plugins, nodeName),
makeInitialNodes(
plugins,
plugins,
nodeName !== undefined ? nodeName : ''
),
makeInitialEdges(plugins, plugins, isSmall),
isSmall
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const Header: React.FC<Props> = ({
<Grid item>{!noNsFilter && <NamespacePicker />}</Grid>
<Grid item pl={DEFAULT_PADDING}>
<Typography noWrap variant="subtitle1">
{nodeName}
{nodeName !== undefined ? nodeName : ''}
</Typography>
</Grid>
</Grid>
Expand Down
5 changes: 3 additions & 2 deletions src/contexts/ApplicationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import { createContext, Dispatch, SetStateAction } from 'react';
import { INamespace, INewEventSet } from '../interfaces';

export interface IApplicationContext {
nodeID: string;
nodeName: string;
nodeID?: string;
nodeName?: string;
selectedNamespace: string;
multiparty: boolean;
setSelectedNamespace: Dispatch<SetStateAction<string>>;
namespaces: INamespace[];
newEvents: INewEventSet;
Expand Down
5 changes: 4 additions & 1 deletion src/interfaces/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ export interface IPagedTransactionResponse {
}

export interface IStatus {
node: {
node?: {
name: string;
registered: boolean;
id: string;
Expand All @@ -451,6 +451,9 @@ export interface IStatus {
name: string;
description: string;
};
multiparty: {
enabled: boolean;
};
plugins: {
blockchain: IStatusPluginDetails[];
database: IStatusPluginDetails[];
Expand Down
28 changes: 19 additions & 9 deletions src/pages/Home/views/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ import { hasAnyEvent } from '../../../utils/wsEvents';

export const HomeDashboard: () => JSX.Element = () => {
const { t } = useTranslation();
const { newEvents, lastRefreshTime, clearNewEvents, selectedNamespace } =
useContext(ApplicationContext);
const {
newEvents,
lastRefreshTime,
clearNewEvents,
selectedNamespace,
multiparty,
} = useContext(ApplicationContext);
const { dateFilter } = useContext(DateFilterContext);
const { poolCache, setPoolCache } = useContext(PoolContext);
const { slideID, setSlideSearchParam } = useContext(SlideContext);
Expand Down Expand Up @@ -294,11 +299,6 @@ export const HomeDashboard: () => JSX.Element = () => {
/>
),
},
{
clickPath: FF_NAV_PATHS.networkPath(selectedNamespace),
headerText: t('networkMap'),
component: <NetworkMap size="small"></NetworkMap>,
},
{
clickPath: FF_NAV_PATHS.myNodePath(selectedNamespace),
headerText: t('myNode'),
Expand All @@ -314,6 +314,14 @@ export const HomeDashboard: () => JSX.Element = () => {
},
];

if (multiparty) {
mediumCards.push({
clickPath: FF_NAV_PATHS.networkPath(selectedNamespace),
headerText: t('networkMap'),
component: <NetworkMap size="small"></NetworkMap>,
});
}

// Medium Card UseEffect
useEffect(() => {
setIsHistLoading(true);
Expand Down Expand Up @@ -347,7 +355,9 @@ export const HomeDashboard: () => JSX.Element = () => {
`${FF_Paths.nsPrefix}/${selectedNamespace}${FF_Paths.status}`
)
.then((statusRes: IStatus) => {
isMounted && setPlugins(statusRes.plugins);
if (isMounted) {
setPlugins(statusRes.plugins);
}
})
.catch((err) => {
reportFetchError(err);
Expand Down Expand Up @@ -508,7 +518,7 @@ export const HomeDashboard: () => JSX.Element = () => {
{mediumCards.map((cardData) => {
return (
<FireFlyCard
size="medium"
size={mediumCards.length % 2 === 0 ? 'large' : 'medium'}
key={cardData.headerText}
cardData={cardData}
/>
Expand Down
18 changes: 10 additions & 8 deletions src/pages/Network/views/Namespaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ export const NetworkNamespaces: () => JSX.Element = () => {
}, []);

useEffect(() => {
isMounted && slideID;
fetchCatcher(`${FF_Paths.nsPrefix}?id=${slideID}`)
.then((nsRes: INamespace[]) => {
isMounted && nsRes.length === 1 && setViewNs(nsRes[0]);
})
.catch((err) => {
reportFetchError(err);
});
if (isMounted && slideID) {
fetchCatcher(`${FF_Paths.nsPrefix}?id=${slideID}`)
.then((nsRes: INamespace[]) => {
console.log(nsRes);
isMounted && nsRes.length === 1 && setViewNs(nsRes[0]);
})
.catch((err) => {
reportFetchError(err);
});
}
}, [slideID, isMounted]);

// Namespaces
Expand Down
9 changes: 7 additions & 2 deletions src/pages/Off-Chain/views/Groups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ export const OffChainGroups: () => JSX.Element = () => {
)
.then((groupRes: IPagedGroupResponse) => {
if (isMounted) {
setGroups(groupRes.items);
setGroupTotal(groupRes.total);
if (groupRes !== undefined) {
setGroups(groupRes.items);
setGroupTotal(groupRes.total);
} else {
setGroups([]);
setGroupTotal(0);
}
}
})
.catch((err) => {
Expand Down

0 comments on commit 8c4e718

Please sign in to comment.