diff --git a/resources/js/Pages/Dashboard.vue b/resources/js/Pages/Dashboard.vue index 48464ff..cd0ba2d 100644 --- a/resources/js/Pages/Dashboard.vue +++ b/resources/js/Pages/Dashboard.vue @@ -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() diff --git a/resources/js/tests/dashboard.test.js b/resources/js/tests/dashboard.test.js index 4f73138..c73e123 100644 --- a/resources/js/tests/dashboard.test.js +++ b/resources/js/tests/dashboard.test.js @@ -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") }); @@ -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 () => {