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' ;
2
8
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' ;
5
12
import { FixedNumber } from 'ethers' ;
6
13
import { FC , useMemo } from 'react' ;
7
14
8
- import { OrderlyDeposit } from '~/components' ;
15
+ import { OrderlyDeposit , PendingButton } from '~/components' ;
9
16
import { useIsTestnet } from '~/hooks' ;
10
17
import { supportedChains , usdFormatter } from '~/utils' ;
11
18
@@ -15,6 +22,8 @@ export const Assets: FC = () => {
15
22
const [ chains ] = useChains ( isTestnet ? 'testnet' : 'mainnet' , {
16
23
filter : ( item : API . Chain ) => supportedChains . includes ( item . network_infos ?. chain_id )
17
24
} ) ;
25
+ const account = useAccountInstance ( ) ;
26
+ const [ _ , customNotification ] = useNotifications ( ) ;
18
27
19
28
const token = useMemo ( ( ) => {
20
29
return Array . isArray ( chains ) ? chains [ 0 ] . token_infos [ 0 ] : undefined ;
@@ -45,6 +54,17 @@ export const Assets: FC = () => {
45
54
< Table . Cell > { usdFormatter . format ( unsettledPnL ) } </ Table . Cell >
46
55
</ Table . Row >
47
56
</ 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 >
48
68
</ Table . Root >
49
69
< OrderlyDeposit
50
70
walletBalance = { FixedNumber . fromString ( deposit . balance , { decimals : 6 } ) }
@@ -53,6 +73,35 @@ export const Assets: FC = () => {
53
73
} ) }
54
74
withdraw = { withdraw }
55
75
/>
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 >
56
105
</ div >
57
106
) ;
58
107
} ;
0 commit comments