-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
78 additions
and
71 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
67 changes: 67 additions & 0 deletions
67
packages/next-common/components/summary/democracyAllMyDelegationPopup/allDelegationBar.js
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,67 @@ | ||
import React, { useMemo, useState } from "react"; | ||
import styled from "styled-components"; | ||
import HStack from "next-common/components/styled/hStack"; | ||
import GreyInfoPanel from "../styled/greyInfoPanel"; | ||
import Tooltip from "next-common/components/tooltip"; | ||
import RemoveButton from "next-common/components/removeButton"; | ||
import { | ||
incMyReferendaDelegationsTrigger, | ||
myReferendaDelegationsSelector, | ||
} from "next-common/store/reducers/myOnChainData/referenda/myReferendaDelegations"; | ||
import { useSelector } from "react-redux"; | ||
import { useDispatch } from "react-redux"; | ||
import useIsUseMetamask from "next-common/hooks/useIsUseMetamask"; | ||
import isMoonChain from "next-common/utils/isMoonChain"; | ||
import UndelegateAllPopup from "../delegation/undelegateAllPopup"; | ||
import MoonUndelegateAllPopup from "../delegation/undelegateAllPopup/moonPopup"; | ||
|
||
const Count = styled.span` | ||
color: var(--textSecondary); | ||
`; | ||
|
||
export default function AllDelegationsBar() { | ||
const dispatch = useDispatch(); | ||
const delegations = useSelector(myReferendaDelegationsSelector); | ||
const [showPopup, setShowPopup] = useState(false); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const isUseMetamask = useIsUseMetamask(); | ||
|
||
let TheUndelegatePopup = UndelegateAllPopup; | ||
if (isMoonChain() && isUseMetamask) { | ||
TheUndelegatePopup = MoonUndelegateAllPopup; | ||
} | ||
|
||
const trackIds = useMemo(() => { | ||
return (delegations || []).map((item) => item.trackId); | ||
}, [delegations]); | ||
|
||
return ( | ||
<> | ||
<HStack space={8}> | ||
<GreyInfoPanel> | ||
My delegation <Count>{delegations?.length || 0}</Count> | ||
</GreyInfoPanel> | ||
|
||
<Tooltip content="Remove all"> | ||
<div> | ||
<RemoveButton | ||
disabled={!delegations?.length || isLoading} | ||
onClick={() => setShowPopup(true)} | ||
/> | ||
</div> | ||
</Tooltip> | ||
</HStack> | ||
{showPopup && ( | ||
<TheUndelegatePopup | ||
trackIds={trackIds} | ||
onClose={() => setShowPopup(false)} | ||
isLoading={isLoading} | ||
setIsLoading={setIsLoading} | ||
onInBlock={() => { | ||
dispatch(incMyReferendaDelegationsTrigger()); | ||
}} | ||
/> | ||
)} | ||
</> | ||
); | ||
} |
68 changes: 2 additions & 66 deletions
68
packages/next-common/components/summary/democracyAllMyDelegationPopup/index.js
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