Skip to content

Commit

Permalink
Resume staking flow modal
Browse files Browse the repository at this point in the history
  • Loading branch information
ioay committed Jan 19, 2024
1 parent 094e27c commit a98ba62
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 10 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.
47 changes: 47 additions & 0 deletions dapp/src/components/Modals/Staking/Resume/index.tsx
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" />
<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>
</>
)
}
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

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)

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])

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
2 changes: 1 addition & 1 deletion dapp/src/constants/staking.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const BITCOIN_MIN_AMOUNT = "1000000" // 0.01 BTC
export const BITCOIN_MIN_AMOUNT = "100" // 0.000001 BTC
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 a98ba62

Please sign in to comment.