Skip to content

Commit

Permalink
allow locked in composite gates
Browse files Browse the repository at this point in the history
  • Loading branch information
julianjelfs committed Jul 24, 2024
1 parent 119b0ea commit e28c3f8
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 13 deletions.
4 changes: 2 additions & 2 deletions frontend/app/src/components/home/NoChatSelected.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import Button from "../Button.svelte";
import page from "page";
import { getContext } from "svelte";
import type { ChatListScope, OpenChat } from "openchat-client";
import { isLocked, type ChatListScope, type OpenChat } from "openchat-client";
import CommunityCard from "./communities/explore/CommunityCard.svelte";
import PreviewWrapper from "./communities/PreviewWrapper.svelte";
import { routeForScope } from "../../routes";
Expand All @@ -14,7 +14,7 @@
$: chatListScope = client.chatListScope;
$: selectedCommunity = client.selectedCommunity;
$: previewingCommunity = $selectedCommunity?.membership.role === "none";
$: locked = $selectedCommunity?.gate?.kind === "locked_gate";
$: locked = isLocked($selectedCommunity?.gate);
$: [title, message] = getMessageForScope($chatListScope.kind);
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/components/home/PreviewFooter.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { createEventDispatcher, getContext } from "svelte";
import Button from "../Button.svelte";
import type { MultiUserChat, OpenChat } from "openchat-client";
import { isLocked, type MultiUserChat, type OpenChat } from "openchat-client";
import { toastStore } from "../../stores/toast";
import page from "page";
import { routeForScope } from "../../routes";
Expand All @@ -20,7 +20,7 @@
$: selectedCommunity = client.selectedCommunity;
$: previewingCommunity = $selectedCommunity?.membership.role === "none";
$: gates = client.accessGatesForChat(chat);
$: locked = gates.some((g) => g.kind === "locked_gate");
$: locked = gates.some((g) => isLocked(g));
let freezingInProgress = false;
Expand Down
3 changes: 2 additions & 1 deletion frontend/app/src/components/home/RecommendedGroup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import {
AvatarSize,
type GroupChatSummary,
isLocked,
type MultiUserChat,
type OpenChat,
routeForChatIdentifier,
Expand Down Expand Up @@ -31,7 +32,7 @@
$: chatListScope = client.chatListScope;
$: chatSummariesStore = client.chatSummariesStore;
$: member = $chatSummariesStore.has(group.id);
$: locked = group.gate.kind === "locked_gate";
$: locked = isLocked(group.gate);
function dismiss({ id }: GroupChatSummary) {
dispatch("dismissRecommendation", id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
<div class="section">
<div class="section-title">{$_("access.chooseGate")}</div>
<div class="choose-gate">
<AccessGateSummary
showNoGate={true}
bind:valid
{level}
editable={gate.kind !== "locked_gate"}
bind:gate />
<AccessGateSummary showNoGate={true} bind:valid {level} editable bind:gate />
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@
.info {
@include font(book, normal, fs-90, 22);
color: var(--txt-light);
}
.section-title {
Expand Down
8 changes: 8 additions & 0 deletions frontend/app/src/utils/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function getGateBindings(): GateBinding[] {
balanceGateFolder,
credentialGate,
uniquePersonGate,
lockedGate,
nftGate,
];
}
Expand Down Expand Up @@ -130,6 +131,13 @@ export const uniquePersonGate: GateBinding = {
enabled: true,
};

export const lockedGate: GateBinding = {
label: "access.lockedGate",
key: "locked_gate",
gate: { kind: "locked_gate" },
enabled: true,
};

export const neuronGateFolder: GateBinding = {
label: "access.neuronHolder",
key: "neuron_gate_folder",
Expand Down
10 changes: 10 additions & 0 deletions frontend/openchat-agent/src/services/common/chatMappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,7 @@ export function apiMaybeAccessGate(domain: AccessGate): [] | [ApiAccessGate] {
if (domain.kind === "no_gate") return [];
if (domain.kind === "nft_gate") return []; // TODO
if (domain.kind === "diamond_gate") return [{ DiamondMember: null }];
if (domain.kind === "locked_gate") return [{ Locked: null }];
if (domain.kind === "credential_gate")
return [
{
Expand Down Expand Up @@ -1664,6 +1665,7 @@ export function apiMaybeAccessGate(domain: AccessGate): [] | [ApiAccessGate] {
}

export function apiAccessGate(domain: AccessGate): ApiAccessGate {
if (domain.kind === "locked_gate") return { Locked: null };
if (domain.kind === "diamond_gate") return { DiamondMember: null };
if (domain.kind === "lifetime_diamond_gate") return { LifetimeDiamondMember: null };
if (domain.kind === "unique_person_gate") return { UniquePerson: null };
Expand Down Expand Up @@ -1763,6 +1765,11 @@ export function accessGate(candid: ApiAccessGate): AccessGate {
kind: "diamond_gate",
};
}
if ("Locked" in candid) {
return {
kind: "locked_gate",
};
}
if ("LifetimeDiamondMember" in candid) {
return {
kind: "lifetime_diamond_gate",
Expand Down Expand Up @@ -2162,6 +2169,9 @@ export function gateCheckFailedReason(candid: ApiGateCheckFailedReason): GateChe
console.warn("FailedVerifiedCredentialCheck: ", candid);
return "failed_verified_credential_check";
}
if ("Locked" in candid) {
return "locked";
}
throw new UnsupportedValueError("Unexpected ApiGateCheckFailedReason type received", candid);
}

Expand Down
16 changes: 15 additions & 1 deletion frontend/openchat-shared/src/domain/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,21 @@ export function shouldPreprocessGate(gate: AccessGate): gate is PreprocessedGate
].includes(gate.kind);
}

export function isLockedGate(gate: AccessGate): gate is LockedGate {
export function isLocked(gate: AccessGate | undefined): boolean {
if (gate === undefined) return false;
if (isCompositeGate(gate)) {
switch (gate.operator) {
case "and":
return gate.gates.some(isLockedGate);
case "or":
return gate.gates.every(isLockedGate);
}
} else {
return isLockedGate(gate);
}
}

function isLockedGate(gate: AccessGate): gate is LockedGate {
return gate.kind === "locked_gate";
}

Expand Down
3 changes: 2 additions & 1 deletion frontend/openchat-shared/src/domain/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,8 @@ export type GateCheckFailedReason =
| "insufficient_balance"
| "failed_verified_credential_check"
| "no_unique_person_proof"
| "not_lifetime_diamond";
| "not_lifetime_diamond"
| "locked";

export type ChatFrozenEvent = {
kind: "chat_frozen";
Expand Down

0 comments on commit e28c3f8

Please sign in to comment.