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

[Issue #2565] network config extended #2609

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
56b0eda
feat: implement dynamic Wagmi configuration and update providers to u…
Da-Colon Dec 6, 2024
a3f879b
refactor: remove unused dynamic Wagmi configuration hook
Da-Colon Dec 7, 2024
999f0f6
feat: integrate automatic chain switching and update Wagmi configurat…
Da-Colon Dec 7, 2024
fb9c751
feat: integrate chain switching functionality in EstablishEssentials …
Da-Colon Dec 10, 2024
d11ff98
Merge branch 'issue/2565-network-config-updates' of github.com:decent…
Da-Colon Dec 10, 2024
c05f818
Merge branch 'issue/2565-network-config-updates' of github.com:decent…
Da-Colon Dec 11, 2024
23cab88
Delay setting current config after switching chain to ensure proper s…
Da-Colon Dec 12, 2024
9f2ffaf
Merge branch 'issue/2565-network-config-updates' of github.com:decent…
Da-Colon Dec 12, 2024
113d28f
Update error message for invalid DAO search to reflect support for al…
Da-Colon Dec 13, 2024
d2319e5
Enhance useIsSafe hook to search across all supported networks and re…
Da-Colon Dec 13, 2024
2bb83c1
Refactor DAOSearch to display multiple network prefixes in SearchDisp…
Da-Colon Dec 13, 2024
8dab85b
Refactor DAOSearch component to remove extra gap
Da-Colon Dec 13, 2024
ef7a3de
revert: changes made to hook.
Da-Colon Dec 13, 2024
2118a5d
Add useResolveAddressMultiChain hook for multi-chain address resolution
Da-Colon Dec 14, 2024
1e8292a
Refactor DAOSearch to use resolved addresses with chain IDs and updat…
Da-Colon Dec 14, 2024
a25fd55
move translation initialization
Da-Colon Dec 14, 2024
8dace81
Remove 'wrongNetwork' type from LoadingProblem component and its usag…
Da-Colon Dec 14, 2024
5b8556b
Merge branch 'issue/2565-network-config-updates' of github.com:decent…
Da-Colon Dec 14, 2024
992c141
Merge branch 'issue/2565-network-config-extended' of github.com:decen…
Da-Colon Dec 14, 2024
89b2989
Merge pull request #2630 from decentdao/issue/2565-cross-chain-dao-se…
Da-Colon Dec 16, 2024
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
1 change: 0 additions & 1 deletion src/components/ui/page/Global/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { Layout } from '../Layout';

const useUserTracking = () => {
const { address } = useAccount();

useEffect(() => {
Sentry.setUser(address ? { id: address } : null);
if (address) {
Expand Down
19 changes: 17 additions & 2 deletions src/hooks/utils/useAutomaticSwitchChain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect } from 'react';
import { useSwitchChain } from 'wagmi';
import { useNetworkConfigStore } from '../../providers/NetworkConfig/useNetworkConfigStore';
import { getChainIdFromPrefix } from '../../utils/url';

Expand All @@ -8,11 +9,25 @@ export const useAutomaticSwitchChain = ({
urlAddressPrefix: string | undefined;
}) => {
const { setCurrentConfig, getConfigByChainId, addressPrefix } = useNetworkConfigStore();
const { switchChain } = useSwitchChain({
mutation: {
onError: () => {
if (addressPrefix !== urlAddressPrefix && urlAddressPrefix !== undefined) {
const chainId = getChainIdFromPrefix(urlAddressPrefix);
switchChain({ chainId });
}
},
},
});
Comment on lines +12 to +21
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny enough, this kinda reverts back to how the file was before only this now we are attempting the switch chain again onError.

While, not ideal. this does work and fixes the current network switcher issues we've been having. Ideally I think we would have completely seperate publicClient by passing the id directly in. and then move all network switching to when a user clicks to send a transaction.

But I'm not sure how that scales at the moment and want to discuss further before we make that change.

So this is the current path of least resistance. currently there are two spots that this is going to be required.

  • useAutomaticSwitchChain
  • EstablishEssentials where a new network switcher will exist.


useEffect(() => {
if (urlAddressPrefix === undefined || addressPrefix === urlAddressPrefix) {
return;
}
setCurrentConfig(getConfigByChainId(getChainIdFromPrefix(urlAddressPrefix)));
}, [addressPrefix, setCurrentConfig, getConfigByChainId, urlAddressPrefix]);
const chainId = getChainIdFromPrefix(urlAddressPrefix);
setCurrentConfig(getConfigByChainId(chainId));
if (addressPrefix !== urlAddressPrefix && urlAddressPrefix !== undefined) {
switchChain({ chainId });
}
}, [addressPrefix, setCurrentConfig, getConfigByChainId, urlAddressPrefix, switchChain]);
};
11 changes: 7 additions & 4 deletions src/providers/NetworkConfig/web3-modal.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,32 @@ const supportedWagmiChains = supportedNetworks.map(network => network.chain);
export const walletConnectProjectId = import.meta.env.VITE_APP_WALLET_CONNECT_PROJECT_ID;
export const queryClient = new QueryClient();

const wagmiMetadata = {
const metadata = {
name: import.meta.env.VITE_APP_NAME,
description:
'Are you outgrowing your Multisig? Decent extends Safe treasuries into on-chain hierarchies of permissions, token flows, and governance.',
url: import.meta.env.VITE_APP_SITE_URL,
icons: [`${import.meta.env.VITE_APP_SITE_URL}/favicon-96x96.png`],
};

const transportsReducer = (accumulator: Record<string, HttpTransport>, network: NetworkConfig) => {
export const transportsReducer = (
accumulator: Record<string, HttpTransport>,
network: NetworkConfig,
) => {
accumulator[network.chain.id] = http(network.rpcEndpoint);
return accumulator;
};

export const wagmiConfig = defaultWagmiConfig({
chains: supportedWagmiChains as [Chain, ...Chain[]],
projectId: walletConnectProjectId,
metadata: wagmiMetadata,
metadata,
transports: supportedNetworks.reduce(transportsReducer, {}),
batch: {
multicall: true,
},
});

if (walletConnectProjectId) {
createWeb3Modal({ wagmiConfig, projectId: walletConnectProjectId });
createWeb3Modal({ wagmiConfig, projectId: walletConnectProjectId, metadata: metadata });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use prop shorthand here as well

}
Loading