diff --git a/src/App.tsx b/src/App.tsx index 2f39ee7..67b1384 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,5 @@ import React, { useState, useEffect } from "react"; +import { Typography } from "@material-ui/core"; import { Provider } from "@project-serum/anchor"; // @ts-ignore import Wallet from "@project-serum/sol-wallet-adapter"; @@ -41,18 +42,25 @@ function App() { }, [params]); return ( -
- {isConnected && ( -
- -
+
+ {isConnected ? ( + + ) : ( + Disconnected )}
); diff --git a/src/components/Context.tsx b/src/components/Context.tsx index c2ab581..92528d5 100644 --- a/src/components/Context.tsx +++ b/src/components/Context.tsx @@ -11,7 +11,12 @@ import { TokenListContainer, TokenInfo } from "@solana/spl-token-registry"; import { getOwnedTokenAccounts } from "../utils/tokens"; const SRM_MINT = new PublicKey("SRMuApVNdxXokk5GT7XD5cUUgXMBCoAz2LHeuAoKWRt"); -const USDC_MINT = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"); +export const USDC_MINT = new PublicKey( + "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" +); +export const USDT_MINT = new PublicKey( + "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB" +); const SwapContext = React.createContext(null); diff --git a/src/components/Swap.tsx b/src/components/Swap.tsx index 001e6a8..4f22661 100644 --- a/src/components/Swap.tsx +++ b/src/components/Swap.tsx @@ -1,5 +1,4 @@ -import React, { useState, useContext } from "react"; -import { BN } from "@project-serum/anchor"; +import { useState } from "react"; import { PublicKey } from "@solana/web3.js"; import { TokenListContainer } from "@solana/spl-token-registry"; import { Provider } from "@project-serum/anchor"; @@ -24,11 +23,13 @@ import { useOwnedTokenAccount, useMintAccount, } from "./Context"; +import TokenDialog from "./TokenDialog"; -const useStyles = makeStyles((theme) => ({ +const useStyles = makeStyles(() => ({ card: { width: "450px", borderRadius: "10px", + border: "solid 1pt #e0e0e0", }, cardContent: { marginLeft: "6px", @@ -229,6 +230,7 @@ function SwapTokenForm({ amount: number; setAmount: (a: number) => void; }) { + const [showTokenDialog, setShowTokenDialog] = useState(false); const tokenAccount = useOwnedTokenAccount(mint); const mintAccount = useMintAccount(mint); @@ -241,7 +243,7 @@ function SwapTokenForm({ justifyContent: "space-between", }} > - + setShowTokenDialog(true)} />
+ setShowTokenDialog(false)} + /> ); } -function TokenButton({ mint }: { mint: PublicKey }) { +function TokenButton({ + mint, + onClick, +}: { + mint: PublicKey; + onClick: () => void; +}) { return ( - ); } -function TokenIcon({ mint }: { mint: PublicKey }) { +export function TokenIcon({ mint, style }: { mint: PublicKey; style: any }) { const tokenList = useTokenList(); let tokenInfo = tokenList.filter((t) => t.address === mint.toString())[0]; return ( @@ -288,7 +301,11 @@ function TokenIcon({ mint }: { mint: PublicKey }) { flexDirection: "column", }} > - + {tokenInfo.logoURI ? ( + token logo + ) : ( +
+ )} ); } diff --git a/src/components/TokenDialog.tsx b/src/components/TokenDialog.tsx new file mode 100644 index 0000000..18aa8c2 --- /dev/null +++ b/src/components/TokenDialog.tsx @@ -0,0 +1,111 @@ +import { useState } from "react"; +import { PublicKey } from "@solana/web3.js"; +import { + makeStyles, + Dialog, + DialogTitle, + DialogContent, + TextField, + List, + ListItem, + Typography, +} from "@material-ui/core"; +import { useSwapContext, useTokenList, USDC_MINT, USDT_MINT } from "./Context"; +import { TokenIcon } from "./Swap"; + +const useStyles = makeStyles((theme) => ({ + dialogContent: { + paddingTop: 0, + }, + textField: { + width: "100%", + border: "solid 1pt #ccc", + borderRadius: "10px", + marginBottom: "8px", + }, +})); + +export default function TokenDialog({ + open, + onClose, + setMint, +}: { + open: boolean; + onClose: () => void; + setMint: (mint: PublicKey) => void; +}) { + const [tokenFilter, setTokenFilter] = useState(""); + const styles = useStyles(); + const { swapClient } = useSwapContext(); + return ( + +
+ Select a token + + setTokenFilter(e.target.value)} + InputProps={{ + disableUnderline: true, + style: { padding: "10px" }, + }} + /> +
+ + {swapClient + .tokens() + .concat([USDC_MINT, USDT_MINT]) + .map((mint) => ( + { + setMint(mint); + onClose(); + }} + /> + ))} + +
+
+
+
+ ); +} + +function TokenListItem({ + mint, + onClick, +}: { + mint: PublicKey; + onClick: (mint: PublicKey) => void; +}) { + return ( + onClick(mint)}> + + + + ); +} + +function TokenName({ mint }: { mint: PublicKey }) { + const tokenList = useTokenList(); + let tokenInfo = tokenList.filter((t) => t.address === mint.toString())[0]; + return ( +
+ {tokenInfo.symbol} + + {tokenInfo.name} + +
+ ); +}