Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rm: lit is optional #3414

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/builder/src/actions/roundApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,16 @@ const dispatchAndLogApplicationError = (
dispatch(applicationError(roundAddress, error, step));
};

export function chainIdToChainName(chainId: number): string {
export function chainIdToChainName(chainId: number): string | undefined {
// eslint-disable-next-line no-restricted-syntax
for (const name in LitJsSdk.LIT_CHAINS) {
if (LitJsSdk.LIT_CHAINS[name].chainId === chainId) {
return name;
}
}

throw new Error(`couldn't find LIT chain name for chainId ${chainId}`);
return undefined;
// throw new Error(`couldn't find LIT chain name for chainId ${chainId}`);
}

const applyToRound =
Expand Down
23 changes: 13 additions & 10 deletions packages/builder/src/utils/RoundApplicationBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,34 @@ export default class RoundApplicationBuilder {

private roundAddress: string;

private chainName: string;

private lit: Lit;
private lit?: Lit;

constructor(
enableEncryption: boolean,
project: Project,
ram: RoundApplicationMetadata,
roundAddress: string,
chainName: string
chainName?: string
) {
this.enableEncryption = enableEncryption;
this.project = project;
this.ram = ram;
this.roundAddress = roundAddress;
this.chainName = chainName;
const litInit = {
chain: chainName,
contract: this.roundAddress,
};

this.lit = new Lit(litInit);
if (chainName) {
const litInit = {
chain: chainName,
contract: this.roundAddress,
};
this.lit = new Lit(litInit);
}
}

async encryptAnswer(answer: string) {
if (!this.lit) {
throw new Error("lit not initialized");
}

if (!this.enableEncryption) {
return {
ciphertext: answer,
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/allo/backends/allo-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,9 @@ export class AlloV2 implements Allo {
token,
amount: 0n, // we send 0 tokens to the pool, we fund it later
metadata: { protocol: 1n, pointer: roundIpfsResult.value },
managers: args.roundData.roundOperators ?? [],
managers: (args.roundData.roundOperators ?? []).map((operator) =>
getAddress(operator)
),
};

const txData = this.allo.createPool(createPoolArgs);
Expand Down
10 changes: 10 additions & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,13 @@ export function isChainIdSupported(chainId: number) {
}
return Object.values(ChainId).includes(chainId);
}

export function isLitUnavailable(chainId: number) {
return [
ChainId.LUKSO_TESTNET,
ChainId.LUKSO,
ChainId.CELO,
ChainId.CELO_ALFAJORES,
ChainId.SEI_DEVNET,
].includes(chainId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { SchemaQuestion, typeToText } from "../api/utils";
import BaseSwitch from "./BaseSwitch";
import { InputIcon } from "./InputIcon";
import Option from "./Option";
import { useWallet } from "./Auth";
import { isLitUnavailable } from "common";

const INITIAL_VALUE = "Select a type";

Expand Down Expand Up @@ -38,6 +40,8 @@ function AddQuestionModal({
}: AddQuestionModalProps) {
const questionExists = question && question.index !== undefined;

const { chain } = useWallet();

const [isOpen, setIsOpen] = useState(show);
const initialQuestion = question;
const [questionOptions, setQuestionOptions] = useState<SchemaQuestion>({
Expand Down Expand Up @@ -82,6 +86,7 @@ function AddQuestionModal({
<BaseSwitch
testid="encrypted-toggle"
key="encrypted"
disabled={isLitUnavailable(chain.id)}
activeLabel="Encrypted"
inactiveLabel="Not Encrypted"
value={
Expand Down
7 changes: 6 additions & 1 deletion packages/round-manager/src/features/common/BaseSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ const BaseSwitch = ({
value,
handler,
testid,
disabled = false,
}: {
activeLabel: string;
inactiveLabel: string;
value: boolean;
handler: (a: boolean) => void;
testid: string;
disabled?: boolean;
}) => (
<Switch.Group
as="div"
className={classNames("flex items-center justify-end")}
className={classNames(
`flex items-center justify-end ${disabled ? "opacity-50" : ""}`
)}
>
<span className="flex-grow">
<Switch.Label
Expand All @@ -46,6 +50,7 @@ const BaseSwitch = ({
</Switch.Label>
</span>
<Switch
disabled={disabled}
data-testid={testid}
className="focus:outline-0! bg-gray-200 relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out"
onChange={handler}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
LockOpenIcon,
} from "@heroicons/react/outline";
import { PencilIcon, PlusSmIcon, XIcon } from "@heroicons/react/solid";
import { useAllo } from "common";
import { isLitUnavailable, useAllo } from "common";
import { Button } from "common/src/styles";
import { RoundCategory } from "data-layer";
import _ from "lodash";
Expand Down Expand Up @@ -44,7 +44,7 @@ import { InputIcon } from "../common/InputIcon";
import PreviewQuestionModal from "../common/PreviewQuestionModal";
import ProgressModal from "../common/ProgressModal";

export const initialQuestionsQF: SchemaQuestion[] = [
export const getInitialQuestionsQF = (chainId: number) => [
{
id: 0,
title: "Payout Wallet Address",
Expand All @@ -59,7 +59,7 @@ export const initialQuestionsQF: SchemaQuestion[] = [
id: 1,
title: "Email Address",
required: true,
encrypted: true,
encrypted: !isLitUnavailable(chainId),
hidden: true,
type: "email",
},
Expand All @@ -81,12 +81,12 @@ export const initialQuestionsQF: SchemaQuestion[] = [
},
];

export const initialQuestionsDirect: SchemaQuestion[] = [
export const getInitialQuestionsDirect = (chainId: number) => [
{
id: 1,
title: "Email Address",
required: true,
encrypted: true,
encrypted: !isLitUnavailable(chainId),
hidden: true,
type: "email",
fixed: true,
Expand Down Expand Up @@ -185,7 +185,7 @@ export function RoundApplicationForm(props: {
const [openPreviewModal, setOpenPreviewModal] = useState(false);
const [openAddQuestionModal, setOpenAddQuestionModal] = useState(false);
const [toEdit, setToEdit] = useState<EditQuestion | undefined>();
const { signer: walletSigner } = useWallet();
const { signer: walletSigner, chain } = useWallet();

const { currentStep, setCurrentStep, stepsCount, formData } =
useContext(FormContext);
Expand All @@ -206,8 +206,8 @@ export function RoundApplicationForm(props: {
const defaultQuestions: ApplicationMetadata["questions"] = questionsArg
? questionsArg
: roundCategory === RoundCategory.QuadraticFunding
? initialQuestionsQF
: initialQuestionsDirect;
? getInitialQuestionsQF(chain.id)
: getInitialQuestionsDirect(chain.id);

const { control, handleSubmit } = useForm<Round>({
defaultValues: {
Expand Down
Loading