Skip to content

Commit

Permalink
Feature: ENFT Improvements (#206)
Browse files Browse the repository at this point in the history
* added existentialNFT property into json config

* build enft with config

* depoy fn dependencies

* builder widgetPreview default value for existentialNFT

* existentialNFT is optional

* remove console.log

* todo for watchAsset

* input instead of infer

* disable paymentoptions changes if enft is deployed

* change warning text

* better warnings

* fix types

* fix WidgetPreview type

* existentialNFT optional

* recaptcha onExpired

* Fix up tests

* update changeset

---------

Co-authored-by: elvijsTDL <[email protected]>
Co-authored-by: Kaspar Kallas <[email protected]>
  • Loading branch information
3 people authored Jan 26, 2024
1 parent 0565290 commit 8801171
Show file tree
Hide file tree
Showing 27 changed files with 836 additions and 3,515 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Typography,
} from "@mui/material";
import {
existentialNFTSchema,
paymentDetailsSchema,
personalDataSchema,
productDetailsSchema,
Expand All @@ -36,6 +37,7 @@ const schema = z.object({
productDetails: productDetailsSchema,
paymentDetails: paymentDetailsSchema,
personalData: personalDataSchema,
existentialNFT: existentialNFTSchema,
type: z.enum(["dialog", "drawer", "full-screen", "page"]),
});

Expand Down Expand Up @@ -106,6 +108,7 @@ const ConfigEditor: FC<ConfigEditorProps> = ({ value, setValue }) => {
setValue("type", parseResult.data.type);
setValue("paymentDetails", parseResult.data.paymentDetails);
setValue("personalData", parseResult.data.personalData);
setValue("existentialNFT", parseResult.data.existentialNFT);
setSaved(true);
setTimeout(() => {
setSaved(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,29 @@ import {
Stack,
Typography,
} from "@mui/material";
import { ChainId } from "@superfluid-finance/widget";
import { ExistentialNFT } from "@superfluid-finance/widget";
import Image from "next/image";
import { FC, useCallback, useMemo } from "react";
import { Address } from "viem";

import Link from "../../Link";

type NFTDeploymentDialogProps = {
cloneAddresses: Record<ChainId, Address | null>[];
cloneAddresses?: ExistentialNFT["deployments"];
open: boolean;
onClose: () => void;
onClose?: () => void;
};

const NFTDeploymentDialog: FC<NFTDeploymentDialogProps> = ({
cloneAddresses,
cloneAddresses = {},
open,
onClose,
}) => {
const exportAddresses = useCallback(() => {
const csv = "data:text/csv;charset=utf-8,";
const headers = "chainId,address\n";
const rows = cloneAddresses
const rows = Object.entries(cloneAddresses)
.map((row) => {
const result = Object.entries(row);

return result.join(",");
return row.join(",");
})
.join("\n");

Expand All @@ -50,7 +47,8 @@ const NFTDeploymentDialog: FC<NFTDeploymentDialogProps> = ({
const [successfulDeployments, failedDeployments] = useMemo(() => {
const succesfulDeployments =
Object.values(cloneAddresses).filter(Boolean).length;
const failedDeployments = cloneAddresses.length - succesfulDeployments;
const failedDeployments =
Object.values(cloneAddresses).length - succesfulDeployments;

return [succesfulDeployments, failedDeployments];
}, [cloneAddresses]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import AddIcon from "@mui/icons-material/Add";
import AutoFixHighIcon from "@mui/icons-material/AutoFixHigh";
import CloseIcon from "@mui/icons-material/Close";
import {
Alert,
AlertTitle,
AppBar,
Box,
Button,
Expand All @@ -19,7 +21,8 @@ import {
Zoom,
} from "@mui/material";
import { PaymentOption } from "@superfluid-finance/widget";
import { FC, useCallback, useEffect, useState } from "react";
import isEmpty from "lodash/isEmpty";
import { FC, useCallback, useEffect, useMemo, useState } from "react";
import { Controller, useFieldArray, useFormContext } from "react-hook-form";

import useDemoMode from "../../hooks/useDemoMode";
Expand All @@ -36,7 +39,10 @@ const ProductEditor: FC = () => {
name: "paymentDetails.paymentOptions", // unique name for your Field Array
});

const [paymentOptions] = watch(["paymentDetails.paymentOptions"]);
const [paymentOptions, existentialNFT] = watch([
"paymentDetails.paymentOptions",
"existentialNFT",
]);

const [dialogMode, setDialogMode] = useState<"add" | "clone" | "edit">();
const [targetedPaymentOption, setTargetedPaymentOption] = useState<{
Expand All @@ -60,6 +66,11 @@ const ProductEditor: FC = () => {
setDemoPaymentDetails();
}, []);

const isENFTDeployed = useMemo(
() => !isEmpty(existentialNFT?.deployments),
[existentialNFT],
);

return (
<>
<Stack direction="column" gap={2}>
Expand All @@ -71,6 +82,17 @@ const ProductEditor: FC = () => {
Enter your preferred payment options to start receiving ongoing
real-time payments powered by the Superfluid Protocol.
</Typography>

{isENFTDeployed && (
<Alert
severity="warning"
sx={{ backgroundColor: "warning.light", mt: 2 }}
>
<AlertTitle>Warning</AlertTitle>
You deployed a Gating NFT contract so you can no longer add new
networks in the payment options
</Alert>
)}
</Box>
<Stack direction="column">
<Stack
Expand Down Expand Up @@ -99,6 +121,7 @@ const ProductEditor: FC = () => {
variant="contained"
size="medium"
color="primary"
disabled={isENFTDeployed}
onClick={() => {
setDialogMode("add");
}}
Expand Down Expand Up @@ -135,6 +158,7 @@ const ProductEditor: FC = () => {
receiverAddress={receiverAddress}
superToken={superToken}
chainId={chainId}
actionsDisabled={isENFTDeployed}
index={i}
clone={(index) => {
setTargetedPaymentOption({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type PaymentOptionViewProps = {
flowRate: FlowRate | undefined;
receiverAddress: `0x${string}`;
chainId: ChainId;
actionsDisabled?: boolean;
index: number;
clone: (index: number) => void;
edit: (index: number) => void;
Expand All @@ -74,6 +75,7 @@ const PaymentOptionView: FC<PaymentOptionViewProps> = ({
flowRate,
receiverAddress: receiverAddress_,
chainId,
actionsDisabled,
index,
clone,
edit,
Expand Down Expand Up @@ -191,6 +193,7 @@ const PaymentOptionView: FC<PaymentOptionViewProps> = ({
>
<Tooltip title="Edit payment option" arrow>
<IconButton
disabled={actionsDisabled}
data-testid="edit-payment-option-button"
onClick={() => edit(index)}
sx={{
Expand All @@ -205,6 +208,7 @@ const PaymentOptionView: FC<PaymentOptionViewProps> = ({

<Tooltip title="Copy payment option" arrow>
<IconButton
disabled={actionsDisabled}
data-testid="clone-payment-option-button"
onClick={() => clone(index)}
sx={{
Expand All @@ -219,6 +223,7 @@ const PaymentOptionView: FC<PaymentOptionViewProps> = ({

<Tooltip title="Delete payment option" arrow>
<IconButton
disabled={actionsDisabled}
data-testid="delete-payment-option-button"
onClick={() => remove(index)}
sx={{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import AutoFixHighIcon from "@mui/icons-material/AutoFixHigh";
import {
Box,
Fab,
Stack,
TextField,
Tooltip,
Typography,
} from "@mui/material";
import { Box, Fab, Stack, TextField, Tooltip, Typography } from "@mui/material";
import {
PersonalDataField,
PersonalDataFieldType,
Expand Down
Loading

3 comments on commit 8801171

@vercel
Copy link

@vercel vercel bot commented on 8801171 Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 8801171 Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 8801171 Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.