Token Balances

This commit is contained in:
Luis Fernando Molina committed 2020-11-19 18:19:24 +01:00
1 parent 6784e6bd0b
commit 5ac6f32bb7
3 files changed
+86 -71

No files matched your search

+47 -1
View File
@@ -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
}
}
}
}
@@ -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": [
@@ -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)
}
}
}