-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.jsx
More file actions
90 lines (83 loc) · 2.79 KB
/
App.jsx
File metadata and controls
90 lines (83 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { useState } from "react";
import { InputBox } from "./components";
import useCurrencyInfo from "./hooks/useCurrencyInfo";
function App() {
const [amount, setAmount] = useState(0);
const [from, setFrom] = useState("usd");
const [to, setTo] = useState("inr");
const [convertedAmount, setConvertedAmount] = useState(0);
const currencyInfo = useCurrencyInfo(from);
const optionsTo = Object.keys(currencyInfo);
const optionsFrom = Object.keys(currencyInfo);
// const options = [1, 2, 3, 4, 5];
const swap = () => {
setFrom(to);
setTo(from);
setConvertedAmount(amount);
setAmount(convertedAmount);
};
const convert = () => {
setConvertedAmount(amount * currencyInfo[to]);
};
const BackgroundImage =
"https://images.pexels.com/photos/534216/pexels-photo-534216.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1";
return (
<div
className="w-full h-screen flex flex-wrap justify-center items-center bg-cover bg-no-repeat"
style={{
backgroundImage: `url(${BackgroundImage})`,
}}
>
<div className="w-full">
<div className="w-full max-w-md mx-auto border border-gray-60 rounded-lg p-5 backdrop-blur-sm bg-white/30">
<form
onSubmit={(e) => {
e.preventDefault();
convert();
}}
>
<div className="w-full mb-1">
<InputBox
label="From"
// amount={amount}
currencyOptions={optionsFrom}
onCurrencyChange={(currency) =>
setAmount(amount) | setFrom(currency)
}
selectCurrency={from}
onAmountChange={(amount) => setAmount(amount)}
/>
</div>
<div className="relative w-full h-0.5">
<button
type="button"
className="absolute left-1/2 -translate-x-1/2 -translate-y-1/2 border-2 border-white rounded-md bg-blue-600 text-white px-2 py-0.5"
onClick={swap}
>
swap
</button>
</div>
<div className="w-full mt-1 mb-4">
<InputBox
label="To"
amount={convertedAmount}
currencyOptions={optionsTo}
onCurrencyChange={(currency) => setTo(currency)}
selectCurrency={to}
amountDisable
/>
</div>
<button
type="submit"
className="w-full bg-blue-600 text-white px-4 py-3 rounded-lg"
>
{/* Convert {from.toUpperCase()} to {to.toUpperCase()} */}
Convert {from} to {to}
</button>
</form>
</div>
</div>
</div>
);
}
export default App;