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

fix: make manager safe app compatible #3737

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions packages/round-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"@openzeppelin/merkle-tree": "^1.0.2",
"@rainbow-me/rainbowkit": "2.1.2",
"@reduxjs/toolkit": "^1.8.1",
"@safe-global/safe-apps-provider": "^0.18.5",
"@safe-global/safe-apps-react-sdk": "^4.7.2",
"@sentry/integrations": "^7.28.0",
"@sentry/react": "^7.27.0",
"@sentry/tracing": "^7.26.0",
Expand Down
31 changes: 31 additions & 0 deletions packages/round-manager/public/manager-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions packages/round-manager/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"short_name": "Manager",
"name": "Gitcoin Safe App Manager",
"description": "Gitcoin Safe App Manager",
"icons": [
{
"src": "manager-logo.svg",
"sizes": "any",
"type": "image/svg+xml"
},
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#FFFFFF",
"background_color": "#FFFFFF"
}
14 changes: 14 additions & 0 deletions packages/round-manager/setUpProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// App is an express application, we can add an express middleware that will set headers for manifest.json request
// https://create-react-app.dev/docs/proxying-api-requests-in-development/#configuring-the-proxy-manually

module.exports = function (app) {
app.use("/manifest.json", function (req, res, next) {
res.set({
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET",
"Access-Control-Allow-Headers":
"X-Requested-With, content-type, Authorization",
});
next();
});
};
54 changes: 43 additions & 11 deletions packages/round-manager/src/app/wagmi.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,58 @@
import "@rainbow-me/rainbowkit/styles.css";
import { QueryClient } from "@tanstack/react-query";
import { Chain as RChain, getDefaultConfig } from "@rainbow-me/rainbowkit";
import { allNetworks, mainnetNetworks } from "common/src/chains";
import { getClient, getConnectorClient } from "@wagmi/core";
import { providers } from "ethers";
import { type Account, type Chain, type Client, type Transport } from "viem";
import {
http,
type Account,
type Chain,
type Client,
type Transport,
} from "viem";
import { Connector } from "wagmi";

export const allChains: RChain[] =
process.env.REACT_APP_ENV === "development" ? allNetworks : mainnetNetworks;
import {
rainbowWallet,
safeWallet,
walletConnectWallet,
coinbaseWallet,
} from "@rainbow-me/rainbowkit/wallets";
import { connectorsForWallets } from "@rainbow-me/rainbowkit";

/* TODO: remove hardcoded value once we have environment variables validation */
const projectId =
process.env.REACT_APP_WALLETCONNECT_PROJECT_ID ??
"2685061cae0bcaf2b244446153eda9e1";
const connectors = connectorsForWallets(
[
{
groupName: "Popular",
wallets: [safeWallet, rainbowWallet, walletConnectWallet, coinbaseWallet],
},
],
{
appName: "Gitcoin Manager",
projectId,
}
);
export const allChains: Chain[] =
process.env.REACT_APP_ENV === "development" ? allNetworks : mainnetNetworks;

import { createConfig } from "wagmi";

const transports = allChains.reduce(
(acc, chain) => {
acc[chain.id] = http();
return acc;
},
{} as Record<number, ReturnType<typeof http>>
);

export const config = getDefaultConfig({
appName: "Gitcoin Manager",
projectId,
chains: [...allChains] as [Chain, ...Chain[]],
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}) as any;
export const config = createConfig({
chains: [...allChains] as unknown as readonly [Chain, ...Chain[]],
connectors,
transports,
});

