Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
rickykuo666 committed Aug 7, 2024
1 parent 855048c commit 99ac02e
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 8 deletions.
10 changes: 8 additions & 2 deletions components/AccountBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,10 @@ export const AccountBody = ({
disabled={
stakingOpsStatus.Delegated && !stakingOpsStatus.CanUnstake
}
onClick={() => unstakeModal.onOpen()}
onClick={() => {
trackGAEvent(GAAction.BUTTON_CLICK, GACategory.CHOOSE_UNSTAKE)
unstakeModal.onOpen()
}}
w='100%'
>
Unstake
Expand All @@ -353,7 +356,10 @@ export const AccountBody = ({
{stakingOpsStatus.Delegated && (
<PrimaryButton
disabled={!stakingOpsStatus.CanStake}
onClick={() => stakeModal.onOpen()}
onClick={() => {
trackGAEvent(GAAction.BUTTON_CLICK, GACategory.CHOOSE_STAKE)
stakeModal.onOpen()
}}
w='100%'
>
Stake
Expand Down
3 changes: 3 additions & 0 deletions components/SuccessModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const setGAEvent = (opType?: OpType) => {
case 'delegate':
trackGAEvent(GAAction.BUTTON_CLICK, GACategory.CONTINUE_AFTER_DELEGATION)
return
case 'stake':
trackGAEvent(GAAction.BUTTON_CLICK, GACategory.CONTINUE_AFTER_STAKE)
return
default:
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useConnection } from '@/providers/ConnectionProvider'
import { Header, BalanceBox, ColumnHeader } from '@/components/modalBody'
import { useOperationResponse } from '@/providers/OperationResponseProvider'
import { ErrorBlock } from '@/components/ErrorBlock'
import { trackGAEvent, GAAction, GACategory } from '@/utils/trackGAEvent'

interface ConfirmFinalizeUnstake {
withdrawAmount: number
Expand Down Expand Up @@ -42,6 +43,7 @@ export const ConfirmFinalizeUnstake = ({
setWaitingOperation(false)

if (response.success) {
trackGAEvent(GAAction.BUTTON_CLICK, GACategory.FINALIZE_END)
setOpHash(response.opHash)
setMessage(
`You have successfully finalized ${withdrawAmount} ꜩ. These funds are now part of your spendable balance.`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { mutezToTez } from '@/utils/mutezToTez'
import { TertiaryButton } from '@/components/buttons/TertiaryButton'
import { FinalizeUnstakeModal } from '.'
import Link from 'next/link'
import { trackGAEvent, GAAction, GACategory } from '@/utils/trackGAEvent'

export const UnstakeOperationBox = ({
unstakeOp,
Expand Down Expand Up @@ -101,7 +102,12 @@ export const UnstakeOperationBox = ({
)}
</Box>
{canFinalize && (
<TertiaryButton onClick={() => finalizeUnstakeModal.onOpen()}>
<TertiaryButton
onClick={() => {
trackGAEvent(GAAction.BUTTON_CLICK, GACategory.FINALIZE_BEGIN)
finalizeUnstakeModal.onOpen()
}}
>
Finalize
</TertiaryButton>
)}
Expand Down
9 changes: 8 additions & 1 deletion components/operationModals/Stake/SelectAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { stake } from '@/components/Operations/operations'
import { useConnection } from '@/providers/ConnectionProvider'
import { useOperationResponse } from '@/providers/OperationResponseProvider'
import { ErrorBlock } from '@/components/ErrorBlock'
import { trackGAEvent, GAAction, GACategory } from '@/utils/trackGAEvent'

export const SelectAmount = ({
spendableBalance,
Expand All @@ -19,12 +20,14 @@ export const SelectAmount = ({
stakedAmount: number
}) => {
const { Tezos, beaconWallet } = useConnection()
const { setMessage, setSuccess, setOpHash } = useOperationResponse()
const { setMessage, setSuccess, setOpHash, setOpType } =
useOperationResponse()
const [errorMessage, setErrorMessage] = useState('')
const [waitingOperation, setWaitingOperation] = useState(false)

const handleChange = (event: any) => {
const val = Number(event.target.value)
trackGAEvent(GAAction.BUTTON_CLICK, GACategory.INPUT_AMOUNT)

if (val <= spendableBalance) setStakedAmount(val)
else if (val === 0) setStakedAmount(0)
Expand Down Expand Up @@ -67,12 +70,16 @@ export const SelectAmount = ({
return
}

trackGAEvent(GAAction.BUTTON_CLICK, GACategory.START_STAKE_BEGIN)

setWaitingOperation(true)
const response = await stake(Tezos, stakedAmount, beaconWallet)
setWaitingOperation(false)

if (response.success) {
trackGAEvent(GAAction.BUTTON_CLICK, GACategory.START_STAKE_END)
setOpHash(response.opHash)
setOpType('stake')
setMessage(`You have successfully staked ${stakedAmount} ꜩ`)
setSuccess(true)
setStakedAmount(0)
Expand Down
14 changes: 12 additions & 2 deletions components/operationModals/Stake/StakeStart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState } from 'react'
import { Flex, Text, Checkbox, Image } from '@chakra-ui/react'
import { Header, Description } from '@/components/modalBody'
import { PrimaryButton } from '@/components/buttons/PrimaryButton'
import { trackGAEvent, GAAction, GACategory } from '@/utils/trackGAEvent'

export const StakeStart = ({
handleOneStepForward
Expand Down Expand Up @@ -34,7 +35,10 @@ export const StakeStart = ({
>
<Checkbox
isChecked={isChecked}
onChange={() => setIsChecked(!isChecked)}
onChange={() => {
trackGAEvent(GAAction.BUTTON_CLICK, GACategory.ACCEPT_DISCLAIMER)
setIsChecked(!isChecked)
}}
/>
<Text
color='#2D3748'
Expand All @@ -48,7 +52,13 @@ export const StakeStart = ({
</Text>
</Text>
</Flex>
<PrimaryButton disabled={!isChecked} onClick={handleOneStepForward}>
<PrimaryButton
disabled={!isChecked}
onClick={() => {
trackGAEvent(GAAction.BUTTON_CLICK, GACategory.CONTINUE_STAKE)
handleOneStepForward()
}}
>
Continue
</PrimaryButton>
</Flex>
Expand Down
4 changes: 4 additions & 0 deletions components/operationModals/Unstake/SelectAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { unstake } from '@/components/Operations/operations'
import { useConnection } from '@/providers/ConnectionProvider'
import { useOperationResponse } from '@/providers/OperationResponseProvider'
import { ErrorBlock } from '@/components/ErrorBlock'
import { trackGAEvent, GAAction, GACategory } from '@/utils/trackGAEvent'

export const SelectAmount = ({
stakedAmount,
Expand Down Expand Up @@ -84,11 +85,14 @@ export const SelectAmount = ({
return
}

trackGAEvent(GAAction.BUTTON_CLICK, GACategory.END_STAKE_BEGIN)

setWaitingOperation(true)
const response = await unstake(Tezos, unstakeAmount, beaconWallet)
setWaitingOperation(false)

if (response.success) {
trackGAEvent(GAAction.BUTTON_CLICK, GACategory.END_STAKE_END)
setOpHash(response.opHash)
setTitle('Unstake Requested')
setMessage(
Expand Down
10 changes: 9 additions & 1 deletion components/operationModals/Unstake/UnstakeStart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Flex, Image } from '@chakra-ui/react'
import { Header, Description } from '@/components/modalBody'
import { PrimaryButton } from '@/components/buttons/PrimaryButton'
import { RoundBorderText } from '../Delegate/DelegateStart'
import { trackGAEvent, GAAction, GACategory } from '@/utils/trackGAEvent'

export const UnstakeStart = ({
handleOneStepForward
Expand All @@ -22,7 +23,14 @@ export const UnstakeStart = ({
<RoundBorderText step={1} text='UNSTAKE' />
<RoundBorderText step={2} text='FINALIZE' />
</Flex>
<PrimaryButton onClick={handleOneStepForward}>I Understand</PrimaryButton>
<PrimaryButton
onClick={() => {
trackGAEvent(GAAction.BUTTON_CLICK, GACategory.CHOOSE_I_UNDERSTAND)
handleOneStepForward()
}}
>
I Understand
</PrimaryButton>
</Flex>
)
}
18 changes: 17 additions & 1 deletion utils/trackGAEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,23 @@ export enum GACategory {
CHANGE_BAKER_SUCCESS = 'change_baker_success',

END_DELEGATE_BEGIN = 'end_delegate_begin',
END_DELEGATE_END = 'end_delegate_end'
END_DELEGATE_END = 'end_delegate_end',

CHOOSE_STAKE = 'choose_stake',
ACCEPT_DISCLAIMER = 'accept_disclaimer',
CONTINUE_STAKE = 'continue_stake',
INPUT_AMOUNT = 'input_amount',
START_STAKE_BEGIN = 'start_stake_begin',
START_STAKE_END = 'start_stake_end',
CONTINUE_AFTER_STAKE = 'continue_after_stake',

CHOOSE_UNSTAKE = 'choose_unstake',
CHOOSE_I_UNDERSTAND = 'choose_i_understand',
END_STAKE_BEGIN = 'end_stake_begin',
END_STAKE_END = 'end_stake_end',

FINALIZE_BEGIN = 'finalize_begin',
FINALIZE_END = 'finalize_end'
}

export const trackGAEvent = (action: GAAction, category: GACategory) => {
Expand Down

0 comments on commit 99ac02e

Please sign in to comment.