Skip to content

Commit a874340

Browse files
authored
fix: make manager safe app compatible (#3737)
* fix: make manager safe app compatible * adds missing dependency to tests * add missing deps for tests
1 parent fc33919 commit a874340

31 files changed

+303
-105
lines changed

packages/round-manager/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
"@openzeppelin/merkle-tree": "^1.0.2",
3939
"@rainbow-me/rainbowkit": "2.1.2",
4040
"@reduxjs/toolkit": "^1.8.1",
41+
"@safe-global/safe-apps-provider": "^0.18.5",
42+
"@safe-global/safe-apps-react-sdk": "^4.7.2",
4143
"@sentry/integrations": "^7.28.0",
4244
"@sentry/react": "^7.27.0",
4345
"@sentry/tracing": "^7.26.0",
Lines changed: 31 additions & 0 deletions
Loading
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"short_name": "Manager",
3+
"name": "Gitcoin Safe App Manager",
4+
"description": "Gitcoin Safe App Manager",
5+
"icons": [
6+
{
7+
"src": "manager-logo.svg",
8+
"sizes": "any",
9+
"type": "image/svg+xml"
10+
},
11+
{
12+
"src": "favicon.ico",
13+
"sizes": "64x64 32x32 24x24 16x16",
14+
"type": "image/x-icon"
15+
},
16+
{
17+
"src": "favicon.ico",
18+
"sizes": "64x64 32x32 24x24 16x16",
19+
"type": "image/x-icon"
20+
},
21+
{
22+
"src": "logo192.png",
23+
"type": "image/png",
24+
"sizes": "192x192"
25+
},
26+
{
27+
"src": "logo512.png",
28+
"type": "image/png",
29+
"sizes": "512x512"
30+
}
31+
],
32+
"start_url": ".",
33+
"display": "standalone",
34+
"theme_color": "#FFFFFF",
35+
"background_color": "#FFFFFF"
36+
}

packages/round-manager/setUpProxy.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// App is an express application, we can add an express middleware that will set headers for manifest.json request
2+
// https://create-react-app.dev/docs/proxying-api-requests-in-development/#configuring-the-proxy-manually
3+
4+
module.exports = function (app) {
5+
app.use("/manifest.json", function (req, res, next) {
6+
res.set({
7+
"Access-Control-Allow-Origin": "*",
8+
"Access-Control-Allow-Methods": "GET",
9+
"Access-Control-Allow-Headers":
10+
"X-Requested-With, content-type, Authorization",
11+
});
12+
next();
13+
});
14+
};

packages/round-manager/src/app/wagmi.ts

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,58 @@
11
import "@rainbow-me/rainbowkit/styles.css";
22
import { QueryClient } from "@tanstack/react-query";
3-
import { Chain as RChain, getDefaultConfig } from "@rainbow-me/rainbowkit";
43
import { allNetworks, mainnetNetworks } from "common/src/chains";
54
import { getClient, getConnectorClient } from "@wagmi/core";
65
import { providers } from "ethers";
7-
import { type Account, type Chain, type Client, type Transport } from "viem";
6+
import {
7+
http,
8+
type Account,
9+
type Chain,
10+
type Client,
11+
type Transport,
12+
} from "viem";
813
import { Connector } from "wagmi";
9-
10-
export const allChains: RChain[] =
11-
process.env.REACT_APP_ENV === "development" ? allNetworks : mainnetNetworks;
14+
import {
15+
rainbowWallet,
16+
safeWallet,
17+
walletConnectWallet,
18+
coinbaseWallet,
19+
} from "@rainbow-me/rainbowkit/wallets";
20+
import { connectorsForWallets } from "@rainbow-me/rainbowkit";
1221

1322
/* TODO: remove hardcoded value once we have environment variables validation */
1423
const projectId =
1524
process.env.REACT_APP_WALLETCONNECT_PROJECT_ID ??
1625
"2685061cae0bcaf2b244446153eda9e1";
26+
const connectors = connectorsForWallets(
27+
[
28+
{
29+
groupName: "Popular",
30+
wallets: [safeWallet, rainbowWallet, walletConnectWallet, coinbaseWallet],
31+
},
32+
],
33+
{
34+
appName: "Gitcoin Manager",
35+
projectId,
36+
}
37+
);
38+
export const allChains: Chain[] =
39+
process.env.REACT_APP_ENV === "development" ? allNetworks : mainnetNetworks;
40+
41+
import { createConfig } from "wagmi";
42+
43+
const transports = allChains.reduce(
44+
(acc, chain) => {
45+
acc[chain.id] = http();
46+
return acc;
47+
},
48+
{} as Record<number, ReturnType<typeof http>>
49+
);
1750

