2022-01-16 03:09:15 +00:00
|
|
|
import { Page } from '../components/page'
|
|
|
|
import { Grid } from 'gridjs-react'
|
|
|
|
import 'gridjs/dist/theme/mermaid.css'
|
|
|
|
import { html } from 'gridjs'
|
|
|
|
import dayjs from 'dayjs'
|
2022-01-24 06:48:06 +00:00
|
|
|
import { usePrivateUsers, useUsers } from '../hooks/use-users'
|
2022-01-16 03:09:15 +00:00
|
|
|
import { useUser } from '../hooks/use-user'
|
|
|
|
import Custom404 from './404'
|
2022-01-18 22:10:40 +00:00
|
|
|
import { useContracts } from '../hooks/use-contracts'
|
2022-01-24 06:48:06 +00:00
|
|
|
import _ from 'lodash'
|
2022-01-16 03:09:15 +00:00
|
|
|
|
|
|
|
function avatarHtml(avatarUrl: string) {
|
|
|
|
return `<img
|
|
|
|
class="h-10 w-10 rounded-full bg-gray-400 flex items-center justify-center"
|
|
|
|
src="${avatarUrl}"
|
|
|
|
alt=""
|
|
|
|
/>`
|
|
|
|
}
|
|
|
|
|
|
|
|
function UsersTable() {
|
|
|
|
let users = useUsers()
|
2022-01-24 06:48:06 +00:00
|
|
|
let privateUsers = usePrivateUsers()
|
|
|
|
|
|
|
|
// Map private users by user id
|
|
|
|
const privateUsersById = _.mapKeys(privateUsers, 'id')
|
|
|
|
console.log('private users by id', privateUsersById)
|
|
|
|
|
|
|
|
// For each user, set their email from the PrivateUser
|
|
|
|
users = users.map((user) => {
|
|
|
|
// @ts-ignore
|
|
|
|
user.email = privateUsersById[user.id]?.email
|
|
|
|
return user
|
|
|
|
})
|
|
|
|
|
2022-01-16 03:09:15 +00:00
|
|
|
// Sort users by createdTime descending, by default
|
|
|
|
users = users.sort((a, b) => b.createdTime - a.createdTime)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Grid
|
|
|
|
data={users}
|
|
|
|
columns={[
|
|
|
|
{
|
|
|
|
id: 'avatarUrl',
|
|
|
|
name: 'Avatar',
|
|
|
|
formatter: (cell) => html(avatarHtml(cell as string)),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'username',
|
|
|
|
name: 'Username',
|
|
|
|
formatter: (cell) =>
|
|
|
|
html(`<a
|
|
|
|
class="hover:underline hover:decoration-indigo-400 hover:decoration-2"
|
|
|
|
href="/${cell}">@${cell}</a>`),
|
|
|
|
},
|
|
|
|
'Email',
|
|
|
|
{
|
|
|
|
id: 'createdTime',
|
|
|
|
name: 'Created Time',
|
|
|
|
formatter: (cell) =>
|
|
|
|
html(
|
|
|
|
`<span class="whitespace-nowrap">${dayjs(cell as number).format(
|
|
|
|
'MMM D, h:mma'
|
|
|
|
)}</span>`
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'balance',
|
|
|
|
name: 'Balance',
|
|
|
|
formatter: (cell) => (cell as number).toFixed(0),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'id',
|
|
|
|
name: 'ID',
|
|
|
|
formatter: (cell) =>
|
|
|
|
html(`<a
|
|
|
|
class="hover:underline hover:decoration-indigo-400 hover:decoration-2"
|
|
|
|
href="https://console.firebase.google.com/project/mantic-markets/firestore/data/~2Fusers~2F${cell}">${cell}</a>`),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
search={true}
|
|
|
|
sort={true}
|
|
|
|
pagination={{
|
|
|
|
enabled: true,
|
|
|
|
limit: 25,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-18 22:10:40 +00:00
|
|
|
function ContractsTable() {
|
|
|
|
let contracts = useContracts() ?? []
|
|
|
|
// Sort users by createdTime descending, by default
|
|
|
|
contracts.sort((a, b) => b.createdTime - a.createdTime)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Grid
|
|
|
|
data={contracts}
|
|
|
|
columns={[
|
|
|
|
{
|
|
|
|
id: 'creatorUsername',
|
|
|
|
name: 'Username',
|
|
|
|
formatter: (cell) =>
|
|
|
|
html(`<a
|
|
|
|
class="hover:underline hover:decoration-indigo-400 hover:decoration-2"
|
|
|
|
target="_blank"
|
|
|
|
href="/${cell}">@${cell}</a>`),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'question',
|
|
|
|
name: 'Question',
|
2022-01-20 06:55:10 +00:00
|
|
|
formatter: (cell) => html(`<div class="w-60">${cell}</div>`),
|
2022-01-18 22:10:40 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'volume24Hours',
|
2022-01-20 06:55:10 +00:00
|
|
|
name: '24h vol',
|
2022-01-18 22:10:40 +00:00
|
|
|
formatter: (cell) => (cell as number).toFixed(0),
|
|
|
|
},
|
2022-01-20 06:55:10 +00:00
|
|
|
{
|
|
|
|
id: 'createdTime',
|
|
|
|
name: 'Created time',
|
|
|
|
formatter: (cell) =>
|
|
|
|
html(
|
|
|
|
`<span class="whitespace-nowrap">${dayjs(cell as number).format(
|
|
|
|
'MMM D, h:mma'
|
|
|
|
)}</span>`
|
|
|
|
),
|
|
|
|
},
|
2022-01-18 22:10:40 +00:00
|
|
|
{
|
|
|
|
id: 'closeTime',
|
|
|
|
name: 'Close time',
|
|
|
|
formatter: (cell) =>
|
|
|
|
html(
|
|
|
|
`<span class="whitespace-nowrap">${dayjs(cell as number).format(
|
|
|
|
'MMM D, h:mma'
|
|
|
|
)}</span>`
|
|
|
|
),
|
2022-01-20 06:55:10 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'resolvedTime',
|
|
|
|
name: 'Resolved time',
|
|
|
|
formatter: (cell) =>
|
|
|
|
html(
|
|
|
|
`<span class="whitespace-nowrap">${dayjs(cell as number).format(
|
|
|
|
'MMM D, h:mma'
|
|
|
|
)}</span>`
|
|
|
|
),
|
2022-01-18 22:10:40 +00:00
|
|
|
},
|
2022-01-18 22:29:49 +00:00
|
|
|
{
|
|
|
|
id: 'visibility',
|
|
|
|
name: 'Visibility',
|
|
|
|
formatter: (cell) => cell,
|
|
|
|
},
|
2022-01-18 22:10:40 +00:00
|
|
|
{
|
|
|
|
id: 'id',
|
|
|
|
name: 'ID',
|
|
|
|
formatter: (cell) =>
|
|
|
|
html(`<a
|
|
|
|
class="hover:underline hover:decoration-indigo-400 hover:decoration-2"
|
|
|
|
target="_blank"
|
|
|
|
href="https://console.firebase.google.com/project/mantic-markets/firestore/data/~2Fcontracts~2F${cell}">${cell}</a>`),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
search={true}
|
|
|
|
sort={true}
|
|
|
|
pagination={{
|
|
|
|
enabled: true,
|
|
|
|
limit: 25,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-16 03:09:15 +00:00
|
|
|
export default function Admin() {
|
|
|
|
const user = useUser()
|
|
|
|
const adminIds = [
|
|
|
|
'igi2zGXsfxYPgB0DJTXVJVmwCOr2', // Austin
|
|
|
|
'5LZ4LgYuySdL1huCWe7bti02ghx2', // James
|
|
|
|
'tlmGNz9kjXc2EteizMORes4qvWl2', // Stephen
|
2022-01-24 06:48:06 +00:00
|
|
|
'IPTOzEqrpkWmEzh6hwvAyY9PqFb2', // Manifold
|
2022-01-16 03:09:15 +00:00
|
|
|
]
|
|
|
|
const isAdmin = adminIds.includes(user?.id || '')
|
|
|
|
return isAdmin ? (
|
|
|
|
<Page wide>
|
|
|
|
<UsersTable />
|
2022-01-18 22:10:40 +00:00
|
|
|
<ContractsTable />
|
2022-01-16 03:09:15 +00:00
|
|
|
</Page>
|
|
|
|
) : (
|
|
|
|
<Custom404 />
|
|
|
|
)
|
|
|
|
}
|