-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #307 from greymass/permissions-page
Permissions page
- Loading branch information
Showing
11 changed files
with
297 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script lang="ts"> | ||
import type { UnicoveContext } from '$lib/state/client.svelte'; | ||
import { cn } from '$lib/utils'; | ||
import type { Name } from '@wharfkit/antelope'; | ||
import { getContext, type Snippet } from 'svelte'; | ||
const { network } = getContext<UnicoveContext>('state'); | ||
interface Props { | ||
children?: Snippet; | ||
name?: Name | string; | ||
action?: Name | string; | ||
class?: string; | ||
} | ||
let { name, action, children, ...props }: Props = $props(); | ||
let href = $derived.by(() => { | ||
const base = `/${network}/contract/${String(name)}`; | ||
if (action) { | ||
return base + `/actions/${action}`; | ||
} | ||
return base; | ||
}); | ||
</script> | ||
|
||
{#if name} | ||
<a class={cn('text-skyBlue-500 hover:text-skyBlue-400', props.class)} {href}> | ||
{#if children} | ||
{@render children()} | ||
{:else} | ||
{String(name)} | ||
{/if} | ||
</a> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<script lang="ts"> | ||
import type { UnicoveContext } from '$lib/state/client.svelte'; | ||
import type { PrivateKey, PublicKey } from '@wharfkit/antelope'; | ||
import { KeyRound } from 'lucide-svelte'; | ||
import { getContext } from 'svelte'; | ||
const { network } = getContext<UnicoveContext>('state'); | ||
interface Props { | ||
key?: PublicKey | PrivateKey | string; | ||
icon?: boolean; | ||
} | ||
let { key, icon }: Props = $props(); | ||
</script> | ||
|
||
{#if key} | ||
<a | ||
class="inline-grid grid-cols-[auto_1fr] items-start gap-2 text-skyBlue-500 hover:text-skyBlue-400" | ||
href="/{network}/key/{String(key)}" | ||
> | ||
{#if icon} | ||
<div class="content-center pt-1"> | ||
<KeyRound class="size-4 shrink-0 " /> | ||
</div> | ||
{/if} | ||
<span class="break-all"> | ||
{String(key)} | ||
</span> | ||
</a> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import dayjs from 'dayjs'; | ||
import duration from 'dayjs/plugin/duration'; | ||
import relativeTime from 'dayjs/plugin/relativeTime'; | ||
|
||
dayjs.extend(duration); | ||
dayjs.extend(relativeTime); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 2 additions & 5 deletions
7
src/routes/[network]/(explorer)/account/[name]/permissions/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
<script lang="ts"> | ||
import Code from '$lib/components/code.svelte'; | ||
import PermissionTree from './permissiontree.svelte'; | ||
const { data } = $props(); | ||
</script> | ||
|
||
{#if data.account} | ||
<div class="space-y-4"> | ||
<h3 class="h3">Permissions</h3> | ||
<Code>{JSON.stringify(data.account.permissions, null, 2)}</Code> | ||
</div> | ||
<PermissionTree permissions={data.tree} /> | ||
{/if} |
45 changes: 45 additions & 0 deletions
45
src/routes/[network]/(explorer)/account/[name]/permissions/+page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { Permission } from '@wharfkit/account'; | ||
import type { PageLoad } from './$types'; | ||
import { Name } from '@wharfkit/antelope'; | ||
|
||
export interface TreePermission { | ||
permission: Permission; | ||
children?: TreePermission[]; | ||
} | ||
|
||
function buildTree(data: TreePermission[], parentId = Name.from('')): TreePermission[] { | ||
const tree: TreePermission[] = []; | ||
data.forEach((item) => { | ||
// Check if the item belongs to the current parent | ||
if (item.permission.parent.equals(parentId)) { | ||
// Recursively build the children of the current item | ||
const children = buildTree(data, item.permission.perm_name); | ||
// If children exist, assign them to the current item | ||
if (children.length) { | ||
item.children = children; | ||
} | ||
// Add the current item to the tree | ||
tree.push(item); | ||
} | ||
}); | ||
return tree; | ||
} | ||
|
||
export const load: PageLoad = async ({ params, parent }) => { | ||
const { network, account } = await parent(); | ||
|
||
let tree: TreePermission[] = []; | ||
if (account.permissions) { | ||
const permissionTree = account.permissions.map((p) => ({ permission: p })); | ||
tree = buildTree(permissionTree); | ||
} | ||
|
||
return { | ||
subtitle: `Permissions on the ${network.chain.name} Network.`, | ||
tree: tree, | ||
pageMetaTags: { | ||
title: `Permissions | ${params.name} | ${network.chain.name} Network`, | ||
description: `Permissions for ${params.name} on the ${network.chain.name} network.` | ||
} | ||
}; | ||
}; |
151 changes: 151 additions & 0 deletions
151
src/routes/[network]/(explorer)/account/[name]/permissions/permission.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
<script lang="ts"> | ||
import Self from './permission.svelte'; | ||
import type { TreePermission } from './+page'; | ||
import Key from '$lib/components/elements/key.svelte'; | ||
import CopyButton from '$lib/components/button/copy.svelte'; | ||
import Account from '$lib/components/elements/account.svelte'; | ||
import Contract from '$lib/components/elements/contract.svelte'; | ||
import dayjs from 'dayjs'; | ||
import { Clock } from 'lucide-svelte'; | ||
interface Props { | ||
permission: TreePermission; | ||
level?: number; | ||
} | ||
let { level = 0, ...props }: Props = $props(); | ||
let { permission, children } = $derived(props.permission); | ||
const anyPermissions = $derived( | ||
permission.required_auth.accounts.length || | ||
permission.required_auth.keys.length || | ||
permission.required_auth.waits.length | ||
); | ||
</script> | ||
|
||
<li | ||
class="relative col-span-full grid grid-cols-subgrid bg-shark-950" | ||
class:pl-4={level !== 0} | ||
class:pt-6={level !== 0} | ||
> | ||
<dl | ||
class="z-20 col-span-full space-y-1 rounded-t-lg bg-mineShaft-950 px-4 py-3 md:col-span-1 md:rounded-l-lg" | ||
> | ||
<div> | ||
<dt class="sr-only">Permission Name</dt> | ||
<dd class="text-xl font-semibold text-white">{permission.perm_name}</dd> | ||
</div> | ||
<div class="text-muted text-nowrap *:inline"> | ||
<dt class="after:content-[':']"><span class="sr-only">Threshold</span> Required</dt> | ||
<dd>{permission.required_auth.threshold}</dd> | ||
</div> | ||
{#if permission.linked_actions} | ||
<div class=""> | ||
<dt class="sr-only">Actions</dt> | ||
{#each permission.linked_actions as { action, account }} | ||
<dd> | ||
<Contract name={account} {action} class="flex"> | ||
<span class="account">{account}</span> | ||
{#if action} | ||
<span class="action">::{action}</span> | ||
{/if} | ||
</Contract> | ||
</dd> | ||
{/each} | ||
</div> | ||
{/if} | ||
</dl> | ||
|
||
<div class="rounded-b-lg bg-mineShaft-950/50 px-4 py-3 md:rounded-r-lg"> | ||
{#if anyPermissions} | ||
<table class="grid grid-cols-[auto_1fr_auto] gap-x-4 gap-y-2"> | ||
<thead class="col-span-full grid grid-cols-subgrid"> | ||
<tr | ||
class="col-span-full grid grid-cols-subgrid text-left *:pt-1 *:text-base *:font-medium" | ||
> | ||
<th>Weight</th> | ||
<th>Authorization</th> | ||
</tr> | ||
</thead> | ||
<tbody class="col-span-full grid grid-cols-subgrid gap-x-4 gap-y-2"> | ||
{#if permission.required_auth.keys} | ||
{#each permission.required_auth.keys as { weight, key }} | ||
<tr | ||
class="col-span-full grid grid-cols-subgrid items-start bg-none text-white" | ||
data-hover-effect="false" | ||
> | ||
<td> | ||
+{weight.toString()} | ||
</td> | ||
<td> | ||
<Key {key} icon /> | ||
</td> | ||
<td> | ||
<CopyButton data={key.toString()} slop={false} /> | ||
</td> | ||
</tr> | ||
{/each} | ||
{/if} | ||
{#if permission.required_auth.accounts} | ||
{#each permission.required_auth.accounts as { weight, permission: account }} | ||
<tr | ||
class="col-span-full grid grid-cols-subgrid bg-none text-white" | ||
data-hover-effect="false" | ||
> | ||
<td> | ||
+{weight.toString()} | ||
</td> | ||
<td> | ||
<Account name={account.actor} icon> | ||
{account} | ||
</Account> | ||
</td> | ||
<td class="*:pt-1"> | ||
<CopyButton data={account.toString()} slop={false} /> | ||
</td> | ||
</tr> | ||
{/each} | ||
{/if} | ||
{#if permission.required_auth.waits} | ||
{#each permission.required_auth.waits as { weight, wait_sec }} | ||
<tr | ||
class="col-span-full grid grid-cols-subgrid bg-none text-white" | ||
data-hover-effect="false" | ||
> | ||
<td> | ||
+{weight.toString()} | ||
</td> | ||
<td class="flex items-center gap-2 text-mineShaft-100"> | ||
<Clock class="size-4" /> | ||
{wait_sec.toString()}s ({dayjs | ||
.duration(wait_sec.toNumber(), 'seconds') | ||
.humanize()}) | ||
</td> | ||
</tr> | ||
{/each} | ||
{/if} | ||
</tbody> | ||
</table> | ||
{/if} | ||
</div> | ||
<!-- The curved connector line --> | ||
{#if level > 0} | ||
<div class="absolute -left-px z-10 size-12 rounded-bl-xl border-b border-l"></div> | ||
{/if} | ||
</li> | ||
|
||
{#if children} | ||
<li class="col-span-full grid grid-cols-subgrid"> | ||
<!-- The border on this ul is the through line --> | ||
<ul | ||
data-solo={children.length === 1} | ||
class="children col-span-full grid grid-cols-subgrid *:data-[solo=false]:border-l last:*:data-[solo=false]:border-transparent" | ||
class:ml-8={level > 0} | ||
class:ml-4={level === 0} | ||
> | ||
<!-- style={`margin-left:calc(1rem * ${level + 1})`} --> | ||
{#each children as child} | ||
<Self permission={child} level={level + 1} /> | ||
{/each} | ||
</ul> | ||
</li> | ||
{/if} |
11 changes: 11 additions & 0 deletions
11
src/routes/[network]/(explorer)/account/[name]/permissions/permissiontree.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script lang="ts"> | ||
import Permission from './permission.svelte'; | ||
let props = $props(); | ||
</script> | ||
|
||
<ul class="grid grid-cols-[auto_1fr] overflow-x-auto"> | ||
{#each props.permissions as permission} | ||
<Permission {permission} /> | ||
{/each} | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters