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 all 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
4 changes: 2 additions & 2 deletions apps/native/tests/shared/pages/ModalPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class ModalPage {
const qrLoadInitiatedTime = new Date();

const qrCode = this.page.getByTestId('qr-code');
await expect(qrCode).toBeVisible();
await expect(qrCode).toBeVisible({ timeout: 20000 });
const uri = await this.clickCopyLink();

const qrLoadedTime = new Date();
Expand All @@ -51,7 +51,7 @@ export class ModalPage {
const qrLoadInitiatedTime = new Date();

const qrCode = this.page.getByTestId('qr-code');
await expect(qrCode).toBeVisible();
await expect(qrCode).toBeVisible({ timeout: 20000 });
const uri = await this.clickCopyLink();
const qrLoadedTime = new Date();
if (timingRecords) {
Expand Down
4 changes: 2 additions & 2 deletions apps/native/tests/shared/pages/WalletPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export class WalletPage {
timeout: 30000
});
await expect(btn).toBeEnabled();
await btn.focus();
await this.page.keyboard.press('Space');
await this.page.waitForTimeout(1000);
await btn.click();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions apps/native/tests/shared/validators/WalletValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ export class WalletValidator {
async expectSessionCard({ visible = true }: { visible?: boolean }) {
if (visible) {
await expect(
this.page.getByTestId('session-card'),
this.page.getByTestId('session-card').first(),
'Session card should be visible'
).toBeVisible({
timeout: MAX_WAIT
});
} else {
await expect(
this.page.getByTestId('session-card'),
this.page.getByTestId('session-card').first(),
'Session card should not be visible'
).not.toBeVisible({
timeout: MAX_WAIT
Expand All @@ -46,7 +46,7 @@ export class WalletValidator {
async expectDisconnected() {
await this.gotoSessions.click();
await expect(
this.page.getByTestId('session-card'),
this.page.getByTestId('session-card').first(),
'Session card should not be visible'
).not.toBeVisible({
timeout: MAX_WAIT
Expand Down
2 changes: 1 addition & 1 deletion apps/native/tests/wallet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ sampleWalletTest('it should disconnect using hook', async () => {
await modalValidator.expectDisconnected();
});

sampleWalletTest('it should disconnect and close modal when connecting from wallet', async () => {
sampleWalletTest('it should disconnect and close modal when disconnecting from wallet', async () => {
await modalValidator.expectDisconnected();
await modalPage.qrCodeFlow(modalPage, walletPage);
await modalValidator.expectConnected();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const client: NetworkControllerClient = {
const initialState = {
_client: client,
supportsAllNetworks: true,
isDefaultCaipNetwork: false,
smartAccountEnabledNetworks: []
};

Expand Down Expand Up @@ -65,7 +64,7 @@ describe('NetworkController', () => {
it('should update state correctly on setDefaultCaipNetwork()', () => {
NetworkController.setDefaultCaipNetwork(caipNetwork);
expect(NetworkController.state.caipNetwork).toEqual(caipNetwork);
expect(NetworkController.state.isDefaultCaipNetwork).toEqual(true);
expect(NetworkController.state.defaultCaipNetwork).toEqual(caipNetwork);
});

it('should reset state correctly when default caip network is true', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/controllers/ConnectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const ConnectionController = {

async connectExternal(options: ConnectExternalOptions) {
await this._getClient().connectExternal?.(options);
ConnectorController.setConnectedConnector(options.type);
await ConnectorController.setConnectedConnector(options.type);
},

async signMessage(message: string) {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/controllers/ConnectorController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ export const ConnectorController = {
return state.connectors.find(c => c.type === 'AUTH');
},

setConnectedConnector(
async setConnectedConnector(
connectorType: ConnectorControllerState['connectedConnector'],
saveStorage = true
) {
state.connectedConnector = connectorType;

if (saveStorage) {
if (connectorType) {
StorageUtil.setConnectedConnector(connectorType);
await StorageUtil.setConnectedConnector(connectorType);
} else {
StorageUtil.removeConnectedConnector();
await StorageUtil.removeConnectedConnector();
}
}
},
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/controllers/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export interface NetworkControllerClient {

export interface NetworkControllerState {
supportsAllNetworks: boolean;
isDefaultCaipNetwork: boolean;
_client?: NetworkControllerClient;
caipNetwork?: CaipNetwork;
defaultCaipNetwork?: CaipNetwork;
requestedCaipNetworks?: CaipNetwork[];
approvedCaipNetworkIds?: CaipNetworkId[];
smartAccountEnabledNetworks: number[];
Expand All @@ -26,7 +26,7 @@ export interface NetworkControllerState {
// -- State --------------------------------------------- //
const state = proxy<NetworkControllerState>({
supportsAllNetworks: true,
isDefaultCaipNetwork: false,
defaultCaipNetwork: undefined,
smartAccountEnabledNetworks: []
});

Expand All @@ -53,7 +53,7 @@ export const NetworkController = {

setDefaultCaipNetwork(caipNetwork: NetworkControllerState['caipNetwork']) {
state.caipNetwork = caipNetwork;
state.isDefaultCaipNetwork = true;
state.defaultCaipNetwork = caipNetwork;
PublicStateController.set({ selectedNetworkId: caipNetwork?.id });
},

Expand Down Expand Up @@ -84,9 +84,11 @@ export const NetworkController = {
},

getApprovedCaipNetworks() {
return state.approvedCaipNetworkIds
const networks = state.approvedCaipNetworkIds
?.map(id => state.requestedCaipNetworks?.find(network => network.id === id))
.filter(Boolean) as CaipNetwork[];

return networks ?? [];
},

getSmartAccountEnabledNetworks() {
Expand All @@ -110,9 +112,7 @@ export const NetworkController = {
},

resetNetwork() {
if (!state.isDefaultCaipNetwork) {
state.caipNetwork = undefined;
}
state.caipNetwork = state.defaultCaipNetwork || undefined;
state.approvedCaipNetworkIds = undefined;
state.supportsAllNetworks = true;
state.smartAccountEnabledNetworks = [];
Expand Down
12 changes: 7 additions & 5 deletions packages/core/src/utils/NetworkUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ import { SwapController } from '../controllers/SwapController';
import type { CaipNetwork } from '../utils/TypeUtil';

export const NetworkUtil = {
async handleNetworkSwitch(network: CaipNetwork) {
async handleNetworkSwitch(network: CaipNetwork, navigate: boolean = true) {
const { isConnected } = AccountController.state;
const { caipNetwork, approvedCaipNetworkIds, supportsAllNetworks } = NetworkController.state;
const isAuthConnected = ConnectorController.state.connectedConnector === 'AUTH';
const isAuthConnector = ConnectorController.state.connectedConnector === 'AUTH';
let eventData = null;

if (isConnected && caipNetwork?.id !== network.id) {
if (approvedCaipNetworkIds?.includes(network.id) && !isAuthConnected) {
if (approvedCaipNetworkIds?.includes(network.id) && !isAuthConnector) {
await NetworkController.switchActiveNetwork(network);
RouterUtil.navigateAfterNetworkSwitch(['ConnectingSiwe']);
if (navigate) {
RouterUtil.goBackOrCloseModal();
}
eventData = { type: 'SWITCH_NETWORK', networkId: network.id };
} else if (supportsAllNetworks || isAuthConnected) {
} else if (supportsAllNetworks || isAuthConnector) {
RouterController.push('SwitchNetwork', { network });
}
} else if (!isConnected) {
Expand Down
17 changes: 4 additions & 13 deletions packages/core/src/utils/RouterUtil.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import { RouterController, type RouterControllerState } from '../controllers/RouterController';
import { RouterController } from '../controllers/RouterController';
import { ModalController } from '../controllers/ModalController';

export const RouterUtil = {
navigateAfterNetworkSwitch(excludeViews: RouterControllerState['view'][] = []) {
if (excludeViews.includes(RouterController.state.view)) {
return;
}

const { history } = RouterController.state;
const networkSelectIndex = history.findIndex(
name => name === 'Networks' || name === 'UnsupportedChain'
);

if (networkSelectIndex >= 1) {
RouterController.goBackToIndex(networkSelectIndex - 1);
goBackOrCloseModal() {
if (RouterController.state.history.length > 1) {
RouterController.goBack();
} else {
ModalController.close();
}
Expand Down
Loading