Skip to content

Commit f7a4304

Browse files
committed
add addresses and filter by supported chains
1 parent 14fdb9c commit f7a4304

File tree

4 files changed

+104
-33
lines changed

4 files changed

+104
-33
lines changed

packages/grant-explorer/src/features/round/DonateToGitcoin/components/DonateToGitcoinContent.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ import {
77
} from "common";
88
import { useState, useRef, useEffect, useMemo } from "react";
99

10-
import { useDonateToGitcoin } from "../../DonateToGitcoinContext";
10+
import {
11+
useDonateToGitcoin,
12+
GITCOIN_RECIPIENT_CONFIG,
13+
} from "../../DonateToGitcoinContext";
1114
import { DonationInput } from "./DonationInput";
1215

1316
import React from "react";
@@ -39,6 +42,7 @@ export const DonateToGitcoinContent = React.memo(
3942

4043
const [isOpen, setIsOpen] = useState(false);
4144
const dropdownRef = useRef<HTMLDivElement>(null);
45+
const [isInitialized, setIsInitialized] = useState(false);
4246

4347
const { votingTokens, tokenAmountInfo } = useMemo(() => {
4448
if (!tokenFilters) {
@@ -80,6 +84,20 @@ export const DonateToGitcoinContent = React.memo(
8084
const [error, setError] = useState<string | null>(null);
8185
const [isLoading, setIsLoading] = useState(false);
8286

87+
// Filter chains to only show Gitcoin supported ones
88+
const supportedChains = useMemo(
89+
() => chains.filter((chain) => chain.id in GITCOIN_RECIPIENT_CONFIG),
90+
[chains]
91+
);
92+
93+
// Handle initial setup
94+
useEffect(() => {
95+
if (supportedChains.length === 1 && !selectedChainId) {
96+
setSelectedChainId(supportedChains[0].id);
97+
}
98+
setIsInitialized(true);
99+
}, [supportedChains, selectedChainId, setSelectedChainId]);
100+
83101
useEffect(() => {
84102
let isMounted = true;
85103

@@ -185,7 +203,7 @@ export const DonateToGitcoinContent = React.memo(
185203
totalDonationsByChain,
186204
]);
187205

188-
if (!isEnabled) return null;
206+
if (!isEnabled || !isInitialized) return null;
189207

190208
const renderChainOption = (chain: TChain) => {
191209
const votingInfo = votingTokens[chain.id];
@@ -219,9 +237,9 @@ export const DonateToGitcoinContent = React.memo(
219237
</span>
220238

221239
<div className="relative flex items-center rounded-lg flex-grow w-full">
222-
{chains.length === 1 ? (
240+
{supportedChains.length === 1 ? (
223241
<div className="w-full p-[9px] rounded-[6px] border-[0.75px] border-[#D7D7D7] bg-white font-modern-era font-medium">
224-
{renderChainOption(chains[0])}
242+
{renderChainOption(supportedChains[0])}
225243
</div>
226244
) : (
227245
<>
@@ -242,7 +260,7 @@ export const DonateToGitcoinContent = React.memo(
242260

243261
{isOpen && (
244262
<div className="absolute top-full left-0 right-0 mt-1 bg-white border border-[#D7D7D7] rounded-[6px] shadow-lg z-10">
245-
{chains
263+
{supportedChains
246264
.sort((a, b) => a.prettyName.localeCompare(b.prettyName))
247265
.map((chain) => (
248266
<div
@@ -274,7 +292,9 @@ export const DonateToGitcoinContent = React.memo(
274292
)}
275293
</div>
276294

277-
{error && <p className="text-[11px] text-red-500">{error}</p>}
295+
{isInitialized && error && (
296+
<p className="text-[11px] text-red-500">{error}</p>
297+
)}
278298
</div>
279299
);
280300
}

packages/grant-explorer/src/features/round/DonateToGitcoinContext.tsx

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,45 @@ type DonateToGitcoinContextType = {
4848
setAmountInWei: (amount: bigint) => void;
4949
};
5050

51-
//todo: update with actual gitcoin data
51+
export const GITCOIN_RECIPIENT_CONFIG: {
52+
[chainId: number]: {
53+
nonce: bigint;
54+
recipient: Hex;
55+
};
56+
} = {
57+
42220: {
58+
// Celo
59+
nonce: 10000n,
60+
recipient: "0x6a02e9bdAd1C5B8cBbC3B200F0aaE67496FFd4d4",
61+
},
62+
42161: {
63+
// Arbitrum One
64+
nonce: 10000n,
65+
recipient: "0x6a02e9bdAd1C5B8cBbC3B200F0aaE67496FFd4d4",
66+
},
67+
10: {
68+
// Optimism
69+
nonce: 10000n,
70+
recipient: "0x6a02e9bdAd1C5B8cBbC3B200F0aaE67496FFd4d4",
71+
},
72+
8453: {
73+
// Base
74+
nonce: 10000n,
75+
recipient: "0x6a02e9bdAd1C5B8cBbC3B200F0aaE67496FFd4d4",
76+
},
77+
};
78+
5279
export const getGitcoinRecipientData = (
5380
chainId: number
5481
): {
5582
nonce: bigint;
5683
recipient: Hex;
5784
} => {
58-
// prepared for different addresses and profiles, like on zksync or so
59-
switch (chainId) {
60-
default:
61-
return {
62-
nonce: 1147166n,
63-
recipient: "0x5645bF145C3f1E974D0D7FB91bf3c68592ab5012",
64-
};
85+
const config = GITCOIN_RECIPIENT_CONFIG[chainId];
86+
if (!config) {
87+
throw new Error(`Unsupported chainId: ${chainId}`);
6588
}
89+
return config;
6690
};
6791

6892
const DonateToGitcoinContext = createContext<DonateToGitcoinContextType | null>(
@@ -178,7 +202,6 @@ export function DonateToGitcoinProvider({
178202
setSelectedChainId(null);
179203
setSelectedToken("");
180204
setAmount("");
181-
setTokenBalances({});
182205
}
183206
}, [isEnabled, setSelectedChainId, setSelectedToken, setAmount]);
184207

packages/grant-explorer/src/features/round/ViewCartPage/ChainConfirmationModalBody.tsx

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { parseChainId } from "common/src/chains";
66
import { Checkbox } from "@chakra-ui/react";
77
import { DonateToGitcoin } from "../DonateToGitcoin";
88
import { zeroAddress } from "viem";
9-
import { useDonateToGitcoin } from "../DonateToGitcoinContext";
9+
import {
10+
useDonateToGitcoin,
11+
GITCOIN_RECIPIENT_CONFIG,
12+
} from "../DonateToGitcoinContext";
1013
import { TotalAmountInclGitcoinDonation } from "../DonateToGitcoin/components/TotalAmountInclGitcoinDonation";
1114

1215
type ChainConfirmationModalBodyProps = {
@@ -69,6 +72,10 @@ export function ChainConfirmationModalBody({
6972
setTokenFilters(tokenFilters);
7073
}, [tokenFilters, setTokenFilters]);
7174

75+
const hasGitcoinSupportedChain = chainIdsBeingCheckedOut.some(
76+
(chainId) => chainId in GITCOIN_RECIPIENT_CONFIG
77+
);
78+
7279
return (
7380
<div className="flex flex-col">
7481
<p className="text-sm text-grey-400">
@@ -108,28 +115,45 @@ export function ChainConfirmationModalBody({
108115
))}
109116
</div>
110117
<div className="">
111-
<div className="flex justify-between items-center py-3 mb-6 border-b border-[#D7D7D7]">
112-
<span className="font-inter text-[15px] font-medium text-black">
113-
Subtotal
114-
</span>
115-
<span className="font-inter text-[15px] font-medium text-black">
116-
~${totalDonationAcrossChainsInUSD.toFixed(2)}
117-
</span>
118-
</div>
119-
<DonateToGitcoin
120-
totalAmount={totalDonationAcrossChainsInUSD.toFixed(2)}
121-
totalDonationsByChain={totalDonationsPerChain}
122-
/>
123-
<div className="pt-6">
124-
<div className="flex justify-between items-center py-3 border-y mb-3 border-[#D7D7D7]">
118+
{hasGitcoinSupportedChain && (
119+
<div className="flex justify-between items-center py-3 mb-6 border-b border-[#D7D7D7]">
120+
<span className="font-inter text-[15px] font-medium text-black">
121+
Subtotal
122+
</span>
123+
<span className="font-inter text-[15px] font-medium text-black">
124+
~${totalDonationAcrossChainsInUSD.toFixed(2)}
125+
</span>
126+
</div>
127+
)}
128+
{hasGitcoinSupportedChain ? (
129+
<DonateToGitcoin
130+
totalAmount={totalDonationAcrossChainsInUSD.toFixed(2)}
131+
totalDonationsByChain={totalDonationsPerChain}
132+
/>
133+
) : (
134+
<div className="flex justify-between items-center mb-3 py-3">
125135
<span className="font-inter text-[15px] font-medium text-black">
126136
Total
127137
</span>
128138
<TotalAmountInclGitcoinDonation
129139
totalDonationAcrossChainsInUSD={totalDonationAcrossChainsInUSD}
130140
/>
131141
</div>
132-
</div>
142+
)}
143+
{hasGitcoinSupportedChain && (
144+
<div className="pt-6">
145+
<div className="flex justify-between items-center py-3 border-y mb-3 border-[#D7D7D7]">
146+
<span className="font-inter text-[15px] font-medium text-black">
147+
Total
148+
</span>
149+
<TotalAmountInclGitcoinDonation
150+
totalDonationAcrossChainsInUSD={
151+
totalDonationAcrossChainsInUSD
152+
}
153+
/>
154+
</div>
155+
</div>
156+
)}
133157
</div>
134158
</div>
135159
</div>

packages/grant-explorer/src/features/round/ViewCartPage/PayoutModals.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ export function PayoutModals({
3838
totalDonationAcrossChainsInUSD: number;
3939
}) {
4040
const {
41-
isEnabled,
4241
selectedChainId,
4342
selectedToken,
44-
amount,
4543
directAllocationPoolId,
4644
amountInWei,
4745
} = useDonateToGitcoin();
@@ -59,6 +57,11 @@ export function PayoutModals({
5957
number[]
6058
>(Object.keys(projectsByChain).map(Number));
6159

60+
const cancelButtonAction = () => {
61+
setOpenChainConfirmationModal(false);
62+
setChainIdsBeingCheckedOut(Object.keys(projectsByChain).map(Number));
63+
};
64+
6265
/** We find the round that ends last, and take its end date as the permit deadline */
6366
const currentPermitDeadline =
6467
rounds && rounds.length > 0
@@ -113,6 +116,7 @@ export function PayoutModals({
113116
title={"Checkout"}
114117
confirmButtonText={"Checkout"}
115118
confirmButtonAction={handleSubmitDonation}
119+
cancelButtonAction={cancelButtonAction}
116120
body={
117121
<ChainConfirmationModalBody
118122
projectsByChain={projectsByChain}

0 commit comments

Comments
 (0)