Skip to content

Commit

Permalink
Merge pull request #1073 from momentum-xyz/feat/node-admin
Browse files Browse the repository at this point in the history
Node Admin UI + blockchain functions calling
  • Loading branch information
dmitry-yudakov authored Oct 17, 2023
2 parents 9cbc750 + 1858222 commit c5a8e39
Show file tree
Hide file tree
Showing 63 changed files with 2,664 additions and 28 deletions.
6 changes: 6 additions & 0 deletions packages/app/src/api/api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import * as versionRepository from './repositories/versionRepository';
import * as configRepository from './repositories/configRepository';
import * as authRepository from './repositories/authRepository';
import * as nodeRepository from './repositories/nodeRepository';
import * as web3Repository from './repositories/web3Repository';
import * as userRepository from './repositories/userRepository';
import * as worldRepository from './repositories/worldRepository';
import * as userProfileRepository from './repositories/userProfileRepository';
import * as pluginsRepository from './repositories/pluginsRepository';
import * as objectAttributeRepository from './repositories/objectAttributeRepository';
import * as userAttributeRepository from './repositories/userAttributeRepository';
import * as nodeAttributeRepository from './repositories/nodeAttributeRepository';
import * as mediaRepository from './repositories/mediaRepository';
import * as newsfeedRepository from './repositories/newsfeedRepository';
import * as timelineRepository from './repositories/timelineRepository';
Expand Down Expand Up @@ -38,6 +40,7 @@ export const api = {
versionRepository,
configRepository,
authRepository,
nodeRepository,
web3Repository,
worldRepository,
userRepository,
Expand All @@ -48,6 +51,7 @@ export const api = {
objectAttributeRepository,
userAttributeRepository,
objectUserAttributeRepository,
nodeAttributeRepository,
mediaRepository,
newsfeedRepository,
timelineRepository,
Expand All @@ -71,13 +75,15 @@ export const api = {
export * from './repositories/versionRepository/versionRepository.api.types';
export * from './repositories/configRepository/configRepository.api.types';
export * from './repositories/authRepository/authRepository.api.types';
export * from './repositories/nodeRepository/nodeRepository.api.types';
export * from './repositories/web3Repository/web3Repository.api.types';
export * from './repositories/userRepository/userRepository.api.types';
export * from './repositories/userProfileRepository/userProfileRepository.api.types';
export * from './repositories/worldRepository/worldRepository.api.types';
export * from './repositories/pluginsRepository/pluginsRepository.api.types';
export * from './repositories/objectAttributeRepository/objectAttribute.api.types';
export * from './repositories/userAttributeRepository/userAttributeRepository.api.types';
export * from './repositories/nodeAttributeRepository/nodeAttributeRepository.api.types';
export * from './repositories/mediaRepository/mediaRepository.api.types';
export * from './repositories/newsfeedRepository/newsfeedRepository.api.types';
export * from './repositories/timelineRepository/timelineRepository.api.types';
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/api/constants/app.variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const appVariables: AppConfigExtendedInterface = {
CONTRACT_DAD_ADDRESS: '0x0244BbA6fcB25eFed05955C4A1B86A458986D2e0',
CONTRACT_NFT_ADDRESS: '0x97E0B10D89a494Eb5cfFCc72853FB0750BD64AcD',
CONTRACT_FAUCET_ADDRESS: '0x9E760F1CddA0694B6156076C60657118CF874289',
CONTRACT_MAPPING_ADDRESS: '0x5178df50BE2021A00C285637b6e78Ae51D1C50a5',
MINT_NFT_AMOUNT: '4.20',
MINT_NFT_DEPOSIT_ADDRESS: '0x683642c22feDE752415D4793832Ab75EFdF6223c',
WIKI_URL: 'https://wiki.odyssey.org/momentum/help/support',
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/api/interfaces/appConfig.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface AppConfigInterface {
CONTRACT_DAD_ADDRESS: string;
CONTRACT_NFT_ADDRESS: string;
CONTRACT_FAUCET_ADDRESS: string;
CONTRACT_MAPPING_ADDRESS: string;
MINT_NFT_AMOUNT: string;
MINT_NFT_DEPOSIT_ADDRESS: string;
NODE_ID: string;
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/api/repositories/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './versionRepository';
export * from './configRepository';
export * from './authRepository';
export * from './nodeRepository';
export * from './web3Repository';
export * from './userRepository';
export * from './userProfileRepository';
Expand All @@ -18,3 +19,4 @@ export * from './assets2dRepository';
export * from './agoraRepository';
export * from './streamChatRepository';
export * from './objectUserAttributeRepository';
export * from './nodeAttributeRepository';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './nodeAttributeRepository.api';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const nodeAttributesRepositoryEndpoints = () => {
const BASE_URL = '/node/attributes';

return {
base: BASE_URL
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {RequestInterface} from '@momentum-xyz/core';

import {request} from 'api/request';

import {nodeAttributesRepositoryEndpoints} from './nodeAttributeRepository.api.endpoints';
import {
NodeAttributeRequest,
NodeAttributeResponse,
NodeAttributeValueRequest
} from './nodeAttributeRepository.api.types';

export const getNodeAttribute: RequestInterface<NodeAttributeRequest, NodeAttributeResponse> = (
options
) => {
const {pluginId, attributeName, ...restOptions} = options;

const requestParams = {
params: {
plugin_id: pluginId,
attribute_name: attributeName
},
...restOptions
};

return request.get(nodeAttributesRepositoryEndpoints().base, requestParams);
};

export const setNodeAttribute: RequestInterface<
NodeAttributeValueRequest,
NodeAttributeResponse
> = (options) => {
const {pluginId, attributeName, attributeValue, ...restOptions} = options;

return request.post(
nodeAttributesRepositoryEndpoints().base,
{plugin_id: pluginId, attribute_name: attributeName, attribute_value: attributeValue},
restOptions
);
};

export const deleteNodeAttribute: RequestInterface<NodeAttributeRequest, null> = (options) => {
const {pluginId, attributeName, ...restOptions} = options;

const requestParams = {
params: {
plugin_id: pluginId,
attribute_name: attributeName
},
...restOptions
};

return request.delete(nodeAttributesRepositoryEndpoints().base, requestParams);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {AttributeValueInterface} from '@momentum-xyz/sdk';

export interface NodeAttributeRequest {
pluginId: string;
attributeName: string;
}

export interface NodeAttributeResponse {
attributeValue: AttributeValueInterface;
}

export interface NodeAttributeValueRequest extends NodeAttributeRequest {
attributeValue: AttributeValueInterface;
}
1 change: 1 addition & 0 deletions packages/app/src/api/repositories/nodeRepository/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './nodeRepository.api';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const configRepositoryEndpoints = () => {
const BASE_URL = '/node';

return {
getChallenge: `${BASE_URL}/get-challenge`,
hostingAllowList: `${BASE_URL}/hosting-allow-list`,
hostingAllowListRemove: `${BASE_URL}/hosting-allow-list/:userId`
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {generatePath} from 'react-router-dom';

import {request} from 'api/request';
import {RequestInterface} from 'api/interfaces';

import {
AddToHostingAllowListRequest,
GetHostingAllowListRequest,
GetHostingAllowListResponse,
GetNodeChallengeRequest,
GetNodeChallengeResponse,
RemoveFromHostingAllowListRequest
} from './nodeRepository.api.types';
import {configRepositoryEndpoints} from './nodeRepository.api.endpoints';

export const getNodeChallenge: RequestInterface<
GetNodeChallengeRequest,
GetNodeChallengeResponse
> = (options) => {
return request.post(configRepositoryEndpoints().getChallenge, options);
};

export const getHostingAllowList: RequestInterface<
GetHostingAllowListRequest,
GetHostingAllowListResponse
> = (options) => {
return request.get(configRepositoryEndpoints().hostingAllowList, options);
};

export const addToHostingAllowList: RequestInterface<AddToHostingAllowListRequest, null> = (
options
) => {
const {wallet, user_id, ...restOptions} = options;

return request.post(configRepositoryEndpoints().hostingAllowList, {wallet, user_id}, restOptions);
};

export const removeFromHostingAllowList: RequestInterface<
RemoveFromHostingAllowListRequest,
null
> = (options) => {
const {user_id, ...restOptions} = options;

return request.delete(
generatePath(configRepositoryEndpoints().hostingAllowListRemove, {userId: user_id}),
restOptions
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export interface GetNodeChallengeRequest {
odyssey_id: string;
}

export interface GetNodeChallengeResponse {
challenge: string;
}

export interface AddToHostingAllowListRequest {
wallet?: string;
user_id?: string;
}

export interface RemoveFromHostingAllowListRequest {
user_id: string;
}

export interface HostingAllowListItemInterface {
user_id: string;
name: string;
avatar_hash: string;
wallets: string[];
}

export interface GetHostingAllowListRequest {}

export interface GetHostingAllowListResponse extends Array<HostingAllowListItemInterface> {}
3 changes: 3 additions & 0 deletions packages/app/src/core/constants/routePaths.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ export const ROUTES = {
disconnected: '/system/disconnected',
maintenance: '/system/maintenance',
wrongBrowser: '/system/wrongBrowser'
},
admin: {
base: '/admin'
}
};
71 changes: 71 additions & 0 deletions packages/app/src/core/models/NodeAttribute/NodeAttribute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {flow, types} from 'mobx-state-tree';
import {RequestModel} from '@momentum-xyz/core';
import {AttributeValueInterface} from '@momentum-xyz/sdk';

import {api} from 'api';
import {PluginIdEnum} from 'api/enums';

export const NodeAttribute = types
.model('NodeAttribute', {
attributeName: types.string,
pluginId: types.optional(types.string, PluginIdEnum.CORE),
_value: types.maybe(types.frozen<AttributeValueInterface>()),
request: types.optional(RequestModel, {})
})
.actions((self) => ({
load: flow(function* () {
const data = {
pluginId: self.pluginId,
attributeName: self.attributeName
};
console.log('NodeAttribute load', data);
const response: AttributeValueInterface | undefined = yield self.request.send(
api.nodeAttributeRepository.getNodeAttribute,
data
);

console.log('NodeAttribute load', data, 'resp:', response);

if (response) {
self._value = response;
}

return response;
}),
set: flow(function* (value: AttributeValueInterface) {
const data = {
pluginId: self.pluginId,
attributeName: self.attributeName,
attributeValue: value
};
console.log('NodeAttribute set:', data);

yield self.request.send(api.nodeAttributeRepository.setNodeAttribute, data);

if (self.request.isError) {
throw new Error('Error setting attribute: ' + self.request.errorCode);
}

self._value = value;
}),
delete: flow(function* () {
const data = {
pluginId: self.pluginId,
attributeName: self.attributeName
};
console.log('NodeAttribute delete:', data);
yield self.request.send(api.nodeAttributeRepository.deleteNodeAttribute, data);

if (self.request.isError) {
throw new Error('Error deleting attribute: ' + self.request.errorCode);
}
})
}))
.views((self) => ({
get value(): AttributeValueInterface | undefined {
return self._value;
},
get isPending(): boolean {
return self.request.isPending;
}
}));
1 change: 1 addition & 0 deletions packages/app/src/core/models/NodeAttribute/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './NodeAttribute';
12 changes: 12 additions & 0 deletions packages/app/src/core/models/NodeConfig/NodeConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {Instance, types} from 'mobx-state-tree';

export const NodeConfig = types.model('NodeConfig', {
node_id: types.maybe(types.string),
hostname: types.string,
name: types.string,
owner: types.maybe(types.string)
});

export interface NodeConfigInterface extends Instance<typeof NodeConfig> {}

export type NodeConfigInputType = Pick<NodeConfigInterface, 'hostname' | 'name'>;
1 change: 1 addition & 0 deletions packages/app/src/core/models/NodeConfig/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './NodeConfig';
2 changes: 2 additions & 0 deletions packages/app/src/core/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './MediaUploader';
export * from './Object';
export * from './ObjectAttribute';
export * from './ObjectUserAttribute';
export * from './NodeAttribute';
export * from './AgoraRemoteUser';
export * from './EmojiDetail';
export * from './PluginLoader';
Expand Down Expand Up @@ -32,3 +33,4 @@ export * from './BigStakerInfo';
export * from './TimelineEntry';
export * from './TrackInfo';
export * from './SkyboxItem';
export * from './NodeConfig';
9 changes: 9 additions & 0 deletions packages/app/src/scenes/App.routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const World2dPage = lazy(() => import('./world/pages/World2dPage/World2dPage'));
const DisconnectedPage = lazy(() => import('./system/pages/DisconnectedPage/DisconnectedPage'));
const WrongBrowserPage = lazy(() => import('./system/pages/WrongBrowserPage/WrongBrowserPage'));
const MaintenancePage = lazy(() => import('./system/pages/MaintenancePage/MaintenancePage'));
const NodeConfigPage = lazy(() => import('./admin/pages/NodeConfig/NodeConfig'));

export const SYSTEM_ROUTES: RouteConfigInterface[] = [
{
Expand Down Expand Up @@ -43,3 +44,11 @@ export const WORLD_ROUTES: RouteConfigInterface[] = [
exact: true
}
];

export const ADMIN_ROUTES: RouteConfigInterface[] = [
{
path: ROUTES.admin.base,
main: () => <NodeConfigPage />,
exact: true
}
];
Loading

0 comments on commit c5a8e39

Please sign in to comment.