-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1073 from momentum-xyz/feat/node-admin
Node Admin UI + blockchain functions calling
- Loading branch information
Showing
63 changed files
with
2,664 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/app/src/api/repositories/nodeAttributeRepository/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './nodeAttributeRepository.api'; |
7 changes: 7 additions & 0 deletions
7
...app/src/api/repositories/nodeAttributeRepository/nodeAttributeRepository.api.endpoints.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
}; |
53 changes: 53 additions & 0 deletions
53
packages/app/src/api/repositories/nodeAttributeRepository/nodeAttributeRepository.api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
14 changes: 14 additions & 0 deletions
14
...ges/app/src/api/repositories/nodeAttributeRepository/nodeAttributeRepository.api.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './nodeRepository.api'; |
9 changes: 9 additions & 0 deletions
9
packages/app/src/api/repositories/nodeRepository/nodeRepository.api.endpoints.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` | ||
}; | ||
}; |
48 changes: 48 additions & 0 deletions
48
packages/app/src/api/repositories/nodeRepository/nodeRepository.api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
}; |
27 changes: 27 additions & 0 deletions
27
packages/app/src/api/repositories/nodeRepository/nodeRepository.api.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/app/src/core/models/NodeAttribute/NodeAttribute.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './NodeAttribute'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './NodeConfig'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.