feat: new operator
This commit is contained in:
parent
b72fbb501f
commit
b57bcb2e8d
30
package.json
30
package.json
|
|
@ -21,10 +21,10 @@
|
|||
"@codemirror/lang-markdown": "6.0.5",
|
||||
"@codemirror/language": "6.3.1",
|
||||
"@codemirror/state": "6.1.4",
|
||||
"@codemirror/view": "6.6.0",
|
||||
"@codemirror/view": "6.7.0",
|
||||
"@emoji-mart/data": "1.0.8",
|
||||
"@emoji-mart/react": "1.0.1",
|
||||
"@floating-ui/react-dom-interactions": "0.13.0",
|
||||
"@floating-ui/react-dom-interactions": "0.13.3",
|
||||
"@headlessui/react": "1.7.4",
|
||||
"@heroicons/react": "2.0.13",
|
||||
"@iconify-json/akar-icons": "1.1.10",
|
||||
|
|
@ -34,13 +34,13 @@
|
|||
"@tanstack/react-query": "4.19.1",
|
||||
"@tanstack/react-query-devtools": "4.19.1",
|
||||
"@tanstack/react-query-persist-client": "4.19.1",
|
||||
"@uiw/codemirror-extensions-events": "4.17.1",
|
||||
"@uiw/react-codemirror": "4.17.1",
|
||||
"@uiw/codemirror-extensions-events": "4.19.1",
|
||||
"@uiw/react-codemirror": "4.19.1",
|
||||
"@urql/core": "3.0.5",
|
||||
"axios": "1.2.0",
|
||||
"axios": "1.2.1",
|
||||
"clsx": "1.2.1",
|
||||
"crossbell.js": "0.11.5",
|
||||
"dayjs": "1.11.6",
|
||||
"crossbell.js": "0.13.0",
|
||||
"dayjs": "1.11.7",
|
||||
"dotenv": "16.0.3",
|
||||
"emoji-mart": "5.3.3",
|
||||
"ethers": "5.7.2",
|
||||
|
|
@ -66,6 +66,7 @@
|
|||
"react-sortablejs": "6.1.4",
|
||||
"refractor": "4.8.0",
|
||||
"rehype-autolink-headings": "6.1.1",
|
||||
"rehype-infer-description-meta": "^1.1.0",
|
||||
"rehype-katex": "^6.0.2",
|
||||
"rehype-prism-plus": "1.5.0",
|
||||
"rehype-raw": "6.1.1",
|
||||
|
|
@ -90,7 +91,7 @@
|
|||
"use-onclickoutside": "0.4.1",
|
||||
"uuid": "9.0.0",
|
||||
"wagmi": "0.8.10",
|
||||
"zustand": "4.1.4"
|
||||
"zustand": "4.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@iconify-json/bi": "1.1.12",
|
||||
|
|
@ -100,11 +101,12 @@
|
|||
"@iconify-json/mdi": "1.1.36",
|
||||
"@next/bundle-analyzer": "13.0.6",
|
||||
"@playwright/test": "1.28.1",
|
||||
"@tailwindcss/line-clamp": "^0.4.2",
|
||||
"@types/cookie": "0.5.1",
|
||||
"@types/hast": "2.3.4",
|
||||
"@types/js-yaml": "4.0.5",
|
||||
"@types/mjml": "4.7.0",
|
||||
"@types/node": "18.11.10",
|
||||
"@types/node": "18.11.11",
|
||||
"@types/prismjs": "1.26.0",
|
||||
"@types/react": "18.0.26",
|
||||
"@types/react-dom": "18.0.9",
|
||||
|
|
@ -117,18 +119,18 @@
|
|||
"@unocss/preset-icons": "0.47.5",
|
||||
"autoprefixer": "10.4.13",
|
||||
"cross-spawn": "7.0.3",
|
||||
"esbuild": "0.15.18",
|
||||
"esbuild": "0.16.2",
|
||||
"esbuild-register": "3.4.1",
|
||||
"eslint": "8.29.0",
|
||||
"eslint-config-next": "13.0.6",
|
||||
"husky": "8.0.2",
|
||||
"lint-staged": "13.1.0",
|
||||
"postcss-import": "15.0.1",
|
||||
"prettier": "2.8.0",
|
||||
"postcss-import": "15.1.0",
|
||||
"prettier": "2.8.1",
|
||||
"tailwindcss": "3.2.4",
|
||||
"typescript": "4.9.3",
|
||||
"typescript": "4.9.4",
|
||||
"unocss": "0.47.5",
|
||||
"vitest": "0.25.3"
|
||||
"vitest": "0.25.6"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
|
|
|
|||
601
pnpm-lock.yaml
601
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
|
@ -61,7 +61,7 @@ export function DashboardLayout({
|
|||
if (userSite.isSuccess && subdomain) {
|
||||
if (
|
||||
!userSite.data?.find((site) => site.username === subdomain) &&
|
||||
!isOperator.data?.data
|
||||
!isOperator.data
|
||||
) {
|
||||
router.push("/dashboard")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import { createClient } from "@urql/core"
|
|||
import axios from "axios"
|
||||
import { indexer } from "~/queries/crossbell"
|
||||
import type { LinkEntity, NoteEntity } from "crossbell.js"
|
||||
import type { Contract } from "crossbell.js"
|
||||
import type { Contract, CharacterOperatorPermission } from "crossbell.js"
|
||||
|
||||
export const checkSubdomain = async ({
|
||||
subdomain,
|
||||
|
|
@ -438,6 +438,12 @@ export async function getNotifications(input: { siteCId: string }) {
|
|||
})
|
||||
}
|
||||
|
||||
const xLogOperatorPermissions: CharacterOperatorPermission[] = [
|
||||
"SET_NOTE_URI",
|
||||
"DELETE_NOTE",
|
||||
"POST_NOTE",
|
||||
]
|
||||
|
||||
export async function addOperator(
|
||||
input: {
|
||||
characterId: number
|
||||
|
|
@ -446,31 +452,53 @@ export async function addOperator(
|
|||
contract?: Contract,
|
||||
) {
|
||||
if (input.operator && input.characterId) {
|
||||
return contract?.addOperator(input.characterId, input.operator)
|
||||
return contract?.grantOperatorPermissionsForCharacter(
|
||||
input.characterId,
|
||||
input.operator,
|
||||
xLogOperatorPermissions,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export async function getOperators(
|
||||
input: {
|
||||
characterId?: number
|
||||
},
|
||||
contract?: Contract,
|
||||
) {
|
||||
export async function getOperators(input: { characterId?: number }) {
|
||||
if (input.characterId) {
|
||||
return contract?.getOperators(input.characterId)
|
||||
const result = await indexer?.getCharacterOperators(input.characterId, {
|
||||
limit: 100,
|
||||
})
|
||||
result.list = result.list
|
||||
.filter(
|
||||
(o) =>
|
||||
o.operator !== "0x0000000000000000000000000000000000000000" &&
|
||||
o.operator !== "0x0f588318a494e4508a121a32b6670b5494ca3357",
|
||||
) // remove 0 and xSync
|
||||
.filter((o) => {
|
||||
for (const permission of xLogOperatorPermissions) {
|
||||
if (!o.permissions.includes(permission)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
export async function isOperators(
|
||||
input: {
|
||||
characterId: number
|
||||
operator: string
|
||||
},
|
||||
contract?: Contract,
|
||||
) {
|
||||
export async function isOperators(input: {
|
||||
characterId: number
|
||||
operator: string
|
||||
}) {
|
||||
if (input.characterId) {
|
||||
return contract?.isOperator(input.characterId, input.operator)
|
||||
const permissions =
|
||||
(await indexer?.getCharacterOperator(input.characterId, input.operator))
|
||||
?.permissions || []
|
||||
for (const permission of xLogOperatorPermissions) {
|
||||
if (!permissions.includes(permission)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
export async function removeOperator(
|
||||
|
|
@ -481,7 +509,11 @@ export async function removeOperator(
|
|||
contract?: Contract,
|
||||
) {
|
||||
if (input.characterId) {
|
||||
return contract?.removeOperator(input.characterId, input.operator)
|
||||
return contract?.grantOperatorPermissionsForCharacter(
|
||||
input.characterId,
|
||||
input.operator,
|
||||
[],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -155,7 +155,6 @@ export default function SiteSettingsGeneralPage() {
|
|||
id="description"
|
||||
className="input is-block"
|
||||
rows={2}
|
||||
help="Support Markdown"
|
||||
{...form.register("description")}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ export default function SiteSettingsNavigationPage() {
|
|||
}
|
||||
|
||||
useEffect(() => {
|
||||
setItems(operators.data || [])
|
||||
setItems(operators.data?.list.map((o) => o.operator) || [])
|
||||
}, [operators.data])
|
||||
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
|
|
|
|||
|
|
@ -185,32 +185,25 @@ export const useGetNotifications = (data: { siteCId?: string }) => {
|
|||
export const useGetOperators = (
|
||||
data: Parameters<typeof siteModel.getOperators>[0],
|
||||
) => {
|
||||
const contract = useContract()
|
||||
return useQuery(["getOperators", data], async () => {
|
||||
if (!data.characterId) {
|
||||
return null
|
||||
}
|
||||
return (await siteModel.getOperators(data, contract))?.data?.filter(
|
||||
(operator) => operator !== "0x0000000000000000000000000000000000000000",
|
||||
)
|
||||
return siteModel.getOperators(data)
|
||||
})
|
||||
}
|
||||
|
||||
export const useIsOperators = (
|
||||
data: Partial<Parameters<typeof siteModel.isOperators>[0]>,
|
||||
) => {
|
||||
const contract = useContract()
|
||||
return useQuery(["isOperators", data], async () => {
|
||||
if (!data.characterId || !data.operator) {
|
||||
return null
|
||||
}
|
||||
return siteModel.isOperators(
|
||||
{
|
||||
characterId: data.characterId,
|
||||
operator: data.operator,
|
||||
},
|
||||
contract,
|
||||
)
|
||||
return siteModel.isOperators({
|
||||
characterId: data.characterId,
|
||||
operator: data.operator,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue