Skip to content

Commit

Permalink
fix: fixed balance waiter
Browse files Browse the repository at this point in the history
  • Loading branch information
jake4take committed Jan 29, 2025
1 parent 0f6c4e3 commit 06a723a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 7 additions & 5 deletions playwright-tests/services/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
* Example:
* ```ts
* 0.12345 => toCut('0.12345', 3) => '0.123'
* 0.101 => toCut('0.101', 2, true) => '0.1'
* ```
*/
export function toCut(amount: any, decimalPlaces: number) {
const result = String(amount).split(/\./);
export function toCut(amount: any, decimalPlaces: number, removeZero = false) {
const parts = String(amount).split(/\./);
let respLength: number;
if (result.length === 2) {
respLength = result[0].length + 1 + decimalPlaces;
if (parts.length === 2) {
respLength = parts[0].length + 1 + decimalPlaces;
}
return String(amount).slice(0, respLength);
const response = String(amount).slice(0, respLength);
return removeZero ? String(parseFloat(response)) : response;
}

/**
Expand Down
10 changes: 9 additions & 1 deletion playwright-tests/services/sdk.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export class SdkService extends LidoSDK {
});
}

/**
Get token balance from SDK without 0 in the end of number
Example:
```ts
// ETH balance = 1.102
getBalanceByToken(stdToken.ETH, 2) => '1.1'
```
*/
async getBalanceByToken(token: sdkToken, decimalPlaces: number) {
let balance: string;
switch (token) {
Expand All @@ -39,7 +47,7 @@ export class SdkService extends LidoSDK {
balance = formatEther(await this.wsteth.balance());
break;
}
return toCut(balance, decimalPlaces);
return toCut(balance, decimalPlaces, true);
}

async exchangeEthToWstEth(amount: any) {
Expand Down

0 comments on commit 06a723a

Please sign in to comment.