Skip to content

Commit 59474e8

Browse files
committed
bracket limit order & fix price
1 parent 79efd26 commit 59474e8

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

app/components/CreateOrder.tsx

+25-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useAccount, useOrderEntry, useSymbolsInfo, useWithdraw } from '@orderly
22
import { AlgoOrderRootType, OrderlyOrder, OrderSide, OrderType } from '@orderly.network/types';
33
import { Separator } from '@radix-ui/themes';
44
import { useNotifications } from '@web3-onboard/react';
5-
import { FC, useCallback, useState } from 'react';
5+
import { FC, useCallback, useEffect, useState } from 'react';
66
import { match } from 'ts-pattern';
77

88
import { ConnectWalletButton, Spinner, TokenInput } from '.';
@@ -28,10 +28,10 @@ export const CreateOrder: FC<{
2828
} = useOrderEntry(symbol, {
2929
initialOrder: {
3030
side: OrderSide.BUY,
31-
order_type: OrderType.MARKET,
32-
trigger_price: undefined,
33-
price: undefined,
34-
order_quantity: undefined
31+
order_type: OrderType.LIMIT,
32+
trigger_price: '',
33+
order_price: '',
34+
order_quantity: ''
3535
}
3636
});
3737
const hasError = useCallback(
@@ -52,11 +52,19 @@ export const CreateOrder: FC<{
5252
);
5353
const [_0, customNotification] = useNotifications();
5454

55+
useEffect(() => {
56+
reset();
57+
console.log('[reset]');
58+
// eslint-disable-next-line react-hooks/exhaustive-deps
59+
}, [formattedOrder.order_type]);
60+
5561
if (symbolsInfo.isNil) {
5662
return <Spinner />;
5763
}
5864

5965
const submitForm = async () => {
66+
console.log('[errors]', errors);
67+
console.log('[formattedOrder]', formattedOrder);
6068
setLoading(true);
6169
const { update } = customNotification({
6270
eventCode: 'createOrder',
@@ -133,16 +141,22 @@ export const CreateOrder: FC<{
133141
if (event.target.value === 'BRACKET_MARKET') {
134142
setValue('order_type', OrderType.MARKET);
135143
setValue('algo_type', AlgoOrderRootType.BRACKET);
144+
} else if (event.target.value === 'BRACKET_LIMIT') {
145+
setValue('order_type', OrderType.LIMIT);
146+
setValue('algo_type', AlgoOrderRootType.BRACKET);
136147
} else {
137148
setValue('order_type', event.target.value);
138149
setValue('algo_type', undefined);
139150
}
140151
}}
141152
>
142153
<option value="MARKET">Market</option>
143-
<option value="LIMIT">Limit</option>
154+
<option value="LIMIT" selected>
155+
Limit
156+
</option>
144157
<option value="STOP_LIMIT">Stop Limit</option>
145158
<option value="BRACKET_MARKET">Bracket Market</option>
159+
<option value="BRACKET_LIMIT">Bracket Limit</option>
146160
</select>
147161

148162
<label
@@ -175,19 +189,19 @@ export const CreateOrder: FC<{
175189
>
176190
<span className="font-bold font-size-4">Price ({quote})</span>
177191
<TokenInput
178-
className={`${hasError('price') ? 'border-[var(--color-red)]' : ''}`}
192+
className={`${hasError('order_price') ? 'border-[var(--color-red)]' : ''}`}
179193
decimals={quoteDecimals}
180194
placeholder="Price"
181-
name="price"
182-
hasError={!!hasError('price')}
195+
name="order_price"
196+
hasError={!!hasError('order_price')}
183197
readonly={match(formattedOrder.order_type)
184198
.with(OrderType.MARKET, () => true)
185199
.otherwise(() => false)}
186200
onValueChange={(value) => {
187-
setValue('price', value.toString());
201+
setValue('order_price', value.toString());
188202
}}
189203
/>
190-
{renderFormError(hasError('price'))}
204+
{renderFormError(hasError('order_price'))}
191205
</label>
192206

193207
<label

app/utils/numberFormat.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export function filterAllowedCharacters(value: string): string {
1111
}
1212

1313
export function getFormattedNumber(value: string, decimals: number): string {
14+
if (value === '') return '';
1415
let commaPos: number;
1516
[value, commaPos] = getNumberAsUInt128(value, decimals);
1617
value = value.slice(0, commaPos) + '.' + value.slice(commaPos);

0 commit comments

Comments
 (0)