11import { bondingManager } from "@lib/api/abis/main/BondingManager" ;
2- import { Button } from "@livepeer/design-system" ;
3- import { useAccountAddress , useHandleTransaction } from "hooks" ;
2+ import {
3+ Box ,
4+ Button ,
5+ Dialog ,
6+ DialogContent ,
7+ DialogTitle ,
8+ Flex ,
9+ Text ,
10+ } from "@livepeer/design-system" ;
11+ import { useAccountAddress } from "hooks" ;
412import { useBondingManagerAddress } from "hooks/useContracts" ;
13+ import { useHandleTransaction } from "hooks/useHandleTransaction" ;
14+ import { useState } from "react" ;
515import { parseEther } from "viem" ;
616import { useSimulateContract , useWriteContract } from "wagmi" ;
717
8- const Undelegate = ( { amount, newPosPrev, newPosNext, disabled } ) => {
18+ interface Props {
19+ amount : string ;
20+ newPosPrev : string ;
21+ newPosNext : string ;
22+ disabled : boolean ;
23+ willDeactivate : boolean ;
24+ }
25+
26+ const Undelegate = ( {
27+ amount,
28+ newPosPrev,
29+ newPosNext,
30+ disabled,
31+ willDeactivate,
32+ } : Props ) => {
933 const accountAddress = useAccountAddress ( ) ;
34+ const [ showConfirmDialog , setShowConfirmDialog ] = useState ( false ) ;
1035
1136 const args = {
1237 amount : parseEther ( amount ? amount . toString ( ) : "0" ) ,
@@ -21,12 +46,34 @@ const Undelegate = ({ amount, newPosPrev, newPosNext, disabled }) => {
2146 address : bondingManagerAddress ,
2247 abi : bondingManager ,
2348 functionName : "unbondWithHint" ,
24- args : [ BigInt ( args . amount . toString ( ) ) , newPosPrev , newPosNext ] ,
49+ args : [
50+ BigInt ( args . amount . toString ( ) ) ,
51+ newPosPrev as `0x${string } `,
52+ newPosNext as `0x${string } `,
53+ ] ,
2554 } ) ;
2655 const { data, isPending, writeContract, error, isSuccess } =
2756 useWriteContract ( ) ;
2857
29- useHandleTransaction ( "unbond" , data , error , isPending , isSuccess , args ) ;
58+ useHandleTransaction ( "unbond" , data , error , isPending , isSuccess , {
59+ ...args ,
60+ wasDeactivated : willDeactivate ,
61+ } ) ;
62+
63+ const handleUndelegate = ( ) => {
64+ if ( willDeactivate ) {
65+ setShowConfirmDialog ( true ) ;
66+ } else if ( config ) {
67+ writeContract ( config . request ) ;
68+ }
69+ } ;
70+
71+ const handleConfirmUnbond = ( ) => {
72+ setShowConfirmDialog ( false ) ;
73+ if ( config ) {
74+ writeContract ( config . request ) ;
75+ }
76+ } ;
3077
3178 if ( ! accountAddress ) {
3279 return null ;
@@ -41,10 +88,90 @@ const Undelegate = ({ amount, newPosPrev, newPosNext, disabled }) => {
4188 css = { {
4289 width : "100%" ,
4390 } }
44- onClick = { ( ) => config && writeContract ( config . request ) }
91+ onClick = { handleUndelegate }
4592 >
4693 { ! amount ? "Enter an amount" : "Undelegate" }
4794 </ Button >
95+
96+ < Dialog open = { showConfirmDialog } onOpenChange = { setShowConfirmDialog } >
97+ < DialogContent
98+ css = { { maxWidth : 390 , width : "100%" } }
99+ onPointerEnterCapture = { undefined }
100+ onPointerLeaveCapture = { undefined }
101+ placeholder = { undefined }
102+ >
103+ < DialogTitle asChild >
104+ < Text
105+ as = "h2"
106+ css = { {
107+ fontWeight : 600 ,
108+ fontSize : "$4" ,
109+ marginBottom : "$3" ,
110+ lineHeight : 1.3 ,
111+ } }
112+ >
113+ Unbonding all stake
114+ </ Text >
115+ </ DialogTitle >
116+
117+ < Text
118+ css = { {
119+ marginBottom : "$4" ,
120+ color : "$neutral11" ,
121+ lineHeight : 1.5 ,
122+ } }
123+ >
124+ This will{ " " }
125+ < Text as = "span" css = { { color : "$yellow9" } } >
126+ deactivate your orchestrator
127+ </ Text > { " " }
128+ and remove you from the active set. You'll stop earning rewards
129+ until you stake again.
130+ </ Text >
131+
132+ < Box
133+ css = { {
134+ background : "$neutral3" ,
135+ border : "1px solid $neutral5" ,
136+ borderRadius : "$2" ,
137+ padding : "$3" ,
138+ marginBottom : "$4" ,
139+ display : "flex" ,
140+ justifyContent : "space-between" ,
141+ alignItems : "center" ,
142+ } }
143+ >
144+ < Text css = { { color : "$neutral11" } } > Amount</ Text >
145+ < Text
146+ css = { {
147+ fontWeight : 600 ,
148+ fontVariantNumeric : "tabular-nums" ,
149+ } }
150+ >
151+ { amount } LPT
152+ </ Text >
153+ </ Box >
154+
155+ < Flex css = { { gap : "$2" , justifyContent : "flex-end" } } >
156+ < Button
157+ size = "3"
158+ ghost
159+ onClick = { ( ) => setShowConfirmDialog ( false ) }
160+ css = { { minWidth : "unset" } }
161+ >
162+ Cancel
163+ </ Button >
164+ < Button
165+ size = "3"
166+ variant = "red"
167+ onClick = { handleConfirmUnbond }
168+ disabled = { ! config }
169+ >
170+ Yes, unbond my stake
171+ </ Button >
172+ </ Flex >
173+ </ DialogContent >
174+ </ Dialog >
48175 </ >
49176 ) ;
50177} ;
0 commit comments