Skip to content

Commit

Permalink
Refactor and making sure that the component is properly initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
manelgavalda committed Jan 14, 2024
1 parent dbfe527 commit 13f79b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
10 changes: 5 additions & 5 deletions resources/js/Pages/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -251,25 +251,25 @@
getWeeklyApy(index) {
const balance = this.tokens[0][index].balance
return (((balance - (this.tokens[6][index] || 0).balance) / balance) * 100 || 0).toFixed(2)
return (((balance - (this.tokens[6][index] || {}).balance) / balance) * 100 || 0).toFixed(2)
},
getWeeklyGain(index) {
const token = this.tokens[0][index]
return ((token.balance - (this.tokens[6][index] || 0).balance) * token.price).toFixed(2)
return ((token.balance - (this.tokens[6][index] || {}).balance) * token.price).toFixed(2)
},
getMonthlyApy(index) {
const balance = this.tokens[0][index].balance
return (((balance - (this.tokens.at(-1)[index] || 0).balance) / balance) * 100 || 0).toFixed(2)
return (((balance - (this.tokens.at(-1)[index] || {}).balance) / balance) * 100 || 0).toFixed(2)
},
getMonthlyGain(index) {
const token = this.tokens[0][index]
return ((token.balance - (this.tokens.at(-1)[index] || 0).balance) * token.price).toFixed(2)
return ((token.balance - (this.tokens.at(-1)[index] || {}).balance) * token.price).toFixed(2)
},
getBalanceHistory(pool) {
return this.tokens.map(token => token[pool] ? token[pool].balance : 0).reverse()
return this.tokens.map(token => (token[pool] || {}).balance).reverse()
},
getPriceHistory(pool) {
return this.tokens.map(token => token[pool] ? (token[pool].balance * token[pool].price) : 0).reverse()
Expand Down
15 changes: 14 additions & 1 deletion resources/js/tests/dashboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ const data = {
}
}

it('is_created', async () => {
expect(dashboard.vm.totals).toEqual({
usd: 1,
btc: 1,
eth: 1,
eur: 1,
pricesUsd: 1,
pricesEur: 1,
btcPricesUsd: 1,
btcPricesEur: 1
})
})

it("returns_daily_change", async () => {
expect(dashboard.vm.getDailyChange('Token 1')).toEqual("11.11")
});
Expand All @@ -110,7 +123,7 @@ it("returns_monthly_gain", async () => {
});

it("returns_balance_history", async () => {
expect(dashboard.vm.getBalanceHistory('Token 1')).toEqual([7, 0, 0, 7, 5, 9, 10])
expect(dashboard.vm.getBalanceHistory('Token 1')).toEqual([7, undefined, undefined, 7, 5, 9, 10])
});

it("returns_price_history", async () => {
Expand Down

0 comments on commit 13f79b6

Please sign in to comment.