Skip to content

Commit

Permalink
Create Dashboard.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 7, 2024
1 parent 0159281 commit 0694cf4
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions projects/PiWalletBot/client/components/Dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import { useAuth } from '../context/auth';
import { useApi } from '../context/api';

const Dashboard = () => {
const auth = useAuth();
const api = useApi();

const handleGetBalance = async () => {
try {
const balance = await api.getPiBalance(auth.user.address);
console.log(`Your balance is ${balance} Pi coins`);
} catch (error) {
console.error(error);
}
};

const handleSendTransaction = async () => {
try {
const amount = 10; // hardcoded for demo purposes
const recipient = 'recipient_address'; // hardcoded for demo purposes
const transaction = await api.sendPiTransaction(auth.user.address, recipient, amount);
console.log(`Transaction sent: ${transaction}`);
} catch (error) {
console.error(error);
}
};

return (
<div className="dashboard">
<h1>Welcome, {auth.user.username}!</h1>
<Button onClick={handleGetBalance}>Get Balance</Button>
<Button onClick={handleSendTransaction}>Send Transaction</Button>
</div>
);
};

export default Dashboard;

0 comments on commit 0694cf4

Please sign in to comment.