Skip to content

Commit

Permalink
Merge pull request #108 from lidofinance/mm-fix-getTokenBalance
Browse files Browse the repository at this point in the history
fix MM getTokenBalance()
  • Loading branch information
itaven authored Nov 29, 2023
2 parents 72ece67 + e7ed7ae commit a02d663
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions packages/wallets/src/metamask/metamask.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,21 @@ export class MetamaskPage implements WalletPage {

async getTokenBalance(tokenName: string) {
await this.navigate();
await this.page
.getByTestId('multichain-token-list-button')
.locator(`p:has-text(${tokenName})`)
.textContent();
//Cannot find locator by exact text since need to find row by text "stETH"/"ETH" but "stETH" contains "ETH"
const elements = await this.page.$$(
'data-testid=multichain-token-list-item-value',
);
let tokenBalance = NaN;
for (const element of elements) {
await element.waitForElementState('visible');
const textContent = await element.textContent();
const letterTextContent = textContent.match(/[a-zA-Z]+/g);
if (letterTextContent.toString().trim() === tokenName) {
tokenBalance = parseFloat(await element.textContent());
break;
}
}
return tokenBalance;
}

async confirmTx(page: Page, setAggressiveGas?: boolean) {
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/src/wallet.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface WalletPage {

openLastTxInEthplorer?(txIndex?: number): Promise<Page>;

getTokenBalance?(tokenName: string): Promise<void>;
getTokenBalance?(tokenName: string): Promise<number>;

confirmAddTokenToWallet?(page: Page): Promise<void>;

Expand Down

0 comments on commit a02d663

Please sign in to comment.