Skip to content

Fix unsupported network detection and UI handling #351

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

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
043efec
Fix unsupported network detection and UI handling
devin-ai-integration[bot] May 22, 2025
d76da53
Fix lint errors and improve network validation
devin-ai-integration[bot] May 22, 2025
78499a8
Fix lint issues and improve network validation
devin-ai-integration[bot] May 22, 2025
4297e21
Update AccountDefaultView and AccountView to handle unsupported networks
devin-ai-integration[bot] May 22, 2025
d119242
Fix formatting in AccountView component
devin-ai-integration[bot] May 22, 2025
f893487
Update AccountDefaultView to show Switch Network when network is not …
devin-ai-integration[bot] May 22, 2025
d3f4859
Fix formatting in AccountDefaultView component
devin-ai-integration[bot] May 22, 2025
75516c9
chore: improvements
ignaciosantise May 22, 2025
634bd4f
fix: handle unsupported network gracefully, also in siwe
ignaciosantise May 23, 2025
2ff7c81
chore: set unsupported network on ethers
ignaciosantise May 26, 2025
89bec04
chore: check namespaces approved networks to set unsupported flags
ignaciosantise May 26, 2025
8d8b931
chore: ethers improvements
ignaciosantise May 27, 2025
23c7822
chore: moved siwe logic to clients
ignaciosantise May 27, 2025
1013fc6
chore: removed old tests
ignaciosantise May 27, 2025
41b2b25
chore: fixed 1CA issue in wagmi connector + solved test issues
ignaciosantise May 28, 2025
e135b8e
fix: compare walletchoice with authtype in approved namespace getter
ignaciosantise May 28, 2025
b76f26d
chore: check supported network only if needed, added timeout for the …
ignaciosantise May 28, 2025
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
10 changes: 10 additions & 0 deletions packages/core/src/__tests__/controllers/NetworkController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,14 @@ describe('NetworkController', () => {
expect(NetworkController.state.approvedCaipNetworkIds).toEqual(undefined);
expect(NetworkController.state.requestedCaipNetworks).toEqual(requestedCaipNetworks);
});

it('should validate if active network is in requested networks', () => {
NetworkController.setRequestedCaipNetworks(requestedCaipNetworks);

NetworkController.setCaipNetwork({ id: 'eip155:1', name: 'Ethereum' });
expect(NetworkController.isActiveNetworkInRequestedNetworks()).toBe(true);

NetworkController.setCaipNetwork({ id: 'eip155:99', name: 'Unknown Network' });
expect(NetworkController.isActiveNetworkInRequestedNetworks()).toBe(false);
});
});
8 changes: 8 additions & 0 deletions packages/core/src/controllers/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,13 @@ export const NetworkController = {
state.approvedCaipNetworkIds = undefined;
state.supportsAllNetworks = true;
state.smartAccountEnabledNetworks = [];
},

isActiveNetworkInRequestedNetworks() {
if (!state.caipNetwork || !state.requestedCaipNetworks?.length) {
return true; // No active network or no requested networks, so no validation needed
}

return state.requestedCaipNetworks.some(network => network.id === state.caipNetwork?.id);
}
};
13 changes: 10 additions & 3 deletions packages/scaffold/src/modal/w3m-network-button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@

export function NetworkButton({ disabled, style }: NetworkButtonProps) {
const { isConnected } = useSnapshot(AccountController.state);
const { caipNetwork } = useSnapshot(NetworkController.state);
const { caipNetwork, requestedCaipNetworks } = useSnapshot(NetworkController.state);
const { loading } = useSnapshot(ModalController.state);
const { themeMode, themeVariables } = useSnapshot(ThemeController.state);

const isNetworkSupported = !caipNetwork || !requestedCaipNetworks?.length ||
requestedCaipNetworks.some(network => network.id === caipNetwork.id);

Check warning on line 26 in packages/scaffold/src/modal/w3m-network-button/index.tsx

View workflow job for this annotation

GitHub Actions / Verify / pre-publish

Better to just use proxy state

const onNetworkPress = () => {
ModalController.open({ view: 'Networks' });
if (isConnected && !isNetworkSupported) {

Check warning on line 29 in packages/scaffold/src/modal/w3m-network-button/index.tsx

View workflow job for this annotation

GitHub Actions / Verify / pre-publish

Better to just use proxy state
ModalController.open({ view: 'UnsupportedChain' });
} else {
ModalController.open({ view: 'Networks' });
}
EventsController.sendEvent({
type: 'track',
event: 'CLICK_NETWORKS'
Expand All @@ -41,7 +48,7 @@
loading={loading}
testID="network-button"
>
{caipNetwork?.name ?? (isConnected ? 'Unknown Network' : 'Select Network')}
{caipNetwork?.name ?? (isConnected ? (isNetworkSupported ? 'Unknown Network' : 'Switch Network') : 'Select Network')}
</NetworkButtonUI>
</ThemeProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export function UnsupportedChainView() {
ListHeaderComponentStyle={styles.header}
ListHeaderComponent={
<Text variant="small-400" color="fg-200" center>
The swap feature doesn't support your current network. Switch to an available option to
continue.
The current network is not supported by this application.
Please switch to an available option to continue.
</Text>
}
contentContainerStyle={styles.contentContainer}
Expand Down
9 changes: 9 additions & 0 deletions packages/wagmi/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,15 @@ export class AppKit extends AppKitScaffold {
imageId: PresetsUtil.EIP155NetworkImageIds[id],
imageUrl: this.options?.chainImages?.[id]
});

const internalState = this.wagmiConfig.chains || [];
const isNetworkSupported = internalState.length === 0 ||
internalState.some((chainItem: Chain) =>
`${ConstantsUtil.EIP155}:${chainItem.id}` === caipChainId);
if (!isNetworkSupported) {
console.warn(`Network ${caipChainId} is not in the requested networks list`);
}

if (isConnected && address && chainId) {
const caipAddress: CaipAddress = `${ConstantsUtil.EIP155}:${id}:${address}`;
this.setCaipAddress(caipAddress);
Expand Down
Loading