Skip to content

Commit

Permalink
fix: upgrade metamask getTokenBalance() function and some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jake4take committed Dec 5, 2024
1 parent 44f8043 commit e5a6849
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/wallets/src/metamask/metamask.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ 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;
}
}
Expand Down
18 changes: 16 additions & 2 deletions packages/wallets/src/okx/okx.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ export class OkxPage implements WalletPage {
/** Checks the is installed the needed network and add new network to wallet (if needed) */
async setupNetwork(standConfig: Record<string, any>) {
await test.step(`Setup "${standConfig.chainName}" Network`, async () => {
await this.navigate();
await this.homePage.networkListButton.click();
await this.addNetwork(
standConfig.chainName,
standConfig.rpcUrl,
Expand Down Expand Up @@ -182,6 +180,12 @@ export class OkxPage implements WalletPage {
timeout: 10000,
});
await operationPage.connectButton.click();
// need wait the page to be closed after the extension is connected
await new Promise<void>((resolve) => {
operationPage.page.on('close', () => {
resolve();
});
});

await test.step('Sync the dApp network with wallet', async () => {
await this.navigate();
Expand Down Expand Up @@ -257,6 +261,16 @@ export class OkxPage implements WalletPage {
});
}

/** Get wallet address from wallet extension*/
async getWalletAddress() {
return await test.step('Get current wallet address', async () => {
await this.navigate();
const address = await this.homePage.getWalletAddress();
await this.page.close();
return address;
});
}

// need realize for mainnet
async openLastTxInEthplorer(txIndex = 0) {
console.error(
Expand Down
14 changes: 14 additions & 0 deletions packages/wallets/src/okx/pages/home.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import { Locator, Page, test } from '@playwright/test';
export class HomePage {
page: Page;
accountListButton: Locator;
copyAddressButton: Locator;
settingButton: Locator;
networkListButton: Locator;
manageCryptoButton: Locator;

constructor(page: Page) {
this.page = page;
this.accountListButton = this.page.locator('image[alt="wallet-avatar"]');
this.copyAddressButton = this.page
.getByTestId('okd-select-reference-value-box')
.locator('../../div')
.first();
this.settingButton = this.page
.getByTestId('okd-select-reference-value-box')
.locator('div')
Expand Down Expand Up @@ -82,4 +87,13 @@ export class HomePage {
// need wait some time to correct network install
await this.page.waitForTimeout(2000);
}

async getWalletAddress() {
await this.copyAddressButton.click();
return await this.page
.locator('span:has-text("address copied")')
.locator('../span')
.nth(1)
.textContent();
}
}

0 comments on commit e5a6849

Please sign in to comment.