Skip to content

Commit

Permalink
feat(deal-ticket): fix size calculation when positionDecimalPlaces is…
Browse files Browse the repository at this point in the history
… negative (#6482)
  • Loading branch information
bglownia authored May 29, 2024
1 parent 9bf0c51 commit d394678
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 17 deletions.
6 changes: 3 additions & 3 deletions apps/trading/e2e/.env
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion apps/trading/e2e/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
6 changes: 3 additions & 3 deletions apps/trading/e2e/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/trading/e2e/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion apps/trading/e2e/tests/spot_market/test_spot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
]
Expand Down
2 changes: 1 addition & 1 deletion apps/trading/e2e/tests/teams/test_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
Expand Down
2 changes: 2 additions & 0 deletions apps/trading/e2e/vegahome/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"name": "VOTE",
"symbol": "VOTE",
"decimals": 5,
"quantum": "1",
"min_lp_stake": "1",
"source": {
"builtin_asset": {
Expand All @@ -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",
Expand Down
22 changes: 15 additions & 7 deletions libs/deal-ticket/src/components/deal-ticket/deal-ticket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit d394678

Please sign in to comment.