Skip to content

Commit

Permalink
Merge branch 'master' of github.com:calimero-network/core into feat--…
Browse files Browse the repository at this point in the history
…expose-proposal-api-to-calimero-sdk
  • Loading branch information
MatejVukosav committed Nov 6, 2024
2 parents a91e016 + c46ce47 commit 683bde5
Show file tree
Hide file tree
Showing 21 changed files with 437 additions and 283 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,17 @@ jobs:
- name: Build
run: cargo build --verbose

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v45
with:
files: |
**.rs
- name: Run tests
env:
CHANGED_RUST_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
run: |
chmod +x $GITHUB_WORKSPACE/scripts/build-all-apps.sh
chmod +x $GITHUB_WORKSPACE/scripts/test.sh
$GITHUB_WORKSPACE/scripts/test.sh
$GITHUB_WORKSPACE/scripts/test.sh --local ${CHANGED_RUST_FILES}
9 changes: 6 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
echo "Running pre-commit hook..."

# Check for changes in Markdown or MDX files
if git diff --cached --name-only | grep -qE '\.mdx?$'; then
if git diff --cached --name-only | grep -q '\.mdx?$'; then
echo "Markdown or MDX files have been changed."
pnpm format:md
fi

# Check for changes in Rust files
if git diff --cached --name-only | grep -qE '\.rs$'; then
if git diff --cached --name-only | grep -q '\.rs$'; then
echo "Running checks for the Rust code..."
cargo +nightly fmt
# Run tests only for the changed files
# changed_rust_files=$(git diff --cached --name-only | grep -E '\.rs$')
# ./scripts/test.sh --local ${changed_rust_files}
fi

# Check for changes in the 'node-ui' directory (Next.js app)
Expand All @@ -25,4 +28,4 @@ fi
if git diff --cached --name-only | grep -q '^packages/calimero-sdk/'; then
echo "Running checks for the packages/calimero-sdk..."
(cd packages/calimero-sdk && pnpm prettier && pnpm lint:fix)
fi
fi
1 change: 1 addition & 0 deletions crates/merod/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub const EXAMPLES: &str = r"
"Examples:",
EXAMPLES
))]

pub struct RootCommand {
#[command(flatten)]
pub args: RootArgs,
Expand Down

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-CEAaf8Ev.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
3 changes: 3 additions & 0 deletions node-ui/src/api/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export class AxiosHttpClient implements HttpClient {
this.axios.interceptors.response.use(
(response: AxiosResponse) => response,
(error: AxiosError) => {
if (error.response?.status === 401) {
window.location.href = '/admin-dashboard/';
}
if (!error.response) {
this.showServerDownPopup();
}
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
8 changes: 6 additions & 2 deletions node-ui/src/pages/setup/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import React from 'react';
import React, { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { setAppEndpointKey } from '../../utils/storage';
import { clearStorage, setAppEndpointKey } from '../../utils/storage';
import ContentWrapper from '../../components/login/ContentWrapper';
import { SetupModal } from '../../components/setup/SetupModal';
import { getNodeUrl } from '../../utils/node';

export default function SetupPage() {
const navigate = useNavigate();

useEffect(() => {
clearStorage();
}, []);

return (
<ContentWrapper>
<SetupModal
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

0 comments on commit 683bde5

Please sign in to comment.