From 63f95de4f0ddc7e464201b7a9f2fa8d5b6b3350c Mon Sep 17 00:00:00 2001 From: Prasanna Anbazhagan Date: Sat, 30 Mar 2024 09:16:02 +0530 Subject: [PATCH] Rename SipFrequency to Frequency --- lib/api/apis/sip_api.dart | 6 ++--- lib/api/db/app_database.dart | 4 +-- lib/api/db/app_database.g.dart | 26 +++++++++---------- .../{sip_frequency.dart => frequency.dart} | 20 +++++++------- lib/domain/models/irr_calculator.dart | 3 ++- lib/domain/models/sip.dart | 4 +-- lib/domain/services/sip_service.dart | 6 ++--- lib/presentation/create_sip_presenter.dart | 8 +++--- lib/presentation/sips_presenter.dart | 4 +-- lib/ui/widgets/create_sip_dialog.dart | 18 ++++++------- 10 files changed, 50 insertions(+), 49 deletions(-) rename lib/contract/{sip_frequency.dart => frequency.dart} (58%) diff --git a/lib/api/apis/sip_api.dart b/lib/api/apis/sip_api.dart index deb5ac6..bc0550a 100644 --- a/lib/api/apis/sip_api.dart +++ b/lib/api/apis/sip_api.dart @@ -1,6 +1,6 @@ import 'package:drift/drift.dart'; import 'package:wealth_wave/api/db/app_database.dart'; -import 'package:wealth_wave/contract/sip_frequency.dart'; +import 'package:wealth_wave/contract/frequency.dart'; class SipApi { final AppDatabase _db; @@ -13,7 +13,7 @@ class SipApi { required final double amount, required final DateTime startDate, required final DateTime? endDate, - required final SipFrequency frequency}) async { + required final Frequency frequency}) async { return _db.into(_db.sipTable).insert(SipTableCompanion.insert( investmentId: investmentId, description: Value(description), @@ -53,7 +53,7 @@ class SipApi { required final double amount, required final DateTime startDate, required final DateTime? endDate, - required final SipFrequency frequency}) async { + required final Frequency frequency}) async { return (_db.update(_db.sipTable)..where((t) => t.id.equals(id))).write( SipTableCompanion( investmentId: Value(investmentId), diff --git a/lib/api/db/app_database.dart b/lib/api/db/app_database.dart index 206146a..34ee6e3 100644 --- a/lib/api/db/app_database.dart +++ b/lib/api/db/app_database.dart @@ -3,7 +3,7 @@ import 'package:drift/wasm.dart'; import 'package:flutter/foundation.dart'; import 'package:wealth_wave/contract/goal_importance.dart'; import 'package:wealth_wave/contract/risk_level.dart'; -import 'package:wealth_wave/contract/sip_frequency.dart'; +import 'package:wealth_wave/contract/frequency.dart'; part 'app_database.g.dart'; @@ -79,7 +79,7 @@ class SipTable extends Table { .check(endDate.isNull() | endDate.isBiggerThan(startDate)) .named('END_DATE')(); - TextColumn get frequency => textEnum().named('FREQUENCY')(); + TextColumn get frequency => textEnum().named('FREQUENCY')(); DateTimeColumn get executedTill => dateTime().nullable().named('EXECUTED_TILL')(); diff --git a/lib/api/db/app_database.g.dart b/lib/api/db/app_database.g.dart index 47341cd..9d7bd4d 100644 --- a/lib/api/db/app_database.g.dart +++ b/lib/api/db/app_database.g.dart @@ -739,10 +739,10 @@ class $SipTableTable extends SipTable static const VerificationMeta _frequencyMeta = const VerificationMeta('frequency'); @override - late final GeneratedColumnWithTypeConverter frequency = + late final GeneratedColumnWithTypeConverter frequency = GeneratedColumn('FREQUENCY', aliasedName, false, type: DriftSqlType.string, requiredDuringInsert: true) - .withConverter($SipTableTable.$converterfrequency); + .withConverter($SipTableTable.$converterfrequency); static const VerificationMeta _executedTillMeta = const VerificationMeta('executedTill'); @override @@ -844,8 +844,8 @@ class $SipTableTable extends SipTable return $SipTableTable(attachedDatabase, alias); } - static JsonTypeConverter2 $converterfrequency = - const EnumNameConverter(SipFrequency.values); + static JsonTypeConverter2 $converterfrequency = + const EnumNameConverter(Frequency.values); } class BaseSipDO extends DataClass implements Insertable { @@ -855,7 +855,7 @@ class BaseSipDO extends DataClass implements Insertable { final double amount; final DateTime startDate; final DateTime? endDate; - final SipFrequency frequency; + final Frequency frequency; final DateTime? executedTill; const BaseSipDO( {required this.id, @@ -946,7 +946,7 @@ class BaseSipDO extends DataClass implements Insertable { double? amount, DateTime? startDate, Value endDate = const Value.absent(), - SipFrequency? frequency, + Frequency? frequency, Value executedTill = const Value.absent()}) => BaseSipDO( id: id ?? this.id, @@ -998,7 +998,7 @@ class SipTableCompanion extends UpdateCompanion { final Value amount; final Value startDate; final Value endDate; - final Value frequency; + final Value frequency; final Value executedTill; const SipTableCompanion({ this.id = const Value.absent(), @@ -1017,7 +1017,7 @@ class SipTableCompanion extends UpdateCompanion { required double amount, required DateTime startDate, this.endDate = const Value.absent(), - required SipFrequency frequency, + required Frequency frequency, this.executedTill = const Value.absent(), }) : investmentId = Value(investmentId), amount = Value(amount), @@ -1052,7 +1052,7 @@ class SipTableCompanion extends UpdateCompanion { Value? amount, Value? startDate, Value? endDate, - Value? frequency, + Value? frequency, Value? executedTill}) { return SipTableCompanion( id: id ?? this.id, @@ -3002,7 +3002,7 @@ class SipDO extends DataClass { final double amount; final DateTime startDate; final DateTime? endDate; - final SipFrequency frequency; + final Frequency frequency; final DateTime? executedTill; final String? investmentName; final int? transactionCount; @@ -3059,7 +3059,7 @@ class SipDO extends DataClass { double? amount, DateTime? startDate, Value endDate = const Value.absent(), - SipFrequency? frequency, + Frequency? frequency, Value executedTill = const Value.absent(), Value investmentName = const Value.absent(), Value transactionCount = const Value.absent()}) => @@ -3206,11 +3206,11 @@ class $SipEnrichedViewView extends ViewInfo<$SipEnrichedViewView, SipDO> 'END_DATE', aliasedName, true, generatedAs: GeneratedAs(sip.endDate, false), type: DriftSqlType.dateTime); - late final GeneratedColumnWithTypeConverter frequency = + late final GeneratedColumnWithTypeConverter frequency = GeneratedColumn('FREQUENCY', aliasedName, false, generatedAs: GeneratedAs(sip.frequency, false), type: DriftSqlType.string) - .withConverter($SipTableTable.$converterfrequency); + .withConverter($SipTableTable.$converterfrequency); late final GeneratedColumn executedTill = GeneratedColumn( 'EXECUTED_TILL', aliasedName, true, generatedAs: GeneratedAs(sip.executedTill, false), diff --git a/lib/contract/sip_frequency.dart b/lib/contract/frequency.dart similarity index 58% rename from lib/contract/sip_frequency.dart rename to lib/contract/frequency.dart index fbfc3b0..e7c3474 100644 --- a/lib/contract/sip_frequency.dart +++ b/lib/contract/frequency.dart @@ -1,28 +1,28 @@ -enum SipFrequency { +enum Frequency { daily, weekly, biweekly, monthly, quarterly, - halfyearly, + halfYearly, yearly, } -Duration getDuration(SipFrequency frequency) { +Duration getDuration(Frequency frequency) { switch (frequency) { - case SipFrequency.daily: + case Frequency.daily: return const Duration(days: 1); - case SipFrequency.weekly: + case Frequency.weekly: return const Duration(days: 7); - case SipFrequency.biweekly: + case Frequency.biweekly: return const Duration(days: 14); - case SipFrequency.monthly: + case Frequency.monthly: return const Duration(days: 30); - case SipFrequency.quarterly: + case Frequency.quarterly: return const Duration(days: 91); - case SipFrequency.halfyearly: + case Frequency.halfYearly: return const Duration(days: 182); - case SipFrequency.yearly: + case Frequency.yearly: return const Duration(days: 365); default: throw Exception('Invalid frequency'); diff --git a/lib/domain/models/irr_calculator.dart b/lib/domain/models/irr_calculator.dart index cad7137..83bc792 100644 --- a/lib/domain/models/irr_calculator.dart +++ b/lib/domain/models/irr_calculator.dart @@ -30,7 +30,8 @@ class IRRCalculator { value: value, totalPayment: totalPayment, totalYears: totalYears); const int maxIterations = 1000; - const double precision = 0.0001; + const double precision = + 0.0001; //This precision gives more accurate result within 1000 iterations for (var i = 0; i < maxIterations; i++) { final valueOnIrr = calculateFutureValueOnIRR( diff --git a/lib/domain/models/sip.dart b/lib/domain/models/sip.dart index 37cd986..7811be3 100644 --- a/lib/domain/models/sip.dart +++ b/lib/domain/models/sip.dart @@ -1,5 +1,5 @@ import 'package:wealth_wave/api/db/app_database.dart'; -import 'package:wealth_wave/contract/sip_frequency.dart'; +import 'package:wealth_wave/contract/frequency.dart'; import 'package:wealth_wave/domain/models/payment.dart'; class Sip { @@ -9,7 +9,7 @@ class Sip { final double amount; final DateTime startDate; final DateTime? endDate; - final SipFrequency frequency; + final Frequency frequency; final DateTime? executedTill; Sip._( diff --git a/lib/domain/services/sip_service.dart b/lib/domain/services/sip_service.dart index 28affe2..00c365b 100644 --- a/lib/domain/services/sip_service.dart +++ b/lib/domain/services/sip_service.dart @@ -1,6 +1,6 @@ import 'package:wealth_wave/api/apis/sip_api.dart'; import 'package:wealth_wave/api/apis/transaction_api.dart'; -import 'package:wealth_wave/contract/sip_frequency.dart'; +import 'package:wealth_wave/contract/frequency.dart'; import 'package:wealth_wave/domain/models/sip.dart'; class SipService { @@ -23,7 +23,7 @@ class SipService { required final double amount, required final DateTime startDate, required final DateTime? endDate, - required final SipFrequency frequency}) => + required final Frequency frequency}) => _sipApi .create( investmentId: investmentId, @@ -56,7 +56,7 @@ class SipService { required final double amount, required final DateTime startDate, required final DateTime? endDate, - required final SipFrequency frequency}) => + required final Frequency frequency}) => _sipApi .update( id: sipId, diff --git a/lib/presentation/create_sip_presenter.dart b/lib/presentation/create_sip_presenter.dart index 5ddab66..70f71c2 100644 --- a/lib/presentation/create_sip_presenter.dart +++ b/lib/presentation/create_sip_presenter.dart @@ -1,4 +1,4 @@ -import 'package:wealth_wave/contract/sip_frequency.dart'; +import 'package:wealth_wave/contract/frequency.dart'; import 'package:wealth_wave/core/presenter.dart'; import 'package:wealth_wave/core/single_event.dart'; import 'package:wealth_wave/domain/models/sip.dart'; @@ -28,7 +28,7 @@ class CreateSipPresenter extends Presenter { final double amount = viewState.amount; final DateTime startDate = viewState.startDate; final DateTime? endDate = viewState.endDate; - final SipFrequency frequency = viewState.frequency; + final Frequency frequency = viewState.frequency; if (idToUpdate != null) { _sipService @@ -72,7 +72,7 @@ class CreateSipPresenter extends Presenter { updateViewState((viewState) => viewState.endDate = date); } - void onFrequencyChanged(SipFrequency frequency) { + void onFrequencyChanged(Frequency frequency) { updateViewState((viewState) => viewState.frequency = frequency); } @@ -97,7 +97,7 @@ class CreateSipViewState { double amount = 0; DateTime startDate = DateTime.now(); DateTime? endDate = DateTime.now().add(const Duration(days: 365)); - SipFrequency frequency = SipFrequency.monthly; + Frequency frequency = Frequency.monthly; SingleEvent? onSipCreated; SingleEvent? onSipLoaded; diff --git a/lib/presentation/sips_presenter.dart b/lib/presentation/sips_presenter.dart index 3c47f73..d6034f4 100644 --- a/lib/presentation/sips_presenter.dart +++ b/lib/presentation/sips_presenter.dart @@ -1,4 +1,4 @@ -import 'package:wealth_wave/contract/sip_frequency.dart'; +import 'package:wealth_wave/contract/frequency.dart'; import 'package:wealth_wave/core/presenter.dart'; import 'package:wealth_wave/domain/models/sip.dart'; import 'package:wealth_wave/domain/services/sip_service.dart'; @@ -37,7 +37,7 @@ class SipVO { final double amount; final DateTime startDate; final DateTime? endDate; - final SipFrequency frequency; + final Frequency frequency; SipVO._( {required this.id, diff --git a/lib/ui/widgets/create_sip_dialog.dart b/lib/ui/widgets/create_sip_dialog.dart index faddb50..eb662b3 100644 --- a/lib/ui/widgets/create_sip_dialog.dart +++ b/lib/ui/widgets/create_sip_dialog.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:wealth_wave/contract/sip_frequency.dart'; +import 'package:wealth_wave/contract/frequency.dart'; import 'package:wealth_wave/core/page_state.dart'; import 'package:wealth_wave/presentation/create_sip_presenter.dart'; import 'package:wealth_wave/ui/app_dimen.dart'; @@ -140,7 +140,7 @@ class _CreateTransactionPage extends PageState( + DropdownButtonFormField( decoration: const InputDecoration( border: OutlineInputBorder(), labelText: 'Frequency'), hint: const Text('Frequency'), @@ -152,31 +152,31 @@ class _CreateTransactionPage extends PageState