Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 1 addition & 1 deletion .github/workflows/ci_develop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 18.x

- name: Create env file
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

- uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 18.x

- name: Create env file
run: |
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.16.0
18.19.0
12 changes: 12 additions & 0 deletions apps/admin/src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@
*/
import 'core-js/stable';
import 'regenerator-runtime/runtime';

// Ensure Buffer is globally available early (before any dynamic imports needing it)
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { Buffer } = require('buffer');
if (typeof window !== 'undefined' && !(window as any).Buffer) {

Check warning on line 13 in apps/admin/src/polyfills.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type

Check warning on line 13 in apps/admin/src/polyfills.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
(window as any).Buffer = Buffer;

Check warning on line 14 in apps/admin/src/polyfills.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
}
} catch (err) {
// eslint-disable-next-line no-console
console.warn('[Polyfills] Buffer polyfill failed', err);
}
84 changes: 62 additions & 22 deletions libs/connect-context/src/Connect.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {
EthereumClient,
w3mConnectors,
w3mProvider,
} from '@web3modal/ethereum';
import { configureChains, createConfig, WagmiConfig } from 'wagmi';
import { SafeConnector } from '@wagmi/connectors/safe';
import { InjectedConnector } from 'wagmi/connectors/injected';
import { MetaMaskConnector } from 'wagmi/connectors/metaMask';
import { CoinbaseWalletConnector } from 'wagmi/connectors/coinbaseWallet';
// WalletConnect v2 included whenever a NX_WALLET_CONNECT_ID is provided (no extra enable flag)
import { WalletConnectConnector } from 'wagmi/connectors/walletConnect';
import { jsonRpcProvider } from 'wagmi/providers/jsonRpc';
import { Web3Modal } from '@web3modal/react';

import {
HAUS_NETWORK_DATA,
Expand All @@ -15,13 +14,26 @@ import {
} from '@daohaus/keychain-utils';

import { ConnectProvider, ConnectProviderProps } from './ConnectContext';
import { logChains } from './utils/debug';

if (!process.env['NX_WALLET_CONNECT_ID']) {
throw new Error('You need to provide NX_WALLET_CONNECT_ID env variable');
// Ensure Buffer global for libraries (e.g., walletconnect QR, qrcode) that expect Node Buffer
// Some build setups (webpack 5) do not auto-polyfill core modules.
// Safe to run always; no-op if already defined.
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { Buffer } = require('buffer');
if (typeof window !== 'undefined' && !(window as unknown as { Buffer?: unknown }).Buffer) {
(window as unknown as { Buffer?: unknown }).Buffer = Buffer;
}
} catch (err) {
// Buffer polyfill failed – non-fatal.
}
export const projectId = process.env['NX_WALLET_CONNECT_ID'];

// Legacy Web3Modal artifacts removed; no external modal client.

const chains = Object.values(VIEM_CHAINS);
// Debug log of chain list
logChains(chains as unknown as { id: number; name?: string }[]);
const { publicClient } = configureChains(
chains,
[
Expand All @@ -33,25 +45,54 @@ const { publicClient } = configureChains(
};
},
}),
w3mProvider({ projectId }),
],
{ retryCount: 10 }
);
const includeSafe = process.env['NX_CONNECT_DISABLE_SAFE'] !== 'true';
const walletConnectProjectId = process.env['NX_WALLET_CONNECT_ID'];

const baseConnectors = [
// Injected first: rename so it doesn't clash label-wise with MetaMask when present
new InjectedConnector({
chains,
options: { shimDisconnect: true, name: 'Browser Wallet' },
}),
new MetaMaskConnector({ chains, options: { shimDisconnect: true } }),
new CoinbaseWalletConnector({
chains,
options: { appName: 'DAOhaus Admin' },
}),
...(includeSafe
? [
new SafeConnector({
chains,
options: {
allowedDomains: [/gnosis-safe.io$/, /app.safe.global$/],
debug: false,
},
}),
]
: []),
...(walletConnectProjectId
? [
new WalletConnectConnector({
chains,
options: {
projectId: walletConnectProjectId,
showQrModal: true, // uses WC's standalone QR (not Web3Modal UI)
},
}),
]
: []),
];

