Skip to content

Commit

Permalink
Rename SipFrequency to Frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
praslnx8 committed Mar 30, 2024
1 parent 72e4230 commit 63f95de
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 49 deletions.
6 changes: 3 additions & 3 deletions lib/api/apis/sip_api.dart
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions lib/api/db/app_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -79,7 +79,7 @@ class SipTable extends Table {
.check(endDate.isNull() | endDate.isBiggerThan(startDate))
.named('END_DATE')();

TextColumn get frequency => textEnum<SipFrequency>().named('FREQUENCY')();
TextColumn get frequency => textEnum<Frequency>().named('FREQUENCY')();

DateTimeColumn get executedTill =>
dateTime().nullable().named('EXECUTED_TILL')();
Expand Down
26 changes: 13 additions & 13 deletions lib/api/db/app_database.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions lib/contract/sip_frequency.dart → lib/contract/frequency.dart
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
3 changes: 2 additions & 1 deletion lib/domain/models/irr_calculator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions lib/domain/models/sip.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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._(
Expand Down
6 changes: 3 additions & 3 deletions lib/domain/services/sip_service.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions lib/presentation/create_sip_presenter.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -28,7 +28,7 @@ class CreateSipPresenter extends Presenter<CreateSipViewState> {
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
Expand Down Expand Up @@ -72,7 +72,7 @@ class CreateSipPresenter extends Presenter<CreateSipViewState> {
updateViewState((viewState) => viewState.endDate = date);
}

void onFrequencyChanged(SipFrequency frequency) {
void onFrequencyChanged(Frequency frequency) {
updateViewState((viewState) => viewState.frequency = frequency);
}

Expand All @@ -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<void>? onSipCreated;
SingleEvent<void>? onSipLoaded;

Expand Down
4 changes: 2 additions & 2 deletions lib/presentation/sips_presenter.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions lib/ui/widgets/create_sip_dialog.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -140,7 +140,7 @@ class _CreateTransactionPage extends PageState<CreateSipViewState,
border: OutlineInputBorder()),
),
const SizedBox(height: AppDimen.defaultPadding),
DropdownButtonFormField<SipFrequency>(
DropdownButtonFormField<Frequency>(
decoration: const InputDecoration(
border: OutlineInputBorder(), labelText: 'Frequency'),
hint: const Text('Frequency'),
Expand All @@ -152,31 +152,31 @@ class _CreateTransactionPage extends PageState<CreateSipViewState,
},
items: const [
DropdownMenuItem(
value: SipFrequency.daily,
value: Frequency.daily,
child: Text('Daily'),
),
DropdownMenuItem(
value: SipFrequency.weekly,
value: Frequency.weekly,
child: Text('Weekly'),
),
DropdownMenuItem(
value: SipFrequency.biweekly,
value: Frequency.biweekly,
child: Text('Bi Weekly'),
),
DropdownMenuItem(
value: SipFrequency.monthly,
value: Frequency.monthly,
child: Text('Monthly'),
),
DropdownMenuItem(
value: SipFrequency.quarterly,
value: Frequency.quarterly,
child: Text('Quarterly'),
),
DropdownMenuItem(
value: SipFrequency.halfyearly,
value: Frequency.halfYearly,
child: Text('Half Yearly'),
),
DropdownMenuItem(
value: SipFrequency.yearly,
value: Frequency.yearly,
child: Text('Yearly'),
),
],
Expand Down

0 comments on commit 63f95de

Please sign in to comment.