From d3946788e92754482b391d52bcd8ffd779896ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20G=C5=82ownia?= Date: Wed, 29 May 2024 18:07:05 +0200 Subject: [PATCH] feat(deal-ticket): fix size calculation when positionDecimalPlaces is negative (#6482) --- apps/trading/e2e/.env | 6 ++--- apps/trading/e2e/config.py | 2 +- apps/trading/e2e/poetry.lock | 6 ++--- apps/trading/e2e/pyproject.toml | 2 +- .../e2e/tests/spot_market/test_spot.py | 2 +- apps/trading/e2e/tests/teams/test_teams.py | 2 +- apps/trading/e2e/vegahome/genesis.json | 2 ++ .../components/deal-ticket/deal-ticket.tsx | 22 +++++++++++++------ 8 files changed, 27 insertions(+), 17 deletions(-) diff --git a/apps/trading/e2e/.env b/apps/trading/e2e/.env index 71208ef3a1..e7cee5a466 100644 --- a/apps/trading/e2e/.env +++ b/apps/trading/e2e/.env @@ -1,4 +1,4 @@ -CONSOLE_IMAGE_NAME=vegaprotocol/trading:latest -VEGA_VERSION=v0.76.1 +CONSOLE_IMAGE_NAME=vegaprotocol/trading:main +VEGA_VERSION=v0.76.8 LOCAL_SERVER=false -VEGA_ENV=STAGNET1 +VEGA_ENV=MAINNET diff --git a/apps/trading/e2e/config.py b/apps/trading/e2e/config.py index 73cda92766..ac3f1b507f 100644 --- a/apps/trading/e2e/config.py +++ b/apps/trading/e2e/config.py @@ -4,6 +4,6 @@ load_dotenv() console_image_name = os.getenv( - "CONSOLE_IMAGE_NAME", default="vegaprotocol/trading:latest" + "CONSOLE_IMAGE_NAME", default="vegaprotocol/trading:main" ) vega_version = os.getenv("VEGA_VERSION", default="latest") diff --git a/apps/trading/e2e/poetry.lock b/apps/trading/e2e/poetry.lock index 103c1eddd8..0bd59540c2 100644 --- a/apps/trading/e2e/poetry.lock +++ b/apps/trading/e2e/poetry.lock @@ -1124,8 +1124,8 @@ profile = ["pytest-profiling", "snakeviz"] [package.source] type = "git" url = "https://github.com/vegaprotocol/vega-market-sim.git/" -reference = "release/vega-v0.76.1" -resolved_reference = "01d1075af32c5deb1132676466ffe16ecde59d69" +reference = "pre-release/vega-v0.76.8" +resolved_reference = "d95ce9b33607f6790f32133e9a9e292e3b32078f" [[package]] name = "websocket" @@ -1391,4 +1391,4 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.11" -content-hash = "4fb5f4b8ca58ee89896526c5f8912f36ffa99c7702585d5e5b87bc13fdcc5042" +content-hash = "7ceabdeb28898a643cc887f9050b1c64d360389c36cdd6d4c1cff1be9496683a" diff --git a/apps/trading/e2e/pyproject.toml b/apps/trading/e2e/pyproject.toml index 4d98e3394f..132c80bb15 100644 --- a/apps/trading/e2e/pyproject.toml +++ b/apps/trading/e2e/pyproject.toml @@ -14,7 +14,7 @@ docker = "6.0.0" requests = "2.26.0" pytest-xdist = "^3.3.1" python-dotenv = "^1.0.0" -vega-sim = { git = "https://github.com/vegaprotocol/vega-market-sim.git/", branch = "release/vega-v0.76.1" } +vega-sim = { git = "https://github.com/vegaprotocol/vega-market-sim.git/", branch = "pre-release/vega-v0.76.8" } [build-system] requires = ["poetry-core"] diff --git a/apps/trading/e2e/tests/spot_market/test_spot.py b/apps/trading/e2e/tests/spot_market/test_spot.py index 4e8c90218f..1a588cc12a 100644 --- a/apps/trading/e2e/tests/spot_market/test_spot.py +++ b/apps/trading/e2e/tests/spot_market/test_spot.py @@ -63,7 +63,7 @@ def test_market_spot_info_market_price(page: Page): "Market price").click() fields = [ ["Mark Price", "107.5"], - ["Best Bid Price", "101.5"], + ["Best Bid Price", "102.0"], ["Best Offer Price", "103.5"], ["Quote Unit", "USDT"], ] diff --git a/apps/trading/e2e/tests/teams/test_teams.py b/apps/trading/e2e/tests/teams/test_teams.py index 041745d9dd..aaeb010c2c 100644 --- a/apps/trading/e2e/tests/teams/test_teams.py +++ b/apps/trading/e2e/tests/teams/test_teams.py @@ -265,7 +265,7 @@ def test_team_page_members_table(team_page: Tuple[Page, str, str, VegaServiceNul "Owner" ) expect(page.get_by_test_id("joinedAt-0")).to_be_visible() - expect(page.get_by_test_id("joinedAtEpoch-0")).to_have_text("8") + expect(page.get_by_test_id("joinedAtEpoch-0")).to_have_text("7") def test_team_page_headline(team_page: Tuple[Page, str, str, VegaServiceNull]): diff --git a/apps/trading/e2e/vegahome/genesis.json b/apps/trading/e2e/vegahome/genesis.json index f03c60dcf5..e95f2cabef 100644 --- a/apps/trading/e2e/vegahome/genesis.json +++ b/apps/trading/e2e/vegahome/genesis.json @@ -36,6 +36,7 @@ "name": "VOTE", "symbol": "VOTE", "decimals": 5, + "quantum": "1", "min_lp_stake": "1", "source": { "builtin_asset": { @@ -62,6 +63,7 @@ }, "network_parameters": { "blockchains.ethereumConfig": "{\"network_id\": \"3\", \"chain_id\": \"3\", \"collateral_bridge_contract\": { \"address\": \"0xa6F1E140daC13002Dfd9789D6dBA59117c717D7a\" }, \"confirmations\": 50, \"staking_bridge_contract\": { \"address\": \"0xfce2CC92203A266a9C8e67461ae5067c78f67235\", \"deployment_block_height\": 11001702}, \"multisig_control_contract\": {\"address\": \"0xCF6d41235911184fe6F35D47207813bFF3B91601\", \"deployment_block_height\": 12710009 } }", + "blockchains.evmBridgeConfigs": "{\"configs\":[{\"network_id\": \"3\", \"chain_id\": \"3\", \"collateral_bridge_contract\": { \"address\": \"0xa6F1E140daC13002Dfd9789D6dBA59117c717D7a\" }, \"confirmations\": 50, \"multisig_control_contract\": {\"address\": \"0xCF6d41235911184fe6F35D47207813bFF3B91601\", \"deployment_block_height\": 12710009 } }]}", "blockchains.ethereumRpcAndEvmCompatDataSourcesConfig": "{\"configs\": []}", "governance.proposal.asset.maxClose": "8760h0m0s", "governance.proposal.asset.maxEnact": "8760h0m0s", diff --git a/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx b/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx index 0901568811..c319bb50a2 100644 --- a/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx +++ b/libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx @@ -438,13 +438,21 @@ export const DealTicket = ({ return; } if (useNotional && !sliderUsed.current) { - const size = - !notional || notional === '0' - ? '0' - : BigNumber(notional) - .dividedBy(toBigNum(notionalPrice, market.decimalPlaces)) - .toFixed(market.positionDecimalPlaces); - + let size = '0'; + if (notional && notional !== '0') { + const s = BigNumber(notional).dividedBy( + toBigNum(notionalPrice, market.decimalPlaces) + ); + if (market.positionDecimalPlaces >= 0) { + size = s.toFixed(market.positionDecimalPlaces); + } else { + const p = market.positionDecimalPlaces * -1; + size = `${s.dividedBy(Math.pow(10, p)).toFixed(0)}${''.padEnd( + p, + '0' + )}`; + } + } setValue('size', size); } else { const notional =