Skip to content

Commit

Permalink
Pause deposit modal - view
Browse files Browse the repository at this point in the history
  • Loading branch information
ioay committed Jan 18, 2024
1 parent 094e27c commit dc84755
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 5 deletions.
10 changes: 10 additions & 0 deletions dapp/src/assets/images/staking-pause-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions dapp/src/components/Modals/Staking/Resume/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from "react"
import {
ModalHeader,
ModalBody,
ModalFooter,
Button,
Spinner,
Stack,
} from "@chakra-ui/react"

import { TextMd } from "../../../shared/Typography"
import { PauseIcon } from "../../../../utils/customIcons"

export default function PausingModal({
onResume,
onClose,
}: {
onResume: () => void
onClose: () => void
}) {
return (
<>
<ModalHeader>Paused</ModalHeader>
<ModalBody textAlign="start" py={6} mx={3}>
<Stack
position="relative"
display="flex"
justifyContent="center"
alignItems="center"
>
<Spinner
thickness="3px"
speed="0.65s"
emptyColor="gold.400"
color="brand.400"
size="xl"
/>
<PauseIcon position="absolute" />
</Stack>

<TextMd>Are your sure you want to cancel?</TextMd>
</ModalBody>
<ModalFooter flexDirection="column" gap={2}>
<Button size="lg" width="100%" onClick={onResume}>
Resume deposit
</Button>
<Button size="lg" width="100%" variant="outline" onClick={onClose}>
Yes, cancel
</Button>
</ModalFooter>
</>
)
}
8 changes: 7 additions & 1 deletion dapp/src/components/Modals/Support/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React from "react"
import {
useModalFlowContext,
useRequestBitcoinAccount,
useRequestEthereumAccount,
useWalletContext,
} from "#/hooks"
import { ConnectBTCAccount, ConnectETHAccount } from "#/static/icons"
import MissingAccount from "./MissingAccount"
import Resume from "../Staking/Resume"

export default function SupportWrapper({
children,
Expand All @@ -15,7 +17,7 @@ export default function SupportWrapper({
const { btcAccount, ethAccount } = useWalletContext()
const { requestAccount: requestBitcoinAccount } = useRequestBitcoinAccount()
const { requestAccount: requestEthereumAccount } = useRequestEthereumAccount()

const { isResumeStep, onClose, onResume } = useModalFlowContext()
if (!btcAccount)
return (
<MissingAccount
Expand All @@ -34,5 +36,9 @@ export default function SupportWrapper({
/>
)

if (isResumeStep) {
return <Resume onClose={onClose} onResume={onResume} />
}

return children
}
20 changes: 17 additions & 3 deletions dapp/src/components/shared/ModalBase/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,29 @@ export default function ModalBase({
const { onOpen: openSideBar, onClose: closeSidebar } = useSidebar()

const [activeStep, setActiveStep] = useState(defaultStep)
const [isResumeStep, setResumeStep] = useState(false)

const handleResume = useCallback(() => {
setResumeStep(false)
}, [])

const handleGoNext = useCallback(() => {
setActiveStep((prevStep) => prevStep + 1)
}, [])

const handleClose = useCallback(() => {
onClose()
}, [onClose])
// TODO: waiting for transaction functionality (show resume modal when transaction is pending)
// currently resuming modal shows always on step no 2
if (!isResumeStep && activeStep === 2) {
setResumeStep(true)
} else {
onClose()
}
}, [activeStep, isResumeStep, onClose])

const resetState = useCallback(() => {
setActiveStep(defaultStep)
setResumeStep(false)
}, [defaultStep])

useEffect(() => {
Expand All @@ -63,10 +75,12 @@ export default function ModalBase({
const contextValue: ModalFlowContextValue = useMemo<ModalFlowContextValue>(
() => ({
activeStep,
isResumeStep,
onClose: handleClose,
onResume: handleResume,
goNext: handleGoNext,
}),
[activeStep, handleGoNext, handleClose],
[activeStep, isResumeStep, handleGoNext, handleClose, handleResume],
)

return (
Expand Down
9 changes: 8 additions & 1 deletion dapp/src/contexts/ModalFlowContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@ import { createContext } from "react"

export type ModalStep = {
goNext: () => void
goBack?: () => void
}

export type ModalFlowContextValue = {
activeStep?: number
isResumeStep?: boolean
onClose: () => void
onResume: () => void
goNext: () => void
goBack?: () => void
}

export const ModalFlowContext = createContext<ModalFlowContextValue>({
activeStep: undefined,
goNext: () => {},
isResumeStep: false,
onClose: () => {},
onResume: () => {},
goNext: () => {},
goBack: () => {},
})
16 changes: 16 additions & 0 deletions dapp/src/utils/customIcons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from "react"
import { createIcon } from "@chakra-ui/react"

export const PauseIcon = createIcon({
displayName: "PauseIcon",
viewBox: "0 0 18 20",
path: (
<path
d="M2 18V2M16 18V2"
stroke="#F34900"
strokeWidth="3"
strokeLinecap="round"
strokeLinejoin="round"
/>
),
})

0 comments on commit dc84755

Please sign in to comment.