Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v7.4.5 #2630

Merged
merged 25 commits into from
Jul 19, 2023
Merged

v7.4.5 #2630

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
aa84aa6
Add a buffer on valid stop loss price
avclarke Jul 13, 2023
297ba94
Fix tests
avclarke Jul 17, 2023
161d33d
Merge branch 'dev' into fix/stop-loss-limit
avclarke Jul 17, 2023
fa948ac
Clean up
avclarke Jul 17, 2023
99a2458
Break up tests
avclarke Jul 17, 2023
2ed483f
Clean up
avclarke Jul 18, 2023
385594d
Merge branch 'dev' into fix/stop-loss-limit
avclarke Jul 18, 2023
a3a5f83
Decimal precision updates
avclarke Jul 18, 2023
19c3dc8
Merge pull request #2595 from Kwenta/fix/stop-loss-limit
avclarke Jul 18, 2023
7207f5a
Bump version
avclarke Jul 18, 2023
33cc5fb
Fixed the re-rendered issue of the socket after switching the network
LeifuChen Jul 18, 2023
f2a988e
Removed the unnecessary changes
LeifuChen Jul 18, 2023
840d819
Merge branch 'dev' into fix/socket-non-op
LeifuChen Jul 18, 2023
7bdb651
Merge pull request #2624 from Kwenta/fix/socket-non-op
avclarke Jul 18, 2023
c73f285
Merge pull request #2623 from Kwenta/bump-version
avclarke Jul 18, 2023
c48640f
Fix chart query
avclarke Jul 18, 2023
e057202
Merge pull request #2625 from Kwenta/fix/chart
avclarke Jul 18, 2023
350ae00
Increased the timeout to 10s
LeifuChen Jul 19, 2023
036a944
Merge pull request #2627 from Kwenta/fix/trading-rewards
avclarke Jul 19, 2023
7930cca
Fix: Minor design and sdk bugs (#2626)
LeifuChen Jul 19, 2023
0310bcf
Revert price impact change
avclarke Jul 19, 2023
88b4fb1
Merge pull request #2628 from Kwenta/revert-impact-change
avclarke Jul 19, 2023
2f49c73
Added aws bucket support
LeifuChen Jul 19, 2023
7825b4c
Create two clients instead of initialising each time
LeifuChen Jul 19, 2023
66f6ff2
Merge pull request #2629 from Kwenta/fix/switch-aws-bucket
avclarke Jul 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kwenta",
"version": "7.4.4",
"version": "7.4.5",
"description": "Kwenta",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kwenta/app",
"version": "7.4.4",
"version": "7.4.5",
"scripts": {
"dev": "next",
"build": "next build",
Expand Down
206 changes: 205 additions & 1 deletion packages/app/src/__tests__/pages/market.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { FuturesMarket } from '@kwenta/sdk/dist/types'
import { FuturesMarket, PositionSide } from '@kwenta/sdk/types'
import { wei } from '@synthetixio/wei'
import { fireEvent, render, waitFor } from '@testing-library/react'
import { ReactNode } from 'react'

import { mockFuturesService } from 'state/__mocks__/sdk'
import { fetchMarkets } from 'state/futures/actions'

import { mockResizeObserver } from '../../../testing/unit/mocks/app'
import { PRELOADED_STATE } from '../../../testing/unit/mocks/data/app'
import {
MOCK_TRADE_PREVIEW,
mockSmartMarginAccount,
preloadedStateWithSmartMarginAccount,
SDK_MARKETS,
Expand Down Expand Up @@ -46,6 +48,12 @@ describe('Futures market page - smart margin', () => {
mockConnector()
})

beforeEach(() => {
// Reset the SDK mock
// @ts-ignore
sdk.futures = mockFuturesService()
})

test('Calculates correct fees from trade preview', async () => {
const { findByTestId, findByText } = render(
<MockProviders
Expand Down Expand Up @@ -194,3 +202,199 @@ describe('Futures market page - smart margin', () => {
expect(submitButton).toBeDisabled()
})
})

describe('Futures market page - stop loss validation', () => {
beforeAll(() => {
jest.setTimeout(60000)
mockUseWindowSize()
mockReactQuery()
mockResizeObserver()
mockConnector()
})

beforeEach(() => {
// Reset the SDK mock
// @ts-ignore
sdk.futures = mockFuturesService()
})

test('Restricts stop loss for LONG trade at correct price depending on leverage', async () => {
const store = setupStore(preloadedStateWithSmartMarginAccount())
const { findByTestId, findByText } = render(
<MockProviders route="market/?accountType=cross_margin&asset=sETH" store={store}>
<Market />
</MockProviders>
)

const marginInput = await findByTestId('set-order-margin-susd-desktop')
fireEvent.change(marginInput, { target: { value: '100' } })

const sizeInput = await findByTestId('set-order-size-amount-susd-desktop')
fireEvent.change(sizeInput, { target: { value: '1000' } })

const fees = await findByText('$1.69')
expect(fees).toBeTruthy()

const submitButton = await findByTestId('trade-panel-submit-button')
expect(submitButton).toBeEnabled()

const expandButton = await findByTestId('expand-sl-tp-button')
fireEvent.click(expandButton)

const approveButton = await findByTestId('sl-tp-ack-proceed')
fireEvent.click(approveButton)

const stopLossInput = await findByTestId('trade-panel-stop-loss-input')
fireEvent.change(stopLossInput, { target: { value: '1700' } })

// Min / Max SL is shown when invalid
const slMinMaxLabel = await findByText('Min: 1,735.52')
expect(slMinMaxLabel).toBeTruthy()
expect(submitButton).toBeDisabled()

// Input valid when above min
fireEvent.change(stopLossInput, { target: { value: '1750' } })
expect(submitButton).toBeEnabled()
})

test('Restricts stop loss for SHORT trade at correct price depending on leverage', async () => {
const store = setupStore(preloadedStateWithSmartMarginAccount())
const { findByTestId, findByText } = render(
<MockProviders route="market/?accountType=cross_margin&asset=sETH" store={store}>
<Market />
</MockProviders>
)

sdk.futures.getCrossMarginTradePreview = () =>
Promise.resolve({
...MOCK_TRADE_PREVIEW,
liqPrice: wei('2172.467580351348039045'),
side: PositionSide.SHORT,
size: wei('-0.541100000000000000'),
})

const shortToggle = await findByTestId('position-side-short-button')
fireEvent.click(shortToggle)

const marginInput = await findByTestId('set-order-margin-susd-desktop')
fireEvent.change(marginInput, { target: { value: '100' } })

const sizeInput = await findByTestId('set-order-size-amount-susd-desktop')
fireEvent.change(sizeInput, { target: { value: '1000' } })

const fees = await findByText('$1.69')
expect(fees).toBeTruthy()

const submitButton = await findByTestId('trade-panel-submit-button')
expect(submitButton).toBeEnabled()

const expandButton = await findByTestId('expand-sl-tp-button')
fireEvent.click(expandButton)

const approveButton = await findByTestId('sl-tp-ack-proceed')
fireEvent.click(approveButton)

const stopLossInput = await findByTestId('trade-panel-stop-loss-input')
fireEvent.change(stopLossInput, { target: { value: '2150' } })

// Min / Max SL is shown when invalid
// Liqudation price is 2,172.46 and stop is limited to 2,100.07
const slMinMaxLabel = await findByText('Max: 2,107.29')
expect(slMinMaxLabel).toBeTruthy()

expect(submitButton).toBeDisabled()

// Input valid when below max
fireEvent.change(stopLossInput, { target: { value: '2099' } })
expect(submitButton).toBeEnabled()
})

test('Stop loss becomes disabled above a certain leverage', async () => {
const store = setupStore(preloadedStateWithSmartMarginAccount())
const { findByTestId, findByText } = render(
<MockProviders route="market/?accountType=cross_margin&asset=sETH" store={store}>
<Market />
</MockProviders>
)

sdk.futures.getCrossMarginTradePreview = () =>
Promise.resolve({
...MOCK_TRADE_PREVIEW,
liqPrice: wei('1760'),
size: wei('1.1'),
leverage: wei('20'),
})

const marginInput = await findByTestId('set-order-margin-susd-desktop')
fireEvent.change(marginInput, { target: { value: '100' } })

const sizeInput = await findByTestId('set-order-size-amount-susd-desktop')
fireEvent.change(sizeInput, { target: { value: '2000' } })

const fees = await findByText('$1.69')
expect(fees).toBeTruthy()

const submitButton = await findByTestId('trade-panel-submit-button')
expect(submitButton).toBeEnabled()

const expandButton = await findByTestId('expand-sl-tp-button')
fireEvent.click(expandButton)

const approveButton = await findByTestId('sl-tp-ack-proceed')
fireEvent.click(approveButton)

const stopLossInput = await findByTestId('trade-panel-stop-loss-input')

await findByText('Leverage Too High')
expect(stopLossInput).toBeDisabled()
})

test('Displays stop-loss warning in confirmation view when within 5% of liquidation price', async () => {
const store = setupStore(preloadedStateWithSmartMarginAccount())
const { findByTestId, findByText } = render(
<MockProviders route="market/?accountType=cross_margin&asset=sETH" store={store}>
<Market />
</MockProviders>
)

sdk.futures.getCrossMarginTradePreview = () =>
Promise.resolve({
...MOCK_TRADE_PREVIEW,
liqPrice: wei('2172.467580351348039045'),
side: PositionSide.SHORT,
size: wei('-0.5411'),
})

const shortToggle = await findByTestId('position-side-short-button')
fireEvent.click(shortToggle)

const marginInput = await findByTestId('set-order-margin-susd-desktop')
fireEvent.change(marginInput, { target: { value: '100' } })

const sizeInput = await findByTestId('set-order-size-amount-susd-desktop')
fireEvent.change(sizeInput, { target: { value: '1000' } })

const fees = await findByText('$1.69')
expect(fees).toBeTruthy()

const expandButton = await findByTestId('expand-sl-tp-button')
fireEvent.click(expandButton)

const approveButton = await findByTestId('sl-tp-ack-proceed')
fireEvent.click(approveButton)

const stopLossInput = await findByTestId('trade-panel-stop-loss-input')
fireEvent.change(stopLossInput, { target: { value: '2090' } })

const submitButton = await findByTestId('trade-panel-submit-button')
fireEvent.click(submitButton)

// Trade confirm button is disabled until the user acknowledges the warning
const confirmButton = await findByTestId('trade-confirm-order-button')
expect(confirmButton).toBeDisabled()

const warningCheck = await findByTestId('sl-risk-warning')
fireEvent.click(warningCheck)
expect(confirmButton).toBeEnabled()
})
})
3 changes: 3 additions & 0 deletions packages/app/src/assets/svg/app/docs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/app/src/assets/svg/app/support.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions packages/app/src/components/AcceptWarningView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import styled from 'styled-components'

import { Checkbox } from 'components/Checkbox'

type Props = {
checked: boolean
message: string
style?: Record<string, string>
id?: string
onChangeChecked: (checked: boolean) => void
}

export default function AcceptWarningView({ checked, id, onChangeChecked, style, message }: Props) {
return (
<Container style={style}>
<Checkbox
id={id ?? 'accept-warning'}
data-testid={id}
label={message}
checkSide="right"
checked={checked}
color="yellow"
onChange={() => onChangeChecked(!checked)}
/>
</Container>
)
}

const Container = styled.div<{ style?: Record<string, string> }>`
color: ${(props) => props.theme.colors.selectedTheme.button.yellow.text};
font-size: 12px;
margin: ${(props) => props.style?.margin ?? '0'};
padding: 15px;
border: 1px solid rgba(239, 104, 104, 0);
background: ${(props) => props.theme.colors.selectedTheme.button.yellow.fill};
border-radius: 8px;
cursor: default;
`
Loading
Loading