Skip to content

Commit

Permalink
Merge pull request #3859 from osmosis-labs/stage
Browse files Browse the repository at this point in the history
Stage -> Master
  • Loading branch information
MaxMillington authored Sep 26, 2024
2 parents 2c99375 + 071740b commit 174c88d
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 50 deletions.
9 changes: 8 additions & 1 deletion packages/stores/src/account/osmosis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { DeliverTxResponse, SignOptions } from "../types";
import { findNewClPositionId } from "./tx-response";

const DEFAULT_SLIPPAGE = "2.5";
const HIGH_DEFAULT_SLIPPAGE = "15";

export interface OsmosisAccount {
osmosis: OsmosisAccountImpl;
Expand Down Expand Up @@ -1414,7 +1415,7 @@ export class OsmosisAccountImpl {
* https://docs.osmosis.zone/developing/modules/spec-gamm.html#exit-pool
* @param poolId Id of pool to exit.
* @param shareInAmount LP shares to redeem.
* @param maxSlippage Max tolerated slippage. Default: 2.5.
* @param maxSlippage Max tolerated slippage. Default: 2.5, 15 with high precision amounts.
* @param memo Transaction memo.
* @param onFulfill Callback to handle tx fullfillment given raw response.
*/
Expand Down Expand Up @@ -1444,6 +1445,12 @@ export class OsmosisAccountImpl {
makeExitPoolMsg.shareCoinDecimals
);

// If the token amount is very large, indicating high precision,
// increase slippage tolerance to allow for the high precision.
if (poolAssets.some(({ amount }) => amount.length > 18)) {
maxSlippage = HIGH_DEFAULT_SLIPPAGE;
}

const maxSlippageDec = new Dec(maxSlippage).quo(
DecUtils.getTenExponentNInPrecisionRange(2)
);
Expand Down
20 changes: 15 additions & 5 deletions packages/web/components/table/asset-balances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,24 @@ export const AssetBalancesTable: FunctionComponent<{
[assetPagesData]
);

const { watchListDenoms, toggleWatchAssetDenom } = useUserWatchlist();

const filteredAssetsData = useMemo(() => {
return assetsData
.map((asset) => {
const isDust = asset?.usdValue?.toDec()?.lte(DUST_THRESHOLD);
if (hideDust && isDust) return null;
return asset;
})
.filter((asset) => asset !== null);
}, [assetsData, hideDust]);
.filter((asset): asset is AssetRow => asset !== null)
.sort((a, b) => {
const aIsFavorite = watchListDenoms.includes(a.coinDenom);
const bIsFavorite = watchListDenoms.includes(b.coinDenom);
if (aIsFavorite && !bIsFavorite) return -1;
if (!aIsFavorite && bIsFavorite) return 1;
return 0;
});
}, [assetsData, hideDust, watchListDenoms]);

const hiddenDustCount = assetsData.length - filteredAssetsData.length;

