diff --git a/Client/web3Server.js b/Client/web3Server.js index c70d89349..0e838d04c 100644 --- a/Client/web3Server.js +++ b/Client/web3Server.js @@ -115,7 +115,53 @@ exports.newWeb3Server = function newWeb3Server() { for (let j = 0; j < walletAccount.tokenBalances.length; j++) { let tokenBalance = walletAccount.tokenBalances[j] - tokenBalance.value = 0 + + if (tokenBalance.referenceParent === undefined) { continue } + if (tokenBalance.referenceParent.parentNode === undefined) { continue } + if (tokenBalance.referenceParent.smartContracts === undefined) { continue } + + if (tokenBalance.referenceParent.config.codeName === undefined) { + tokenBalance.error = 'Reference Parent without config.codeName defined.' + continue + } + + if (tokenBalance.referenceParent.smartContracts.config.address === undefined) { + tokenBalance.error = 'Reference Parent Smart Contract without config.address defined.' + continue + } + + let tokenContractAddress = tokenBalance.referenceParent.smartContracts.config.address + // The minimum ABI to get ERC20 Token balance + let minABI = [ + // balanceOf + { + "constant": true, + "inputs": [{ "name": "_owner", "type": "address" }], + "name": "balanceOf", + "outputs": [{ "name": "balance", "type": "uint256" }], + "type": "function" + }, + // decimals + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [{ "name": "", "type": "uint8" }], + "type": "function" + } + ]; + + let contract = new web3.eth.Contract(minABI, tokenContractAddress); + + try { + tokenBalance.value = await contract.methods.balanceOf(walletAccount.config.address).call() + } catch (err) { + if (err.message.indexOf('Provided address') >= 0) { + walletAccount.error = 'Invalid configured address.' + } else { + walletAccount.error = err.message + } + } } } diff --git a/Integrations/Projects/Ethereum/Schemas/AppSchema.json b/Integrations/Projects/Ethereum/Schemas/AppSchema.json index 653fd490f..1de8383bf 100644 --- a/Integrations/Projects/Ethereum/Schemas/AppSchema.json +++ b/Integrations/Projects/Ethereum/Schemas/AppSchema.json @@ -278,9 +278,7 @@ "menuItems": [ { "action": "Add UI Object", - "label": "Add Token Definition", - "disableIfPropertyIsDefined": true, - "propertyToCheckFor": "ethereumToken", + "label": "Add Ethereum Token", "relatedUiObject": "Ethereum Token", "actionFunction": "payload.executeAction" }, @@ -302,8 +300,8 @@ "propertyNameAtParent": "erc-20TokenType", "properties": [ { - "name": "ethereumToken", - "type": "node", + "name": "ethereumTokens", + "type": "array", "childType": "Ethereum Token" } ], @@ -314,9 +312,7 @@ "menuItems": [ { "action": "Add UI Object", - "label": "Add Token Definition", - "disableIfPropertyIsDefined": true, - "propertyToCheckFor": "ethereumToken", + "label": "Add Ethereum Token", "relatedUiObject": "Ethereum Token", "actionFunction": "payload.executeAction" }, @@ -338,8 +334,8 @@ "propertyNameAtParent": "erc-223TokenType", "properties": [ { - "name": "ethereumToken", - "type": "node", + "name": "ethereumTokens", + "type": "array", "childType": "Ethereum Token" } ], @@ -350,9 +346,7 @@ "menuItems": [ { "action": "Add UI Object", - "label": "Add Token Definition", - "disableIfPropertyIsDefined": true, - "propertyToCheckFor": "ethereumToken", + "label": "Add Ethereum Token", "relatedUiObject": "Ethereum Token", "actionFunction": "payload.executeAction" }, @@ -374,8 +368,8 @@ "propertyNameAtParent": "erc-721TokenType", "properties": [ { - "name": "ethereumToken", - "type": "node", + "name": "ethereumTokens", + "type": "array", "childType": "Ethereum Token" } ], @@ -386,9 +380,7 @@ "menuItems": [ { "action": "Add UI Object", - "label": "Add Token Definition", - "disableIfPropertyIsDefined": true, - "propertyToCheckFor": "ethereumToken", + "label": "Add Ethereum Token", "relatedUiObject": "Ethereum Token", "actionFunction": "payload.executeAction" }, @@ -410,8 +402,8 @@ "propertyNameAtParent": "erc-777TokenType", "properties": [ { - "name": "ethereumToken", - "type": "node", + "name": "ethereumTokens", + "type": "array", "childType": "Ethereum Token" } ], @@ -457,7 +449,7 @@ "chainAttachesTo": { "compatibleTypes": "->ERC-20 Token Type->ERC-223 Token Type->ERC-721 Token Type->ERC-777 Token Type->" }, - "propertyNameAtParent": "ethereumToken", + "propertyNameAtParent": "ethereumTokens", "properties": [ { "name": "smartContracts", @@ -465,7 +457,17 @@ "childType": "Smart Contract" } ], - "icon": "ethereum" + "icon": "ethereum", + "alternativeIcons": [ + { + "codeName": "USDT", + "iconName": "tether" + }, + { + "codeName": "BNB", + "iconName": "binance-coin" + } + ] }, { "type": "Ethereum Blockchain", @@ -605,12 +607,12 @@ "type": "Smart Contract", "menuItems": [ { - "action": "Add UI Object", - "disableIfPropertyIsDefined": true, - "propertyToCheckFor": "smartContractAccount", - "label": "Add Smart Contract Account", - "relatedUiObject": "Smart Contract Account", - "actionFunction": "payload.executeAction" + "action": "Configure", + "label": "Configure", + "iconPathOn": "configuration", + "iconPathOff": "configuration", + "dontShowAtFullscreen": true, + "actionFunction": "uiObject.configEditor.activate" }, { "action": "Add UI Object", @@ -630,6 +632,12 @@ "actionFunction": "payload.executeAction" } ], + "editors": { + "config": true + }, + "initialValues": { + "config": "{ \n\"address\": \"\"\n}" + }, "chainAttachesTo": { "compatibleTypes": "->Token Definition->Ethereum Decentralized Application->" }, @@ -637,11 +645,6 @@ "addLeftIcons": true, "level": 1, "properties": [ - { - "name": "smartContractAccount", - "type": "node", - "childType": "Smart Contract Account" - }, { "name": "solidityCode", "type": "node", @@ -650,41 +653,6 @@ ], "icon": "ethereum" }, - { - "type": "Smart Contract Account", - "menuItems": [ - { - "action": "Configure", - "label": "Configure", - "iconPathOn": "configuration", - "iconPathOff": "configuration", - "dontShowAtFullscreen": true, - "actionFunction": "uiObject.configEditor.activate" - }, - { - "action": "Delete UI Object", - "askConfirmation": true, - "confirmationLabel": "Confirm to Delete", - "label": "Delete", - "iconPathOn": "delete", - "iconPathOff": "delete", - "actionFunction": "payload.executeAction" - } - ], - "editors": { - "config": true - }, - "initialValues": { - "config": "{ \n\"value\": \"\"\n}" - }, - "addLeftIcons": true, - "level": 3, - "chainAttachesTo": { - "compatibleTypes": "->Smart Contract->" - }, - "propertyNameAtParent": "smartContractAccount", - "icon": "ethereum" - }, { "type": "Solidity Code", "menuItems": [ diff --git a/Integrations/Projects/Ethereum/Spaces/Wallet-Space/Wallet.js b/Integrations/Projects/Ethereum/Spaces/Wallet-Space/Wallet.js index d31fb207f..66bdb9de4 100644 --- a/Integrations/Projects/Ethereum/Spaces/Wallet-Space/Wallet.js +++ b/Integrations/Projects/Ethereum/Spaces/Wallet-Space/Wallet.js @@ -89,7 +89,7 @@ function newEthereumWalletSpace() { 'Wallet Account->' + 'ETH Balance->' + 'Token Balance->' + - 'Ethereum Token->' + + '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) @@ -134,8 +134,9 @@ function newEthereumWalletSpace() { 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(tokenBalance.value + ' ' + uiObject.payload.node.name) + uiObject.setValue(value + ' ' + tokenBalance.referenceParent.config.codeName) } } }