Skip to content

Commit

Permalink
chore: fix typings
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Jul 12, 2024
1 parent 1af3283 commit 7a07006
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/Permissions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
NIP_47_PAY_INVOICE_METHOD,
Scope,
WalletCapabilities,
iconMap,
scopeDescriptions,
scopeIconMap,
} from "src/types";

interface PermissionsProps {
Expand Down Expand Up @@ -122,7 +122,7 @@ const Permissions: React.FC<PermissionsProps> = ({
<p className="text-sm font-medium mb-2">Scopes</p>
<div className="flex flex-col mb-2">
{[...permissions.scopes].map((rm) => {
const PermissionIcon = iconMap[rm];
const PermissionIcon = scopeIconMap[rm];
return (
<div
key={rm}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/components/Scopes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
SCOPE_GROUP_FULL_ACCESS,
SCOPE_GROUP_READ_ONLY,
Scope,
ScopeGroupType,
ScopeGroup,
WalletCapabilities,
scopeDescriptions,
scopeGroupDescriptions,
Expand Down Expand Up @@ -55,7 +55,7 @@ const Scopes: React.FC<ScopesProps> = ({
);
}, [capabilities.scopes]);

const [scopeGroup, setScopeGroup] = React.useState<ScopeGroupType>(() => {
const [scopeGroup, setScopeGroup] = React.useState<ScopeGroup>(() => {
if (!scopes.size || isSetEqual(scopes, fullAccessScopes)) {
return SCOPE_GROUP_FULL_ACCESS;
} else if (isSetEqual(scopes, readOnlyScopes)) {
Expand All @@ -73,7 +73,7 @@ const Scopes: React.FC<ScopesProps> = ({
}
}, [fullAccessScopes, onScopeChange, scopeGroup, scopes]);

const handleScopeGroupChange = (scopeGroup: ScopeGroupType) => {
const handleScopeGroupChange = (scopeGroup: ScopeGroup) => {
setScopeGroup(scopeGroup);
switch (scopeGroup) {
case SCOPE_GROUP_FULL_ACCESS:
Expand Down Expand Up @@ -109,7 +109,7 @@ const Scopes: React.FC<ScopesProps> = ({
SCOPE_GROUP_FULL_ACCESS,
SCOPE_GROUP_READ_ONLY,
SCOPE_GROUP_CUSTOM,
] as ScopeGroupType[]
] as ScopeGroup[]
).map((sg, index) => {
const ScopeGroupIcon = scopeGroupIconMap[sg];
return (
Expand Down
18 changes: 11 additions & 7 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,19 @@ export type ReadOnlyScope =
| "list_transactions"
| "notifications";

export type ScopeGroupType = "full_access" | "read_only" | "custom";
export type ScopeGroup = "full_access" | "read_only" | "custom";

export type Nip47NotificationType = "payment_received" | "payment_sent";

export type IconMap = {
[key in string]: LucideIcon;
export type ScopeIconMap = {
[key in Scope]: LucideIcon;
};

export const iconMap: IconMap = {
export type ScopeGroupIconMap = {
[key in ScopeGroup]: LucideIcon;
};

export const scopeIconMap: ScopeIconMap = {
[NIP_47_GET_BALANCE_METHOD]: WalletMinimal,
[NIP_47_GET_INFO_METHOD]: Info,
[NIP_47_LIST_TRANSACTIONS_METHOD]: NotebookTabs,
Expand All @@ -95,7 +99,7 @@ export const iconMap: IconMap = {
[NIP_47_NOTIFICATIONS_PERMISSION]: Bell,
};

export const scopeGroupIconMap: IconMap = {
export const scopeGroupIconMap: ScopeGroupIconMap = {
[SCOPE_GROUP_FULL_ACCESS]: ArrowDownUp,
[SCOPE_GROUP_READ_ONLY]: MoveDown,
[SCOPE_GROUP_CUSTOM]: SquarePen,
Expand Down Expand Up @@ -126,13 +130,13 @@ export const scopeDescriptions: Record<Scope, string> = {
[NIP_47_NOTIFICATIONS_PERMISSION]: "Receive wallet notifications",
};

export const scopeGroupTitle: Record<ScopeGroupType, string> = {
export const scopeGroupTitle: Record<ScopeGroup, string> = {
[SCOPE_GROUP_FULL_ACCESS]: "Full Access",
[SCOPE_GROUP_READ_ONLY]: "Read Only",
[SCOPE_GROUP_CUSTOM]: "Custom",
};

export const scopeGroupDescriptions: Record<ScopeGroupType, string> = {
export const scopeGroupDescriptions: Record<ScopeGroup, string> = {
[SCOPE_GROUP_FULL_ACCESS]: "Complete wallet control",
[SCOPE_GROUP_READ_ONLY]: "Only view wallet info",
[SCOPE_GROUP_CUSTOM]: "Define permissions",
Expand Down

0 comments on commit 7a07006

Please sign in to comment.