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

WIP: Staking flow survey #332

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/components/Modal/DappSurveyModal/RadioCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
Box,
Card,
Radio,
useRadio,
RadioProps,
} from "@threshold-network/components"
import theme from "../../../theme"

const RadioCard = (props: RadioProps) => {
const { getInputProps, getCheckboxProps } = useRadio(props)

const input = getInputProps()
const checkbox = getCheckboxProps()

return (
<Box as="label">
<input {...input} />
<Card
{...checkbox}
boxShadow="none"
cursor="pointer"
display="flex"
_checked={{
border: `2px solid ${theme.colors.brand[400]}`,
}}
p={4}
>
{/* @ts-ignore*/}
<Radio isChecked={input.checked} />
<Box>{props.children}</Box>
</Card>
</Box>
)
}

export default RadioCard
97 changes: 97 additions & 0 deletions src/components/Modal/DappSurveyModal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { FC, useState } from "react"
import {
Box,
Button,
Divider,
H5,
ModalBody,
ModalCloseButton,
ModalFooter,
ModalHeader,
RadioGroup,
Stack,
Textarea,
useRadioGroup,
} from "@threshold-network/components"
import { BaseModalProps } from "../../../types"
import withBaseModal from "../withBaseModal"
import InfoBox from "../../InfoBox"
import { PosthogEvent } from "../../../types/posthog"
import RadioCard from "./RadioCard"

interface SurveyQuestion {
text: string
value: string
}

interface DappSurveyModalProps extends BaseModalProps {
title: string
captureEvent: PosthogEvent
surveyQuestions: SurveyQuestion[]
}

const DappSurveyModal: FC<DappSurveyModalProps> = ({
closeModal,
title,
captureEvent,
surveyQuestions,
}) => {
const [value, setValue] = useState("")
const [extraInfo, setExtraInfo] = useState("")

const handleSubmit = () => {
console.log("post hog capture ", captureEvent)
}

const { getRootProps, getRadioProps } = useRadioGroup({
defaultValue: "",
onChange: setValue,
})

const group = getRootProps()

return (
<>
<ModalHeader>dApp Survey</ModalHeader>
<ModalCloseButton />
<ModalBody>
<InfoBox>
<H5 mb={2}>{title}</H5>
</InfoBox>
<Box px={4} my={4}>
<RadioGroup onChange={setValue} value={value}>
<Stack spacing={2} {...group}>
{surveyQuestions.map(({ value, text }) => {
const radio = getRadioProps({ value })
return (
<RadioCard key={value} {...radio}>
{text}
</RadioCard>
)
})}
</Stack>
</RadioGroup>
{value === "OTHER" && (
<Textarea
mt={2}
placeholder="Type your reasons here"
value={extraInfo}
onChange={(e) => setExtraInfo(e.target.value)}
/>
)}
</Box>
<Divider />
</ModalBody>
<ModalFooter>
<Button onClick={closeModal} variant="outline" mr={2}>
Dismiss
</Button>
<Button disabled={value === ""} onClick={handleSubmit}>
Submit
</Button>
</ModalFooter>
</>
)
}

export default withBaseModal(DappSurveyModal)
17 changes: 16 additions & 1 deletion src/components/Modal/ModalCloseButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import { FC } from "react"
import { ModalCloseButton as _ModalCloseButton } from "@threshold-network/components"
import { useStyles } from "@chakra-ui/system"
import { CloseButton } from "@chakra-ui/close-button"

