Skip to content

Commit b91f711

Browse files
committed
settle pnl
1 parent 1f9bd40 commit b91f711

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

app/components/Assets.tsx

+53-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import { useChains, useCollateral, useDeposit, useWithdraw } from '@orderly.network/hooks';
1+
import {
2+
useAccountInstance,
3+
useChains,
4+
useCollateral,
5+
useDeposit,
6+
useWithdraw
7+
} from '@orderly.network/hooks';
28
import { API } from '@orderly.network/types';
3-
import { Table } from '@radix-ui/themes';
4-
import { useSetChain } from '@web3-onboard/react';
9+
import { QuestionMarkCircledIcon } from '@radix-ui/react-icons';
10+
import { Table, Tooltip } from '@radix-ui/themes';
11+
import { useNotifications, useSetChain } from '@web3-onboard/react';
512
import { FixedNumber } from 'ethers';
613
import { FC, useMemo } from 'react';
714

8-
import { OrderlyDeposit } from '~/components';
15+
import { OrderlyDeposit, PendingButton } from '~/components';
916
import { useIsTestnet } from '~/hooks';
1017
import { supportedChains, usdFormatter } from '~/utils';
1118

@@ -15,6 +22,8 @@ export const Assets: FC = () => {
1522
const [chains] = useChains(isTestnet ? 'testnet' : 'mainnet', {
1623
filter: (item: API.Chain) => supportedChains.includes(item.network_infos?.chain_id)
1724
});
25+
const account = useAccountInstance();
26+
const [_, customNotification] = useNotifications();
1827

1928
const token = useMemo(() => {
2029
return Array.isArray(chains) ? chains[0].token_infos[0] : undefined;
@@ -45,6 +54,17 @@ export const Assets: FC = () => {
4554
<Table.Cell>{usdFormatter.format(unsettledPnL)}</Table.Cell>
4655
</Table.Row>
4756
</Table.Body>
57+
<Table.Row>
58+
<Table.RowHeaderCell className="flex">
59+
<Tooltip content="The maximum withdrawable amount. 'freeCollateral - unsettledPnL'">
60+
<div className="content">
61+
Withdrawable Balance <QuestionMarkCircledIcon />
62+
</div>
63+
</Tooltip>
64+
:
65+
</Table.RowHeaderCell>
66+
<Table.Cell>{usdFormatter.format(availableWithdraw)}</Table.Cell>
67+
</Table.Row>
4868
</Table.Root>
4969
<OrderlyDeposit
5070
walletBalance={FixedNumber.fromString(deposit.balance, { decimals: 6 })}
@@ -53,6 +73,35 @@ export const Assets: FC = () => {
5373
})}
5474
withdraw={withdraw}
5575
/>
76+
<PendingButton
77+
onClick={async () => {
78+
const { update } = customNotification({
79+
eventCode: 'settle',
80+
type: 'pending',
81+
message: 'Settling PnL...'
82+
});
83+
try {
84+
await account.settle();
85+
update({
86+
eventCode: 'settleSuccess',
87+
type: 'success',
88+
message: 'Successfully settled PnL!',
89+
autoDismiss: 5_000
90+
});
91+
} catch (err) {
92+
console.error(err);
93+
update({
94+
eventCode: 'settleError',
95+
type: 'error',
96+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
97+
message: (err as any).message ?? 'Something went wrong',
98+
autoDismiss: 15_000
99+
});
100+
}
101+
}}
102+
>
103+
Settle PnL
104+
</PendingButton>
56105
</div>
57106
);
58107
};

app/components/Positions.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const Positions: FC<{ symbol: API.Symbol }> = ({ symbol }) => {
2222
return (
2323
<Table.Root>
2424
<Table.Header>
25-
<Table.Row>
25+
<Table.Row className="[&>*]:align-mid">
2626
<Table.ColumnHeaderCell>Symbol</Table.ColumnHeaderCell>
2727
<Table.ColumnHeaderCell>Quantity</Table.ColumnHeaderCell>
2828
<Table.ColumnHeaderCell>Avg. Open</Table.ColumnHeaderCell>
@@ -34,7 +34,7 @@ export const Positions: FC<{ symbol: API.Symbol }> = ({ symbol }) => {
3434
</Table.Header>
3535
<Table.Body>
3636
{positions.rows.map((position) => (
37-
<Table.Row key={position.symbol}>
37+
<Table.Row key={position.symbol} className="[&>*]:align-mid">
3838
<Table.Cell>{position.symbol}</Table.Cell>
3939
<Table.Cell>{baseFormatter.format(position.position_qty)}</Table.Cell>
4040
<Table.Cell>{usdFormatter.format(position.average_open_price)}</Table.Cell>

0 commit comments

Comments
 (0)