Skip to content

Commit

Permalink
adde wllet tx and exchange rate tonapi
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisZerbib committed Jun 4, 2024
1 parent 300b9de commit aef2c42
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 4 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
"@tonconnect/ui-react": "^2.0.0-beta.2",
"@twa-dev/sdk": "^6.4.2",
"axios": "^1.7.2",
"binance": "^2.11.2",
"buffer": "^6.0.3",
"mapbox-gl": "^3.4.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-leaflet": "^4.2.1",
"react-router-dom": "^6.23.1",
"react-toastify": "^10.0.5",
"styled-components": "^5.3.6",
Expand Down
4 changes: 3 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import OrdersDrawer from "./components/OrderDrawer";
import PriceConverter from "./components/PriceConverter";
import CurrencySwitcher from "./components/CurrencySwitcher";
import { useCurrency } from "./providers/useCurrency";
import WalletBalanceTon from "./components/WalletBalanceTon";
// import WalletBalanceTon from "./components/WalletBalanceTon";
// import WalletTxList from "./components/WalletTxList";

function App() {
const { network } = useTonConnect();
Expand Down Expand Up @@ -148,6 +149,7 @@ function App() {
></NetworkBadge>
</div>
{/* {network && wallet && <WalletBalanceTon walletAddress={wallet} />} */}
{/* {network && wallet && <WalletTxList walletAddress={wallet} />} */}
</div>
</div>
</FlexBoxRowSpaceBetween>
Expand Down
4 changes: 4 additions & 0 deletions src/components/OrderDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
faCircleXmark,
} from "@fortawesome/free-solid-svg-icons";
import { fas } from "@fortawesome/free-solid-svg-icons";
import { useTonConnect } from "../hooks/useTonConnect";

interface OrdersDrawerProps {
orders: OrderProps[];
Expand All @@ -28,6 +29,9 @@ const OrdersDrawer: React.FC<OrdersDrawerProps> = ({
open,
onClose,
}) => {
const { connected } = useTonConnect();
const { wallet } = useTonConnect();

const toggleDrawer = (open: boolean) => (event: React.KeyboardEvent) => {
if (event.key !== "Tab" && event.key !== "Shift") {
onClose(!open);
Expand Down
74 changes: 74 additions & 0 deletions src/components/WalletTxList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React, { useEffect, useState } from "react";
import { TonClient, Transaction } from "ton";
import { Address } from "@ton/core";
import { useTonConnect } from "../hooks/useTonConnect";
import { CHAIN } from "@tonconnect/protocol";

interface WalletTxListProps {
walletAddress: string;
}

const WalletTxList: React.FC<WalletTxListProps> = ({ walletAddress }) => {
const { network } = useTonConnect();
const [transactions, setTransactions] = useState<any[]>([]);

useEffect(() => {
const fetchTxList = async () => {
try {
const client = new TonClient({
endpoint:
network === CHAIN.MAINNET
? "https://toncenter.com/api/v2/jsonRPC"
: "https://testnet.toncenter.com/api/v2/jsonRPC",
});
const url = network === CHAIN.MAINNET ? "" : "testnet";
//testnet.tonapi.io/v2/blockchain/accounts/0%3A85105e63637de52c526e809985b882d841cc20ede907bbc2d5b01a55ec96c84f/transactions?limit=100&sort_order=desc

const address = Address.parse(walletAddress);
const myPrivateWallet =
"0:85105e63637de52c526e809985b882d841cc20ede907bbc2d5b01a55ec96c84f";
const queryToGetTransactions = `https://${url}.tonapi.io/v2/blockchain/accounts/${address.toString()}/transactions?limit=100&sort_order=desc`;
const response = await fetch(queryToGetTransactions);
const { transactions } = await response.json();

console.log("transactions", transactions);
setTransactions(transactions);
} catch (error) {
console.error("Failed to fetch transactions:", error);
setTransactions([]);
}
};

fetchTxList();
}, [walletAddress, network]);

return (
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
gap: "10px",
marginTop: "10px",
}}
>
{transactions.map((tx, index) => {
return (
<div key={index}>
<ul
style={{
color: tx.success === true ? "green" : "red",
}}
>
<li>Hash: {tx.hash}</li>
<li>Success: {tx.success ? "Yes" : "No"}</li>
<li>Destination: {tx.in_msg.destination.address.toString()}</li>
</ul>
</div>
);
})}
</div>
);
};

export default WalletTxList;
1 change: 0 additions & 1 deletion src/services/exchangeRateService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// services/exchangeRateService.js

import axios from 'axios';
import { useEffect, useState } from 'react'; // Import useState for local state management

interface TonApiResponse {
rates: {
Expand Down

0 comments on commit aef2c42

Please sign in to comment.