Skip to content

Commit 55f51bc

Browse files
committed
use emergencyExit function
1 parent 758427b commit 55f51bc

File tree

6 files changed

+235
-118
lines changed

6 files changed

+235
-118
lines changed

apps/hub/src/app/_components/stake/hooks/use-action-status-content.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,10 @@ export function useActionStatusContent(
137137
}))
138138

139139
// compound flow
140-
.with({ type: 'compound', step: 'initialize' }, state => ({
140+
.with({ type: 'compound', step: 'initialize' }, () => ({
141141
state: 'pending',
142142
showCloseButton: true,
143-
content: <CompoundStatusContent amount={state.amount} />,
143+
content: <CompoundStatusContent />,
144144
}))
145145
.with({ type: 'compound', step: 'processing' }, state => ({
146146
title: `Compounding ${formatSNT(state.amount ?? 0)} points`,

apps/hub/src/app/_components/vaults/modals/withdraw-vault-modal.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { InfoIcon } from '@status-im/icons/12'
77
import { Button } from '@status-im/status-network/components'
88
import { useAccount } from 'wagmi'
99

10-
import { useVaultWithdraw } from '~hooks/useVaultWithdraw'
10+
import { useVaultEmergencyExit } from '~hooks/useVaultEmergencyExit'
1111

1212
import { BaseVaultModal } from './base-vault-modal'
1313

@@ -30,26 +30,22 @@ export function WithdrawVaultModal(props: WithdrawVaultModalProps) {
3030
props
3131

3232
const { address } = useAccount()
33-
const { mutate: withdraw } = useVaultWithdraw()
33+
const { mutate: emergencyExit } = useVaultEmergencyExit()
3434

3535
const handleVaultWithdrawal = useCallback(() => {
3636
if (!address) {
3737
console.error('No address found - wallet not connected')
3838
return
3939
}
4040

41-
try {
42-
withdraw({
43-
amountWei,
44-
vaultAddress,
45-
onSigned: () => {
46-
onClose()
47-
},
48-
})
49-
} catch (error) {
50-
console.error('Error calling withdraw:', error)
51-
}
52-
}, [address, amountWei, onClose, vaultAddress, withdraw])
41+
emergencyExit({
42+
amountWei,
43+
vaultAddress,
44+
onSigned: () => {
45+
onClose()
46+
},
47+
})
48+
}, [address, amountWei, onClose, vaultAddress, emergencyExit])
5349

5450
return (
5551
<BaseVaultModal

apps/hub/src/app/_components/vaults/table-columns.tsx

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface TableColumnsProps {
1818
openModalVaultId: string | null
1919
setOpenModalVaultId: (vaultId: string | null) => void
2020
emergencyModeEnabled: unknown
21-
// isConnected: boolean
21+
isConnected: boolean
2222
}
2323

2424
// Calculate total staked across all vaults
@@ -50,12 +50,15 @@ const validateLockTime = (_: string, days: string): string | null => {
5050
}
5151

5252
// Modal action configurations - static, never change
53-
const EXTEND_LOCK_ACTIONS = [
53+
const EXTEND_LOCK_ACTIONS: [{ label: string }, { label: string }] = [
5454
{ label: 'Cancel' },
5555
{ label: 'Extend lock' },
56-
] as const
56+
]
5757

58-
const LOCK_VAULT_ACTIONS = [{ label: "Don't lock" }, { label: 'Lock' }] as const
58+
const LOCK_VAULT_ACTIONS: [{ label: string }, { label: string }] = [
59+
{ label: "Don't lock" },
60+
{ label: 'Lock' },
61+
]
5962

6063
const LOCK_INFO_MESSAGE =
6164
'Boost the rate at which you receive Karma. The longer you lock your vault, the higher your boost, and the faster you accumulate Karma. You can add more SNT at any time, but withdrawing your SNT is only possible once the vault unlocks.' as const
@@ -265,46 +268,40 @@ export const createVaultTableColumns = ({
265268

266269
return (
267270
<div className="flex items-end justify-end gap-2 lg:gap-4">
271+
{Boolean(emergencyModeEnabled) && (
272+
<WithdrawVaultModal
273+
open={isWithdrawModalOpen}
274+
onOpenChange={open =>
275+
setOpenModalVaultId(open ? withdrawModalId : null)
276+
}
277+
onClose={() => setOpenModalVaultId(null)}
278+
vaultAddress={row.original.address}
279+
amountWei={row.original.data?.stakedBalance || 0n}
280+
>
281+
<Button variant="danger" size="24" iconBefore={<AlertIcon />}>
282+
Withdraw funds
283+
</Button>
284+
</WithdrawVaultModal>
285+
)}
268286
{isLocked ? (
269-
<div className="flex items-center gap-2">
270-
{Boolean(emergencyModeEnabled) && (
271-
<WithdrawVaultModal
272-
open={isWithdrawModalOpen}
273-
onOpenChange={open =>
274-
setOpenModalVaultId(open ? withdrawModalId : null)
275-
}
276-
onClose={() => setOpenModalVaultId(null)}
277-
vaultAddress={row.original.address}
278-
amountWei={row.original.data?.stakedBalance || 0n}
279-
>
280-
<Button
281-
variant="danger"
282-
size="24"
283-
iconBefore={<AlertIcon />}
284-
>
285-
Withdraw funds
286-
</Button>
287-
</WithdrawVaultModal>
288-
)}
289-
<LockVaultModal
290-
open={isLockModalOpen}
291-
onOpenChange={open =>
292-
setOpenModalVaultId(open ? lockModalId : null)
293-
}
294-
vaultAddress={row.original.address}
295-
title="Extend lock time"
296-
initialYears="2"
297-
initialDays="732"
298-
description="Extending lock time increasing Karma boost"
299-
actions={EXTEND_LOCK_ACTIONS}
300-
onClose={() => setOpenModalVaultId(null)}
301-
infoMessage={LOCK_INFO_MESSAGE}
302-
>
303-
<Button variant="primary" size="24" iconBefore={<TimeIcon />}>
304-
Extend lock time
305-
</Button>
306-
</LockVaultModal>
307-
</div>
287+
<LockVaultModal
288+
open={isLockModalOpen}
289+
onOpenChange={open =>
290+
setOpenModalVaultId(open ? lockModalId : null)
291+
}
292+
vaultAddress={row.original.address}
293+
title="Extend lock time"
294+
initialYears="2"
295+
initialDays="732"
296+
description="Extending lock time increasing Karma boost"
297+
actions={EXTEND_LOCK_ACTIONS}
298+
onClose={() => setOpenModalVaultId(null)}
299+
infoMessage={LOCK_INFO_MESSAGE}
300+
>
301+
<Button variant="primary" size="24" iconBefore={<TimeIcon />}>
302+
Extend lock time
303+
</Button>
304+
</LockVaultModal>
308305
) : (
309306
<LockVaultModal
310307
open={isLockModalOpen}

apps/hub/src/app/_components/vaults/vaults-table.tsx

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {
99
getCoreRowModel,
1010
useReactTable,
1111
} from '@tanstack/react-table'
12-
import { useAccount } from 'wagmi'
12+
import { useAccount, useReadContract } from 'wagmi'
1313

14-
// import { STAKING_MANAGER } from '~constants/index'
14+
import { STAKING_MANAGER } from '~constants/address'
1515
import { useCreateVault } from '~hooks/useCreateVault'
1616
import { type StakingVault, useStakingVaults } from '~hooks/useStakingVaults'
1717

@@ -120,66 +120,20 @@ function TableFooter({ table }: TableProps) {
120120
// Main Component
121121
// ============================================================================
122122

123-
// Mock data for development
124-
const MOCK_VAULTS: StakingVault[] = [
125-
{
126-
address: '0x1234567890123456789012345678901234567890' as `0x${string}`,
127-
data: {
128-
stakedBalance: BigInt('1000000000000000000000'), // 1000 SNT
129-
rewardIndex: BigInt('1000000000000000000'),
130-
mpAccrued: BigInt('500000000000000000000'),
131-
maxMP: BigInt('2000000000000000000000'),
132-
lastMPUpdateTime: BigInt(Math.floor(Date.now() / 1000) - 86400),
133-
lockUntil: BigInt(Math.floor(Date.now() / 1000) + 86400 * 365), // Locked for 1 year
134-
rewardsAccrued: BigInt('50000000000000000000'), // 50 KARMA
135-
},
136-
},
137-
{
138-
address: '0x2345678901234567890123456789012345678901' as `0x${string}`,
139-
data: {
140-
stakedBalance: BigInt('5000000000000000000000'), // 5000 SNT
141-
rewardIndex: BigInt('1000000000000000000'),
142-
mpAccrued: BigInt('1500000000000000000000'),
143-
maxMP: BigInt('10000000000000000000000'),
144-
lastMPUpdateTime: BigInt(Math.floor(Date.now() / 1000) - 43200),
145-
lockUntil: BigInt(Math.floor(Date.now() / 1000) + 86400 * 730), // Locked for 2 years
146-
rewardsAccrued: BigInt('250000000000000000000'), // 250 KARMA
147-
},
148-
},
149-
{
150-
address: '0x3456789012345678901234567890123456789012' as `0x${string}`,
151-
data: {
152-
stakedBalance: BigInt('2500000000000000000000'), // 2500 SNT
153-
rewardIndex: BigInt('1000000000000000000'),
154-
mpAccrued: BigInt('800000000000000000000'),
155-
maxMP: BigInt('5000000000000000000000'),
156-
lastMPUpdateTime: BigInt(Math.floor(Date.now() / 1000)),
157-
lockUntil: BigInt(0), // Unlocked
158-
rewardsAccrued: BigInt('125000000000000000000'), // 125 KARMA
159-
},
160-
},
161-
]
162-
163123
export function VaultsTable() {
164124
const [openModalVaultId, setOpenModalVaultId] = useState<string | null>(null)
165125
const { data: vaultDataList } = useStakingVaults()
166126
const { isConnected } = useAccount()
167127
const { mutate: createVault } = useCreateVault()
168128

169-
// Use mock data in development when no real vaults exist
170-
const displayVaults =
171-
vaultDataList && vaultDataList.length > 0 ? vaultDataList : MOCK_VAULTS
172-
173-
// const { data: emergencyModeEnabled } = useReadContract({
174-
// address: STAKING_MANAGER.address,
175-
// abi: STAKING_MANAGER.abi,
176-
// functionName: 'emergencyModeEnabled',
177-
// query: {
178-
// refetchInterval: 30000,
179-
// },
180-
// })
181-
182-
const emergencyModeEnabled = true
129+
const { data: emergencyModeEnabled } = useReadContract({
130+
address: STAKING_MANAGER.address,
131+
abi: STAKING_MANAGER.abi,
132+
functionName: 'emergencyModeEnabled',
133+
query: {
134+
refetchInterval: 30000,
135+
},
136+
})
183137

184138
// Stable callback reference prevents column recreation on every render
185139
const handleSetOpenModalVaultId = useCallback(
@@ -191,14 +145,14 @@ export function VaultsTable() {
191145
const columns = useMemo(
192146
() =>
193147
createVaultTableColumns({
194-
vaults: displayVaults,
148+
vaults: vaultDataList,
195149
openModalVaultId,
196150
setOpenModalVaultId: handleSetOpenModalVaultId,
197151
emergencyModeEnabled,
198152
isConnected,
199153
}),
200154
[
201-
displayVaults,
155+
vaultDataList,
202156
openModalVaultId,
203157
handleSetOpenModalVaultId,
204158
emergencyModeEnabled,
@@ -208,7 +162,7 @@ export function VaultsTable() {
208162

209163
// Initialize TanStack Table
210164
const table = useReactTable({
211-
data: displayVaults,
165+
data: vaultDataList || [],
212166
columns,
213167
getCoreRowModel: getCoreRowModel(),
214168
})

0 commit comments

Comments
 (0)