Skip to content

Commit

Permalink
Merge pull request #21 from lkdm/main
Browse files Browse the repository at this point in the history
Deal with deployment warnings.
  • Loading branch information
lkdm authored Aug 31, 2021
2 parents 8ea1b1d + 309f715 commit 4d8ea72
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 28 deletions.
8 changes: 2 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ import React, { useState, useEffect } from 'react';
import 'bootstrap/dist/css/bootstrap.min.css';
import './styles/style.css'
import Form from './components/calculator/Form'
import {Strategy, YearResult, Result} from './store/types'
import {cleanNumber, cleanMoney, cleanPercent, cleanYears} from './services/InputCleaners'
import {Strategy, Result} from './store/types'
import {cleanMoney, cleanPercent, cleanYears} from './services/InputCleaners'
import { calculateCompoundInterest } from './services/CompoundInterest'
import ResultChart from './components/result/ResultChart'
import ResultsText from './components/result/ResultsText'

interface Props {
strategy: Strategy
}

const defaultStrategy: Strategy = {
initialDeposit: 0, // in cents
regularDeposit: 0, // in cents
Expand Down
8 changes: 4 additions & 4 deletions src/components/result/ResultChart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { PureComponent } from 'react';
import { BarChart, Bar, Cell, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, TooltipProps } from 'recharts';
import { YearResult, Result, Money } from '../../store/types';
import React from 'react';
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, TooltipProps } from 'recharts';
import { Result, Money } from '../../store/types';
import formatMoney from '../../services/FormatMoney'

interface Props {
Expand Down Expand Up @@ -53,7 +53,7 @@ const CustomTooltip = ({ active, payload, label }: TooltipProps<number, string>)
const ResultChart: React.FC<Props> = ({data, initialDeposit}) => {

// Guard
if (data == undefined) return null
if (data === undefined) return null

return (
<ResponsiveContainer width="100%" height="90%">
Expand Down
4 changes: 2 additions & 2 deletions src/components/result/ResultsText.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { YearResult, Result, Money } from '../../store/types';
import { Result, Money } from '../../store/types';
import formatMoney from '../../services/FormatMoney'

interface Props {
Expand All @@ -9,7 +9,7 @@ interface Props {
const ResultsText: React.FC<Props> = ({data, initialDeposit}) => {

// Guard
if (data == undefined) return null
if (data === undefined) return null

// Get last year result
const result = data[data.length - 1]
Expand Down
18 changes: 2 additions & 16 deletions src/services/CompoundInterest.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import { Frequency, Strategy, YearResult, Result } from '../store/types'
import { Frequency, Strategy, Result } from '../store/types'
/*
Calculate Compound Interest
*/

/*
initialDeposit: number,
regularDeposit: number,
depositFrequency: Frequency,
compoundFrequency: Frequency,
numberOfYears: number,
annualInterestRate: number
*/

// Find new principal each compound:
// newPrincipal = currentPrincipal * (1 + r)
// Find interest rate per compound (where f is compound)
// r/f

// Calculate interest rate for each compound, given annual rate and compounds/year
const ratePerCompound = (annualInterestRate: number, compoundFrequency: Frequency): number => annualInterestRate/frequencyPerYear(compoundFrequency)

Expand All @@ -26,7 +12,7 @@ const sumDepositsForPeriod = (amount: number, depositFrequency: Frequency, compo
* Calculate the sum of deposits made per compound period
* Given: Deposit amount, deposits per year, and compounds per year
*/
if (compoundFrequency == "Monthly")
if (compoundFrequency === "Monthly")
return amount * frequencyPerYear(depositFrequency) / 12 // <-----
// Yearly
return amount * frequencyPerYear(depositFrequency)
Expand Down

0 comments on commit 4d8ea72

Please sign in to comment.