diff --git a/Projects/Governance/Icons/DE.png b/Projects/Governance/Icons/DE.png new file mode 100644 index 000000000..49a0eedb9 Binary files /dev/null and b/Projects/Governance/Icons/DE.png differ diff --git a/Projects/Governance/Icons/EN.png b/Projects/Governance/Icons/EN.png new file mode 100644 index 000000000..932293250 Binary files /dev/null and b/Projects/Governance/Icons/EN.png differ diff --git a/Projects/Governance/Icons/bitcoin.png b/Projects/Governance/Icons/bitcoin.png new file mode 100644 index 000000000..a4ee2a209 Binary files /dev/null and b/Projects/Governance/Icons/bitcoin.png differ diff --git a/Projects/Governance/Icons/bitfinex.png b/Projects/Governance/Icons/bitfinex.png new file mode 100644 index 000000000..d5d3db0e2 Binary files /dev/null and b/Projects/Governance/Icons/bitfinex.png differ diff --git a/Projects/Governance/Icons/dogecoin.png b/Projects/Governance/Icons/dogecoin.png new file mode 100644 index 000000000..0c3efe978 Binary files /dev/null and b/Projects/Governance/Icons/dogecoin.png differ diff --git a/Projects/Governance/Icons/ethereum.png b/Projects/Governance/Icons/ethereum.png new file mode 100644 index 000000000..33b2853a1 Binary files /dev/null and b/Projects/Governance/Icons/ethereum.png differ diff --git a/Projects/Governance/Icons/kraken.png b/Projects/Governance/Icons/kraken.png new file mode 100644 index 000000000..cf7e2d59e Binary files /dev/null and b/Projects/Governance/Icons/kraken.png differ diff --git a/Projects/Governance/Icons/tron.png b/Projects/Governance/Icons/tron.png new file mode 100644 index 000000000..65ebcbd98 Binary files /dev/null and b/Projects/Governance/Icons/tron.png differ diff --git a/Projects/Superalgos/Schemas/App-Schema/assets-structure.json b/Projects/Governance/Schemas/App-Schema/assets-structure.json similarity index 70% rename from Projects/Superalgos/Schemas/App-Schema/assets-structure.json rename to Projects/Governance/Schemas/App-Schema/assets-structure.json index 1fa75ad28..1f986969d 100644 --- a/Projects/Superalgos/Schemas/App-Schema/assets-structure.json +++ b/Projects/Governance/Schemas/App-Schema/assets-structure.json @@ -1,17 +1,17 @@ { - "type": "Assets Structure", + "type": "Assets", "menuItems": [ { "action": "Add UI Object", "actionFunction": "payload.executeAction", - "label": "Add Project Asset Class", - "relatedUiObject": "Project Asset Class" + "label": "Add Asset Class", + "relatedUiObject": "Asset Class" }, { "action": "Add UI Object", "actionFunction": "payload.executeAction", - "label": "Add Project Asset", - "relatedUiObject": "Project Asset" + "label": "Add Asset", + "relatedUiObject": "Asset" }, { "action": "Delete UI Object", @@ -31,15 +31,15 @@ }, "childrenNodesProperties": [ { - "name": "projectAssetClasses", + "name": "assetClasses", "type": "array", - "childType": "Project Asset Class", + "childType": "Asset Class", "autoAdd": false }, { - "name": "projectAssets", + "name": "assets", "type": "array", - "childType": "Project Asset", + "childType": "Asset", "autoAdd": false } ], diff --git a/Projects/Superalgos/Schemas/App-Schema/civic-contributions.json b/Projects/Governance/Schemas/App-Schema/civic-contributions.json similarity index 100% rename from Projects/Superalgos/Schemas/App-Schema/civic-contributions.json rename to Projects/Governance/Schemas/App-Schema/civic-contributions.json diff --git a/Projects/Superalgos/Schemas/App-Schema/community-contributions.json b/Projects/Governance/Schemas/App-Schema/community-contributions.json similarity index 100% rename from Projects/Superalgos/Schemas/App-Schema/community-contributions.json rename to Projects/Governance/Schemas/App-Schema/community-contributions.json diff --git a/Projects/Superalgos/Schemas/App-Schema/contributed-asset.json b/Projects/Governance/Schemas/App-Schema/contributed-asset.json similarity index 95% rename from Projects/Superalgos/Schemas/App-Schema/contributed-asset.json rename to Projects/Governance/Schemas/App-Schema/contributed-asset.json index 6d4bb4e38..f75d6d45c 100644 --- a/Projects/Superalgos/Schemas/App-Schema/contributed-asset.json +++ b/Projects/Governance/Schemas/App-Schema/contributed-asset.json @@ -34,7 +34,7 @@ "compatibleTypes": "->Software Contributions->" }, "referencingRules": { - "compatibleTypes": "->Project Asset->" + "compatibleTypes": "->Asset->" }, "propertyNameAtParent": "contributedAssets", "icon": "tron" diff --git a/Projects/Superalgos/Schemas/App-Schema/contributed-time.json b/Projects/Governance/Schemas/App-Schema/contributed-time.json similarity index 89% rename from Projects/Superalgos/Schemas/App-Schema/contributed-time.json rename to Projects/Governance/Schemas/App-Schema/contributed-time.json index 3c171cca6..3ea1c677e 100644 --- a/Projects/Superalgos/Schemas/App-Schema/contributed-time.json +++ b/Projects/Governance/Schemas/App-Schema/contributed-time.json @@ -19,7 +19,8 @@ } ], "title": [ - "Use Reference Parent" + "Use Reference Parent", + "Use Reference Parent Parent" ], "editors": { "config": true @@ -33,7 +34,7 @@ "compatibleTypes": "->Governance Contributions->" }, "referencingRules": { - "compatibleTypes": "->Project Rank->" + "compatibleTypes": "->Ranking Position->" }, "propertyNameAtParent": "contributedTimes", "icon": "dogecoin" diff --git a/Projects/Superalgos/Schemas/App-Schema/contributed-vote.json b/Projects/Governance/Schemas/App-Schema/contributed-vote.json similarity index 100% rename from Projects/Superalgos/Schemas/App-Schema/contributed-vote.json rename to Projects/Governance/Schemas/App-Schema/contributed-vote.json diff --git a/Projects/Superalgos/Schemas/App-Schema/contributed-youtube-video.json b/Projects/Governance/Schemas/App-Schema/contributed-youtube-video.json similarity index 82% rename from Projects/Superalgos/Schemas/App-Schema/contributed-youtube-video.json rename to Projects/Governance/Schemas/App-Schema/contributed-youtube-video.json index 2e9289784..089b52a8c 100644 --- a/Projects/Superalgos/Schemas/App-Schema/contributed-youtube-video.json +++ b/Projects/Governance/Schemas/App-Schema/contributed-youtube-video.json @@ -11,8 +11,8 @@ { "action": "Add UI Object", "actionFunction": "payload.executeAction", - "label": "Add Project Asset", - "relatedUiObject": "Project Asset" + "label": "Add Asset", + "relatedUiObject": "Asset" }, { "action": "Delete UI Object", @@ -33,14 +33,14 @@ "addLeftIcons": true, "level": 2, "attachingRules": { - "compatibleTypes": "->Assets Structure->Project Asset->" + "compatibleTypes": "->Assets->Asset->" }, "propertyNameAtParent": "softwareContributions", "childrenNodesProperties": [ { - "name": "projectAssetClass", + "name": "assetClass", "type": "array", - "childType": "Project Asset", + "childType": "Asset", "autoAdd": false } ], diff --git a/Projects/Superalgos/Schemas/App-Schema/features-structure.json b/Projects/Governance/Schemas/App-Schema/features-structure.json similarity index 100% rename from Projects/Superalgos/Schemas/App-Schema/features-structure.json rename to Projects/Governance/Schemas/App-Schema/features-structure.json diff --git a/Projects/Superalgos/Schemas/App-Schema/governance-contributions.json b/Projects/Governance/Schemas/App-Schema/governance-contributions.json similarity index 100% rename from Projects/Superalgos/Schemas/App-Schema/governance-contributions.json rename to Projects/Governance/Schemas/App-Schema/governance-contributions.json diff --git a/Projects/Governance/Schemas/App-Schema/governance-project.json b/Projects/Governance/Schemas/App-Schema/governance-project.json new file mode 100644 index 000000000..8e259b680 --- /dev/null +++ b/Projects/Governance/Schemas/App-Schema/governance-project.json @@ -0,0 +1,47 @@ +{ + "type": "Governance Project", + "menuItems": [ + { + "action": "Add UI Object", + "label": "Add Assets", + "relatedUiObject": "Assets", + "actionFunction": "payload.executeAction" + }, + { + "action": "Add UI Object", + "label": "Add Ranking", + "relatedUiObject": "Ranking", + "actionFunction": "payload.executeAction" + }, + { + "action": "Add UI Object", + "label": "Add User Contributions", + "relatedUiObject": "User Contributions", + "actionFunction": "payload.executeAction" + }, + { + "action": "Delete UI Object", + "askConfirmation": true, + "confirmationLabel": "Confirm to Delete", + "actionFunction": "payload.executeAction", + "label": "Delete", + "iconPathOn": "delete-entity", + "iconPathOff": "delete-entity" + } + ], + "isProjectHead": true, + "isTitleAllwaysVisible": false, + "addLeftIcons": true, + "isPinned": true, + "positionLocked": true, + "icon": "bitcoin", + "childrenNodesProperties": [ + { + "name": "projectDefinition", + "type": "node", + "childType": "Project Definition", + "project": "Superalgos", + "autoAdd": true + } + ] +} \ No newline at end of file diff --git a/Projects/Superalgos/Schemas/App-Schema/governance-structure.json b/Projects/Governance/Schemas/App-Schema/governance-structure.json similarity index 77% rename from Projects/Superalgos/Schemas/App-Schema/governance-structure.json rename to Projects/Governance/Schemas/App-Schema/governance-structure.json index ea30dcd79..79c5de3d3 100644 --- a/Projects/Superalgos/Schemas/App-Schema/governance-structure.json +++ b/Projects/Governance/Schemas/App-Schema/governance-structure.json @@ -1,10 +1,10 @@ { - "type": "Governance Structure", + "type": "Ranking", "menuItems": [ { "action": "Add UI Object", - "label": "Add Project Rank", - "relatedUiObject": "Project Rank", + "label": "Add Ranking Position", + "relatedUiObject": "Ranking Position", "actionFunction": "payload.executeAction" }, { @@ -23,9 +23,9 @@ "level": 0, "childrenNodesProperties": [ { - "name": "projectRanks", + "name": "rankingPositions", "type": "array", - "childType": "Project Rank", + "childType": "Ranking Position", "autoAdd": false } ], diff --git a/Projects/Superalgos/Schemas/App-Schema/marketing-contributions.json b/Projects/Governance/Schemas/App-Schema/marketing-contributions.json similarity index 100% rename from Projects/Superalgos/Schemas/App-Schema/marketing-contributions.json rename to Projects/Governance/Schemas/App-Schema/marketing-contributions.json diff --git a/Projects/Superalgos/Schemas/App-Schema/project-asset-class.json b/Projects/Governance/Schemas/App-Schema/project-asset-class.json similarity index 69% rename from Projects/Superalgos/Schemas/App-Schema/project-asset-class.json rename to Projects/Governance/Schemas/App-Schema/project-asset-class.json index 96263ff58..938beef44 100644 --- a/Projects/Superalgos/Schemas/App-Schema/project-asset-class.json +++ b/Projects/Governance/Schemas/App-Schema/project-asset-class.json @@ -1,5 +1,5 @@ { - "type": "Project Asset Class", + "type": "Asset Class", "menuItems": [ { "action": "Configure", @@ -11,14 +11,14 @@ { "action": "Add UI Object", "actionFunction": "payload.executeAction", - "label": "Add Project Asset Class", - "relatedUiObject": "Project Asset Class" + "label": "Add Asset Class", + "relatedUiObject": "Asset Class" }, { "action": "Add UI Object", "actionFunction": "payload.executeAction", - "label": "Add Project Asset", - "relatedUiObject": "Project Asset" + "label": "Add Asset", + "relatedUiObject": "Asset" }, { "action": "Delete UI Object", @@ -39,23 +39,23 @@ "addLeftIcons": true, "level": 2, "attachingRules": { - "compatibleTypes": "->Assets Structure->Project Asset Class->" + "compatibleTypes": "->Assets->Asset Class->" }, "referencingRules": { - "compatibleTypes": "->Team->Project Rank->" + "compatibleTypes": "->Team->Ranking Position->" }, - "propertyNameAtParent": "projectAssetClasses", + "propertyNameAtParent": "assetClasses", "childrenNodesProperties": [ { - "name": "projectAssetClasses", + "name": "assetClasses", "type": "array", - "childType": "Project Asset Class", + "childType": "Asset Class", "autoAdd": false }, { - "name": "projectAssets", + "name": "assets", "type": "array", - "childType": "Project Asset", + "childType": "Asset", "autoAdd": false } ], diff --git a/Projects/Superalgos/Schemas/App-Schema/project-asset.json b/Projects/Governance/Schemas/App-Schema/project-asset.json similarity index 70% rename from Projects/Superalgos/Schemas/App-Schema/project-asset.json rename to Projects/Governance/Schemas/App-Schema/project-asset.json index 0aff5313c..43e6cf0fc 100644 --- a/Projects/Superalgos/Schemas/App-Schema/project-asset.json +++ b/Projects/Governance/Schemas/App-Schema/project-asset.json @@ -1,5 +1,5 @@ { - "type": "Project Asset", + "type": "Asset", "menuItems": [ { "action": "Configure", @@ -11,14 +11,14 @@ { "action": "Add UI Object", "actionFunction": "payload.executeAction", - "label": "Add Project Asset Class", - "relatedUiObject": "Project Asset Class" + "label": "Add Asset Class", + "relatedUiObject": "Asset Class" }, { "action": "Add UI Object", "actionFunction": "payload.executeAction", - "label": "Add Project Asset", - "relatedUiObject": "Project Asset" + "label": "Add Asset", + "relatedUiObject": "Asset" }, { "action": "Delete UI Object", @@ -39,23 +39,23 @@ "addLeftIcons": true, "level": 2, "attachingRules": { - "compatibleTypes": "->Project Asset Class->Project Asset->" + "compatibleTypes": "->Asset Class->Asset->" }, "referencingRules": { - "compatibleTypes": "->Team->Project Rank->" + "compatibleTypes": "->Team->Ranking Position->" }, - "propertyNameAtParent": "projectAssets", + "propertyNameAtParent": "assets", "childrenNodesProperties": [ { - "name": "projectAssetClasses", + "name": "assetClasses", "type": "array", - "childType": "Project Asset Class", + "childType": "Asset Class", "autoAdd": false }, { - "name": "projectAssets", + "name": "assets", "type": "array", - "childType": "Project Asset", + "childType": "Asset", "autoAdd": false } ], diff --git a/Projects/Superalgos/Schemas/App-Schema/project-feature.json b/Projects/Governance/Schemas/App-Schema/project-feature.json similarity index 100% rename from Projects/Superalgos/Schemas/App-Schema/project-feature.json rename to Projects/Governance/Schemas/App-Schema/project-feature.json diff --git a/Projects/Superalgos/Schemas/App-Schema/project-rank.json b/Projects/Governance/Schemas/App-Schema/project-rank.json similarity index 81% rename from Projects/Superalgos/Schemas/App-Schema/project-rank.json rename to Projects/Governance/Schemas/App-Schema/project-rank.json index a3ff0cec4..7c77d314a 100644 --- a/Projects/Superalgos/Schemas/App-Schema/project-rank.json +++ b/Projects/Governance/Schemas/App-Schema/project-rank.json @@ -1,5 +1,5 @@ { - "type": "Project Rank", + "type": "Ranking Position", "menuItems": [ { "action": "Configure", @@ -11,8 +11,8 @@ { "action": "Add UI Object", "actionFunction": "payload.executeAction", - "label": "Add Project Rank", - "relatedUiObject": "Project Rank" + "label": "Add Ranking Position", + "relatedUiObject": "Ranking Position" }, { "action": "Add UI Object", @@ -39,14 +39,14 @@ "addLeftIcons": true, "level": 2, "attachingRules": { - "compatibleTypes": "->Governance Structure->Project Rank->Team->" + "compatibleTypes": "->Ranking->Ranking Position->Team->" }, - "propertyNameAtParent": "projectRanks", + "propertyNameAtParent": "rankingPositions", "childrenNodesProperties": [ { - "name": "projectRanks", + "name": "rankingPositions", "type": "array", - "childType": "Project Rank", + "childType": "Ranking Position", "autoAdd": false }, { diff --git a/Projects/Superalgos/Schemas/App-Schema/software-contributions.json b/Projects/Governance/Schemas/App-Schema/software-contributions.json similarity index 100% rename from Projects/Superalgos/Schemas/App-Schema/software-contributions.json rename to Projects/Governance/Schemas/App-Schema/software-contributions.json diff --git a/Projects/Superalgos/Schemas/App-Schema/team.json b/Projects/Governance/Schemas/App-Schema/team.json similarity index 86% rename from Projects/Superalgos/Schemas/App-Schema/team.json rename to Projects/Governance/Schemas/App-Schema/team.json index c4be415c5..af27c192c 100644 --- a/Projects/Superalgos/Schemas/App-Schema/team.json +++ b/Projects/Governance/Schemas/App-Schema/team.json @@ -11,8 +11,8 @@ { "action": "Add UI Object", "actionFunction": "payload.executeAction", - "label": "Add Project Rank", - "relatedUiObject": "Project Rank" + "label": "Add Ranking Position", + "relatedUiObject": "Ranking Position" }, { "action": "Add UI Object", @@ -39,14 +39,14 @@ "addLeftIcons": true, "level": 2, "attachingRules": { - "compatibleTypes": "->Project Rank->Team->" + "compatibleTypes": "->Ranking Position->Team->" }, "propertyNameAtParent": "teams", "childrenNodesProperties": [ { - "name": "projectRanks", + "name": "rankingPositions", "type": "array", - "childType": "Project Rank", + "childType": "Ranking Position", "autoAdd": false }, { diff --git a/Projects/Superalgos/Schemas/App-Schema/user-contributions.json b/Projects/Governance/Schemas/App-Schema/user-contributions.json similarity index 100% rename from Projects/Superalgos/Schemas/App-Schema/user-contributions.json rename to Projects/Governance/Schemas/App-Schema/user-contributions.json diff --git a/Projects/Governance/UI/Function-Libraries/Accounts.js b/Projects/Governance/UI/Function-Libraries/Accounts.js new file mode 100644 index 000000000..d84df1548 --- /dev/null +++ b/Projects/Governance/UI/Function-Libraries/Accounts.js @@ -0,0 +1,53 @@ +function newEthereumFunctionLibraryAccounts() { + let thisObject = { + createWalletAccount: createWalletAccount + } + + return thisObject + + function createWalletAccount(node) { + + let walletAccountNode = UI.projects.superalgos.functionLibraries.uiObjectsFromNodes.addUIObject(node, 'Wallet Account') + + let params = { + method: 'createWalletAccount', + entropy: walletAccountNode.id + } + + let url = 'WEB3' // we don't need to ask this to any specific superalgos node. + + httpRequest(JSON.stringify(params), url, onResponse) + + function onResponse(err, data) { + /* Lets check the result of the call through the http interface */ + if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { + node.payload.uiObject.setErrorMessage('Call via HTTP Interface failed.') + walletAccountNode.payload.uiObject.menu.internalClick('Delete UI Object') + walletAccountNode.payload.uiObject.menu.internalClick('Delete UI Object') + return + } + + let response = JSON.parse(data) + + /* Lets check the result of the method call */ + if (response.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { + node.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. ' + response.error) + walletAccountNode.payload.uiObject.menu.internalClick('Delete UI Object') + walletAccountNode.payload.uiObject.menu.internalClick('Delete UI Object') + return + } + + let config = { + address: response.address, + privateKey: response.privateKey + } + + walletAccountNode.config = JSON.stringify(config, null, 4) + walletAccountNode.name = + response.address[response.address.length - 4] + + response.address[response.address.length - 3] + + response.address[response.address.length - 2] + + response.address[response.address.length - 1] + } + } +} diff --git a/Projects/Governance/UI/Function-Libraries/ActionSwitch.js b/Projects/Governance/UI/Function-Libraries/ActionSwitch.js new file mode 100644 index 000000000..201d3a795 --- /dev/null +++ b/Projects/Governance/UI/Function-Libraries/ActionSwitch.js @@ -0,0 +1,28 @@ +function newGovernanceActionSwitch() { + + let thisObject = { + executeAction: executeAction, + initialize: initialize, + finalize: finalize + } + + + return thisObject + + function finalize() { + + } + + function initialize() { + /* Nothing to initialize since a Function Library does not hold any state. */ + } + + async function executeAction(action) { + switch (action.name) { + case 'Create Wallet Account': { + UI.projects.ethereum.functionLibraries.accounts.createWalletAccount(action.node) + break + } + } + } +} diff --git a/Projects/Governance/UI/Globals/ChainIds.js b/Projects/Governance/UI/Globals/ChainIds.js new file mode 100644 index 000000000..e17cf4226 --- /dev/null +++ b/Projects/Governance/UI/Globals/ChainIds.js @@ -0,0 +1,18 @@ +function newEthereumGlobalsChainIds() { + let thisObject = { + chainNameById: chainNameById + } + return thisObject + + function chainNameById(chainId) { + switch(chainId) { + case 1: return 'Ethereum Mainnet' + case 3: return 'Ethereum Ropsten' + case 4: return 'Ethereum Rinkeby' + case 42: return 'Ethereum Kovan' + case 61: return 'Ethereum Classic Mainnet' + case 62: return 'Ethereum Classic Morden' + default: return 'Unknown Network' + } + } +} \ No newline at end of file diff --git a/Projects/Governance/UI/Spaces/Assets-Space/Assets.js b/Projects/Governance/UI/Spaces/Assets-Space/Assets.js new file mode 100644 index 000000000..37f63d57e --- /dev/null +++ b/Projects/Governance/UI/Spaces/Assets-Space/Assets.js @@ -0,0 +1,180 @@ +function newEthereumBlockchainSpace() { + const MODULE_NAME = 'Blockchain Space' + + let thisObject = { + container: undefined, + physics: physics, + draw: draw, + getContainer: getContainer, + finalize: finalize, + initialize: initialize + } + + thisObject.container = newContainer() + thisObject.container.initialize(MODULE_NAME) + + let lastTryToReconnectDatetime + + return thisObject + + function finalize() { + + thisObject.container.finalize() + thisObject.container = undefined + clientMap = undefined + } + + function initialize() { + + } + + function physics() { + networkClientStatusPhysics() + } + + async function networkClientStatusPhysics() { + + /* We will query the node only every 3 seconds */ + if (lastTryToReconnectDatetime === undefined) { + checkStatus() + lastTryToReconnectDatetime = (new Date()).valueOf() + } else { + let now = (new Date()).valueOf() + if (now - lastTryToReconnectDatetime > 3000) { + checkStatus() + lastTryToReconnectDatetime = now + } + } + + async function checkStatus() { + try { + if (UI.projects.superalgos.spaces.designSpace.workspace === undefined) { return } + + let blockchain = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeadByNodeType('Ethereum Blockchain') + if (blockchain === undefined) { return } + for (let i = 0; i < blockchain.blockchainNetworks.length; i++) { + let blockchainNetwork = blockchain.blockchainNetworks[i] + for (let j = 0; j < blockchainNetwork.networkClients.length; j++) { + let networkClient = blockchainNetwork.networkClients[j] + + let route = UI.projects.ethereum.utilities.routeToClient.buildRouteToClient(networkClient) + + if (route === undefined) { continue } // something went wrong building the route. + + route.params.method = 'getNetworkClientStatus' + + httpRequest(JSON.stringify(route.params), route.url, onResponse) + + function onResponse(err, data) { + /* Lets check the result of the call through the http interface */ + if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { + networkClient.payload.uiObject.setErrorMessage('Call via HTTP Interface failed.') + return + } + + let status = JSON.parse(data) + + /* Lets check the result of the method call */ + if (status.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { + networkClient.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. ' + status.error) + return + } + + showStatus(status) + } + + async function showStatus(status) { + const ANNIMATION_CYCLES_TO_LAST = 300 + + networkClient.payload.uiObject.resetErrorMessage() + + if (status.isSyncing === false && status.chainId === 0) { + networkClient.payload.uiObject.setStatus('Client is looking for peers...', ANNIMATION_CYCLES_TO_LAST) + return + } + + if (status.chainId > 0) { + let networkName = UI.projects.ethereum.globals.chainIds.chainNameById(status.chainId) + networkClient.payload.uiObject.setStatus('Connected to ' + networkName + ' via the ' + route.params.interface + ' interface, through ' + networkClient.payload.referenceParent.name + ' Network Node.', ANNIMATION_CYCLES_TO_LAST) + + networkClient.payload.uiObject.valueAtAngle = false + networkClient.payload.uiObject.setValue( + 'Current Block Number ' + splitLargeNumber(status.currentBlockNumber) + , 200) + networkClient.payload.uiObject.setPercentage('100.00', ANNIMATION_CYCLES_TO_LAST) + return + } + + /* If it is not syncing, then we have the current block and the highets block too */ + let percentage = (status.isSyncing.currentBlock * 100 / status.isSyncing.highestBlock).toFixed(4) + let extraStatus = '' + if (status.isSyncing.highestBlock - status.isSyncing.currentBlock < 300) { + extraStatus = 'Block Download Phase Finished. Downloading Trie Data Structure.' + } else { + extraStatus = 'Block Download Phase.' + networkClient.payload.uiObject.setPercentage(percentage, ANNIMATION_CYCLES_TO_LAST) + } + + networkClient.payload.uiObject.valueAtAngle = false + networkClient.payload.uiObject.setValue( + 'Block ' + splitLargeNumber(status.isSyncing.currentBlock) + + ' from ' + splitLargeNumber(status.isSyncing.highestBlock) + + '. State ' + splitLargeNumber(status.isSyncing.pulledStates) + + ' from ' + splitLargeNumber(status.isSyncing.knownStates) + , 200) + + if (status.isSyncing.currentBlock !== status.isSyncing.highestBlock) { + networkClient.payload.uiObject.setStatus('Connected via http. Client is Syncing... ' + extraStatus, ANNIMATION_CYCLES_TO_LAST) + } + + function splitLargeNumber(number) { + let label = number.toString() + let result = label + switch (label.length) { + case 4: { + return label[0] + ',' + label[1] + label[2] + label[3] + } + case 5: { + return label[0] + label[1] + ',' + label[2] + label[3] + label[4] + } + case 6: { + return label[0] + label[1] + label[2] + ',' + label[3] + label[4] + label[5] + } + case 7: { + return label[0] + ',' + label[1] + label[2] + label[3] + ',' + label[4] + label[5] + label[6] + } + case 8: { + return label[0] + label[1] + ',' + label[2] + label[3] + label[4] + ',' + label[5] + label[6] + label[7] + } + case 9: { + return label[0] + label[1] + label[2] + ',' + label[3] + label[4] + label[5] + ',' + label[6] + label[7] + label[8] + } + case 10: { + return label[0] + ',' + label[1] + label[2] + label[3] + ',' + label[4] + label[5] + label[6] + ',' + label[7] + label[8] + label[9] + } + } + return result + } + } + } + } + } catch (err) { + console.log('[ERROR] checkStatus -> err = ' + err.stack) + } + } + } + + function getContainer(point) { + + if (thisObject.container.frame.isThisPointHere(point, true) === true) { + thisObject.container.space = MODULE_NAME + return thisObject.container + } else { + return undefined + } + } + + function draw() { + + } +} diff --git a/Projects/Governance/UI/Spaces/Wallet-Space/Wallet.js b/Projects/Governance/UI/Spaces/Wallet-Space/Wallet.js new file mode 100644 index 000000000..66bdb9de4 --- /dev/null +++ b/Projects/Governance/UI/Spaces/Wallet-Space/Wallet.js @@ -0,0 +1,163 @@ +function newEthereumWalletSpace() { + const MODULE_NAME = 'Wallet Space' + + let thisObject = { + container: undefined, + physics: physics, + draw: draw, + getContainer: getContainer, + finalize: finalize, + initialize: initialize + } + + thisObject.container = newContainer() + thisObject.container.initialize(MODULE_NAME) + + let lastTryToReconnectDatetime + + return thisObject + + function finalize() { + + thisObject.container.finalize() + thisObject.container = undefined + } + + function initialize() { + + } + + function physics() { + walletBalancesPhysics() + } + + async function walletBalancesPhysics() { + + /* We will query the node only every 3 seconds */ + if (lastTryToReconnectDatetime === undefined) { + checkBalances() + lastTryToReconnectDatetime = (new Date()).valueOf() + } else { + let now = (new Date()).valueOf() + if (now - lastTryToReconnectDatetime > 3000) { + checkBalances() + lastTryToReconnectDatetime = now + } + } + + async function checkBalances() { + try { + if (UI.projects.superalgos.spaces.designSpace.workspace === undefined) { return } + + let wallets = [] + let hierarchyHeads = UI.projects.superalgos.spaces.designSpace.workspace.getHierarchyHeads() + for (let i = 0; i < hierarchyHeads.length; i++) { + let hierarchyHead = hierarchyHeads[i] + if (hierarchyHead.type === 'Ethereum Wallet') { + wallets.push(hierarchyHead) + } + } + + for (let i = 0; i < wallets.length; i++) { + let wallet = wallets[i] + + if (wallet.networkClientReference === undefined) { + wallet.payload.uiObject.setWarningMessage('A Network Client Reference is needed in order to fetch Account Balances from a Network Client.') + continue + } + + if (wallet.networkClientReference.payload === undefined) { + // node exists without payload, probably has been deleted. + continue + } + + if (wallet.networkClientReference.payload.referenceParent === undefined) { + wallet.networkClientReference.payload.uiObject.setWarningMessage('A reference to a Network Client is needed in order to fetch Account Balances from a Network Client.') + continue + } + + let networkClient = wallet.networkClientReference.payload.referenceParent + + let route = UI.projects.ethereum.utilities.routeToClient.buildRouteToClient(networkClient) + + if (route === undefined) { continue } // something went wrong building the route. + + route.params.method = 'getWalletBalances' + + let lightingPath = '' + + 'Ethereum Wallet->' + + 'Wallet Account->' + + 'ETH Balance->' + + 'Token Balance->' + + 'Ethereum Token->Smart Contract->' + + 'ERC-20 Token Type->ERC-223 Token Type->ERC-721 Token Type->ERC-777 Token Type->' + + route.params.walletDefinition = UI.projects.superalgos.functionLibraries.protocolNode.getProtocolNode(wallet, false, true, true, false, false, lightingPath) + + httpRequest(JSON.stringify(route.params), route.url, onResponse) + + function onResponse(err, data) { + /* Lets check the result of the call through the http interface */ + if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { + networkClient.payload.uiObject.setErrorMessage('Call via HTTP Interface failed.') + return + } + + let response = JSON.parse(data) + + /* Lets check the result of the method call */ + if (response.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) { + networkClient.payload.uiObject.setErrorMessage('Call to WEB3 Server failed. ' + response.error) + return + } + + showBalances(response.walletDefinition) + } + + function showBalances(walletDefinition) { + for (let i = 0; i < walletDefinition.walletAccounts.length; i++) { + let walletAccount = walletDefinition.walletAccounts[i] + + if (walletAccount.ethBalance !== undefined) { + + let uiObject = wallet.walletAccounts[i].ethBalance.payload.uiObject + + if (walletAccount.error !== undefined) { + uiObject.setErrorMessage(walletAccount.error) + } else { + let value = walletAccount.ethBalance.value / 1000000000000000000 + uiObject.valueAtAngle = false + uiObject.setValue(value + ' ETH') + } + } + + for (let j = 0; j < walletAccount.tokenBalances.length; j++) { + let tokenBalance = walletAccount.tokenBalances[j] + let uiObject = wallet.walletAccounts[i].tokenBalances[j].payload.uiObject + let value = tokenBalance.value / 1000000000000000000 + uiObject.valueAtAngle = false + uiObject.setValue(value + ' ' + tokenBalance.referenceParent.config.codeName) + } + } + } + } + } catch (err) { + console.log('[ERROR] checkBalances -> err = ' + err.stack) + } + } + } + + function getContainer(point) { + + if (thisObject.container.frame.isThisPointHere(point, true) === true) { + thisObject.container.space = MODULE_NAME + return thisObject.container + } else { + return undefined + } + } + + function draw() { + + } +} diff --git a/Projects/Governance/UI/Utilities/RouteToClient.js b/Projects/Governance/UI/Utilities/RouteToClient.js new file mode 100644 index 000000000..a371b08b9 --- /dev/null +++ b/Projects/Governance/UI/Utilities/RouteToClient.js @@ -0,0 +1,53 @@ +function newEthereumUtilitiesRouteToClient() { + let thisObject = { + buildRouteToClient: buildRouteToClient + } + + return thisObject + + function buildRouteToClient(networkClient) { + let config = JSON.parse(networkClient.config) + if (config.host === undefined) { + networkClient.payload.uiObject.setErrorMessage('Property host not defined at node config.') + return + } + if (config.httpPort === undefined && config.webSocketsPort === undefined) { + networkClient.payload.uiObject.setErrorMessage('Property httpPort or webSocketsPort must be defined at node config.') + return + } + + /* Web Sockets would be the default protocol */ + let clientPort + let clientInterface + if (config.webSocketsPort !== undefined) { + clientInterface = 'ws' + clientPort = config.webSocketsPort + } else { + clientInterface = 'http' + clientPort = config.httpPort + } + + let params = { + host: config.host, + port: clientPort, + interface: clientInterface + } + + /* + Next, we will check which Superalgos Network Node we need as a gateway + to the Ethereum Client. We will use the current node reference parent for that. + */ + if (networkClient.payload.referenceParent === undefined) { + networkClient.payload.uiObject.setErrorMessage('You need to reference a Superalgos Network Node so that it acts as a gateway to the Ethereum Client.') + return + } + + let networkNodeConfig = JSON.parse(networkClient.payload.referenceParent.config) + let url = 'http://' + networkNodeConfig.host + ':' + networkNodeConfig.webPort + '/' + 'WEB3' + + return { + params: params, + url: url + } + } +} \ No newline at end of file diff --git a/Projects/ProjectsSchema.json b/Projects/ProjectsSchema.json index e746b67c4..4c09979b7 100644 --- a/Projects/ProjectsSchema.json +++ b/Projects/ProjectsSchema.json @@ -982,5 +982,62 @@ } ] } + }, + { + "name": "Governance", + "propertyName": "governance", + "UI": { + "globals": [ + { + "name": "ChainIds", + "propertyName": "chainIds", + "functionName": "newEthereumGlobalsChainIds" + } + ], + "functionLibraries": [ + { + "name": "Accounts", + "propertyName": "accounts", + "functionName": "newEthereumFunctionLibraryAccounts" + } + ], + "utilities": [ + { + "name": "Route To Client", + "propertyName": "routeToClient", + "functionName": "newEthereumUtilitiesRouteToClient" + } + ], + "spaces": [ + { + "name": "Blockchain Space", + "folderName": "Blockchain-Space", + "propertyName": "blockchainSpace", + "functionName": "newEthereumBlockchainSpace", + "initializationIndex": 0, + "animationPhysicsIndex": 0, + "animationDrawIndex": 0, + "onMouseWheelIndex": 0, + "onMouseOverIndex": 0, + "onMouseClickIndex": 0, + "onMouseDownIndex": 0 + }, + { + "name": "Wallet Space", + "folderName": "Wallet-Space", + "propertyName": "walletSpace", + "functionName": "newEthereumWalletSpace", + "initializationIndex": 1, + "animationPhysicsIndex": 1, + "animationDrawIndex": 1, + "onMouseWheelIndex": 1, + "onMouseOverIndex": 1, + "onMouseClickIndex": 1, + "onMouseDownIndex": 1 + } + ] + }, + "TS": {}, + "CL": {} } ] diff --git a/Projects/Superalgos/Schemas/App-Schema/other-hierarchies.json b/Projects/Superalgos/Schemas/App-Schema/other-hierarchies.json index 72ae1a9d1..96a182740 100644 --- a/Projects/Superalgos/Schemas/App-Schema/other-hierarchies.json +++ b/Projects/Superalgos/Schemas/App-Schema/other-hierarchies.json @@ -31,24 +31,6 @@ "relatedUiObject": "API Map", "actionFunction": "payload.executeAction" }, - { - "action": "Add UI Object", - "label": "Add Assets Structure", - "relatedUiObject": "Assets Structure", - "actionFunction": "payload.executeAction" - }, - { - "action": "Add UI Object", - "label": "Add Governance Structure", - "relatedUiObject": "Governance Structure", - "actionFunction": "payload.executeAction" - }, - { - "action": "Add UI Object", - "label": "Add User Contributions", - "relatedUiObject": "User Contributions", - "actionFunction": "payload.executeAction" - }, { "action": "Delete UI Object", "askConfirmation": true,