Skip to content

Commit

Permalink
Merge pull request #243 from 00labs/notifi-v2
Browse files Browse the repository at this point in the history
Notifi V2
  • Loading branch information
mliu authored Sep 14, 2024
2 parents 64ba9d6 + 38bc24c commit c3a83d3
Show file tree
Hide file tree
Showing 10 changed files with 536 additions and 146 deletions.
1 change: 1 addition & 0 deletions packages/huma-shared/src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const checkIsDev = () =>
window.location.hostname.startsWith('v2') ||
window.location.hostname.startsWith('pr-') ||
window.location.hostname.startsWith('deploy-preview') ||
window.location.hostname.startsWith('localhost') ||
process.env.NODE_ENV === 'development'
)
8 changes: 6 additions & 2 deletions packages/huma-shared/src/utils/notifi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChainEnum } from './chain'

export function getBlockchainConfigFromChain(
chainEnum: ChainEnum,
): 'POLYGON' | 'ETHEREUM' | 'CELO' {
): 'POLYGON' | 'ETHEREUM' | 'CELO' | 'SCROLL' {
switch (chainEnum) {
case ChainEnum.Celo:
case ChainEnum.Alfajores:
Expand All @@ -12,6 +12,9 @@ export function getBlockchainConfigFromChain(
return 'POLYGON'
case ChainEnum.Goerli:
return 'ETHEREUM'
case ChainEnum.Scroll:
case ChainEnum.ScrollSepolia:
return 'SCROLL'
default:
throw new Error('Invalid chain')
}
Expand All @@ -23,12 +26,13 @@ export function doesChainSupportNotifi(
): boolean {
switch (chainEnum) {
case ChainEnum.Celo:
return true
case ChainEnum.Polygon:
case ChainEnum.Scroll:
return true
case ChainEnum.Alfajores:
case ChainEnum.Mumbai:
case ChainEnum.Goerli:
case ChainEnum.ScrollSepolia:
return isDev
default:
return false
Expand Down
4 changes: 3 additions & 1 deletion packages/huma-widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@emotion/styled": "^11.3.0",
"@ethersproject/address": "^5.7.0",
"@ethersproject/bignumber": "^5.6.0",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/constants": "^5.7.0",
"@ethersproject/contracts": "^5.7.0",
"@ethersproject/experimental": "^5.7.0",
Expand All @@ -38,7 +39,8 @@
"@mui/styles": "^5.0.2",
"@mui/system": "^5.0.6",
"@mui/x-date-pickers": "^5.0.7",
"@notifi-network/notifi-frontend-client": "^0.91.1",
"@notifi-network/notifi-frontend-client": "^1.1.2",
"@notifi-network/notifi-react": "^1.1.2",
"@reduxjs/toolkit": "^1.8.6",
"@types/utf8": "^3.0.1",
"@walletconnect/ethereum-provider": "1.8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@ export function Notifications({
}
}, [campaign, dispatch, handleAction])

return <NotifiSubscriptionModal handleSuccess={handleUserAction} />
return (
<NotifiSubscriptionModal
successText={campaign ? 'VIEW POINTS' : undefined}
handleSuccess={handleUserAction}
/>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { arrayify } from '@ethersproject/bytes'
import { ChainEnum, getBlockchainConfigFromChain } from '@huma-finance/shared'
import { NotifiContextProvider } from '@notifi-network/notifi-react'
import { useWeb3React } from '@web3-react/core'
import { providers } from 'ethers'
import React, { useMemo } from 'react'

type Props = {
chainId: number | undefined
// eslint-disable-next-line @typescript-eslint/no-explicit-any
children?: any
}

export function NotifiContextWrapper({
chainId,
children,
}: Props): React.ReactElement | null {
const { account, provider } = useWeb3React()
const signer = useMemo(() => {
if (provider instanceof providers.JsonRpcProvider) {
return provider.getSigner()
}
return undefined
}, [provider])

if (account == null || signer == null || chainId == null) {
return null
}

let cardId = ''
if (chainId === ChainEnum.Celo || chainId === ChainEnum.Alfajores) {
cardId = process.env.REACT_APP_NOTIFI_CONFIG_ID_CELO ?? ''
} else if (chainId === ChainEnum.Polygon || chainId === ChainEnum.Amoy) {
cardId = process.env.REACT_APP_NOTIFI_CONFIG_ID_POLYGON ?? ''
} else if (
chainId === ChainEnum.Scroll ||
chainId === ChainEnum.ScrollSepolia
) {
cardId = process.env.REACT_APP_NOTIFI_CONFIG_ID_SCROLL ?? ''
}

return (
<NotifiContextProvider
tenantId='humafinanceprod'
env='Production'
signMessage={async (message: Uint8Array) => {
const result = await signer.signMessage(message)
return arrayify(result)
}}
walletPublicKey={account}
walletBlockchain={getBlockchainConfigFromChain(chainId)}
cardId={cardId}
>
{children}
</NotifiContextProvider>
)
}
Loading

0 comments on commit c3a83d3

Please sign in to comment.