Skip to content

Commit

Permalink
Merge pull request #157 from 00labs/notifi-fixes
Browse files Browse the repository at this point in the history
Notifi fixes
  • Loading branch information
mliu authored Mar 12, 2024
2 parents adf5203 + bf680fa commit 5ff3b81
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 31 deletions.
4 changes: 0 additions & 4 deletions packages/huma-shared/src/utils/notifi.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { ChainEnum } from './chain'

export function getNotifiDappId(isDev: boolean): string {
return isDev ? 'humadapp' : 'humafinanceprod'
}

export function getBlockchainConfigFromChain(
chainEnum: ChainEnum,
): 'POLYGON' | 'ETHEREUM' {
Expand Down
15 changes: 0 additions & 15 deletions packages/huma-shared/tests/utils/notifi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,8 @@ import { ChainEnum } from '../../src/utils/chain'
import {
doesChainSupportNotifi,
getBlockchainConfigFromChain,
getNotifiDappId,
} from '../../src/utils/notifi'

describe('getNotifiDappId', () => {
it('returns the correct dappId for development', () => {
const result = getNotifiDappId(true)

expect(result).toBe('humadapp')
})

it('returns the correct dappId for production', () => {
const result = getNotifiDappId(false)

expect(result).toBe('humafinanceprod')
})
})

describe('getBlockchainConfigFromChain', () => {
it('returns POLYGON for Polygon and Mumbai chains', () => {
expect(getBlockchainConfigFromChain(ChainEnum.Polygon)).toBe('POLYGON')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
checkIsDev,
getBlockchainConfigFromChain,
txAtom,
} from '@huma-finance/shared'
import { getBlockchainConfigFromChain, txAtom } from '@huma-finance/shared'
import { Box, css, TextField, Typography, useTheme } from '@mui/material'
import {
BroadcastEventTypeItem,
Expand Down Expand Up @@ -95,7 +91,7 @@ export function NotifiSubscriptionModal({
const [isLoading, setIsLoading] = useState<boolean>(false)
const [emailAddress, setEmailAddress] = useState<string>('')
const [emailValid, setEmailValid] = useState<boolean>()
const { notifiClient } = useNotifiClient(account, chainId, checkIsDev())
const { notifiClient } = useNotifiClient(account, chainId)

const signMessage: Uint8SignMessageFunction = async (
message: Uint8Array,
Expand Down
10 changes: 4 additions & 6 deletions packages/huma-widget/src/hooks/useNotifi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
checkIsDev,
doesChainSupportNotifi,
getBlockchainConfigFromChain,
getNotifiDappId,
} from '@huma-finance/shared'
import {
NotifiFrontendClient,
Expand Down Expand Up @@ -34,7 +33,6 @@ export const useDoesChainSupportNotifi = (
export const useNotifiClient = (
account: string | undefined,
chainId: number | undefined,
isDev: boolean,
) => {
const [notifiClient, setNotifiClient] = useState<NotifiFrontendClient | null>(
null,
Expand All @@ -46,8 +44,8 @@ export const useNotifiClient = (
if (account != null && chainId != null && notifiChainSupported) {
const client = newFrontendClient({
account: { publicKey: account },
tenantId: getNotifiDappId(isDev),
env: isDev ? 'Development' : 'Production',
tenantId: 'humafinanceprod',
env: 'Production',
walletBlockchain: getBlockchainConfigFromChain(chainId),
})
await client.initialize()
Expand All @@ -56,7 +54,7 @@ export const useNotifiClient = (
}

createNotifiClient()
}, [account, chainId, isDev, notifiChainSupported])
}, [account, chainId, notifiChainSupported])

return { notifiClient }
}
Expand All @@ -66,7 +64,7 @@ export const useIsFirstTimeNotifiUser = (
chainId: number | undefined,
) => {
const [isFirstTimeNotifiUser, setIsFirstTimeNotifiUser] = useState(false)
const { notifiClient } = useNotifiClient(account, chainId, checkIsDev())
const { notifiClient } = useNotifiClient(account, chainId)
const { notifiChainSupported } = useDoesChainSupportNotifi(account, chainId)

useEffect(() => {
Expand Down

0 comments on commit 5ff3b81

Please sign in to comment.