Skip to content

Commit

Permalink
feat(customization): update custom dashboard for scroll (#2647)
Browse files Browse the repository at this point in the history
* feat(customization): update custom dashboard for scroll

* feat(customization): add button background color

* feat(customization): properly configure on chain button

* feat(customization): minor changes

* 2614 scroll endpoints (#2624)

* Added an endpoint to check eligibility for minting a badge.

* Added a function to check badge eligibility using the Gitcoin Passport Decoder contract.

* Revert "Added a function to check badge eligibility using the Gitcoin Passport Decoder contract."

This reverts commit dd476c42a0f09d736e07ee0e738be69bb5435072.

* Moved the `verifyAttestation` function to a separate `eas.ts` file and updated the `verifyCoinbaseAttestation` function to use the new function.

* feat: claim endpoint

* feat: upgradeing eas & ethers lib, continue work on the  API

* chore(iam): globally upgrade to ethers v6

* fix: remaining tests

* Update node version in ci.yml

* fix: failing test, have upgrdated typescript target to es2020

* fix: linter complaints

* Update node version in job check-provider-bitmap in ci.yml

* feat: upgrading node version acorss all workflow files

* fix: linter issues in app

* fix: remove logs in iam

* fix: remaining build isues with ethers upgrade

* feat: parse score from eas scan

* fix: pass passport attester to endpoint and error handling

* chore: fix serialization

* chore: mock getattestations

---------

Co-authored-by: Gerald Iakobinyi-Pich <nutrina9@gmail.com>

* feat: adding debug statements for review (#2643)

* Revert ethers scroll updates (#2651)

* Revert "feat: adding debug statements for review (#2643)"

This reverts commit dbf7b72.

* Revert "2614 scroll endpoints (#2624)"

This reverts commit 5451968.

* feat(customization): wip fix tests

* feat(customization): fix tests

* feat(customization): modify button action type

* feat(customization): add type for button action type

---------

Co-authored-by: Tim <6887938+digitalmnt@users.noreply.github.com>
Co-authored-by: Gerald Iakobinyi-Pich <nutrina9@gmail.com>
  • Loading branch information
3 people committed Jul 2, 2024
1 parent 8a37840 commit 9c0ed7d
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 5 deletions.
4 changes: 4 additions & 0 deletions app/__tests__/hooks/useCustomization.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ jest.mock("axios", () => {
customizationBackground1: "232 65 66",
customizationBackground2: "0 0 0",
customizationForeground1: "255 255 255",
customizationForeground2: "255 255 255",
customizationBackground3: "255 136 70",
},
},
},
Expand Down Expand Up @@ -107,6 +109,8 @@ jest.mock("axios", () => {
customizationBackground1: "255 136 70",
customizationBackground2: "255 136 70",
customizationForeground1: "255 255 255",
customizationForeground2: "255 255 255",
customizationBackground3: "255 136 70",
},
},
},
Expand Down
59 changes: 54 additions & 5 deletions app/components/CustomDashboardPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import React, { useMemo } from "react";
import React, { useMemo, useState, Ref, ReactElement, JSXElementConstructor } from "react";
import { VeraxPanel } from "../components/VeraxPanel";
import { TestingPanel } from "../components/TestingPanel";
import { Button } from "../components/Button";
import { CustomizationLogoBackground } from "../utils/customizationUtils";
import { useCustomization } from "../hooks/useCustomization";
import { OnchainSidebar } from "./OnchainSidebar";
import { ExclamationCircleIcon } from "@heroicons/react/24/solid";
import { Popover } from "@headlessui/react";
import { usePopper } from "react-popper";
import { renderToString } from "react-dom/server";

type CustomDashboardPanelProps = {
logo: {
Expand Down Expand Up @@ -63,6 +68,20 @@ export const CustomDashboardPanel = ({ logo, className, children }: CustomDashbo

export const DynamicCustomDashboardPanel = ({ className }: { className: string }) => {
const customization = useCustomization();
const [showSidebar, setShowSidebar] = useState<boolean>(false);
const [referenceElement, setReferenceElement] = useState(null);
const [popperElement, setPopperElement] = useState(null);

const { styles, attributes } = usePopper(referenceElement, popperElement, {
modifiers: [
{
name: "preventOverflow",
options: {
padding: 24,
},
},
],
});

if (customization.key === "verax") {
return <VeraxPanel className={className} />;
Expand All @@ -71,20 +90,50 @@ export const DynamicCustomDashboardPanel = ({ className }: { className: string }
if (customization.key === "testing") {
return <TestingPanel className={className} />;
}

const { logo, body } = customization.dashboardPanel;

const onButtonClick = () => {
if (body.action?.type === "Onchain Push") {
setShowSidebar(true);
} else {
window.open(body.action.url, "_blank");
}
};
return (
<CustomDashboardPanel className={className} logo={logo}>
<div>{body.mainText}</div>
{body.displayInfoTooltip && body.displayInfoTooltip.shouldDisplay && body.displayInfoTooltip.text ? (
<Popover className={`group cursor-pointer px-2 self-end absolute top-0 right-0 p-2`}>
<Popover.Button as="div" ref={setReferenceElement as unknown as Ref<HTMLButtonElement>}>
<div className="mr-4 w-4 self-end">
<ExclamationCircleIcon height={24} color={"rgb(var(--color-customization-background-1))"} />
</div>
</Popover.Button>
<Popover.Panel
ref={setPopperElement as unknown as Ref<HTMLDivElement>}
className={`invisible z-20 max-w-screen-md rounded-md border border-customization-background-1 bg-background text-sm text-color-1 group-hover:visible`}
style={styles.popper}
{...attributes.popper}
static
>
<div className="px-4 py-2">{body.displayInfoTooltip.text}</div>
</Popover.Panel>
</Popover>
) : null}
<div
dangerouslySetInnerHTML={{
__html: renderToString(body.mainText as ReactElement<any, string | JSXElementConstructor<any>>) || "",
}}
/>

<div className="text-sm grow">{body.subText}</div>
<Button
variant="custom"
className={`rounded-s mr-2 mt-2 w-fit self-end bg-customization-background-1 text-customization-foreground-1 hover:bg-customization-background-1/75 enabled:hover:text-color-1 disabled:bg-customization-background-1 disabled:brightness-100`}
onClick={() => window.open(body.action.url, "_blank")}
className={`rounded-s mr-2 mt-2 w-fit self-end bg-customization-background-3 text-customization-foreground-2 hover:bg-customization-background-3/75 disabled:bg-customization-background-1 disabled:brightness-100`}
onClick={onButtonClick}
>
{body.action.text}
</Button>
<OnchainSidebar isOpen={showSidebar} onClose={() => setShowSidebar(false)} />
</CustomDashboardPanel>
);
};
2 changes: 2 additions & 0 deletions app/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ module.exports = {
// colors defined by an API call
"customization-background-1": "rgb(var(--color-customization-background-1) / <alpha-value>)",
"customization-background-2": "rgb(var(--color-customization-background-2) / <alpha-value>)",
"customization-background-3": "rgb(var(--color-customization-background-3) / <alpha-value>)",
"customization-foreground-1": "rgb(var(--color-customization-foreground-1) / <alpha-value>)",
"customization-foreground-2": "rgb(var(--color-customization-foreground-2) / <alpha-value>)",

// Temporary, to be removed
accent: "#000",
Expand Down
16 changes: 16 additions & 0 deletions app/utils/customizationUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const initializeDOMPurify = () => {
};

export type CustomizationLogoBackground = "dots" | "none";
export type BodyActionType = "Simple Link" | "Onchain Push";

export type Customization = {
key: string;
Expand All @@ -38,6 +39,11 @@ export type Customization = {
action: {
text: string;
url: string;
type?: BodyActionType;
};
displayInfoTooltip?: {
shouldDisplay?: boolean;
text?: string;
};
};
};
Expand Down Expand Up @@ -77,6 +83,11 @@ type CustomizationResponse = {
action?: {
text?: string;
url?: string;
type?: BodyActionType;
};
displayInfoTooltip?: {
shouldDisplay?: boolean;
text?: string;
};
};
};
Expand Down Expand Up @@ -141,6 +152,11 @@ export const requestCustomizationConfig = async (customizationKey: string): Prom
action: {
text: customizationResponse.dashboardPanel?.body?.action?.text || "",
url: sanitize(customizationResponse.dashboardPanel?.body?.action?.url || ""),
type: customizationResponse.dashboardPanel?.body?.action?.type,
},
displayInfoTooltip: {
shouldDisplay: customizationResponse.dashboardPanel?.body?.displayInfoTooltip?.shouldDisplay || false,
text: customizationResponse.dashboardPanel?.body?.displayInfoTooltip?.text || "",
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions app/utils/theme/setCustomizationTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const setCustomizationTheme = ({ colors }: CustomizationTheme) => {
r.style.setProperty("--color-customization-background-1", convertHexToRGB(colors.customizationBackground1));
r.style.setProperty("--color-customization-background-2", convertHexToRGB(colors.customizationBackground2));
r.style.setProperty("--color-customization-foreground-1", convertHexToRGB(colors.customizationForeground1));
r.style.setProperty("--color-customization-foreground-2", convertHexToRGB(colors.customizationForeground2));
r.style.setProperty("--color-customization-background-3", convertHexToRGB(colors.customizationBackground3));
};

const convertHexToRGB = (color: string) => {
Expand Down
2 changes: 2 additions & 0 deletions app/utils/theme/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ export type CustomizationTheme = {
customizationBackground1: string;
customizationBackground2: string;
customizationForeground1: string;
customizationForeground2: string;
customizationBackground3: string;
};
};

0 comments on commit 9c0ed7d

Please sign in to comment.