Skip to content

Commit a381a0f

Browse files
committed
fixed bug with validating gas price and multiple promises resolving on /api/token get request
1 parent 24a3dfb commit a381a0f

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ GANACHE_MIGRATE_ADDRESS=0xcf068555df7eab0a9bad97829aa1a187bbffbdba
5353
ROPSTEN_MIGRATE_ADDRESS=0xa8ebf36b0a34acf98395bc5163103efc37621052
5454
```
5555

56-
Currently, the best way to change the network you want to have the API connect web3 to, is to change the `NODE_URL`. So you can have multiple values but only have one uncommented. Below the second will be used.
56+
Currently, the best way to change the network you want to have the API connect web3 to, is to change the `NODE_URL`. So you can have multiple values but only have one uncommented. The example below will make the second url enabled.
5757

5858
```
5959
#NODE_URL=http://127.0.0.1:7545
60-
NODE_URL=http://10.10.0.163:8545
60+
NODE_URL=http://127.0.0.1:8545
6161
```
6262

6363
**Remember to restart your server after changing environment variables. If running nodemon run `npm run nodemon` again**

server/app/helpers/ethereum.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ async function processTxInfoData(txObject) {
149149
// get gas prices
150150
const getCurrentGasPrices = async () => {
151151
let response = await axios.get(gasAPI)
152-
// let response = await axios.get('https://ethgasstation.info/json/ethgasAPI.json')
153152
let prices = {
154153
low: response.data.safeLow / 10,
155154
medium: response.data.average / 10,
@@ -163,12 +162,17 @@ async function processTxInfoData(txObject) {
163162
let gasPriceTypeCustom = txObject.gasPrice != null ? txObject.gasPrice.toLowerCase() : null;
164163
// validate gasPrice
165164
let gasPrice;
166-
if (gasPrices[gasPriceTypeCustom] === undefined){
165+
if(gasPriceTypeCustom == null) {
167166
gasPrice = gasPriceDefault
168-
reject(new Error('gasPrice is invalid'))
169167
} else {
170-
gasPrice = gasPrices[gasPriceTypeCustom] * 1000000000;
168+
if (gasPrices[gasPriceTypeCustom] === undefined){
169+
gasPrice = gasPriceDefault
170+
reject(new Error('gasPrice is invalid'))
171+
} else {
172+
gasPrice = gasPrices[gasPriceTypeCustom] * 1000000000;
173+
}
171174
}
175+
console.log('gasPrice',gasPrice)
172176
// let gasPrice = gasPriceTypeCustom != null ? gasPrices[gasPriceTypeCustom] * 1000000000 : gasPriceDefault;
173177

174178
// set tx object to calculate transaction gas

server/app/helpers/token.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,23 @@ Token = {
9595
tokenInstance.name(),
9696
tokenInstance.symbol(),
9797
tokenInstance.decimals(),
98-
tokenInstance.totalSupply()
98+
tokenInstance.totalSupply(),
99+
tokenInstance.balanceOf(value.owner)
99100
]
100-
Promise.all(infoArray).then((values) => {
101+
return Promise.all(infoArray).then((values) => {
101102
obj.tokenName = values[0];
102103
obj.tokenSymbol = values[1];
103104
obj.tokenDecimals = values[2];
104-
obj.tokenInitialSupply = values[3];
105+
obj.totalSupply = values[3];
106+
obj.tokenBalance = values[4];
107+
return obj;
105108
})
106109
//initial variable but changed by addTokenToTotalSupply()
107110
// tokenInstance.INITIAL_SUPPLY().then((value) => {
108111
// obj.tokenInitialSupply = value;
109112
// });
110-
return tokenInstance.balanceOf(value.owner);
111113
}).then(function (result) {
112-
// obj.tokenBalance = result.toFixed(obj.tokenDecimals);
113-
obj.tokenBalance = result;
114-
return obj;
114+
return result;
115115
}).catch(function (err) {
116116
console.log(err.message);
117117
return obj.error = err.message;

0 commit comments

Comments
 (0)