Skip to content

Commit

Permalink
Move zkp snap connector to store (#44)
Browse files Browse the repository at this point in the history
* move mm zkp snap to identity store
  • Loading branch information
lukachi authored Feb 12, 2024
1 parent 884a6cf commit c9200e3
Show file tree
Hide file tree
Showing 22 changed files with 596 additions and 757 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@mui/icons-material": "^5.14.19",
"@mui/material": "^5.14.20",
"@mui/x-date-pickers": "^6.18.7",
"@rarimo/rarime-connector": "^2.0.1",
"@rarimo/rarime-connector": "^2.1.0-rc.0",
"@walletconnect/modal": "^2.6.2",
"copy-to-clipboard": "^3.3.3",
"i18next": "^22.4.3",
Expand Down
16 changes: 7 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { CircularProgress, CssBaseline, Stack, ThemeProvider } from '@mui/material'
import { FC, HTMLAttributes, memo, useCallback, useEffect, useMemo, useState } from 'react'

import { ToastsManager } from '@/contexts'
import { ErrorHandler } from '@/helpers'
import { useAuth, useMetamaskZkpSnapContext, useViewportSizes, useWeb3Context } from '@/hooks'

import { ToastsManager } from './contexts'
import { AppRoutes } from './routes'
import { useUiState } from './store'
import { createTheme } from './theme'
import { useAuth, useViewportSizes, useWeb3Context } from '@/hooks'
import { AppRoutes } from '@/routes'
import { useUiState, web3Store } from '@/store'
import { createTheme } from '@/theme'

const App: FC<HTMLAttributes<HTMLDivElement>> = () => {
const [isAppInitialized, setIsAppInitialized] = useState(false)

const { provider, isValidChain } = useWeb3Context()
const { checkSnapStatus } = useMetamaskZkpSnapContext()
const { paletteMode } = useUiState()
const { connectProviders } = useAuth()

Expand All @@ -23,7 +21,7 @@ const App: FC<HTMLAttributes<HTMLDivElement>> = () => {
if (provider?.address) return

try {
const { isMetamaskInstalled, isSnapInstalled } = await checkSnapStatus()
const { isMetamaskInstalled, isSnapInstalled } = await web3Store.checkSnapStatus()

if (isMetamaskInstalled && isSnapInstalled) {
await connectProviders()
Expand All @@ -33,7 +31,7 @@ const App: FC<HTMLAttributes<HTMLDivElement>> = () => {
}

setIsAppInitialized(true)
}, [provider?.address, checkSnapStatus, connectProviders])
}, [provider?.address, connectProviders])

const theme = useMemo(() => createTheme(paletteMode), [paletteMode])

Expand Down
8 changes: 8 additions & 0 deletions src/api/clients/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { config } from '@config'
import { JsonApiClient } from '@distributedlab/jac'
import { enableSnap, SnapConnector } from '@rarimo/rarime-connector'

export const api = new JsonApiClient({
baseUrl: config.API_URL,
})

export let zkpSnap: SnapConnector

export const initZkpSnap = async () => {
const snap = await enableSnap()
zkpSnap = await snap.getConnector()
}
5 changes: 3 additions & 2 deletions src/api/modules/orgs/hooks/org.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useCallback, useMemo } from 'react'

import { loadOrgById, OrgsIncludes } from '@/api/modules/orgs'
import { useLoading, useMetamaskZkpSnapContext } from '@/hooks'
import { useLoading } from '@/hooks'
import { useIdentityState } from '@/store'

export const useOrg = (id: string) => {
const { userDid } = useMetamaskZkpSnapContext()
const { userDid } = useIdentityState()

const loadOrg = useCallback(async () => {
if (!id) return undefined
Expand Down
5 changes: 2 additions & 3 deletions src/common/AppNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { NavLink, useLocation } from 'react-router-dom'

import { ProfileMenu } from '@/common'
import { Icons, RoutePaths } from '@/enums'
import { useMetamaskZkpSnapContext } from '@/hooks'
import { uiStore, useUiState } from '@/store'
import { uiStore, useIdentityState, useUiState } from '@/store'
import { Transitions } from '@/theme/constants'
import { UiIcon, UiIconButton } from '@/ui'

Expand Down Expand Up @@ -48,7 +47,7 @@ const NavbarLink = ({ children, to }: NavbarLinkProps) => {
const AppNavbar = () => {
const { palette } = useTheme()
const { paletteMode } = useUiState()
const { userDid } = useMetamaskZkpSnapContext()
const { userDid } = useIdentityState()

const navbarItems = useMemo(
() => [
Expand Down
5 changes: 3 additions & 2 deletions src/common/FillRequestForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import type { ObjectShape } from 'yup'
import { CredentialRequest, fillOrgGroupRequest, OrgGroupRequest } from '@/api/modules/orgs'
import { ParsedCredentialSchemaProperty } from '@/api/modules/zkp'
import { ErrorHandler } from '@/helpers'
import { useForm, useMetamaskZkpSnapContext } from '@/hooks'
import { useForm } from '@/hooks'
import { useIdentityState } from '@/store'
import { UiButton, UiTextField } from '@/ui'

type Props = StackProps & {
Expand All @@ -24,7 +25,7 @@ export default function FillRequestForm({
onRequestFilled,
...rest
}: Props) {
const { userDid } = useMetamaskZkpSnapContext()
const { userDid } = useIdentityState()

const {
formState,
Expand Down
1 change: 0 additions & 1 deletion src/contexts/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './metamask-zkp-snap'
export { default as ToastsManager } from './toasts-manager'
export * from './web3'
237 changes: 0 additions & 237 deletions src/contexts/metamask-zkp-snap.tsx

This file was deleted.

Loading

0 comments on commit c9200e3

Please sign in to comment.