From 17234edc6270945ee6f6f3a7c6ddf0a5e5659718 Mon Sep 17 00:00:00 2001 From: Aziz FADIL Date: Sat, 7 Sep 2024 16:38:10 -0400 Subject: [PATCH 1/4] Fix Activity form validation --- src/lib/schemas.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/schemas.ts b/src/lib/schemas.ts index ba604f9..660dafa 100644 --- a/src/lib/schemas.ts +++ b/src/lib/schemas.ts @@ -34,9 +34,9 @@ export const newGoalSchema = z.object({ export const newActivitySchema = z.object({ id: z.string().uuid().optional(), - accountId: z.string(), + accountId: z.string().min(1, { message: 'Account ID is required' }), activityDate: z.date(), - currency: z.string(), + currency: z.string().min(1, { message: 'Currency is required' }), fee: z.coerce .number({ required_error: 'Please enter a valid fee.', @@ -51,7 +51,7 @@ export const newActivitySchema = z.object({ invalid_type_error: 'Quantity must be a positive number.', }) .min(0, { message: 'Quantity must be a positive number.' }), - assetId: z.string(), + assetId: z.string().min(1, { message: 'Asset ID is required' }), activityType: z.enum([ 'BUY', 'SELL', From 5135049c97226e0dea5f2dd3bba717f2325468a3 Mon Sep 17 00:00:00 2001 From: Aziz FADIL Date: Sat, 7 Sep 2024 17:00:30 -0400 Subject: [PATCH 2/4] small bug fixes --- src-tauri/src/models.rs | 18 ---------- src-tauri/src/portfolio/portfolio_service.rs | 4 +-- src/pages/activity/activity-page.tsx | 16 +++++---- src/pages/activity/import/import-form.tsx | 35 ++++++++++++-------- 4 files changed, 33 insertions(+), 40 deletions(-) diff --git a/src-tauri/src/models.rs b/src-tauri/src/models.rs index 00676c9..cb2c51b 100644 --- a/src-tauri/src/models.rs +++ b/src-tauri/src/models.rs @@ -327,24 +327,6 @@ pub struct Holding { pub sectors: Option>, } -#[derive(QueryableByName, Debug)] -pub struct AggregatedHolding { - #[diesel(sql_type = Text)] - pub account_id: String, - #[diesel(sql_type = Text)] - pub account_name: String, - #[diesel(sql_type = Text)] - pub asset_id: String, - #[diesel(sql_type = Text)] - pub asset_name: String, // Assuming this is the field name for asset_symbol - #[diesel(sql_type = Nullable)] - pub quantity: Option, - #[diesel(sql_type = Double)] - pub book_value: f64, - #[diesel(sql_type = Nullable)] - pub average_cost: Option, -} - // FinancialSnapshot and FinancialHistory structs with serde for serialization/deserialization #[derive(Serialize, Deserialize, Debug)] #[serde(rename_all = "camelCase")] diff --git a/src-tauri/src/portfolio/portfolio_service.rs b/src-tauri/src/portfolio/portfolio_service.rs index 0af0581..8a7a2a2 100644 --- a/src-tauri/src/portfolio/portfolio_service.rs +++ b/src-tauri/src/portfolio/portfolio_service.rs @@ -416,8 +416,8 @@ impl PortfolioService { cumulative_cash += activity_amount * activity.unit_price - activity_fee; } "WITHDRAWAL" | "TRANSFER_OUT" | "CONVERSION_OUT" => { - cumulative_cash -= activity_amount + activity_fee; - net_deposit -= activity_amount; + cumulative_cash -= activity_amount * activity.unit_price + activity_fee; + net_deposit -= activity_amount * activity.unit_price; } "FEE" | "TAX" => { cumulative_cash -= activity_fee; diff --git a/src/pages/activity/activity-page.tsx b/src/pages/activity/activity-page.tsx index 8b324ab..310c177 100644 --- a/src/pages/activity/activity-page.tsx +++ b/src/pages/activity/activity-page.tsx @@ -9,7 +9,6 @@ import ActivityTable from './components/activity-table'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { Account, ActivityDetails } from '@/lib/types'; import { getAccounts } from '@/commands/account'; -// import { getActivities } from '@/commands/activity'; import { ActivityDeleteModal } from './components/activity-delete-modal'; import { deleteActivity } from '@/commands/activity'; import { toast } from '@/components/ui/use-toast'; @@ -65,15 +64,15 @@ const ActivityPage = () => {
- -
@@ -97,7 +96,10 @@ const ActivityPage = () => { } activity={selectedActivity} open={showEditModal} - onClose={() => setShowEditModal(false)} + onClose={() => { + setShowEditModal(false); + setSelectedActivity(null); + }} /> )} /> - +
+ + +
); From 72767806f500bf6d0030c0e64814c9f577c856c8 Mon Sep 17 00:00:00 2001 From: Aziz FADIL Date: Sat, 7 Sep 2024 17:19:09 -0400 Subject: [PATCH 3/4] small fiexes and improvements --- src-tauri/src/asset/asset_service.rs | 10 +++++---- src-tauri/src/models.rs | 1 - src/pages/onboarding/onboarding-page.tsx | 27 ++++++++++++------------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src-tauri/src/asset/asset_service.rs b/src-tauri/src/asset/asset_service.rs index d1190f3..052be71 100644 --- a/src-tauri/src/asset/asset_service.rs +++ b/src-tauri/src/asset/asset_service.rs @@ -328,13 +328,15 @@ impl AssetService { for yahoo_quote in quotes_history { let timestamp = yahoo_quote.timestamp as i64; + let naive_datetime = chrono::DateTime::from_timestamp(timestamp, 0) + .ok_or_else(|| format!("Invalid timestamp: {}", timestamp))? + .naive_utc(); + let new_quote = Quote { id: uuid::Uuid::new_v4().to_string(), - created_at: chrono::NaiveDateTime::from_timestamp_opt(timestamp, 0) - .ok_or_else(|| format!("Invalid timestamp: {}", timestamp))?, + created_at: naive_datetime, data_source: "YAHOO".to_string(), - date: chrono::NaiveDateTime::from_timestamp_opt(timestamp, 0) - .ok_or_else(|| format!("Invalid date timestamp: {}", timestamp))?, + date: naive_datetime, symbol: symbol.to_string(), open: yahoo_quote.open, high: yahoo_quote.high, diff --git a/src-tauri/src/models.rs b/src-tauri/src/models.rs index cb2c51b..b314326 100644 --- a/src-tauri/src/models.rs +++ b/src-tauri/src/models.rs @@ -1,6 +1,5 @@ use chrono::NaiveDateTime; use diesel::prelude::*; -use diesel::sql_types::{Double, Nullable, Text}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; #[derive(Queryable, Identifiable, AsChangeset, Serialize, Deserialize, Debug)] diff --git a/src/pages/onboarding/onboarding-page.tsx b/src/pages/onboarding/onboarding-page.tsx index e764454..040a67b 100644 --- a/src/pages/onboarding/onboarding-page.tsx +++ b/src/pages/onboarding/onboarding-page.tsx @@ -10,11 +10,11 @@ export const OnboardingPage = () => { const renderStepIcon = (stepNumber: number) => { return currentStep >= stepNumber ? ( -
+
) : ( -
+
{stepNumber}
); @@ -22,7 +22,7 @@ export const OnboardingPage = () => { return (
-
+
Illustration { />
-

+

Welcome to Wealthfolio

@@ -45,22 +45,21 @@ export const OnboardingPage = () => { started:

- + {renderStepIcon(1)}

Set your main currency

+ - -
- 2 -
+ + {renderStepIcon(2)}

Add your accounts

+ -
-
- 3 -
+ + {renderStepIcon(3)}

Add or import activities

-
+ +