18-
export const config = getDefaultConfig({
19-
appName: "Gitcoin Manager",
20-
projectId,
21-
chains: [...allChains] as [Chain, ...Chain[]],
22-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
23-
}) as any;
51+
export const config = createConfig({
52+
chains: [...allChains] as unknown as readonly [Chain, ...Chain[]],
53+
connectors,
54+
transports,
55+
});
2456

2557
const queryClient = new QueryClient();
2658

packages/round-manager/src/context/program/__tests__/ReadProgramContext.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ jest.mock("wagmi", () => ({
2626
chainId: 1,
2727
address: "0x0",
2828
}),
29+
createConfig: jest.fn(),
2930
}));
3031
jest.mock("@rainbow-me/rainbowkit", () => ({
3132
ConnectButton: jest.fn(),
32-
getDefaultConfig: jest.fn(),
33+
connectorsForWallets: jest.fn(),
3334
}));
3435
jest.mock("data-layer", () => ({
3536
...jest.requireActual("data-layer"),

packages/round-manager/src/context/round/__tests__/ReclaimFundsContext.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jest.mock("wagmi", () => ({
1212
useAccount: () => ({
1313
chainId: 1,
1414
}),
15+
createConfig: jest.fn(),
1516
}));
1617
jest.mock("../../../features/api/payoutStrategy/payoutStrategy");
1718

@@ -23,7 +24,6 @@ jest.mock("viem", () => ({
2324
jest.mock("common", () => ({
2425
...jest.requireActual("common"),
2526
useAllo: jest.fn(),
26-
2727
}));
2828

2929
const alloBackend = new AlloV1({
@@ -37,7 +37,6 @@ const alloBackend = new AlloV1({
3737
transactionSender: createMockTransactionSender(),
3838
});
3939

40-
4140
const testParams: ReclaimFundsParams = {
4241
allo: alloBackend,
4342
payoutStrategy: "0x0000000000000000000000000000000000000001",

packages/round-manager/src/context/round/__tests__/RoundContext.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ jest.mock("wagmi", () => ({
1212
useAccount: () => ({
1313
chainId: 1,
1414
}),
15+
createConfig: jest.fn(),
1516
}));
1617
jest.mock("@rainbow-me/rainbowkit", () => ({
1718
ConnectButton: jest.fn(),
18-
getDefaultConfig: jest.fn(),
19+
connectorsForWallets: jest.fn(),
1920
}));
2021
jest.mock("../../../features/common/Auth", () => ({
2122
useWallet: () => mockWallet,

packages/round-manager/src/context/round/__tests__/UpdateRoundContext.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ jest.mock("wagmi", () => ({
3131
useAccount: () => ({
3232
chainId: 1,
3333
}),
34+
createConfig: jest.fn(),
3435
}));
3536
jest.mock("@rainbow-me/rainbowkit", () => ({
3637
ConnectButton: jest.fn(),
37-
getDefaultConfig: jest.fn(),
38+
connectorsForWallets: jest.fn(),
3839
}));
3940

4041
jest.mock("../../../features/api/round");
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useEffect } from "react";
2+
3+
import { useConnect, useAccount } from "wagmi";
4+
5+
const AUTOCONNECTED_CONNECTOR_IDS = ["safe"];
6+
7+
function useAutoConnect() {
8+
const { connect, connectors } = useConnect();
9+
const { address } = useAccount();
10+
11+
useEffect(() => {
12+
AUTOCONNECTED_CONNECTOR_IDS.forEach((connector) => {
13+
const connectorInstance = connectors.find((c) => c.id === connector);
14+
const isIframe = window.top !== window.self;
15+
if (connectorInstance && isIframe) {
16+
connect({ connector: connectorInstance });
17+
}
18+
});
19+
}, [connect, connectors, address]);
20+
}
21+
22+
export const SafeAutoConnect = ({
23+
children,
24+
}: {
25+
children: JSX.Element | JSX.Element[];
26+
}) => {
27+
useAutoConnect();
28+
return <>{children}</>;
29+
};

0 commit comments

Comments
 (0)