|
| 1 | +import { Page } from 'playwright-core'; |
| 2 | +import { waitForChromeState } from '../../../helpers'; |
| 3 | +import { AddNetwork, UpdateNetworkRpc } from '../../../types'; |
| 4 | +import { goHome } from './helpers'; |
| 5 | + |
| 6 | +export const addNetwork = |
| 7 | + (page: Page) => |
| 8 | + async (options: AddNetwork): Promise<void> => { |
| 9 | + await page.getByTestId('settings-navigation-link').click(); |
| 10 | + await page.getByTestId('network-setting-cell-pressable').click(); |
| 11 | + await page.getByTestId('add-custom-network').click(); |
| 12 | + await page.getByTestId('custom-network-name-input').fill(options.networkName); |
| 13 | + await page.getByTestId('custom-network-rpc-url-input').fill(options.rpc); |
| 14 | + await page.getByTestId('custom-network-chain-id-input').fill(options.chainId.toString()); |
| 15 | + await page.getByTestId('custom-network-currency-symbol-input').fill(options.symbol); |
| 16 | + await page.getByTestId('custom-network-save').click(); |
| 17 | + |
| 18 | + // Check for error messages |
| 19 | + let errorNode; |
| 20 | + try { |
| 21 | + errorNode = await page.waitForSelector('//span[@data-testid="text-input-error-label"]', { |
| 22 | + timeout: 50, |
| 23 | + }); |
| 24 | + } catch { |
| 25 | + // No errors found |
| 26 | + } |
| 27 | + |
| 28 | + if (errorNode) { |
| 29 | + const errorMessage = await errorNode.textContent(); |
| 30 | + throw new SyntaxError(errorMessage); |
| 31 | + } |
| 32 | + |
| 33 | + await waitForChromeState(page); |
| 34 | + await goHome(page); |
| 35 | + }; |
| 36 | + |
| 37 | +export const deleteNetwork = |
| 38 | + (page: Page) => |
| 39 | + async (name: string): Promise<void> => { |
| 40 | + await page.getByTestId('settings-navigation-link').click(); |
| 41 | + await page.getByTestId('network-setting-cell-pressable').click(); |
| 42 | + |
| 43 | + // Search for network then click on the first result |
| 44 | + await page.getByTestId('network-list-search').fill(name); |
| 45 | + await (await page.waitForSelector('//div[@data-testid="list-"][1]//button')).click(); |
| 46 | + |
| 47 | + await page.getByTestId('custom-network-delete').click(); |
| 48 | + await goHome(page); |
| 49 | + }; |
| 50 | + |
| 51 | +export const hasNetwork = |
| 52 | + (page: Page) => |
| 53 | + async (name: string): Promise<boolean> => { |
| 54 | + await page.getByTestId('settings-navigation-link').click(); |
| 55 | + await page.getByTestId('network-setting').click(); |
| 56 | + await page.getByTestId('network-list-search').fill(name); |
| 57 | + const networkIsListed = await page.isVisible('//div[@data-testid="list-"][1]//button'); |
| 58 | + await goHome(page); |
| 59 | + return networkIsListed; |
| 60 | + }; |
| 61 | + |
| 62 | +export const switchNetwork = async (_: string): Promise<void> => { |
| 63 | + // eslint-disable-next-line no-console |
| 64 | + console.warn('switchNetwork not implemented'); |
| 65 | +}; |
| 66 | + |
| 67 | +// TODO: Cannot implement until verified coinbase wallet bug is fixed. |
| 68 | +export const confirmNetworkSwitch = async (): Promise<void> => { |
| 69 | + // eslint-disable-next-line no-console |
| 70 | + console.warn('confirmNetorkSwitch not implemented'); |
| 71 | +}; |
| 72 | + |
| 73 | +export const updateNetworkRpc = async (_: UpdateNetworkRpc): Promise<void> => { |
| 74 | + // eslint-disable-next-line no-console |
| 75 | + console.warn('updateNetworkRpc not implemented - Coinbase uses different network management'); |
| 76 | +}; |
0 commit comments