export const wagmiConfig = createConfig({
autoConnect: true,
connectors: [
...w3mConnectors({ projectId, chains }),
new SafeConnector({
chains,
options: {
allowedDomains: [/gnosis-safe.io$/, /app.safe.global$/],
debug: false,
},
}),
],
connectors: baseConnectors,
publicClient,
});
export const ethereumClient = new EthereumClient(wagmiConfig, chains);
// Placeholder for backward compatibility; no external client now
export const ethereumClient = undefined as unknown as Record<string, never>;

export const Connect = ({
children,
Expand All @@ -70,7 +111,6 @@ export const Connect = ({
>
{children}
</ConnectProvider>
<Web3Modal projectId={projectId} ethereumClient={ethereumClient} />
</WagmiConfig>
);
};
37 changes: 28 additions & 9 deletions libs/connect-context/src/ConnectContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
useMemo,
useState,
} from 'react';
import { useWeb3Modal } from '@web3modal/react';
import {
useAccount,
useDisconnect,
Expand All @@ -23,12 +22,12 @@ import {
isValidNetwork,
NetworkConfigs,
ValidNetwork,
VIEM_CHAINS,
} from '@daohaus/keychain-utils';

import { defaultConnectValues } from './utils/defaults';
import { ConnectLifecycleFns, UserProfile } from './utils/types';
import { loadProfile } from './utils';
import InternalConnectModal from './components/InternalConnectModal';

export type UserConnectType = {
networks: NetworkConfigs;
Expand Down Expand Up @@ -58,14 +57,16 @@ export type ConnectProviderProps = {
daoChainId?: string;
};

// Always use internal connect modal (Web3Modal removed)
const useInternal = true;

export const ConnectProvider = ({
children,
networks = HAUS_NETWORK_DATA,
lifeCycleFns,
daoChainId,
daoId,
}: ConnectProviderProps) => {
const { open, setDefaultChain } = useWeb3Modal();
const { address, isConnecting } = useAccount();
const { disconnect } = useDisconnect();
const { chain } = useNetwork();
Expand Down Expand Up @@ -93,13 +94,11 @@ export const ConnectProvider = ({
[chainId, networks]
);

const connectWallet = useCallback(async () => {
if (daoChainId && VIEM_CHAINS[daoChainId as ValidNetwork]) {
setDefaultChain(VIEM_CHAINS[daoChainId as ValidNetwork]);
}
const [internalOpen, setInternalOpen] = useState(false);

open();
}, [open, setDefaultChain, daoChainId]);
const connectWallet = useCallback(async () => {
setInternalOpen(true);
}, []);

const handleSwitchNetwork = async (_chainId: string | number) => {
switchNetwork?.(Number(_chainId));
Expand Down Expand Up @@ -135,6 +134,19 @@ export const ConnectProvider = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [address, chainId]);

// Auto switch to daoChainId if provided and connected and mismatch
useEffect(() => {
if (
daoChainId &&
isConnected &&
chain &&
Number(daoChainId) !== chain.id &&
switchNetwork
) {
switchNetwork(Number(daoChainId));
}
}, [daoChainId, isConnected, chain, switchNetwork]);

return (
<ConnectContext.Provider
value={{
Expand All @@ -155,6 +167,13 @@ export const ConnectProvider = ({
}}
>
{children}
{useInternal && (
<InternalConnectModal
open={internalOpen}
onClose={() => setInternalOpen(false)}
defaultChainId={daoChainId ? Number(daoChainId) : undefined}
/>
)}
</ConnectContext.Provider>
);
};
Expand Down
26 changes: 26 additions & 0 deletions libs/connect-context/src/assets/icons/MetaMask-icon-fox.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions libs/connect-context/src/assets/icons/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Module declarations for icon asset imports local to connect-context
// Ensures TypeScript understands imported SVG/PNG modules in this lib.
declare module '*.svg' {
const content: string;
export default content;
}

declare module '*.png' {
const content: string;
export default content;
}
Loading
Loading