-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): download history data buttons (#414)
- Loading branch information
1 parent
e840084
commit 06f5acf
Showing
27 changed files
with
429 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import usePolkadotApi from '@/hooks/usePolkadotApi' | ||
import useSignAndSend from '@/hooks/useSignAndSend' | ||
import type {DelegationCommonFragment} from '@/lib/subsquidQuery' | ||
import {chainAtom} from '@/store/common' | ||
import MoreVert from '@mui/icons-material/MoreVert' | ||
import { | ||
IconButton, | ||
Menu, | ||
MenuItem, | ||
type SxProps, | ||
type Theme, | ||
} from '@mui/material' | ||
import {useAtom} from 'jotai' | ||
import {type FC, useRef, useState} from 'react' | ||
import type {OnAction} from './List' | ||
|
||
const DelegationMenu: FC<{ | ||
onAction?: OnAction | ||
delegation: DelegationCommonFragment | ||
sx?: SxProps<Theme> | ||
}> = ({delegation, onAction, sx}) => { | ||
const api = usePolkadotApi() | ||
const signAndSend = useSignAndSend() | ||
const {basePool} = delegation | ||
const [chain] = useAtom(chainAtom) | ||
const [menuOpen, setMenuOpen] = useState(false) | ||
const moreRef = useRef(null) | ||
const poolHasWithdrawal = delegation.basePool.withdrawingShares !== '0' | ||
const isVault = basePool.kind === 'Vault' | ||
const reclaim = async (): Promise<void> => { | ||
if (api == null) return | ||
await signAndSend( | ||
isVault | ||
? api.tx.phalaVault.checkAndMaybeForceWithdraw(basePool.id) | ||
: api.tx.phalaStakePoolv2.checkAndMaybeForceWithdraw(basePool.id), | ||
) | ||
} | ||
|
||
return ( | ||
<> | ||
<IconButton | ||
ref={moreRef} | ||
onClick={() => { | ||
setMenuOpen(true) | ||
}} | ||
sx={sx} | ||
> | ||
<MoreVert /> | ||
</IconButton> | ||
<Menu | ||
open={menuOpen} | ||
anchorEl={moreRef.current} | ||
onClose={() => { | ||
setMenuOpen(false) | ||
}} | ||
> | ||
<MenuItem | ||
onClick={() => { | ||
onAction?.(delegation, 'withdraw') | ||
setMenuOpen(false) | ||
}} | ||
> | ||
Withdraw | ||
</MenuItem> | ||
<MenuItem | ||
disabled={!poolHasWithdrawal} | ||
onClick={() => { | ||
void reclaim() | ||
setMenuOpen(false) | ||
}} | ||
> | ||
Reclaim | ||
</MenuItem> | ||
<MenuItem | ||
onClick={() => { | ||
location.href = `/api/${chain}/snapshots/delegation/${delegation.id}` | ||
setMenuOpen(false) | ||
}} | ||
> | ||
Download history data | ||
</MenuItem> | ||
</Menu> | ||
</> | ||
) | ||
} | ||
|
||
export default DelegationMenu |
Oops, something went wrong.