Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update admin dashboard api #932

Merged
merged 5 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node-ui/build/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
})(window.location);
</script>
<!-- End Single Page Apps for GitHub Pages -->
<script type="module" crossorigin src="/admin-dashboard/assets/main-Bzv535nm.js"></script>
<script type="module" crossorigin src="/admin-dashboard/assets/main-B1C-7lql.js"></script>
<link rel="stylesheet" crossorigin href="/admin-dashboard/assets/main-BesWMiQO.css">
</head>
<body>
Expand Down
32 changes: 15 additions & 17 deletions node-ui/src/api/dataSource/NodeDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,20 @@ export interface SigningKey {
signingKey: string;
}

// This is most likely obsolete
export interface Context {
applicationId: string;
id: string;
signingKey: SigningKey;
rootHash: String;
}

export interface ContextList {
contexts: Context[];
export interface CreateContextResponse {
contextId: string;
memberPublicKey: SigningKey;
}

export interface ContextsList<T> {
joined: T[];
export interface GetContextsResponse {
contexts: Context[];
}

export interface RootKey {
Expand Down Expand Up @@ -113,10 +115,6 @@ export interface ClientKey {
applicationId: string;
}

export interface ApiContext {
context: Context;
}

interface Did {
client_keys: ClientKey[];
contexts: Context[];
Expand Down Expand Up @@ -288,7 +286,7 @@ export interface WalletSignatureData {
}

export interface InstallApplicationResponse {
application_id: string;
applicationId: string;
}

export interface UninstallApplicationResponse
Expand Down Expand Up @@ -362,13 +360,13 @@ export class NodeDataSource implements NodeApi {
}
}

async getContexts(): ApiResponse<ContextList> {
async getContexts(): ApiResponse<GetContextsResponse> {
try {
const headers: Header | null = await createAuthHeader(
getAppEndpointKey() as string,
getNearEnvironment(),
);
const response = await this.client.get<ContextList>(
const response = await this.client.get<GetContextsResponse>(
`${getAppEndpointKey()}/admin-api/contexts`,
headers ?? {},
);
Expand All @@ -379,13 +377,13 @@ export class NodeDataSource implements NodeApi {
}
}

async getContext(contextId: string): ApiResponse<ApiContext> {
async getContext(contextId: string): ApiResponse<Context> {
try {
const headers: Header | null = await createAuthHeader(
contextId,
getNearEnvironment(),
);
const response = await this.client.get<ApiContext>(
const response = await this.client.get<Context>(
`${getAppEndpointKey()}/admin-api/contexts/${contextId}`,
headers ?? {},
);
Expand Down Expand Up @@ -472,10 +470,10 @@ export class NodeDataSource implements NodeApi {
}
}

async startContexts(
async createContexts(
applicationId: string,
initArguments: string,
): ApiResponse<Context> {
): ApiResponse<CreateContextResponse> {
try {
const headers: Header | null = await createAuthHeader(
JSON.stringify({
Expand All @@ -488,7 +486,7 @@ export class NodeDataSource implements NodeApi {
const encodedArgs = encoder.encode(JSON.stringify(initArguments));
const initializationParams = Array.from(encodedArgs);

const response = await this.client.post<Context>(
const response = await this.client.post<CreateContextResponse>(
`${getAppEndpointKey()}/admin-api/contexts`,
{
applicationId,
Expand Down
14 changes: 7 additions & 7 deletions node-ui/src/api/nodeApi.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import {
ContextStorage,
Context,
HealthRequest,
HealthStatus,
ContextClientKeysList,
ContextUsersList,
GetInstalledApplicationsResponse,
ApiContext,
ContextList,
DidResponse,
DeleteContextResponse,
JoinContextResponse,
Expand All @@ -20,6 +17,9 @@ import {
ContextIdentitiesResponse,
CreateTokenResponse,
UninstallApplicationResponse,
CreateContextResponse,
GetContextsResponse,
Context,
} from './dataSource/NodeDataSource';
import { ApiResponse } from './response';

Expand All @@ -28,15 +28,15 @@ export interface NodeApi {
getInstalledApplicationDetails(
appId: string,
): ApiResponse<InstalledApplication>;
getContexts(): ApiResponse<ContextList>;
getContext(contextId: string): ApiResponse<ApiContext>;
getContexts(): ApiResponse<GetContextsResponse>;
getContext(contextId: string): ApiResponse<Context>;
getContextClientKeys(contextId: string): ApiResponse<ContextClientKeysList>;
getContextUsers(contextId: string): ApiResponse<ContextUsersList>;
deleteContext(contextId: string): ApiResponse<DeleteContextResponse>;
startContexts(
createContexts(
applicationId: string,
initArguments: string,
): ApiResponse<Context>;
): ApiResponse<CreateContextResponse>;
getDidList(): ApiResponse<DidResponse>;
health(request: HealthRequest): ApiResponse<HealthStatus>;
getContextStorageUsage(contextId: string): ApiResponse<ContextStorage>;
Expand Down
5 changes: 2 additions & 3 deletions node-ui/src/components/context/ContextTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import ListTable from '../common/ListTable';
import rowItem from './RowItem';
import StatusModal, { ModalContent } from '../common/StatusModal';
import ActionDialog from '../common/ActionDialog';
import { ContextsList } from '../../api/dataSource/NodeDataSource';
import { ContextObject } from '../../types/context';
import { ContextObject, ContextsList } from '../../types/context';

const FlexWrapper = styled.div`
flex: 1;
`;

interface ContextTableProps {
nodeContextList: ContextsList<ContextObject>;
nodeContextList: ContextsList;
navigateToStartContext: () => void;
currentOption: string;
setCurrentOption: (option: string) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import apiClient from '../../../api';
import {
Context,
ContextIdentitiesResponse,
ContextList,
CreateTokenResponse,
GetContextsResponse,
} from '../../../api/dataSource/NodeDataSource';
import { ResponseData } from '../../../api/response';
import SelectContextStep from './SelectContextStep';
Expand Down Expand Up @@ -48,11 +48,8 @@ export default function AppLoginPopup({

useEffect(() => {
const fetchAvailableContexts = async () => {
const fetchContextsResponse: ResponseData<ContextList> = await apiClient(
showServerDownPopup,
)
.node()
.getContexts();
const fetchContextsResponse: ResponseData<GetContextsResponse> =
await apiClient(showServerDownPopup).node().getContexts();
const contexts =
fetchContextsResponse.data?.contexts.filter(
(context) => context.applicationId === applicationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function StartContextStep({
}
const startContextResponse = await apiClient(showServerDownPopup)
.node()
.startContexts(applicationId, argumentsJson);
.createContexts(applicationId, argumentsJson);
if (startContextResponse.error) {
setStartContextStatus({
title: t.startContextErrorTitle,
Expand Down
6 changes: 2 additions & 4 deletions node-ui/src/pages/ContextDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,10 @@ export default function ContextDetailsPage() {
const applicationMetadata = (
await apiClient(showServerDownPopup)
.node()
.getInstalledApplicationDetails(
nodeContext.data.context.applicationId,
)
.getInstalledApplicationDetails(nodeContext.data.applicationId)
).data?.metadata;
const contextObject = await generateContextObjects(
nodeContext.data.context,
nodeContext.data,
id,
applicationMetadata,
);
Expand Down
21 changes: 6 additions & 15 deletions node-ui/src/pages/Contexts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ import { ContextOptions } from '../constants/ContextConstants';
import { useNavigate } from 'react-router-dom';
import { useRPC } from '../hooks/useNear';
import apiClient from '../api/index';
import {
Context,
ContextList,
ContextsList,
} from '../api/dataSource/NodeDataSource';
import { Context, GetContextsResponse } from '../api/dataSource/NodeDataSource';
import { ModalContent } from '../components/common/StatusModal';
import { TableOptions } from '../components/common/OptionsHeader';
import { ResponseData } from '../api/response';
import { ContextObject } from '../types/context';
import { ContextObject, ContextsList } from '../types/context';
import { useServerDown } from '../context/ServerDownContext';
import { parseAppMetadata } from '../utils/metadata';

Expand Down Expand Up @@ -47,9 +43,7 @@ export default function ContextsPage() {
message: '',
error: false,
});
const [nodeContextList, setNodeContextList] = useState<
ContextsList<ContextObject>
>({
const [nodeContextList, setNodeContextList] = useState<ContextsList>({
joined: [],
});

Expand Down Expand Up @@ -89,11 +83,8 @@ export default function ContextsPage() {

const fetchNodeContexts = useCallback(async () => {
setErrorMessage('');
const fetchContextsResponse: ResponseData<ContextList> = await apiClient(
showServerDownPopup,
)
.node()
.getContexts();
const fetchContextsResponse: ResponseData<GetContextsResponse> =
await apiClient(showServerDownPopup).node().getContexts();
// TODO - fetch invitations
if (fetchContextsResponse.error) {
setErrorMessage(fetchContextsResponse.error.message);
Expand All @@ -105,7 +96,7 @@ export default function ContextsPage() {
nodeContexts.contexts,
);

setNodeContextList((prevState: ContextsList<ContextObject>) => ({
setNodeContextList((prevState: ContextsList) => ({
...prevState,
joined: joinedContexts,
}));
Expand Down
2 changes: 1 addition & 1 deletion node-ui/src/pages/InstallApplication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default function InstallApplication() {
message: `Installed application ${application.name}, version ${application.version}.`,
error: false,
});
return response.data.application_id;
return response.data.applicationId;
}
};

Expand Down
4 changes: 2 additions & 2 deletions node-ui/src/pages/StartContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function StartContextPage() {
}
const startContextResponse = await apiClient(showServerDownPopup)
.node()
.startContexts(appId, argumentsJson);
.createContexts(appId, argumentsJson);
if (startContextResponse.error) {
setStartContextStatus({
title: t.startContextErrorTitle,
Expand Down Expand Up @@ -93,7 +93,7 @@ export default function StartContextPage() {
message: `Installed application ${application.name}, version ${application.version}.`,
error: false,
});
return response.data.application_id;
return response.data.applicationId;
}
};

Expand Down
4 changes: 4 additions & 0 deletions node-ui/src/types/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ export interface ContextObject {
id: string;
package: Package | null;
}

export interface ContextsList {
joined: ContextObject[];
}
Loading