Expand Down Expand Up @@ -243,14 +252,15 @@ export const AssetBalancesTable: FunctionComponent<{
/** Columns collapsed for screen size responsiveness. */
const collapsedColumns = useMemo(() => {
const collapsedColIds: string[] = [];
if (width < Breakpoint.lg) collapsedColIds.push("price");
if (width < Breakpoint.md) collapsedColIds.push("assetActions");
if (width < Breakpoint.lg) {
collapsedColIds.push("price");
collapsedColIds.push("assetActions");
}
return columns.filter(({ id }) => id && !collapsedColIds.includes(id));
}, [columns, width]);

const table = useReactTable({
data: filteredAssetsData,
// @ts-expect-error
columns: collapsedColumns,
manualSorting: true,
manualFiltering: true,
Expand Down
53 changes: 28 additions & 25 deletions packages/web/e2e/pages/swap-page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* eslint-disable import/no-extraneous-dependencies */
import { BrowserContext, expect, Locator, Page } from "@playwright/test";
import {
type BrowserContext,
expect,
type Locator,
type Page,
} from "@playwright/test";

import { BasePage } from "~/e2e/pages/base-page";

Expand Down Expand Up @@ -37,7 +42,7 @@ export class SwapPage extends BasePage {
// we expect that after 2 seconds tokens are loaded and any failure after this point should be considered a bug.
await this.page.waitForTimeout(2000);
const currentUrl = this.page.url();
console.log("FE opened at: " + currentUrl);
console.log(`FE opened at: ${currentUrl}`);
}

async flipTokenPair() {
Expand All @@ -52,7 +57,7 @@ export class SwapPage extends BasePage {
await this.page.waitForTimeout(2000);
await expect(this.swapInput).toHaveValue(amount, { timeout: 3000 });
const exchangeRate = await this.getExchangeRate();
console.log("Swap " + amount + " with rate: " + exchangeRate);
console.log(`Swap ${amount} with rate: ${exchangeRate}`);
}

async swapAndGetWalletMsg(context: BrowserContext) {
Expand All @@ -68,15 +73,15 @@ export class SwapPage extends BasePage {
const approvePage = await pageApprove;
await approvePage.waitForLoadState();
const approvePageTitle = approvePage.url();
console.log("Approve page is opened at: " + approvePageTitle);
console.log(`Approve page is opened at: ${approvePageTitle}`);
const approveBtn = approvePage.getByRole("button", {
name: "Approve",
});
await expect(approveBtn).toBeEnabled();
const msgContentAmount = await approvePage
.getByText("type: osmosis/poolmanager/")
.textContent();
console.log("Wallet is approving this msg: \n" + msgContentAmount);
console.log(`Wallet is approving this msg: \n${msgContentAmount}`);
// Approve trx
await approveBtn.click();
// wait for trx confirmation
Expand All @@ -88,53 +93,51 @@ export class SwapPage extends BasePage {

async selectPair(from: string, to: string) {
// Filter does not show already selected tokens
console.log("Select pair " + from + " to " + to);
console.log(`Select pair ${from} to ${to}`);
const tokenLocator =
'//img[@alt="token icon"]/../..//h5 | //img[@alt="token icon"]/../..//span[@class="subtitle1"]';
const fromToken = this.page.locator(tokenLocator).nth(0);
const toToken = this.page.locator(tokenLocator).nth(1);

let fromTokenText = await fromToken.innerText();
let toTokenText = await toToken.innerText();
console.log("Current pair: " + fromTokenText + " / " + toTokenText);
const fromTokenText = await fromToken.innerText();
const toTokenText = await toToken.innerText();
console.log(`Current pair: ${fromTokenText} / ${toTokenText}`);

if (fromTokenText == from && toTokenText == to) {
if (fromTokenText === from && toTokenText === to) {
console.log(
"Current pair: " + fromTokenText + toTokenText + " is already matching."
`Current pair: ${fromTokenText}${toTokenText} is already matching.`
);
return;
}

if (fromTokenText == to && toTokenText == from) {
if (fromTokenText === to && toTokenText === from) {
await this.flipTokenPair();
console.log(
"Current pair: " + fromTokenText + toTokenText + " is fliped."
);
console.log(`Current pair: ${fromTokenText}${toTokenText} is fliped.`);
return;
}

if (from == toTokenText || to == fromTokenText) {
if (from === toTokenText || to === fromTokenText) {
await this.flipTokenPair();
}

if (fromTokenText != from && toTokenText != from) {
if (fromTokenText !== from && toTokenText !== from) {
await fromToken.click();
// we expect that after 1 second token filter is displayed.
await this.page.waitForTimeout(1000);
await this.page.getByPlaceholder("Search").fill(from);
const fromLocator = this.page.locator(
"//div/button[@data-testid]//h6[.='" + from + "']"
`//div/button[@data-testid]//h6[.='${from}']`
);
await fromLocator.click();
}

if (toTokenText != to && fromTokenText != to) {
if (toTokenText !== to && fromTokenText !== to) {
await toToken.click();
// we expect that after 1 second token filter is displayed.
await this.page.waitForTimeout(1000);
await this.page.getByPlaceholder("Search").fill(to);
const toLocator = this.page.locator(
"//div/button[@data-testid]//h6[.='" + to + "']"
`//div/button[@data-testid]//h6[.='${to}']`
);
await toLocator.click();
}
Expand All @@ -157,7 +160,7 @@ export class SwapPage extends BasePage {

async getTransactionUrl() {
const trxUrl = await this.trxLink.getAttribute("href");
console.log("Trx url: " + trxUrl);
console.log(`Trx url: ${trxUrl}`);
return trxUrl;
}

Expand All @@ -181,7 +184,7 @@ export class SwapPage extends BasePage {
async showSwapInfo() {
const swapInfo = this.page.locator("//button//span[.='Show details']");
await swapInfo.click();
console.log("Price Impact: " + (await this.getPriceInpact()));
console.log(`Price Impact: ${await this.getPriceInpact()}`);
}

async getPriceInpact() {
Expand All @@ -204,9 +207,9 @@ export class SwapPage extends BasePage {
const fromToken = this.page.locator(tokenLocator).nth(0);
const toToken = this.page.locator(tokenLocator).nth(1);

let fromTokenText = await fromToken.innerText();
let toTokenText = await toToken.innerText();
console.log("Current pair: " + `${fromTokenText}/${toTokenText}`);
const fromTokenText = await fromToken.innerText();
const toTokenText = await toToken.innerText();
console.log(`Current pair: ${fromTokenText}/${toTokenText}`);
return `${fromTokenText}/${toTokenText}`;
}
}
37 changes: 21 additions & 16 deletions packages/web/e2e/pages/trade-page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/* eslint-disable import/no-extraneous-dependencies */
import { BrowserContext, expect, Locator, Page } from "@playwright/test";
import {
type BrowserContext,
expect,
type Locator,
type Page,
} from "@playwright/test";

import { BasePage } from "~/e2e/pages/base-page";

Expand Down Expand Up @@ -59,7 +64,7 @@ export class TradePage extends BasePage {
// we expect that after 2 seconds tokens are loaded and any failure after this point should be considered a bug.
await this.page.waitForTimeout(2000);
const currentUrl = this.page.url();
console.log("FE opened at: " + currentUrl);
console.log(`FE opened at: ${currentUrl}`);
}

async gotoOrdersHistory(timeout: number = 1) {
Expand All @@ -68,7 +73,7 @@ export class TradePage extends BasePage {
await this.page.waitForTimeout(1000);
await new Promise((f) => setTimeout(f, timeout * 1000));
const currentUrl = this.page.url();
console.log("FE opened at: " + currentUrl);
console.log(`FE opened at: ${currentUrl}`);
}

async openBuyTab() {
Expand All @@ -86,7 +91,7 @@ export class TradePage extends BasePage {

async getLimitPrice() {
const lp = await this.limitPrice.inputValue();
console.log("Current limit price is: " + lp);
console.log(`Current limit price is: ${lp}`);
return lp;
}

Expand Down Expand Up @@ -119,7 +124,7 @@ export class TradePage extends BasePage {
await this.page.waitForTimeout(2000);
await expect(this.inputAmount).toHaveValue(amount, { timeout: 3000 });
const exchangeRate = await this.getExchangeRate();
console.log("Swap " + amount + " with rate: " + exchangeRate);
console.log(`Swap ${amount} with rate: ${exchangeRate}`);
}

async swapAndGetWalletMsg(context: BrowserContext) {
Expand All @@ -136,15 +141,15 @@ export class TradePage extends BasePage {
const approvePage = await pageApprove;
await approvePage.waitForLoadState();
const approvePageTitle = approvePage.url();
console.log("Approve page is opened at: " + approvePageTitle);
console.log(`Approve page is opened at: ${approvePageTitle}`);
const approveBtn = approvePage.getByRole("button", {
name: "Approve",
});
await expect(approveBtn).toBeEnabled();
const msgContentAmount = await approvePage
.getByText("type: osmosis/poolmanager/")
.textContent();
console.log("Wallet is approving this msg: \n" + msgContentAmount);
console.log(`Wallet is approving this msg: \n${msgContentAmount}`);
// Approve trx
await approveBtn.click();
// wait for trx confirmation
Expand All @@ -162,14 +167,14 @@ export class TradePage extends BasePage {
await this.page.waitForTimeout(1000);
await this.page.getByPlaceholder("Search").fill(token);
const fromLocator = this.page.locator(
"//div/button[@data-testid='token-select-asset']//span[.='" + token + "']"
`//div/button[@data-testid='token-select-asset']//span[.='${token}']`
);
await fromLocator.click();
}

async selectPair(from: string, to: string) {
// Filter does not show already selected tokens
console.log("Select pair " + from + " to " + to);
console.log(`Select pair ${from} to ${to}`);
const fromToken = this.page.locator(
"//div//button[@data-testid='token-in']//img[@alt]"
);
Expand Down Expand Up @@ -218,7 +223,7 @@ export class TradePage extends BasePage {

async getTransactionUrl() {
const trxUrl = await this.trxLink.getAttribute("href");
console.log("Trx url: " + trxUrl);
console.log(`Trx url: ${trxUrl}`);
return trxUrl;
}

Expand Down Expand Up @@ -249,7 +254,7 @@ export class TradePage extends BasePage {
async showSwapInfo() {
const swapInfo = this.page.locator("//button//span[.='Show details']");
await swapInfo.click();
console.log("Price Impact: " + (await this.getPriceInpact()));
console.log(`Price Impact: ${await this.getPriceInpact()}`);
}

async getPriceInpact() {
Expand All @@ -271,9 +276,9 @@ export class TradePage extends BasePage {
const fromToken = this.page.locator(tokenLocator).nth(0);
const toToken = this.page.locator(tokenLocator).nth(1);
await expect(fromToken).toBeVisible({ timeout: 2000 });
let fromTokenText = await fromToken.innerText();
let toTokenText = await toToken.innerText();
console.log("Current pair: " + `${fromTokenText}/${toTokenText}`);
const fromTokenText = await fromToken.innerText();
const toTokenText = await toToken.innerText();
console.log(`Current pair: ${fromTokenText}/${toTokenText}`);
return `${fromTokenText}/${toTokenText}`;
}

Expand Down Expand Up @@ -304,7 +309,7 @@ export class TradePage extends BasePage {
const msgContentAmount = await approvePage
.getByText(msgTextLocator)
.textContent();
console.log("Wallet is approving this msg: \n" + msgContentAmount);
console.log(`Wallet is approving this msg: \n${msgContentAmount}`);
// Approve trx
await approveBtn.click();
// wait for trx confirmation
Expand Down Expand Up @@ -340,7 +345,7 @@ export class TradePage extends BasePage {
const msgContentAmount = await approvePage
.getByText(msgTextLocator)
.textContent();
console.log("Wallet is approving this msg: \n" + msgContentAmount);
console.log(`Wallet is approving this msg: \n${msgContentAmount}`);
// Approve trx
await approveBtn.click();
// wait for trx confirmation
Expand Down
Loading

0 comments on commit 174c88d

Please sign in to comment.