const ModalCloseButton: FC<{ onClick?: VoidFunction }> = ({ onClick }) => {
const styles = useStyles()

if (onClick) {
// avoids the auto-close functionality of the ModalCloseButton if a custom click handler is passed
return (
<CloseButton
__css={styles.closeButton}
className="chakra-modal__close-btn ph-no-capture"
onClick={onClick}
/>
)
}

const ModalCloseButton: FC = () => {
return <_ModalCloseButton className="ph-no-capture" />
}

Expand Down
35 changes: 35 additions & 0 deletions src/components/Modal/StakingBounceSurveyModal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { FC } from "react"
import DappSurveyModal from "../DappSurveyModal"
import { PosthogEvent } from "../../../types/posthog"
import { BaseModalProps } from "../../../types"

const StakingBounceSurveyModal: FC<BaseModalProps> = (props) => {
return (
<DappSurveyModal
title="We've noticed you did not complete your staking. What happened?"
captureEvent={PosthogEvent.StakingFlowBounce}
surveyQuestions={[
{ text: "I misclicked", value: "MISCLICK" },
{
text: "I have trouble with my hardware wallet",
value: "HARDWARE_ISSUE",
},
{
text: "I added one wrong address",
value: "ADDED_WRONG_ADDRESS",
},
{
text: "I just wanted to test the dApp",
value: "TEST",
},
{
text: "Other",
value: "OTHER",
},
]}
{...props}
/>
)
}

export default StakingBounceSurveyModal
13 changes: 9 additions & 4 deletions src/components/Modal/SubmitStake/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { FC } from "react"
import {
Button,
Divider,
ModalBody,
ModalFooter,
ModalHeader,
Divider,
} from "@chakra-ui/react"
import { BodyLg, BodySm, H5 } from "@threshold-network/components"
import withBaseModal from "../withBaseModal"
Expand All @@ -19,7 +19,12 @@ import StakingStats from "../../StakingStats"
import ModalCloseButton from "../ModalCloseButton"

const SubmitStakeModal: FC<BaseModalProps> = () => {
const { closeModal, openModal } = useModal()
const { openModal } = useModal()

const openStakingBounceSurveyModal = () => {
console.log("opening the modal....?")
openModal(ModalType.StakingBounceSurvey)
}

// stake transaction, opens success modal on success callback
const { stake } = useStakeTransaction((tx) =>
Expand All @@ -41,7 +46,7 @@ const SubmitStakeModal: FC<BaseModalProps> = () => {
<H5 mr={2}>Stake Tokens</H5>
<BodySm>(Step 1)</BodySm>
</ModalHeader>
<ModalCloseButton />
<ModalCloseButton onClick={openStakingBounceSurveyModal} />
<ModalBody>
<InfoBox variant="modal" spacing={6} mb={6}>
<H5>You are about to make a deposit into the T Staking Contract.</H5>
Expand All @@ -59,7 +64,7 @@ const SubmitStakeModal: FC<BaseModalProps> = () => {
<Divider mt="4" />
</ModalBody>
<ModalFooter>
<Button onClick={closeModal} variant="outline" mr={2}>
<Button onClick={openStakingBounceSurveyModal} variant="outline" mr={2}>
Cancel
</Button>
<Button onClick={submitStake}>Stake</Button>
Expand Down
1 change: 1 addition & 0 deletions src/enums/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ export enum ModalType {
DeauthorizationInitiated = "DEAUTHORIZATION_INITIATED",
Analytics = "ANALYTICS",
FeedbackSubmission = "FEEDBACK_SUBMIT",
StakingBounceSurvey = "STAKING_BOUNCE_SURVEY",
}
3 changes: 2 additions & 1 deletion src/types/modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import MapOperatorToStakingProviderConfirmationModal from "../components/Modal/M
import { MapOperatorToStakingProviderSuccess } from "../components/Modal/MapOperatorToStakingProviderSuccessModal"
import AnalyticsModal from "../components/Modal/AnalyticsModal"
import FeedbackSubmissionModal from "../components/Modal/FeedbackSubmissionModal"
import StakingBounceSurveyModal from "../components/Modal/StakingBounceSurveyModal"

export const MODAL_TYPES: Record<ModalType, ElementType> = {
[ModalType.SelectWallet]: SelectWalletModal,
Expand Down Expand Up @@ -82,14 +83,14 @@ export const MODAL_TYPES: Record<ModalType, ElementType> = {
[ModalType.StakingApplicationsAuthorized]: StakingApplicationsAuthorized,
[ModalType.IncreaseAuthorization]: IncreaseAuthorization,
[ModalType.IncreaseAuthorizationSuccess]: IncreaseAuthorizationSuccess,
[ModalType.SubmitStake]: SubmitStakeModal,
[ModalType.NewStakerAuthorizeStakingApplication]:
NewStakerAuthorizeStakingApplicationModal,
[ModalType.ConfirmDeauthorization]: ConfirmDeauthorization,
[ModalType.DeauthorizationCompleted]: DeauthorizationCompleted,
[ModalType.DeauthorizationInitiated]: DeauthorizationInitiated,
[ModalType.Analytics]: AnalyticsModal,
[ModalType.FeedbackSubmission]: FeedbackSubmissionModal,
[ModalType.StakingBounceSurvey]: StakingBounceSurveyModal,
}

export interface BaseModalProps {
Expand Down
1 change: 1 addition & 0 deletions src/types/posthog.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export enum PosthogEvent {
ClosedModal = "Closed Modal",
StakingFlowBounce = "Staking Flow Bounce",
}