Skip to content

Commit

Permalink
shwo tx history
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcasey committed Oct 18, 2024
1 parent d69fec4 commit faca255
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type { ButtonProps } from '@mui/material';
import { useState } from 'react';
import type { ReactNode } from 'react';

import { ManageUserModal } from './ManageUserModal';
import { AddUserModal } from './AddUserModal';

export function ManageUserButton({
export function AddUserButton({
children,
...props
}: {
Expand All @@ -19,7 +19,7 @@ export function ManageUserButton({
<Button onClick={() => setIsModalOpen(true)} {...props}>
{children}
</Button>
<ManageUserModal open={isModalOpen} onClose={() => setIsModalOpen(false)} onAdd={() => {}} />
<AddUserModal open={isModalOpen} onClose={() => setIsModalOpen(false)} onAdd={() => {}} />
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Props = {
onAdd: () => void;
};

export function ManageUserModal({ open, onClose, onAdd }: Props) {
export function AddUserModal({ open, onClose, onAdd }: Props) {
const [repoInput, setRepoInput] = useState('');
const { trigger: createUser, isMutating: isCreating } = useCreateUser();
const debouncedFilterString = useDebouncedValue(repoInput);
Expand Down
13 changes: 9 additions & 4 deletions apps/scoutgameadmin/components/users/UsersDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import { useSearchUsers } from 'hooks/api/users';
import { useDebouncedValue } from 'hooks/useDebouncedValue';
import type { SortField, SortOrder, ScoutGameUser } from 'lib/users/getUsers';

import { ManageUserButton } from './AddUserButton/ManageUserButton';
import { AddUserButton } from './AddUserButton/AddUserButton';
import { ViewTransactionsButton } from './ViewTransactionsButton/ViewTransactionsButton';

export function UsersDashboard({ users }: { users: ScoutGameUser[] }) {
const [filterString, setFilter] = useState('');
Expand Down Expand Up @@ -97,9 +98,9 @@ export function UsersDashboard({ users }: { users: ScoutGameUser[] }) {
}}
/>
<Box>
<ManageUserButton variant='contained' color='primary' sx={{ mr: 2 }}>
<AddUserButton variant='contained' color='primary' sx={{ mr: 2 }}>
Add User
</ManageUserButton>
</AddUserButton>
<ExportButton variant='outlined' filename='scoutgame_users.tsv' src='/api/users/export'>
Export Users
</ExportButton>
Expand Down Expand Up @@ -166,7 +167,11 @@ export function UsersDashboard({ users }: { users: ScoutGameUser[] }) {
<TableCell>{user.farcasterId}</TableCell>
<TableCell>{user.builderStatus || 'N/A'}</TableCell>
<TableCell>{user.currentBalance}</TableCell>
<TableCell>{user.nftsPurchased}</TableCell>
<TableCell>
<ViewTransactionsButton size='small' variant='outlined' scoutId={user.id}>
{user.nftsPurchased}
</ViewTransactionsButton>
</TableCell>
<TableCell>{new Date(user.createdAt).toLocaleDateString()}</TableCell>
</TableRow>
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use client';

import { Button } from '@mui/material';
import type { ButtonProps } from '@mui/material';
import { useState } from 'react';
import type { ReactNode } from 'react';

import { ViewTransactionsModal } from './ViewTransactionsModal';

export function ViewTransactionsButton({
children,
scoutId,
...props
}: {
children: ReactNode;
scoutId: string;
} & ButtonProps) {
const [isModalOpen, setIsModalOpen] = useState(false);
return (
<>
<Button onClick={() => setIsModalOpen(true)} {...props}>
{children}
</Button>
<ViewTransactionsModal open={isModalOpen} onClose={() => setIsModalOpen(false)} scoutId={scoutId} />
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { LoadingButton } from '@mui/lab';
import {
Dialog,
DialogTitle,
DialogContent,
DialogActions,
Stack,
Button,
TextField,
CircularProgress,
InputAdornment,
Link,
Typography,
Box
} from '@mui/material';
import React from 'react';

import { useGetScoutEvents } from 'hooks/api/onchain';

type Props = {
open: boolean;
onClose: () => void;
scoutId: string;
};

export function ViewTransactionsModal({ open, onClose, scoutId }: Props) {
const { data, error, isLoading } = useGetScoutEvents(open ? scoutId : '');
return (
<Dialog open={open} onClose={onClose} PaperProps={{ sx: { maxWidth: 800 } }} fullWidth>
<DialogTitle>NFT Purchase transactions</DialogTitle>
<DialogContent>
<Box component='pre' maxHeight={600} overflow='auto' fontFamily='monospace' fontSize={12}>
{JSON.stringify(data, null, 2)}
</Box>
{isLoading && <CircularProgress />}
{error && (
<Typography variant='caption' color='red'>
{error.message}
</Typography>
)}
</DialogContent>
</Dialog>
);
}
11 changes: 11 additions & 0 deletions apps/scoutgameadmin/hooks/api/onchain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { RepoSearchResult } from '../../app/api/github/search-repos/route';

import { useGET } from './helpers';

export function useGetScoutEvents(scoutId: string) {
return useGET<RepoSearchResult[]>(scoutId ? '/api/onchain/scout-events' : null, { scoutId });
}

export function useGetTransactionStatus({ chainId, txHash }: { chainId: string; txHash: string }) {
return useGET<RepoSearchResult[]>(chainId && txHash ? '/api/onchain/transaction-status' : null, { chainId, txHash });
}
2 changes: 1 addition & 1 deletion apps/scoutgameadmin/hooks/api/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function useSearchUsers({
sortOrder?: SortOrder;
filter?: UserFilter;
}) {
return useGETImmutable<ScoutGameUser[]>(searchString ? '/api/users' : null, {
return useGETImmutable<ScoutGameUser[]>(searchString || sortField || filter ? '/api/users' : null, {
searchString,
sortField,
sortOrder,
Expand Down
13 changes: 9 additions & 4 deletions apps/scoutgameadmin/lib/users/getUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function getUsers({
const userFid = getNumberFromString(searchString);

const users = await prisma.scout.findMany({
take: 500,
take: sortField === 'nftsPurchased' ? 1000 : 500, // return more for nft sort since we sort in the frontend
orderBy:
!userFid && typeof searchString === 'string'
? {
Expand All @@ -36,9 +36,14 @@ export async function getUsers({
sort: 'desc'
}
}
: sortField
? { [sortField]: sortOrder || 'asc' }
: { createdAt: 'desc' },
: sortField === 'nftsPurchased'
? {
/* TODO - sort by nfts purchased */
createdAt: sortOrder || 'desc'
}
: sortField
? { [sortField]: sortOrder || 'asc' }
: { createdAt: sortOrder || 'desc' },
where: userFid
? { farcasterId: userFid }
: typeof searchString === 'string'
Expand Down

0 comments on commit faca255

Please sign in to comment.