I am trying to figure out how to solve this issue where the app is crashing when trying to read the 'total' property. The problem is that the issue is not happening when I am viewing in development. But when I deploy to Heroku, it happens. Any idea what it could be?
const determineDefaultQuote = () => {
const exchangeInternalAccount = holdingsByAccount.find(account => account.exchange === 'EXCHANGE');
const usdcBalance = exchangeInternalAccount && exchangeInternalAccount.assets.find(item => item.name === 'USD').freeTotal;
const usdtBalance = exchangeInternalAccount && exchangeInternalAccount.assets.find(item => item.name === 'SHIB').freeTotal;
if (usdBalance > shibBalance) return 'USD';
return 'SHIB';
};
The error I am seeing is:
main.d3a0d78b.js:1 uncaught at q TypeError: Cannot read properties of undefined (reading 'freeTotal')
Related
Hey just having issues with fetching reaction count i have this
const getStats = (message) => {
return Promise.all([
message.reactions.resolve(SUGGESTIONS.EMOJI.UP_VOTE).fetch(),
message.reactions.resolve(SUGGESTIONS.EMOJI.DOWN_VOTE).fetch()
]).then(([fetchedReaction, fetchedReaction2]) => {
const upVotes = fetchedReaction.count - 1;
const downVotes = fetchedReaction2.count - 1;
return [upVotes, downVotes];
});
}
but im getting TypeError: Cannot read properties of null (reading 'fetch')
i have tryed using count instead fetch but still getting count as null
I'm trying to figure out why I'm getting this Type Error: TypeError: Cannot read properties of null (reading 'toString')
The error is coming from this method:
private search = (rows: Array<any>) => {
const columns = rows[0] && Object.keys(rows[0])
return rows.filter((row) =>
columns.some((column : any) => row[column].toString().toLowerCase().indexOf(this.state.queryText.toLowerCase()) > -1)
)
}
I'm just not sure whats causing it or even how to fix it.
This error occurs because an element of the row variable (line 4) is null, so null.toString() is not defined. You could fix this issue with another value check:
columns.some((column : any) => row[column] && row[column].toString().toLowerCase().indexOf(this.state.queryText.toLowerCase()) > -1)
I am working on a quiz app for class and I keep getting the error "Uncaught SyntaxError: Unexpected token o in JSON at position 1" in the console. I have tried looking up YouTube videos for solutions and have even tried fixing the code through similar posts on this site. I am at a loss and can't figure out what is wrong.
const username = document.querySelector('#username');
const saveScoreBtn = document.querySelector('#saveScoreBtn');
const finalScore = document.querySelector('#finalScore');
const mostRecentScore = localStorage.getItem('mostRecentScore');
const highScores = JSON.parse(localStorage.getItem('highScores')) || [];
const MAX_HIGH_SCORES = 5;
finalScore.innerText = mostRecentScore;
username.addEventListener('keyup', () => {
saveScoreBtn.disabled = !username.value;
});
saveHighScore = e => {
e.preventDefault();
const score = {
score: mostRecentScore,
name: username.value
};
highScores.push(score);
highScores.sort((a,b) =>{
return b.score - a.score;
})
highScores.splice(5);
localStorage.setItem('highscores', JSON.stringify(highScores));
window.location.assign('../high-scores/highscores.html')
};
"Uncaught SyntaxError: Unexpected token o in JSON at position 1"
That means this is not json formated code. Check your json again.
I'm setting up a searchbar in a web app, and I've got most of it done(i.e. it's successfully finding the objects that I'm looking for), however, a dispatch at the end of the searchbar code. This is being built using Javascript, React and Redux. I'm entirely new to react, and my teams React guy is off for the week, so any help would be a massive help.
searchInList = (e) => {
const { dispatch, employees } = this.props;
const valueSearched = e.target.value;
let currentList = [];
let newList = [];
if (valueSearched !== ' ') {
currentList = employees;
currentList.map(employeeObject => {
Object.values(employeeObject).filter(item => {
let itemString;
if (typeof (item) != 'string') {
itemString = JSON.stringify(item);
} else {
itemString = item;
}
let lc = itemString.toLowerCase();
const filter = valueSearched.toLowerCase();
if (lc.includes(filter)) {
if (!newList.includes(employeeObject)) {
newList.push(employeeObject);
}
}
});
});
} else {
newList = employees;
}
console.log(newList);
dispatch(onChangeEmployee('employees', newList));
};
This should just narrow down the amount of objects being displayed (within the search terms), but it crashes and throws up this error: "TypeError: Cannot set property 'employees' of undefined".
It crashes on the dispatch(onChangeEmployee('employees', newList)); line
From
Cannot set property 'employees' of undefined
I can see you do something like
var a
a.employees='hello'
However, you never refer employees property of an object in the snippet presented
So the chance is high that the error is from onChangeEmployee
I'm trying to count the number of misbehavior on the two routes I've made in my database. Below are the structure of my firebase database under drivers and reports database respectively:
[drivers database] - i.stack.imgur.com/Q6GKs.png
[reports database] - i.stack.imgur.com/ALWPu.png
Here's my counter for counting the number of misbehavior:
<script>
var route1Count = 0;
var route2Count = 0;
var drivers;
var reports;
var driversRef = firebase.database().ref('drivers/');
var reportsRef = firebase.database().ref('reports/');
driversRef.once('value', (snapshot) => {
drivers = snapshot;
});
reportsRef.once('value', (snapshot) => {
reports = snapshot;
});
drivers.forEach((driver) => {
var violationCount = reports.filter((report) => report.val().plateNumber === driver.key).length;
if(driver.val().route === "Fairview - Quiapo"){
route1Count += violationCount;
}else if(driver.val().route === "Quiapo - Fairview"){
route2Count += violationCount;
}
});
document.getElementById("demo").innerHTML = "route1: " + route1Count + "route2: " + route2Count;
</script>
I get this error message:
Uncaught TypeError: Cannot read property 'forEach' of undefined
at drivers.forEach, all inputs will be greatly appreciated! Thanks!
Error Message :
you could nest them, or if you run this in an environment that supports es6's Promise object (which your code suggests), you could use the once() returning a promise and more elegantly do:
Promise.all([driversRef.once('value'), reportsRef.once('value')])
.then(([driversSnapshot, reportsSnapshot]) => {
// ...
})