const queryClient = new QueryClient();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jest.mock("wagmi", () => ({
}));
jest.mock("@rainbow-me/rainbowkit", () => ({
ConnectButton: jest.fn(),
getDefaultConfig: jest.fn(),
connectorsForWallets: jest.fn(),
}));
jest.mock("data-layer", () => ({
...jest.requireActual("data-layer"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jest.mock("wagmi", () => ({
}));
jest.mock("@rainbow-me/rainbowkit", () => ({
ConnectButton: jest.fn(),
getDefaultConfig: jest.fn(),
connectorsForWallets: jest.fn(),
}));
jest.mock("../../../features/common/Auth", () => ({
useWallet: () => mockWallet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jest.mock("wagmi", () => ({
}));
jest.mock("@rainbow-me/rainbowkit", () => ({
ConnectButton: jest.fn(),
getDefaultConfig: jest.fn(),
connectorsForWallets: jest.fn(),
}));

jest.mock("../../../features/api/round");
Expand Down
29 changes: 29 additions & 0 deletions packages/round-manager/src/features/api/SafeAutoConnect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useEffect } from "react";

import { useConnect, useAccount } from "wagmi";

const AUTOCONNECTED_CONNECTOR_IDS = ["safe"];

function useAutoConnect() {
const { connect, connectors } = useConnect();
const { address } = useAccount();

useEffect(() => {
AUTOCONNECTED_CONNECTOR_IDS.forEach((connector) => {
const connectorInstance = connectors.find((c) => c.id === connector);
const isIframe = window.top !== window.self;
if (connectorInstance && isIframe) {
connect({ connector: connectorInstance });
}
});
}, [connect, connectors, address]);
}

export const SafeAutoConnect = ({
children,
}: {
children: JSX.Element | JSX.Element[];
}) => {
useAutoConnect();
return <>{children}</>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jest.mock("wagmi", () => ({
}));
jest.mock("@rainbow-me/rainbowkit", () => ({
ConnectButton: jest.fn(),
getDefaultConfig: jest.fn(),
connectorsForWallets: jest.fn(),
}));

describe("TransactionBuilder", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ErrorModal from "../../common/ErrorModal";
jest.mock("../../common/Auth");
jest.mock("@rainbow-me/rainbowkit", () => ({
ConnectButton: jest.fn(),
getDefaultConfig: jest.fn(),
connectorsForWallets: jest.fn(),
}));

describe("<ErrorModal />", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jest.mock("../../api/ipfs");
jest.mock("../../common/Auth");
jest.mock("@rainbow-me/rainbowkit", () => ({
ConnectButton: jest.fn(),
getDefaultConfig: jest.fn(),
connectorsForWallets: jest.fn(),
}));

jest.mock("../../../constants", () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jest.mock("wagmi", () => ({
}));
jest.mock("@rainbow-me/rainbowkit", () => ({
ConnectButton: jest.fn(),
getDefaultConfig: jest.fn(),
connectorsForWallets: jest.fn(),
}));
jest.mock("data-layer", () => ({
...jest.requireActual("data-layer"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jest.mock("../../common/Auth");
jest.mock("../../api/program");
jest.mock("@rainbow-me/rainbowkit", () => ({
ConnectButton: jest.fn(),
getDefaultConfig: jest.fn(),
connectorsForWallets: jest.fn(),
}));
jest.mock("react-router-dom", () => ({
...jest.requireActual("react-router-dom"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export default function ViewApplicationPage() {
};

if (roundChainId) fetchApplications();
}, [roundChainId, roundId]);
}, [roundChainId, roundId, id, dataLayer]);

useEffect(() => {
if (contractUpdatingStatus === ProgressStatus.IS_ERROR) {
Expand Down Expand Up @@ -334,7 +334,10 @@ export default function ViewApplicationPage() {

if (application?.answers && application.answers.length > 0) {
for (let _answerBlock of application.answers) {
if (_answerBlock.encryptedAnswer && !isLitUnavailable(round.chainId!)) {
if (
_answerBlock.encryptedAnswer &&
!isLitUnavailable(round.chainId!)
) {
try {
const encryptedAnswer = _answerBlock.encryptedAnswer;
const base64EncryptedString = [
Expand All @@ -349,7 +352,7 @@ export default function ViewApplicationPage() {
chainId: Number(roundChainId!),
contract: roundId.startsWith("0x")
? roundId
: round?.payoutStrategy.id ?? "",
: (round?.payoutStrategy.id ?? ""),
});

const decryptedString = await lit.decryptString(
Expand Down Expand Up @@ -816,7 +819,7 @@ export default function ViewApplicationPage() {
answerBlocks?.map((block: AnswerBlock) => {
const answerText = Array.isArray(block.answer)
? block.answer.join(", ")
: block.answer ?? "";
: (block.answer ?? "");

return (
<div key={block.questionId} className="pb-5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jest.mock("wagmi", () => ({
}));
jest.mock("@rainbow-me/rainbowkit", () => ({
ConnectButton: jest.fn(),
getDefaultConfig: jest.fn(),
connectorsForWallets: jest.fn(),
}));
jest.mock("../../api/application");
jest.mock("../../common/Auth", () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jest.mock("wagmi", () => ({

jest.mock("@rainbow-me/rainbowkit", () => ({
ConnectButton: jest.fn(),
getDefaultConfig: jest.fn(),
connectorsForWallets: jest.fn(),
}));

jest.mock("common/src/allo/backends/allo-v1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jest.mock("wagmi", () => ({
}));
jest.mock("@rainbow-me/rainbowkit", () => ({
ConnectButton: jest.fn(),
getDefaultConfig: jest.fn(),
connectorsForWallets: jest.fn(),
}));
jest.mock("../../common/Navbar");
jest.mock("../../common/Auth");
Expand All @@ -33,9 +33,7 @@ jest.mock("react-router-dom", () => ({
}));

describe("<CreateRoundPage />", () => {
beforeEach(() => {

});
beforeEach(() => {});

it("sends program to form wizard", () => {
const programs = [makeProgramData({ id: programId })];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jest.mock("../../../app/wagmi", () => ({
}));
jest.mock("@rainbow-me/rainbowkit", () => ({
ConnectButton: jest.fn(),
getDefaultConfig: jest.fn(),
connectorsForWallets: jest.fn(),
}));

jest.mock("react-router-dom", () => ({
Expand Down Expand Up @@ -105,18 +105,14 @@ describe("fund contract tabr", () => {
// )
// )
// );

// const fundContractTab = screen.getByTestId("fund-contract");
// fireEvent.click(fundContractTab);

// expect(screen.getByText("Details")).toBeInTheDocument();

// if (process.env.REACT_APP_ALLO_VERSION === "allo-v1") {
// expect(screen.getByText("Contract Address:")).toBeInTheDocument();
// expect(screen.getByTestId("fund-contract-btn")).toBeInTheDocument();
// expect(screen.getByTestId("view-contract-btn")).toBeInTheDocument();
// }

// expect(screen.getByText("Payout token:")).toBeInTheDocument();
// expect(screen.getByText("Matching pool size:")).toBeInTheDocument();
// expect(screen.getByText("Protocol fee:")).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import QuadraticFundingForm from "../QuadraticFundingForm";
jest.mock("../../common/Auth");
jest.mock("@rainbow-me/rainbowkit", () => ({
ConnectButton: jest.fn(),
getDefaultConfig: jest.fn(),
connectorsForWallets: jest.fn(),
}));
jest.mock("wagmi", () => ({
useAccount: () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jest.mock("../../common/Auth");

jest.mock("@rainbow-me/rainbowkit", () => ({
ConnectButton: jest.fn(),
getDefaultConfig: jest.fn(),
connectorsForWallets: jest.fn(),
}));

jest.mock("../../../app/wagmi", () => ({
Expand Down
Loading
Loading