@@ -13,6 +13,7 @@ import {
1313 contractsReady ,
1414 getConfiguredChainId ,
1515 getContractsState ,
16+ MAX_LOCK_SECONDS ,
1617 MAX_LOCK_WEEKS ,
1718 MIN_LOCK_WEEKS ,
1819 weeksToDuration ,
@@ -82,6 +83,22 @@ export function ManagePosition({ tokenId, compact = false }: Props) {
8283 query : { enabled : ready } ,
8384 } ) ;
8485
86+ const { data : autoExtend } = useReadContract ( {
87+ address : escrow ,
88+ abi : abis . VotingEscrow ,
89+ functionName : "autoExtend" ,
90+ args : [ tokenId ] ,
91+ query : { enabled : ready } ,
92+ } ) ;
93+
94+ const { data : exitQuote } = useReadContract ( {
95+ address : escrow ,
96+ abi : abis . VotingEscrow ,
97+ functionName : "previewExit" ,
98+ args : [ tokenId ] ,
99+ query : { enabled : ready && ! Boolean ( closed ) } ,
100+ } ) ;
101+
85102 const { data : weight } = useReadContract ( {
86103 address : escrow ,
87104 abi : abis . VotingEscrow ,
@@ -114,6 +131,12 @@ export function ManagePosition({ tokenId, compact = false }: Props) {
114131 const cooldownDone = readyAt > 0 && Date . now ( ) / 1000 >= readyAt ;
115132 const unlockEnd = lock ? Number ( lock . end ) : 0 ;
116133 const matured = unlockEnd > 0 && Date . now ( ) / 1000 >= unlockEnd ;
134+ const nowSec = Math . floor ( Date . now ( ) / 1000 ) ;
135+ const secondsLeft = unlockEnd > nowSec ? unlockEnd - nowSec : 0 ;
136+ const earlyExitBlocked = ! matured && secondsLeft > 0 && secondsLeft <= cooldownSec ;
137+ const emergencyButMature = exitKind === ExitKind . Emergency && matured ;
138+ const penaltyNow = exitQuote ? exitQuote [ 1 ] : undefined ;
139+ const penaltyBpsNow = exitQuote ? Number ( exitQuote [ 2 ] ) : undefined ;
117140 const isClosed = Boolean ( closed ) ;
118141 const busy = isPending || confirming ;
119142 const writesOk = ready && isConnected && onExpectedChain && ! ! address && ! isClosed ;
@@ -256,6 +279,25 @@ export function ManagePosition({ tokenId, compact = false }: Props) {
256279 >
257280 Extend to ~{ formatDate ( newUnlock ) }
258281 </ button >
282+ < button
283+ type = "button"
284+ className = { styles . secondary }
285+ disabled = { ! writesOk || exitPending || busy }
286+ onClick = { ( ) => {
287+ const now = Math . floor ( Date . now ( ) / 1000 ) ;
288+ run ( ( ) =>
289+ writeContract ( {
290+ chainId : writeChainId ,
291+ address : escrow ,
292+ abi : abis . VotingEscrow ,
293+ functionName : "increaseUnlockTime" ,
294+ args : [ tokenId , BigInt ( now + MAX_LOCK_SECONDS ) ] ,
295+ } ) ,
296+ ) ;
297+ } }
298+ >
299+ Max lock ({ MAX_LOCK_WEEKS } w)
300+ </ button >
259301 < button
260302 type = "button"
261303 className = { styles . secondary }
@@ -266,21 +308,25 @@ export function ManagePosition({ tokenId, compact = false }: Props) {
266308 chainId : writeChainId ,
267309 address : escrow ,
268310 abi : abis . VotingEscrow ,
269- functionName : "keepAtMaxLock " ,
270- args : [ tokenId ] ,
311+ functionName : "setAutoExtend " ,
312+ args : [ tokenId , ! autoExtend ] ,
271313 } ) ,
272314 )
273315 }
274316 >
275- Max lock ( { MAX_LOCK_WEEKS } w)
317+ { autoExtend ? "Turn off auto-extend" : "Turn on auto-extend" }
276318 </ button >
277319 </ div >
320+ < p className = { styles . groupHint } >
321+ Auto-extend lets the keeper push this lock back to 104 weeks, and only in the last 2 hours of an epoch.
322+ </ p >
278323 </ div >
279324
280325 < div className = { styles . group } >
281326 < h3 className = { styles . groupTitle } > Claim</ h3 >
282327 < p className = { styles . groupHint } >
283- Rewards pay the NFT recipient. Claim & lock compounds WXDC into this position.
328+ Rewards pay the NFT recipient. A week's yield can be claimed 8 weeks after that week.
329+ An early exit forfeits yield that has not finished the wait. Claim & lock compounds WXDC into this position.
284330 </ p >
285331 < div className = { styles . row } >
286332 < ClaimButton tokenId = { tokenId } mode = "claim" />
@@ -291,18 +337,33 @@ export function ManagePosition({ tokenId, compact = false }: Props) {
291337 < div className = { styles . group } >
292338 < h3 className = { styles . groupTitle } > Exit</ h3 >
293339 < p className = { styles . groupHint } >
294- Request → wait cooldown → finalize. Emergency applies a penalty snapshotted at request .
340+ Request, wait out the cooldown, then finalize .
295341 { cooldownSec > 0
296342 ? ` Cooldown ${ Math . round ( cooldownSec / 3600 ) } h.`
297343 : " Cooldown is currently 0." }
344+ { ! matured && ! isClosed && penaltyNow !== undefined && penaltyNow > 0n
345+ ? ` An early exit now costs ${ formatXdc ( penaltyNow ) } XDC (${ ( penaltyBpsNow ?? 0 ) / 100 } %).`
346+ : "" }
347+ { earlyExitBlocked
348+ ? " The cooldown would outlast this lock, so an early exit is not available."
349+ : "" }
298350 </ p >
299351
300352 { exitPending ? (
301353 < div className = { styles . exitPending } >
302354 < p className = { styles . pendingLabel } >
303- { exitKind === ExitKind . Emergency ? "Emergency" : "Withdraw" } exit armed
355+ { emergencyButMature
356+ ? "Lock matured during the cooldown"
357+ : exitKind === ExitKind . Emergency
358+ ? "Emergency exit armed"
359+ : "Withdraw armed" }
304360 { readyAt > 0 ? ` · ${ formatCountdown ( readyAt ) } ` : "" }
305361 </ p >
362+ { emergencyButMature && (
363+ < p className = { styles . groupHint } >
364+ Finalizing pays the full principal and does not forfeit yield.
365+ </ p >
366+ ) }
306367 < div className = { styles . row } >
307368 { exitKind === ExitKind . Withdraw && (
308369 < button
@@ -341,7 +402,7 @@ export function ManagePosition({ tokenId, compact = false }: Props) {
341402 )
342403 }
343404 >
344- Finalize emergency exit
405+ Finalize
345406 </ button >
346407 ) }
347408 < button
@@ -388,8 +449,14 @@ export function ManagePosition({ tokenId, compact = false }: Props) {
388449 < button
389450 type = "button"
390451 className = { styles . danger }
391- disabled = { ! writesOk || busy || matured }
392- title = { matured ? "Lock matured — use withdraw" : undefined }
452+ disabled = { ! writesOk || busy || matured || earlyExitBlocked }
453+ title = {
454+ matured
455+ ? "Lock matured — use withdraw"
456+ : earlyExitBlocked
457+ ? "The cooldown would outlast this lock"
458+ : undefined
459+ }
393460 onClick = { ( ) =>
394461 run ( ( ) =>
395462 writeContract ( {
0 commit comments