Skip to content

Commit

Permalink
feat: update OKX methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jake4take committed Dec 9, 2024
1 parent 8f0df3e commit 3d11478
Show file tree
Hide file tree
Showing 15 changed files with 776 additions and 197 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
"branches": [
"main",
{
"name": "develop",
"name": "okx-wallet",
"channel": "alpha",
"prerelease": "alpha"
"prerelease": "okx"
}
]
}
Expand Down
62 changes: 23 additions & 39 deletions packages/wallets/src/metamask/metamask.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {
AccountMenu,
} from './pages/elements';
import { getAddress } from 'viem';
import { isNetworkPopular } from './services/service';

export class MetamaskPage implements WalletPage {
page: Page | undefined;
header: Header;
homePage: HomePage;
settingsPage: SettingsPage;
loginPage: LoginPage;
walletOperation: WalletOperationPage;
onboardingPage: OnboardingPage;
Expand All @@ -35,11 +35,6 @@ export class MetamaskPage implements WalletPage {
this.page = await this.browserContext.newPage();
this.header = new Header(this.page);
this.homePage = new HomePage(this.page, this.extensionUrl, this.config);
this.settingsPage = new SettingsPage(
this.page,
this.extensionUrl,
this.config,
);
this.loginPage = new LoginPage(this.page, this.config);
this.walletOperation = new WalletOperationPage(this.page);
this.onboardingPage = new OnboardingPage(this.page, this.config);
Expand Down Expand Up @@ -70,7 +65,11 @@ export class MetamaskPage implements WalletPage {
await this.popoverElements.closePopover();
await this.walletOperation.cancelAllTxInQueue(); // reject all tx in queue if exist
}
await this.settingsPage.setupNetworkChangingSetting(); // need to make it possible to change the wallet network
await new SettingsPage(
await this.browserContext.newPage(),
this.extensionUrl,
this.config,
).setupNetworkChangingSetting(); // need to make it possible to change the wallet network
});
}

Expand All @@ -79,21 +78,13 @@ export class MetamaskPage implements WalletPage {
await this.navigate();
await this.header.networkListButton.click();
await this.header.networkList.clickToNetwork(networkName);
if (networkName === 'Linea Mainnet') {
if (networkName === 'Linea') {
await this.popoverElements.closePopover(); //Linea network require additional confirmation
}
await this.page.close();
});
}

async switchNetwork(networkName = 'Linea Mainnet') {
await test.step(`Switch network to "${networkName}"`, async () => {
await this.navigate();
await this.header.networkList.switchNetwork(networkName);
await this.page.close();
});
}

async setupNetwork(standConfig: Record<string, any>) {
await test.step(`Setup "${standConfig.chainName}" Network`, async () => {
await this.header.networkListButton.click();
Expand Down Expand Up @@ -130,32 +121,21 @@ export class MetamaskPage implements WalletPage {
) {
await test.step(`Add new network "${networkName}"`, async () => {
await this.navigate();
await this.header.networkList.addNetworkManually(
networkName,
networkUrl,
chainId,
tokenSymbol,
blockExplorer,
);
if (await isNetworkPopular(networkName)) {
await this.header.networkList.addPopularNetwork(networkName);
} else {
await this.header.networkList.addNetworkManually(
networkName,
networkUrl,
chainId,
tokenSymbol,
blockExplorer,
);
}
if (isClosePage) await this.page.close();
});
}

async addPopularNetwork(networkName: string) {
await this.navigate();
await this.header.networkListButton.click();
const networkListText = await this.header.networkList.getNetworkListText();
if (networkListText.includes(networkName)) {
await this.header.networkList.clickToNetworkItemButton(networkName);
} else {
await test.step(`Add popular network "${networkName}"`, async () => {
await this.header.networkList.networkDisplayCloseBtn.click();
await this.header.networkList.addPopularNetwork(networkName);
});
}
await this.page.close();
}

async importKey(key: string) {
await test.step('Import key', async () => {
await this.navigate();
Expand Down Expand Up @@ -217,10 +197,14 @@ export class MetamaskPage implements WalletPage {
.toString()
.trim();
if (tokenNameFromValue === tokenName) {
tokenBalance = parseFloat(await value.textContent());
await value.click();
tokenBalance = parseFloat(
await this.homePage.tokensListItemValues.textContent(),
);
break;
}
}
await this.page.close();
return tokenBalance;
});
}
Expand Down
58 changes: 35 additions & 23 deletions packages/wallets/src/metamask/pages/elements/networkList.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,28 +119,40 @@ export class NetworkList {
}

async addPopularNetwork(networkName: string) {
await test.step(`Open the form to add the popular network (${networkName})`, async () => {
await this.networkListButton.click();
});
await test.step(`Add the "${networkName}" network`, async () => {
await this.dialogSection
.getByText(networkName)
.locator('../../..')
.locator('button:has-text("Add")')
.click();
// Without awaiting the button is not clickable
await this.page.waitForTimeout(500);
await this.approveAddNetworkButton.click();
await this.dialogSection.waitFor({ state: 'hidden' });
// Need to wait while the network to be added to the wallet
try {
await this.page
.getByText('Connecting to')
.waitFor({ state: 'visible', timeout: 5000 });
await this.page.getByText('Connecting to').waitFor({ state: 'hidden' });
} catch {
console.error('Connecting network was without loader');
}
});
await this.networkListButton.click();
const networkListText = await this.getNetworkListText();
if (networkListText.includes(networkName)) {
await this.clickToNetworkItemButton(networkName);
} else {
await test.step(`Add popular network "${networkName}"`, async () => {
await this.networkDisplayCloseBtn.click();
await test.step(`Open the form to add the popular network (${networkName})`, async () => {
await this.networkListButton.click();
});
await test.step(`Add the "${networkName}" network`, async () => {
await this.dialogSection
.getByText(networkName)
.locator('../../..')
.locator('button:has-text("Add")')
.click();
// Without awaiting the button is not clickable
await this.page.waitForTimeout(500);
await this.approveAddNetworkButton.click();
await this.dialogSection.waitFor({ state: 'hidden' });
// Need to wait while the network to be added to the wallet
try {
await this.page
.getByText('Connecting to')
.waitFor({ state: 'visible', timeout: 5000 });
await this.page
.getByText('Connecting to')
.waitFor({ state: 'hidden' });
} catch {
console.error('Connecting network was without loader');
}
});
});
}
await this.page.close();
}
}
13 changes: 13 additions & 0 deletions packages/wallets/src/metamask/services/service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const MMPopularNetworks = [
'zkSync Era Mainnet',
'OP Mainnet',
'Arbitrum One',
'Polygon Mainnet',
'Base Mainnet',
'Binance Smart Chain',
'Linea',
];

export async function isNetworkPopular(networkName: string) {
return MMPopularNetworks.includes(networkName);
}
Loading

0 comments on commit 3d11478

Please sign in to comment.