@@ -13,7 +13,8 @@ import {
13
13
delegateSettlePnL ,
14
14
usdFormatter ,
15
15
settlePnL ,
16
- getUnsettledPnL
16
+ getUnsettledPnL ,
17
+ withdraw
17
18
} from './helpers' ;
18
19
19
20
export const Assets : FC < {
@@ -69,6 +70,9 @@ export const Assets: FC<{
69
70
return ;
70
71
}
71
72
const address = wallet . accounts [ 0 ] . address ;
73
+ console . log ( 'address' , address ) ;
74
+ console . log ( 'usdcContract' , usdcContract ) ;
75
+ console . log ( 'getUSDCAddress(connectedChain.id)' , getUSDCAddress ( connectedChain . id ) ) ;
72
76
usdcContract . balanceOf ( address ) . then ( setBalance ) ;
73
77
usdcContract . allowance ( address , getVaultAddress ( connectedChain . id ) ) . then ( setAllowance ) ;
74
78
} ;
@@ -82,6 +86,7 @@ export const Assets: FC<{
82
86
setContractBalance ( undefined ) ;
83
87
return ;
84
88
}
89
+ console . log ( 'contractAddress' , contractAddress ) ;
85
90
const fetchContractBalance = async ( ) => {
86
91
if ( ! usdcContract || ! contractAddress ) {
87
92
setContractBalance ( undefined ) ;
@@ -161,32 +166,19 @@ export const Assets: FC<{
161
166
</ Table . Body >
162
167
</ Table . Root >
163
168
164
- { showEOA && (
165
- < Flex direction = "column" gap = "4" >
166
- < Button
167
- disabled = { ! wallet || ! connectedChain || ! brokerId || ! orderlyKey }
168
- onClick = { async ( ) => {
169
- if ( ! wallet || ! connectedChain || ! brokerId || ! orderlyKey ) return ;
170
- await settlePnL ( wallet , connectedChain . id , brokerId , accountId , orderlyKey ) ;
171
- } }
172
- >
173
- Settle PnL
174
- </ Button >
175
- </ Flex >
176
- ) }
169
+ < Flex direction = "column" gap = "4" >
170
+ < TextField . Root
171
+ style = { { gridArea : 'input' } }
172
+ type = "number"
173
+ step = "0.01"
174
+ min = "0"
175
+ placeholder = "USDC amount"
176
+ onChange = { ( event ) => {
177
+ setAmount ( event . target . value ) ;
178
+ } }
179
+ />
177
180
178
- { ! showEOA && (
179
- < Flex direction = "column" gap = "4" >
180
- < TextField . Root
181
- style = { { gridArea : 'input' } }
182
- type = "number"
183
- step = "0.01"
184
- min = "0"
185
- placeholder = "USDC amount"
186
- onChange = { ( event ) => {
187
- setAmount ( event . target . value ) ;
188
- } }
189
- />
181
+ { ! showEOA && (
190
182
< Button
191
183
disabled = {
192
184
! wallet ||
@@ -233,7 +225,29 @@ export const Assets: FC<{
233
225
>
234
226
{ needsApproval ? 'Approve' : 'Deposit to Contract' }
235
227
</ Button >
228
+ ) }
236
229
230
+ { showEOA ? (
231
+ < Button
232
+ disabled = { ! wallet || ! connectedChain || ! brokerId || ! orderlyKey }
233
+ onClick = { async ( ) => {
234
+ if ( ! wallet || ! connectedChain || ! orderlyKey || ! amount ) return ;
235
+ const amountBN = parseUnits ( amount , 6 ) ;
236
+ if ( parseUnits ( String ( vaultBalance ) , 6 ) < amountBN ) return ;
237
+ await withdraw (
238
+ wallet ,
239
+ connectedChain . id ,
240
+ brokerId ,
241
+ accountId ,
242
+ orderlyKey ,
243
+ amountBN . toString ( ) ,
244
+ wallet . accounts [ 0 ] . address
245
+ ) ;
246
+ } }
247
+ >
248
+ Withdraw
249
+ </ Button >
250
+ ) : (
237
251
< Button
238
252
disabled = {
239
253
! wallet ||
@@ -262,7 +276,19 @@ export const Assets: FC<{
262
276
>
263
277
Withdraw from Contract
264
278
</ Button >
279
+ ) }
265
280
281
+ { showEOA ? (
282
+ < Button
283
+ disabled = { ! wallet || ! connectedChain || ! brokerId || ! orderlyKey }
284
+ onClick = { async ( ) => {
285
+ if ( ! wallet || ! connectedChain || ! brokerId || ! orderlyKey ) return ;
286
+ await settlePnL ( wallet , connectedChain . id , brokerId , accountId , orderlyKey ) ;
287
+ } }
288
+ >
289
+ Settle PnL
290
+ </ Button >
291
+ ) : (
266
292
< Button
267
293
disabled = { ! wallet || ! connectedChain || ! brokerId || ! orderlyKey }
268
294
onClick = { async ( ) => {
@@ -279,8 +305,8 @@ export const Assets: FC<{
279
305
>
280
306
Settle Delegate PnL
281
307
</ Button >
282
- </ Flex >
283
- ) }
308
+ ) }
309
+ </ Flex >
284
310
</ Flex >
285
311
) ;
286
312
} ;
0 commit comments