diff --git a/App.js b/App.js
new file mode 100644
index 0000000..42814b2
--- /dev/null
+++ b/App.js
@@ -0,0 +1,13 @@
+import ConvertPi from "./ConvertPi";
+import SwapCrypto from "./SwapCrypto";
+
+function App() {
+ return (
+
+
+
+
+ );
+}
+
+export default App;
diff --git a/ConvertPi.js b/ConvertPi.js
new file mode 100644
index 0000000..11ab55c
--- /dev/null
+++ b/ConvertPi.js
@@ -0,0 +1,34 @@
+import { useState } from "react";
+import axios from "axios";
+
+const ConvertPi = () => {
+ const [currency, setCurrency] = useState("usd");
+ const [amount, setAmount] = useState(1);
+ const [converted, setConverted] = useState(null);
+
+ const convertPi = async () => {
+ try {
+ const response = await axios.get(`http://localhost:5000/convert/${currency}`);
+ setConverted(response.data["pi-network"][currency] * amount);
+ } catch (error) {
+ console.error("Error fetching exchange rate:", error);
+ }
+ };
+
+ return (
+
+
Konversi Pi Coin
+
setAmount(e.target.value)} />
+
+
+ {converted !== null &&
Hasil: {converted} {currency.toUpperCase()}
}
+
+ );
+};
+
+export default ConvertPi;
diff --git a/SwapCrypto.js b/SwapCrypto.js
new file mode 100644
index 0000000..ac4dd5f
--- /dev/null
+++ b/SwapCrypto.js
@@ -0,0 +1,40 @@
+import { useState } from "react";
+import axios from "axios";
+
+const SwapCrypto = () => {
+ const [from, setFrom] = useState("pi-network");
+ const [to, setTo] = useState("btc");
+ const [amount, setAmount] = useState(1);
+ const [swapResult, setSwapResult] = useState(null);
+
+ const swapCrypto = async () => {
+ try {
+ const response = await axios.get(`http://localhost:5000/swap/${from}/${to}`);
+ setSwapResult(amount * response.data.rate);
+ } catch (error) {
+ console.error("Error fetching swap rate:", error);
+ }
+ };
+
+ return (
+
+
Swap Kripto
+
setAmount(e.target.value)} />
+
+
➡
+
+
+ {swapResult !== null &&
Hasil: {swapResult} {to.toUpperCase()}
}
+
+ );
+};
+
+export default SwapCrypto; yg
diff --git a/server.js b/server.js
new file mode 100644
index 0000000..7dca5b3
--- /dev/null
+++ b/server.js
@@ -0,0 +1,39 @@
+require("dotenv").config();
+const express = require("express");
+const axios = require("axios");
+const cors = require("cors");
+
+const app = express();
+app.use(express.json());
+app.use(cors());
+
+const COINGECKO_API = "https://api.coingecko.com/api/v3/simple/price";
+
+// Mendapatkan nilai tukar Pi Coin ke mata uang lain
+app.get("/convert/:currency", async (req, res) => {
+ try {
+ const currency = req.params.currency.toLowerCase();
+ const response = await axios.get(`${COINGECKO_API}?ids=pi-network&vs_currencies=${currency}`);
+ res.json(response.data);
+ } catch (error) {
+ res.status(500).json({ error: "Gagal mendapatkan nilai tukar" });
+ }
+});
+
+// Swap antara dua mata uang kripto
+app.get("/swap/:from/:to", async (req, res) => {
+ try {
+ const { from, to } = req.params;
+ const response = await axios.get(`${COINGECKO_API}?ids=${from},${to}&vs_currencies=usd`);
+
+ const fromPrice = response.data[from].usd;
+ const toPrice = response.data[to].usd;
+
+ const swapRate = fromPrice / toPrice;
+ res.json({ rate: swapRate });
+ } catch (error) {
+ res.status(500).json({ error: "Gagal mendapatkan nilai tukar" });
+ }
+});
+
+app.listen(5000, () => console.log("Server berjalan di port 5000"));