diff --git a/src/views/wallet/index.tsx b/src/views/wallet/index.tsx index 816976fc6..fea306746 100644 --- a/src/views/wallet/index.tsx +++ b/src/views/wallet/index.tsx @@ -1,9 +1,11 @@ -import { Tab, TabList, TabPanel, TabPanels, Tabs } from "@chakra-ui/react"; +import { useState } from "react"; +import { Button, Tab, TabList, TabPanel, TabPanels, Tabs, useToast } from "@chakra-ui/react"; import { kinds } from "nostr-tools"; import { WalletBalanceQuery } from "applesauce-wallet/queries"; +import { CreateWallet } from "applesauce-wallet/actions"; import { WALLET_HISTORY_KIND, WALLET_TOKEN_KIND } from "applesauce-wallet/helpers"; -import { useActiveAccount, useStoreQuery } from "applesauce-react/hooks"; +import { useActionHub, useActiveAccount, useStoreQuery } from "applesauce-react/hooks"; import SimpleView from "../../components/layout/presets/simple-view"; import useTimelineLoader from "../../hooks/use-timeline-loader"; import useUserMailboxes from "../../hooks/use-user-mailboxes"; @@ -18,8 +20,10 @@ import useUserWallet from "../../hooks/use-user-wallet"; import WalletUnlockButton from "./components/wallet-unlock-button"; export default function WalletHomeView() { + const toast = useToast(); const account = useActiveAccount()!; const wallet = useUserWallet(account.pubkey); + const actions = useActionHub(); const mailboxes = useUserMailboxes(account.pubkey); const readRelays = useReadRelays(mailboxes?.outboxes); @@ -32,6 +36,18 @@ export default function WalletHomeView() { ]); const balance = useStoreQuery(WalletBalanceQuery, [account.pubkey]); + const [creating, setCreating] = useState(false); + const create = async () => { + try { + setCreating(true); + await actions.run(CreateWallet, []); + toast({ status: "success", description: "Created new wallet" }); + } catch (error) { + if (error instanceof Error) toast({ status: "error", description: error.message }); + } + setCreating(false); + }; + const callback = useTimelineCurserIntersectionCallback(loader); return ( @@ -40,27 +56,35 @@ export default function WalletHomeView() { title="Wallet" actions={wallet?.locked && } > - + {wallet ? ( + + ) : ( + + )} {wallet?.locked && } - - - History ({events.filter((e) => e.kind === WALLET_HISTORY_KIND).length}) - Tokens ({events.filter((e) => e.kind === WALLET_TOKEN_KIND).length}) - Mints ({balance ? Object.keys(balance).length : 0}) - - - - - - - - - - - - - + {wallet && ( + + + History ({events.filter((e) => e.kind === WALLET_HISTORY_KIND).length}) + Tokens ({events.filter((e) => e.kind === WALLET_TOKEN_KIND).length}) + Mints ({balance ? Object.keys(balance).length : 0}) + + + + + + + + + + + + + + )} );