Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resuming deposit modal #138

Merged
merged 11 commits into from
Jan 29, 2024
10 changes: 10 additions & 0 deletions dapp/src/assets/images/staking-pause-circle.svg
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions dapp/src/components/Modals/Staking/Resume/index.tsx
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from "react"
import {
ModalHeader,
ModalBody,
ModalFooter,
Button,
Stack,
} from "@chakra-ui/react"

import Spinner from "#/components/shared/Spinner"
import { PauseIcon } from "#/utils/customIcons"
import { TextMd } from "#/components/shared/Typography"

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 size="xl" />
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved
<PauseIcon position="absolute" />
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved
</Stack>
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved

<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>
</>
)
}
10 changes: 6 additions & 4 deletions dapp/src/components/Modals/Staking/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ import Overview from "./Overview"
import ActionForm from "../ActionForm"
import SignMessage from "./SignMessage"
import DepositBTC from "./DepositBTC"
import { STAKING_STEPS } from "./utils/stakingSteps"

function ActiveStakingStep() {
const { activeStep } = useModalFlowContext()
const { ACTION_FORM, OVERVIEW, SIGN_MESSAGE, DEPOSIT_BTC } = STAKING_STEPS
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved

switch (activeStep) {
case 1:
case ACTION_FORM:
return <ActionForm action="stake" />
case 2:
case OVERVIEW:
return <Overview />
case 3:
case SIGN_MESSAGE:
return <SignMessage />
case 4:
case DEPOSIT_BTC:
return <DepositBTC />
default:
return null
Expand Down
6 changes: 6 additions & 0 deletions dapp/src/components/Modals/Staking/utils/stakingSteps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const STAKING_STEPS = {
ACTION_FORM: 1,
OVERVIEW: 2,
SIGN_MESSAGE: 3,
DEPOSIT_BTC: 4,
}
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
}
24 changes: 21 additions & 3 deletions dapp/src/components/shared/ModalBase/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
TransactionContextProvider,
} from "#/contexts"
import SupportWrapper from "#/components/Modals/Support"
import { STAKING_STEPS } from "#/components/Modals/Staking/utils/stakingSteps"

export default function ModalBase({
isOpen,
Expand All @@ -29,17 +30,32 @@ export default function ModalBase({
const { onOpen: openSideBar, onClose: closeSidebar } = useSidebar()

const [activeStep, setActiveStep] = useState(defaultStep)
const [isResumeStep, setResumeStep] = useState(false)
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved

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

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

const isStakingPending = useCallback(() => {
const { SIGN_MESSAGE, DEPOSIT_BTC } = STAKING_STEPS
return activeStep === SIGN_MESSAGE || activeStep === DEPOSIT_BTC
}, [activeStep])

const handleClose = useCallback(() => {
onClose()
}, [onClose])
if (!isResumeStep && isStakingPending()) {
setResumeStep(true)
} else {
onClose()
}
}, [isResumeStep, isStakingPending, onClose])
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved

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

useEffect(() => {
Expand All @@ -63,10 +79,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
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved
}

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,
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved
onClose: () => {},
onResume: () => {},
goNext: () => {},
goBack: () => {},
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved
})
16 changes: 16 additions & 0 deletions dapp/src/utils/customIcons.tsx
kkosiorowska marked this conversation as resolved.
Show resolved Hide resolved
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"
/>
),
})