diff --git a/packages/site/src/components/Header.tsx b/packages/site/src/components/Header.tsx index b50e2a5..124aac9 100644 --- a/packages/site/src/components/Header.tsx +++ b/packages/site/src/components/Header.tsx @@ -82,19 +82,15 @@ export const Header = ({ metamaskDispatch({ type: MetamaskActions.SetError, payload: e }); } }; - - const handleConnectWalletClick = async () => { - try { - const token = await getTariWalletToken(); - console.log({token}); - tariDispatch({ - type: TariActions.SetToken, - payload: token, - }); - } catch (e) { - console.error(e); - metamaskDispatch({ type: MetamaskActions.SetError, payload: e }); - } + + const goToBalances = () => { + // TODO: proper react navigation + window.location.href = "./balances"; + }; + + const goToTransactions = () => { + // TODO: proper react navigation + window.location.href = "./transactions"; }; return ( @@ -104,14 +100,15 @@ export const Header = ({ Tari Wallet - Balances - Transactions + Balances + Transactions metamaskDispatch(v)} onConnectClick={handleMetamaskConnectClick} - onTariWalletClick={handleSetTariWalletClick} - onTariTokenClick={handleConnectWalletClick}/> + metamaskState={metamaskState} + metamaskDispatch={(v) => metamaskDispatch(v)} + onConnectClick={handleMetamaskConnectClick} + onTariWalletClick={handleSetTariWalletClick}/> ); diff --git a/packages/site/src/pages/index.tsx b/packages/site/src/pages/index.tsx index a88d69a..1d58ae0 100644 --- a/packages/site/src/pages/index.tsx +++ b/packages/site/src/pages/index.tsx @@ -1,45 +1,14 @@ -import { useContext, useEffect } from 'react'; -import { MetamaskActions, MetaMaskContext, TariContext } from '../hooks'; -import { - connectSnap, - getSnap, - getTariWalletToken, - isLocalSnap, - sendWalletRequest, - setTariWallet, - shouldDisplayReconnectButton, -} from '../utils'; -import { - ConnectButton, - InstallFlaskButton, - ReconnectButton, - SendHelloButton, - Card, -} from '../components'; -import { defaultSnapOrigin } from '../config'; -import Container from '@mui/material/Container'; -import Typography from '@mui/material/Typography'; -import Box from '@mui/material/Box'; -import Button from '@mui/material/Button'; -import Paper from '@mui/material/Paper'; -import Stack from '@mui/material/Stack'; -import ContentCopyIcon from '@mui/icons-material/ContentCopy'; -import IconButton from '@mui/material/IconButton'; -import Table from '@mui/material/Table'; -import TableRow from '@mui/material/TableRow'; -import TableCell from '@mui/material/TableCell'; -import TableHead from '@mui/material/TableHead'; -import TableBody from '@mui/material/TableBody'; -import { SendDialog } from '../components/SendDialog'; -import React from 'react'; -import { ReceiveDialog } from '../components/ReceiveDialog'; -import { Route, Routes } from 'react-router-dom'; +import React, { useEffect } from 'react'; const Index = () => { + + useEffect(() => { + // TODO: proper react navigation + window.location.href = "./balances"; + }); + return ( -
- index -
+
); }; diff --git a/packages/site/src/pages/transactions.tsx b/packages/site/src/pages/transactions.tsx index dc57b41..efb059a 100644 --- a/packages/site/src/pages/transactions.tsx +++ b/packages/site/src/pages/transactions.tsx @@ -2,45 +2,96 @@ import { useContext, useEffect } from 'react'; import { MetamaskActions, MetaMaskContext, TariContext } from '../hooks'; import { - connectSnap, - getSnap, - getTariWalletToken, - isLocalSnap, sendWalletRequest, - setTariWallet, - shouldDisplayReconnectButton, } from '../utils'; -import { - ConnectButton, - InstallFlaskButton, - ReconnectButton, - SendHelloButton, - Card, -} from '../components'; -import { defaultSnapOrigin } from '../config'; import Container from '@mui/material/Container'; import Typography from '@mui/material/Typography'; -import Box from '@mui/material/Box'; -import Button from '@mui/material/Button'; import Paper from '@mui/material/Paper'; import Stack from '@mui/material/Stack'; -import ContentCopyIcon from '@mui/icons-material/ContentCopy'; -import IconButton from '@mui/material/IconButton'; import Table from '@mui/material/Table'; import TableRow from '@mui/material/TableRow'; import TableCell from '@mui/material/TableCell'; import TableHead from '@mui/material/TableHead'; import TableBody from '@mui/material/TableBody'; import React from 'react'; -import { SendDialog } from '../components/SendDialog'; -import { ReceiveDialog } from '../components/ReceiveDialog'; +import ContentCopyIcon from '@mui/icons-material/ContentCopy'; +import IconButton from '@mui/material/IconButton'; function Transactions() { const [metamaskState, metamaskDispatch] = useContext(MetaMaskContext); const [tariState, tariDispatch] = useContext(TariContext); + const [transactions, setTransactions] = React.useState([]); + + useEffect(() => { + if (tariState.token) { + refreshTransactions(); + } + }, [tariState]); + + const refreshTransactions = async () => { + const transactions = await getTransactions(); + console.log({ transactions }); + } + + const getTransactions = async () => { + try { + const walletRequest = { + method: 'transactions.get_all_by_status', + params: { + status: null, + } + }; + const response = await sendWalletRequest(tariState.token, walletRequest); + + if (response && response.transactions) { + setTransactions(response.transactions); + } + } catch (e) { + console.error(e); + metamaskDispatch({ type: MetamaskActions.SetError, payload: e }); + } + }; + + const handleCopyClick = async (text: string) => { + navigator.clipboard.writeText(text); + }; + return ( -
Transactions will go here
+ + + + + Transactions + + + + + + Id + Status + + + + { + transactions.map((tx) => ( + + + {tx[0].id} handleCopyClick(tx[0].id)}> + + + + {tx[2]} + + )) + } + +
+
+
); } diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index 4ef27a7..9518e85 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/template-snap-monorepo.git" }, "source": { - "shasum": "Ztmc+egLnpLeXqw0vWYrya7BYGMhfVQlyw+/StS5x2Y=", + "shasum": "wot30s3ki38/+aY/W90A93D0I4z+D+p+mC+2CCo3Rpo=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/snap/src/index.ts b/packages/snap/src/index.ts index 527ca93..5aca3ce 100644 --- a/packages/snap/src/index.ts +++ b/packages/snap/src/index.ts @@ -70,7 +70,14 @@ async function getWalletToken(_request: JsonRpcRequest