@huma-finance/widgets 0.0.43-beta.112 → 0.0.43-beta.122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +189 -191
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.js +190 -192
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/components/Notifi/NotifiSubscriptionModal.tsx +3 -23
- package/src/hooks/useNotifi.ts +38 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@huma-finance/widgets",
|
|
3
|
-
"version": "0.0.43-beta.
|
|
3
|
+
"version": "0.0.43-beta.122+c9ac2ce",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"@ethersproject/experimental": "^5.7.0",
|
|
31
31
|
"@ethersproject/providers": "^5.6.0",
|
|
32
32
|
"@ethersproject/units": "^5.6.0",
|
|
33
|
-
"@huma-finance/sdk": "^0.0.
|
|
34
|
-
"@huma-finance/shared": "^0.0.
|
|
33
|
+
"@huma-finance/sdk": "^0.0.42",
|
|
34
|
+
"@huma-finance/shared": "^0.0.42",
|
|
35
35
|
"@mui/icons-material": "^5.3.0",
|
|
36
36
|
"@mui/material": "^5.0.6",
|
|
37
37
|
"@mui/styles": "^5.0.2",
|
|
@@ -192,5 +192,5 @@
|
|
|
192
192
|
"optionalDependencies": {
|
|
193
193
|
"encoding": "^0.1.13"
|
|
194
194
|
},
|
|
195
|
-
"gitHead": "
|
|
195
|
+
"gitHead": "c9ac2ce4c0d689146c54d3db561fb30ffd62eec3"
|
|
196
196
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import React, { useCallback,
|
|
1
|
+
import React, { useCallback, useState } from 'react'
|
|
2
2
|
import { useWeb3React } from '@web3-react/core'
|
|
3
3
|
import {
|
|
4
4
|
NotifiFrontendClient,
|
|
5
|
-
newFrontendClient,
|
|
6
5
|
Uint8SignMessageFunction,
|
|
7
6
|
SignMessageParams,
|
|
8
7
|
CardConfigItemV1,
|
|
@@ -14,7 +13,6 @@ import {
|
|
|
14
13
|
checkIsDev,
|
|
15
14
|
getBlockchainConfigFromChain,
|
|
16
15
|
txAtom,
|
|
17
|
-
getNotifiDappId,
|
|
18
16
|
} from '@huma-finance/shared'
|
|
19
17
|
import { ethers } from 'ethers'
|
|
20
18
|
import {
|
|
@@ -34,6 +32,7 @@ import { LoadingModal } from '../LoadingModal'
|
|
|
34
32
|
import { CheckIcon } from '../icons'
|
|
35
33
|
import { resetState } from '../../store/widgets.reducers'
|
|
36
34
|
import { useAppDispatch } from '../../hooks/useRedux'
|
|
35
|
+
import { useNotifiClient } from '../../hooks/useNotifi'
|
|
37
36
|
|
|
38
37
|
type Props = {
|
|
39
38
|
handleSuccess: () => void
|
|
@@ -100,30 +99,11 @@ export function NotifiSubscriptionModal({
|
|
|
100
99
|
const reset = useResetAtom(txAtom)
|
|
101
100
|
const dispatch = useAppDispatch()
|
|
102
101
|
const { account, chainId, provider } = useWeb3React()
|
|
103
|
-
const [notifiClient, setNotifiClient] = useState<NotifiFrontendClient>()
|
|
104
102
|
const [showSuccessScreen, setShowSuccessScreen] = useState<boolean>(false)
|
|
105
103
|
const [isLoading, setIsLoading] = useState<boolean>(false)
|
|
106
104
|
const [emailAddress, setEmailAddress] = useState<string>('')
|
|
107
105
|
const [emailValid, setEmailValid] = useState<boolean>()
|
|
108
|
-
|
|
109
|
-
useEffect(() => {
|
|
110
|
-
const initializeClient = async () => {
|
|
111
|
-
if (account != null && chainId != null) {
|
|
112
|
-
const client = newFrontendClient({
|
|
113
|
-
account: { publicKey: account },
|
|
114
|
-
tenantId: getNotifiDappId(checkIsDev()),
|
|
115
|
-
env: checkIsDev() ? 'Development' : 'Production',
|
|
116
|
-
walletBlockchain: getBlockchainConfigFromChain(chainId),
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
await client.initialize()
|
|
120
|
-
|
|
121
|
-
setNotifiClient(client)
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
initializeClient()
|
|
126
|
-
}, [account, chainId])
|
|
106
|
+
const { notifiClient } = useNotifiClient(account, chainId, checkIsDev())
|
|
127
107
|
|
|
128
108
|
const signMessage: Uint8SignMessageFunction = async (
|
|
129
109
|
message: Uint8Array,
|
package/src/hooks/useNotifi.ts
CHANGED
|
@@ -3,37 +3,64 @@ import {
|
|
|
3
3
|
checkIsDev,
|
|
4
4
|
doesChainSupportNotifi,
|
|
5
5
|
getBlockchainConfigFromChain,
|
|
6
|
+
getNotifiDappId,
|
|
6
7
|
} from '@huma-finance/shared'
|
|
7
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
NotifiFrontendClient,
|
|
10
|
+
newFrontendClient,
|
|
11
|
+
} from '@notifi-network/notifi-frontend-client'
|
|
8
12
|
|
|
9
|
-
export const
|
|
13
|
+
export const useNotifiClient = (
|
|
10
14
|
account: string | undefined,
|
|
11
15
|
chainId: number | undefined,
|
|
16
|
+
isDev: boolean,
|
|
12
17
|
) => {
|
|
13
|
-
const [
|
|
18
|
+
const [notifiClient, setNotifiClient] = useState<NotifiFrontendClient | null>(
|
|
19
|
+
null,
|
|
20
|
+
)
|
|
14
21
|
|
|
15
22
|
useEffect(() => {
|
|
16
|
-
const
|
|
23
|
+
const createNotifiClient = async () => {
|
|
17
24
|
if (account != null && chainId != null) {
|
|
18
25
|
const client = newFrontendClient({
|
|
19
26
|
account: { publicKey: account },
|
|
20
|
-
tenantId:
|
|
21
|
-
env:
|
|
27
|
+
tenantId: getNotifiDappId(isDev),
|
|
28
|
+
env: isDev ? 'Development' : 'Production',
|
|
22
29
|
walletBlockchain: getBlockchainConfigFromChain(chainId),
|
|
23
30
|
})
|
|
31
|
+
await client.initialize()
|
|
32
|
+
setNotifiClient(client)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
createNotifiClient()
|
|
37
|
+
}, [account, chainId, isDev])
|
|
24
38
|
|
|
25
|
-
|
|
39
|
+
return { notifiClient }
|
|
40
|
+
}
|
|
26
41
|
|
|
42
|
+
export const useIsFirstTimeNotifiUser = (
|
|
43
|
+
account: string | undefined,
|
|
44
|
+
chainId: number | undefined,
|
|
45
|
+
) => {
|
|
46
|
+
const [isFirstTimeNotifiUser, setIsFirstTimeNotifiUser] = useState(false)
|
|
47
|
+
const { notifiClient } = useNotifiClient(account, chainId, checkIsDev())
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const checkIsFirstTimeNotifiUser = async () => {
|
|
51
|
+
if (notifiClient != null) {
|
|
52
|
+
const { userState } = notifiClient
|
|
27
53
|
// If the user is not authenticated or expired, they are a first time user
|
|
28
54
|
if (
|
|
29
|
-
userState
|
|
30
|
-
userState.status !== '
|
|
55
|
+
userState == null ||
|
|
56
|
+
(userState.status !== 'authenticated' &&
|
|
57
|
+
userState.status !== 'expired')
|
|
31
58
|
) {
|
|
32
59
|
setIsFirstTimeNotifiUser(true)
|
|
33
60
|
} else if (userState.status === 'authenticated') {
|
|
34
61
|
// If a user is authenticated, check if they have a target group (AKA email)
|
|
35
62
|
// associated with their wallet. If they do not, show them the notifi onboarding flow.
|
|
36
|
-
const targetGroups = await
|
|
63
|
+
const targetGroups = await notifiClient.getTargetGroups()
|
|
37
64
|
const emailTargets = targetGroups[0]?.emailTargets?.[0]
|
|
38
65
|
|
|
39
66
|
if (emailTargets == null || emailTargets.emailAddress == null) {
|
|
@@ -44,7 +71,7 @@ export const useIsFirstTimeNotifiUser = (
|
|
|
44
71
|
}
|
|
45
72
|
|
|
46
73
|
checkIsFirstTimeNotifiUser()
|
|
47
|
-
}, [
|
|
74
|
+
}, [notifiClient])
|
|
48
75
|
|
|
49
76
|
return { isFirstTimeNotifiUser }
|
|
50
77
|
}
|