Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exchange App #1

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
91100c0
project setup and fetching of rates
kivenalaric Jul 10, 2023
31b7036
deposit function implemementation and styling of wallets
kivenalaric Jul 12, 2023
0f06420
addition of styling on app.css and removal of console.log
kivenalaric Jul 12, 2023
9bc9008
integration of deposit function and adjustment on styling
kivenalaric Jul 14, 2023
b6c897d
addition of default input section
kivenalaric Jul 15, 2023
45a61f9
creation of transfer modal
kivenalaric Jul 25, 2023
e5d7a7f
addition of transfer function
kivenalaric Jul 26, 2023
c7d87bd
addition of code in app.jsx and transaction.jsx
Jul 27, 2023
813612c
Merge branch 'feature/exchange-app' of https://github.com/kivenalaric…
Jul 27, 2023
fa3ed90
removal of a state in transaction.jsx
Jul 27, 2023
4c2e3d2
edit of utils file and transaction.jsx
Jul 27, 2023
9e5000c
transfer functionality done
Jul 27, 2023
77cf0ff
styling edits
Jul 27, 2023
13a032a
linter edit
Jul 27, 2023
e9843f8
linter edit
Jul 27, 2023
473b3af
changes made on app.jsx
Jul 28, 2023
6116c1f
linter edit
Jul 28, 2023
a5cc6f6
linter edit
Jul 29, 2023
58903ab
text addition to update deployment
Jul 29, 2023
daa817d
change of api key
Jul 29, 2023
cb7f8be
text addition to update deployment
Jul 29, 2023
df31a2f
change of api key
Jul 29, 2023
c535c5f
change of api key
Jul 29, 2023
ee25d15
modification of app.jsx useeffect
Jul 29, 2023
823c747
modification of app.jsx useeffect
Jul 29, 2023
f190076
removal of unused function from app.jsx
Jul 29, 2023
e319294
change of api key
kivenalaric Sep 9, 2023
81789ba
change of api key
kivenalaric Sep 9, 2023
0e8bbb5
change of api key
kivenalaric Oct 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
{
"extensions": [".js", ".jsx"]
}
]
],
"prettier/prettier": ["error", { "endOfLine": "auto" }]
}
}
1,367 changes: 942 additions & 425 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-modal": "^3.16.1",
"react-router-dom": "^6.14.1",
"react-scripts": "^5.0.1",
"styled-components": "^6.0.3",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
60 changes: 32 additions & 28 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
.App {
text-align: center;
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #282c34;
#main {
width: 100vw;
height: fit-content;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
background-color: #1b182e;
}

