Skip to content

MP-40 update state after dice success -> dev #657

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

Merged
merged 1 commit into from
Jun 15, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Dispatch, FC, SetStateAction, useEffect, useState } from 'react'
import { toast } from 'react-toastify'
import { KeyedMutator } from 'swr'

import { Button, Collapsible, FormToggleSwitch } from '~/libs/ui'
import { diceIdLogo, MFAImage, SettingSection } from '~/apps/accounts/src/lib'
Expand All @@ -15,7 +16,10 @@ interface SecurityProps {
const Security: FC<SecurityProps> = (props: SecurityProps) => {
const [setupDiceModalOpen, setSetupDiceModalOpen]: [boolean, Dispatch<SetStateAction<boolean>>] = useState(false)

const mfaStatusData: MemberMFAStatus | undefined = useMemberMFAStatus(props.profile.userId)
const { data: mfaStatusData, mutate: mutateMFAData }: {
data: MemberMFAStatus | undefined
mutate: KeyedMutator<any>,
} = useMemberMFAStatus(props.profile.userId)

const [mfaEnabled, setMFAEnabled]: [boolean, Dispatch<SetStateAction<boolean>>] = useState(false)

Expand Down Expand Up @@ -91,6 +95,7 @@ const Security: FC<SecurityProps> = (props: SecurityProps) => {

{setupDiceModalOpen && (
<DiceSetupModal
mutateMFAData={mutateMFAData}
onClose={handleDiceModalStatus}
profile={props.profile}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Dispatch, FC, SetStateAction, useEffect, useState } from 'react'
import { QRCodeSVG } from 'qrcode.react'
import { get, isUndefined, lowerCase } from 'lodash'
import { toast } from 'react-toastify'
import { KeyedMutator } from 'swr'

import { BaseModal, Button } from '~/libs/ui'
import {
Expand All @@ -20,6 +21,7 @@ import styles from './DiceSetupModal.module.scss'
const GooglePlayLink: string = 'https://play.google.com/store/apps/details?id=com.diwallet1'
const AppleStoreLink: string = 'https://apps.apple.com/us/app/dice-id/id1548148979'
interface DiceSetupModalProps {
mutateMFAData: KeyedMutator<any>
onClose: () => void
profile: UserProfile
}
Expand Down Expand Up @@ -72,6 +74,7 @@ const DiceSetupModal: FC<DiceSetupModalProps> = (props: DiceSetupModalProps) =>
},
})
.then(() => {
props.mutateMFAData()
setStep(4)
// eslint-disable-next-line max-len
toast.success('Your credentials have been verified and you are all set for MFA using your decentralized identity (DICE ID).')
Expand Down
16 changes: 12 additions & 4 deletions src/libs/core/lib/profile/data-providers/useMemberMFAStatus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import useSWR, { SWRResponse } from 'swr'
import useSWR, { KeyedMutator, SWRResponse } from 'swr'

import { memberModifyMfaURL } from '~/libs/core'

Expand All @@ -13,8 +13,16 @@ export interface MemberMFAStatus {
userId: number
}

export function useMemberMFAStatus(userId: number): MemberMFAStatus | undefined {
const { data }: SWRResponse = useSWR(memberModifyMfaURL(userId))
export interface UseMemberMFAStatusAPI {
data: MemberMFAStatus | undefined
mutate: KeyedMutator<any>
}

export function useMemberMFAStatus(userId: number): UseMemberMFAStatusAPI {
const { data, mutate }: SWRResponse = useSWR(memberModifyMfaURL(userId))

return data ? data.result.content : undefined
return {
data: data ? data.result.content : undefined,
mutate,
}
}