Skip to content

Commit

Permalink
Delegation setup flow (#481)
Browse files Browse the repository at this point in the history
* Delegation setup flow

* Zero address fallback

* Updated top issue icons
  • Loading branch information
andreitr authored Sep 3, 2024
1 parent c6b957a commit 806d967
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/app/api/common/metrics/getMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { cache } from "react";

async function getMetrics() {
const { namespace, contracts } = Tenant.current();
const totalSupply = await contracts.token.contract.totalSupply();

try {
const totalSupply = await contracts.token.contract.totalSupply();
const votableSupply = await prisma[`${namespace}VotableSupply`].findFirst(
{}
);
Expand All @@ -18,7 +18,7 @@ async function getMetrics() {
// Handle prisma errors for new tenants
return {
votableSupply: "0",
totalSupply: totalSupply.toString(),
totalSupply: "0",
};
}
}
Expand Down
28 changes: 16 additions & 12 deletions src/app/info/components/InfoHero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import Image, { StaticImageData } from "next/image";
import Link from "next/link";
import Tenant from "@/lib/tenant/tenant";
import { icons } from "@/assets/icons/icons";
import { TENANT_NAMESPACES } from "@/lib/constants";

export const InfoHero = () => {
const { ui } = Tenant.current();
const { ui, namespace } = Tenant.current();
const page = ui!.page("info");

const rotationClasses = ["-rotate-2", "rotate-4", "-rotate-5", "rotate-1"];
Expand All @@ -20,17 +21,20 @@ export const InfoHero = () => {
{page!.description}
</p>
</div>
<div className="flex flex-row">
{page!.links!.map((link, idx) => (
<Card
className={rotationClasses[idx % rotationClasses.length]}
image={link.image || ""}
key={`card-${idx}`}
link={link.url}
linkText={link.title}
/>
))}
</div>

{namespace !== TENANT_NAMESPACES.SCROLL && (
<div className="flex flex-row">
{page!.links!.map((link, idx) => (
<Card
className={rotationClasses[idx % rotationClasses.length]}
image={link.image || ""}
key={`card-${idx}`}
link={link.url}
linkText={link.title}
/>
))}
</div>
)}
</div>
);
};
Expand Down
26 changes: 19 additions & 7 deletions src/components/Dialogs/DelegateDialog/DelegateDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function DelegateDialog({
addressOrENSName: string
) => Promise<DelegateePayload | null>;
}) {
const { contracts, slug } = Tenant.current();
const { ui, contracts, slug, token } = Tenant.current();

const { address: accountAddress } = useAccount();

Expand All @@ -42,6 +42,8 @@ export function DelegateDialog({
const { setRefetchDelegate } = useConnectButtonContext();
const sameDelegatee = delegate.address === delegatee?.delegatee;

const isDisabledInTenant = ui.toggle("delegates/delegate")?.enabled === false;

const { data: delegateEnsName } = useEnsName({
chainId: 1,
address: delegate.address as `0x${string}`,
Expand Down Expand Up @@ -71,16 +73,26 @@ export function DelegateDialog({
setIsReady(false);
if (!accountAddress) return;

const vp = await fetchBalanceForDirectDelegation(accountAddress);
setVotingPower(vp.toString());

const direct = await fetchDirectDelegatee(accountAddress);
setDelegatee(direct);
try {
const vp = await fetchBalanceForDirectDelegation(accountAddress);
setVotingPower(vp.toString());

setIsReady(true);
const direct = await fetchDirectDelegatee(accountAddress);
setDelegatee(direct);
} finally {
setIsReady(true);
}
}, [fetchBalanceForDirectDelegation, accountAddress, fetchDirectDelegatee]);

const renderActionButtons = () => {
if (isDisabledInTenant) {
return (
<Button disabled={true}>
{token.symbol} delegation is disabled at this time
</Button>
);
}

if (sameDelegatee) {
return (
<ShadcnButton variant="outline" className="cursor-not-allowed">
Expand Down
7 changes: 6 additions & 1 deletion src/hooks/useConnectedDelegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { useConnectButtonContext } from "@/contexts/ConnectButtonContext";
import { useQuery } from "@tanstack/react-query";
import { timeout } from "@/lib/utils";
import { fetchDelegate } from "@/app/delegates/actions";
import Tenant from "@/lib/tenant/tenant";
import { ZERO_ADDRESS } from "@/lib/constants";

/**
* Define maximum number of retries, max retries 10 means 180 seconds waiting in total (advanced delegation voting power
Expand All @@ -18,13 +20,16 @@ const MAX_RETRIES = 10;
// TODO: think about strategy to fetch, since balance and voting power can change on every block,
// also to prevent additional unnecessary fetches being done right now
const useConnectedDelegate = () => {
const { contracts } = Tenant.current();
const isTestToken = contracts.token.address === ZERO_ADDRESS;

const { refetchDelegate, setRefetchDelegate } = useConnectButtonContext();
const { address } = useAccount();
const [retries, setRetries] = useState<number>(0);
const [lastVotingPower, setLastVotingPower] = useState<string | null>(null);

const data = useQuery({
enabled: !!address,
enabled: !(!address || isTestToken),
queryKey: ["useConnectedDelegate", address, refetchDelegate, retries],
queryFn: async () => {
const [delegate, advancedDelegators, balance] =
Expand Down
3 changes: 3 additions & 0 deletions src/icons/beaker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/icons/codeBracketSquare.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/icons/globeAlt.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/icons/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,23 @@ import vote from "./vote.svg";
import wallet from "./wallet.svg";
import walletConnected from "./walletConnected.svg";
import world from "./world.svg";
import wrenchScrewdriverIcon from "./wrenchScredriver.svg";
import globeAlt from "./globeAlt.svg";
import presentationChartLine from "./presentationChartLine.svg";
import scale from "./scale.svg";
import codeBracketSquare from "./codeBracketSquare.svg";
import beaker from "./beaker.svg";
import shieldCheck from "./shieldCheck.svg";

export const icons = {
anonNoun,
badge,
scale,
codeBracketSquare,
beaker,
shieldCheck,
wrenchScrewdriverIcon,
presentationChartLine,
ballot,
banknotes,
cardView,
Expand All @@ -58,6 +71,7 @@ export const icons = {
expand,
github,
globe,
globeAlt,
info,
link,
liquid,
Expand Down
3 changes: 3 additions & 0 deletions src/icons/presentationChartLine.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/icons/scale.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/icons/shieldCheck.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/icons/wrenchScredriver.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export const INDEXER_DELAY = 3000;

export const SECONDS_IN_HOUR = 3600;

export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";

export enum FREQUENCY_FILTERS {
DAY = "24h",
WEEK = "7d",
Expand Down
7 changes: 4 additions & 3 deletions src/lib/tenant/configs/contracts/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { scroll } from "viem/chains";

import { IGovernorContract } from "@/lib/contracts/common/interfaces/IGovernorContract";
import { JsonRpcProvider } from "ethers";
import { ZERO_ADDRESS } from "@/lib/constants";

interface Props {
isProd: boolean;
Expand All @@ -19,9 +20,9 @@ export const scrollTenantContractConfig = ({
isProd,
alchemyId,
}: Props): TenantContracts => {
const TOKEN = "0x5300000000000000000000000000000000000004";
const GOVERNOR = "0x0000000000000000000000000000000000000000";
const TREASURY = "0x0000000000000000000000000000000000000000";
const TOKEN = ZERO_ADDRESS;
const GOVERNOR = ZERO_ADDRESS;
const TREASURY = ZERO_ADDRESS;
const provider = new JsonRpcProvider(
`https://scroll-mainnet.g.alchemy.com/v2/${alchemyId}`
);
Expand Down
49 changes: 48 additions & 1 deletion src/lib/tenant/configs/ui/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,49 @@ export const scrollTenantUIConfig = new TenantUI({
brandSecondary: "#F2F2F2",
},

governanceIssues: [
{
icon: "wrenchScrewdriverIcon",
title: "Builders",
key: "builders",
},
{
icon: "community",
title: "Community",
key: "community",
},
{
icon: "globeAlt",
title: "Decentralization",
key: "decentralization",
},
{
icon: "presentationChartLine",
title: "Ecosystem Growth",
key: "ecosystemGrowth",
},
{
icon: "scale",
title: "Governance",
key: "governance",
},
{
icon: "codeBracketSquare",
title: "Protocol",
key: "protocol",
},
{
icon: "beaker",
title: "Research & Development",
key: "researchDevelopment",
},
{
icon: "shieldCheck",
title: "Security",
key: "security",
},
],

pages: [
{
route: "/",
Expand Down Expand Up @@ -148,12 +191,16 @@ export const scrollTenantUIConfig = new TenantUI({
},
{
name: "delegates/endorsed-filter",
enabled: true,
enabled: false,
},
{
name: "delegates/edit",
enabled: true,
},
{
name: "delegates/delegate",
enabled: false,
},
{
name: "delegates/code-of-conduct",
enabled: true,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/tenant/tenantTokenFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class TenantTokenFactory {
case TENANT_NAMESPACES.SCROLL:
return {
name: "Scroll",
symbol: "SCROLL",
symbol: "SCR",
decimals: 18,
};
default:
Expand Down

0 comments on commit 806d967

Please sign in to comment.