#nav {
width: 100vw;
background-color: #1f1e25;
color: #fff;
display: flex;
flex-direction: row;
justify-content: space-between;
padding: 0.4rem 5rem;
}
.welcome {
font-size: 3rem;
background: -webkit-linear-gradient(#083fd0, #0179be, #00efc5);
background-clip: initial;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}

.App-link {
color: #61dafb;
small {
color: #1b182e;
font-size: 1rem;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
h3 {
font-size: 1.5rem;
text-shadow: 0px 2px 2px rgba(255, 255, 255, 0.4);
font-weight: 500;
}
119 changes: 100 additions & 19 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,107 @@
import logo from './logo.svg';
/* eslint-disable react/jsx-no-constructed-context-values */
import React, { useState, useEffect } from 'react';
import './App.css';
import { BrowserRouter, Route, Routes } from 'react-router-dom';
import MyContext from './context/context';
import Transaction from './pages/Transaction_Page/Transaction';
import { getFromLocalStorage, saveToLocalStorage } from './services/utils';

function App() {
const ApiKey = '6ebde43530287d1fef886116a4bd36a0';
const options = { method: 'GET', headers: { accept: 'application/json' } };
const [baseCurrency, setMyBaseCurrency] = useState({
baseAmnt: 0,
baseCurr: '',
});
const [dispWallet, setDispWallet] = useState(null);
const [wallet, setWallet] = useState([]);
const [modal, setModal] = useState(false);
const [transModal, setTransModal] = useState(false);
const [modal2, setModal2] = useState(false);
const [fetchedCurrencyRates, setFetchedCurrencyRates] = useState([]);

useEffect(() => {
const baseC = getFromLocalStorage('baseCurr');
const baseA = getFromLocalStorage('baseAmount');
const fetchData = async () => {
try {
const response = await fetch(
`https://api.fastforex.io/fetch-all?api_key=${ApiKey}`,
options
);
const data = await response.json();
setFetchedCurrencyRates(data.results);
if (!baseC && !baseA) {
setMyBaseCurrency((prev) => ({
...prev,
baseCurr: data.base,
baseAmnt: 0,
}));
saveToLocalStorage('baseCurr', data.base);
saveToLocalStorage('baseAmount', baseCurrency.baseAmnt);
} else {
setMyBaseCurrency((prev) => ({
...prev,
baseCurr: baseC,
baseAmnt: baseA,
}));
}
} catch (err) {
throw new Error(err);
}
};
fetchData();

const walletFromLocalStorage = getFromLocalStorage('wallet') || [];
// const baseFromLocalStorage = getFromLocalStorage('baseCurr');
// setMyBaseCurrency(baseFromLocalStorage);
// sumWallet(
// walletFromLocalStorage,
// baseCurrency.baseCurr,
// fetchedCurrencyRates
// );

setDispWallet(walletFromLocalStorage);
setMyBaseCurrency((prev) => ({ ...prev, baseAmnt: baseA }));
}, []);

const toogleModal2 = () => {
setModal2((prev) => !prev);
};

const toogleModal = () => {
setModal((prev) => !prev);
};

const toogleTransModal = () => {
setTransModal((prev) => !prev);
};

return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit
<code>src/App.js</code>
and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
<MyContext.Provider
value={{
// fetchedCurrencyOptions,
fetchedCurrencyRates,
toogleModal,
modal,
wallet,
setWallet,
baseCurrency,
setMyBaseCurrency,
dispWallet,
setDispWallet,
toogleModal2,
modal2,
transModal,
toogleTransModal,
}}
>
<BrowserRouter>
<Routes>
<Route index path="/" element={<Transaction />} />
</Routes>
</BrowserRouter>
</MyContext.Provider>
);
}

Expand Down
1 change: 1 addition & 0 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
import { render, screen } from '@testing-library/react';
import App from './App';

Expand Down
Binary file added src/assets/images/pngaaa.com-2105281.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/pngegg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 114 additions & 0 deletions src/components/DepositModal/DepositModal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import React, { useState, useContext } from 'react';
import {
Main,
MainM,
DepositInput,
DepositForm,
Inputsec,
Input,
Select,
} from './styles';
import { Button } from '../../pages/Transaction_Page/styles';
import MyContext from '../../context/context';
import { saveToLocalStorage, toBaseCurrency } from '../../services/utils';
import CloseBtn from '../currency-card/CloseBtn/CloseBtn';

function DepositModal() {
const [money, setMoney] = useState({ amount: 0, currency: '' });
const {
wallet,
dispWallet,
setDispWallet,
fetchedCurrencyRates,
toogleModal,
baseCurrency,
setMyBaseCurrency,
} = useContext(MyContext);

const depositToWallet = () => {
const prevCur = dispWallet.find((wall) => wall.currency === money.currency);
if (prevCur) {
const update = dispWallet.map((cur) => {
if (cur.currency === money.currency) {
return { ...cur, amount: +cur.amount + +money.amount };
}
return cur;
});

// calculate baseAmount;
const res = toBaseCurrency(update, baseCurrency, fetchedCurrencyRates);
// console.log({ res, update, baseCurrency, fetchedCurrencyRates });
setMyBaseCurrency((prev) => ({ ...prev, baseAmnt: res }));

setDispWallet([...update]);
saveToLocalStorage('wallet', [...update]);
return;
}
const update = wallet;
update.push(money);
setDispWallet([...update]);
const res = toBaseCurrency(update, baseCurrency, fetchedCurrencyRates);
// console.log({ res, update, baseCurrency, fetchedCurrencyRates });
setMyBaseCurrency((prev) => ({ ...prev, baseAmnt: res }));
saveToLocalStorage('wallet', [...update]);
};

const handleAmntChange = (e) => {
setMoney((prev) => ({
...prev,
amount: e.target.value,
}));
};

const handleCurrChange = (e) => {
setMoney((prev) => ({
...prev,
currency: e.target.value,
}));
};

return (
<Main>
<CloseBtn onClick={toogleModal} />
<MainM>
<h1>Make a deposit!</h1>
<DepositInput>
<DepositForm
onSubmit={(e) => {
e.preventDefault(e);
depositToWallet();
toogleModal();
}}
>
<Inputsec>
<Input
type="number"
id="amount"
value={money.amount}
placeholder="Make Deposit here"
onChange={handleAmntChange}
required
/>
<Select
name="currency"
id="money"
value={money.currency}
onChange={handleCurrChange}
>
{[...Object.keys(fetchedCurrencyRates)].map((option) => (
<option value={option} id="option" key={option}>
{option}
{/* {`${option} : ${fetchedCurrencyRates[option]}`} */}
</option>
))}
</Select>
</Inputsec>
<Button type="submit">Deposit +</Button>
</DepositForm>
</DepositInput>
</MainM>
</Main>
);
}

export default DepositModal;
Loading