@@ -13,8 +13,9 @@ import { useIsTestnet } from '~/hooks';
13
13
export const OrderlyDeposit : FC < {
14
14
walletBalance : FixedNumber ;
15
15
orderlyBalance : FixedNumber ;
16
+ availableWithdraw : FixedNumber ;
16
17
withdraw : ReturnType < typeof useWithdraw > [ 'withdraw' ] ;
17
- } > = ( { walletBalance, orderlyBalance, withdraw } ) => {
18
+ } > = ( { walletBalance, orderlyBalance, availableWithdraw , withdraw } ) => {
18
19
const [ amount , setAmount ] = useState < FixedNumber > ( ) ;
19
20
const [ open , setOpen ] = useState ( false ) ;
20
21
const [ disabled , setDisabled ] = useState ( true ) ;
@@ -174,6 +175,32 @@ export const OrderlyDeposit: FC<{
174
175
}
175
176
}
176
177
} else {
178
+ if ( availableWithdraw . lt ( orderlyBalance ) ) {
179
+ const { update } = customNotification ( {
180
+ eventCode : 'settle' ,
181
+ type : 'pending' ,
182
+ message : 'Settling PnL...'
183
+ } ) ;
184
+ try {
185
+ await account . settle ( ) ;
186
+ update ( {
187
+ eventCode : 'settleSuccess' ,
188
+ type : 'success' ,
189
+ message : 'Successfully settled PnL!' ,
190
+ autoDismiss : 5_000
191
+ } ) ;
192
+ } catch ( err ) {
193
+ console . error ( err ) ;
194
+ update ( {
195
+ eventCode : 'settleError' ,
196
+ type : 'error' ,
197
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
198
+ message : ( err as any ) . message ?? 'Something went wrong' ,
199
+ autoDismiss : 15_000
200
+ } ) ;
201
+ }
202
+ }
203
+
177
204
const { update } = customNotification ( {
178
205
eventCode : 'withdraw' ,
179
206
type : 'pending' ,
@@ -223,7 +250,7 @@ export const OrderlyDeposit: FC<{
223
250
const { update } = customNotification ( {
224
251
eventCode : 'mint' ,
225
252
type : 'pending' ,
226
- message : 'Minting 1k USDC on testnet...'
253
+ message : 'Minting USDC on testnet...'
227
254
} ) ;
228
255
try {
229
256
const chainNamespace = state . chainNamespace ;
0 commit comments