@huma-finance/widgets 0.0.43-beta.114 → 0.0.43-beta.125

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@huma-finance/widgets",
3
- "version": "0.0.43-beta.114+436d9a7",
3
+ "version": "0.0.43-beta.125+a289bbf",
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.43-beta.114+436d9a7",
34
- "@huma-finance/shared": "^0.0.42",
33
+ "@huma-finance/sdk": "^0.0.43-beta.125+a289bbf",
34
+ "@huma-finance/shared": "^0.0.43-beta.125+a289bbf",
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": "436d9a7f96793c58b55bb1653c654a19c69f229d"
195
+ "gitHead": "a289bbfb4c4be42aa42fc0d23f88fada1a064844"
196
196
  }
@@ -1,8 +1,7 @@
1
- import React, { useCallback, useEffect, useState } from 'react'
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,
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!-- Generator: Adobe Illustrator 27.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3
+ <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
4
+ viewBox="0 0 250 250" style="enable-background:new 0 0 250 250;" xml:space="preserve">
5
+ <style type="text/css">
6
+ .stcelo{fill:#FCFF52;}
7
+ </style>
8
+ <circle class="stcelo" cx="125" cy="125" r="125"/>
9
+ <path d="M188.9,60.7H60.7v128.2h128.2v-44.8h-21.3c-7.3,16.3-23.8,27.7-42.7,27.7c-26,0-47.1-21.3-47.1-47.1c0-25.9,21.1-47,47.1-47
10
+ c19.3,0,35.8,11.7,43.1,28.4h20.9V60.7z"/>
11
+ </svg>
@@ -16,6 +16,7 @@ import { ReactComponent as AutoPaybackSvg } from './auto-payback.svg'
16
16
  import { ReactComponent as ApproveLenderSvg } from './approve-lender.svg'
17
17
  import { ReactComponent as DonutSvg } from './donut.svg'
18
18
  import { ReactComponent as UsdcSvg } from './usdc.svg'
19
+ import { ReactComponent as CeloSvg } from './celo.svg'
19
20
 
20
21
  export function HumaIcon(props: SvgIconProps): React.ReactElement {
21
22
  return <HumaLogoSvg {...props} />
@@ -85,9 +86,17 @@ export function UsdcIcon(props: SvgIconProps): React.ReactElement {
85
86
  return <UsdcSvg {...props} />
86
87
  }
87
88
 
89
+ export function CeloIcon(props: SvgIconProps): React.ReactElement {
90
+ return <CeloSvg {...props} />
91
+ }
92
+
88
93
  export function getIcon(icon: string) {
89
- if (icon === 'USDC') {
90
- return UsdcIcon
91
- }
92
- return null
94
+ if (!icon) return null
95
+
96
+ return (
97
+ {
98
+ USDC: UsdcIcon,
99
+ Celo: CeloIcon,
100
+ }[icon] || null
101
+ )
93
102
  }
@@ -3,37 +3,87 @@ import {
3
3
  checkIsDev,
4
4
  doesChainSupportNotifi,
5
5
  getBlockchainConfigFromChain,
6
+ getNotifiDappId,
6
7
  } from '@huma-finance/shared'
7
- import { newFrontendClient } from '@notifi-network/notifi-frontend-client'
8
+ import {
9
+ NotifiFrontendClient,
10
+ newFrontendClient,
11
+ } from '@notifi-network/notifi-frontend-client'
8
12
 
9
- export const useIsFirstTimeNotifiUser = (
13
+ export const useDoesChainSupportNotifi = (
10
14
  account: string | undefined,
11
15
  chainId: number | undefined,
12
16
  ) => {
13
- const [isFirstTimeNotifiUser, setIsFirstTimeNotifiUser] = useState(false)
17
+ const [notifiChainSupported, setNotifiChainSupported] = useState(false)
14
18
 
15
19
  useEffect(() => {
16
- const checkIsFirstTimeNotifiUser = async () => {
20
+ const checkNotifiChainSupported = async () => {
17
21
  if (account != null && chainId != null) {
22
+ setNotifiChainSupported(
23
+ doesChainSupportNotifi(chainId, checkIsDev(), account),
24
+ )
25
+ }
26
+ }
27
+
28
+ checkNotifiChainSupported()
29
+ }, [account, chainId])
30
+
31
+ return { notifiChainSupported }
32
+ }
33
+
34
+ export const useNotifiClient = (
35
+ account: string | undefined,
36
+ chainId: number | undefined,
37
+ isDev: boolean,
38
+ ) => {
39
+ const [notifiClient, setNotifiClient] = useState<NotifiFrontendClient | null>(
40
+ null,
41
+ )
42
+ const { notifiChainSupported } = useDoesChainSupportNotifi(account, chainId)
43
+
44
+ useEffect(() => {
45
+ const createNotifiClient = async () => {
46
+ if (account != null && chainId != null && notifiChainSupported) {
18
47
  const client = newFrontendClient({
19
48
  account: { publicKey: account },
20
- tenantId: 'humadapp',
21
- env: checkIsDev() ? 'Development' : 'Production',
49
+ tenantId: getNotifiDappId(isDev),
50
+ env: isDev ? 'Development' : 'Production',
22
51
  walletBlockchain: getBlockchainConfigFromChain(chainId),
23
52
  })
53
+ await client.initialize()
54
+ setNotifiClient(client)
55
+ }
56
+ }
57
+
58
+ createNotifiClient()
59
+ }, [account, chainId, isDev, notifiChainSupported])
60
+
61
+ return { notifiClient }
62
+ }
24
63
 
25
- const userState = await client.initialize()
64
+ export const useIsFirstTimeNotifiUser = (
65
+ account: string | undefined,
66
+ chainId: number | undefined,
67
+ ) => {
68
+ const [isFirstTimeNotifiUser, setIsFirstTimeNotifiUser] = useState(false)
69
+ const { notifiClient } = useNotifiClient(account, chainId, checkIsDev())
70
+ const { notifiChainSupported } = useDoesChainSupportNotifi(account, chainId)
26
71
 
72
+ useEffect(() => {
73
+ const checkIsFirstTimeNotifiUser = async () => {
74
+ if (notifiClient != null && notifiChainSupported) {
75
+ const { userState } = notifiClient
27
76
  // If the user is not authenticated or expired, they are a first time user
28
77
  if (
29
- userState.status !== 'authenticated' &&
30
- userState.status !== 'expired'
78
+ userState == null ||
79
+ (userState.status !== 'authenticated' &&
80
+ userState.status !== 'expired')
31
81
  ) {
32
82
  setIsFirstTimeNotifiUser(true)
33
83
  } else if (userState.status === 'authenticated') {
34
84
  // If a user is authenticated, check if they have a target group (AKA email)
35
85
  // associated with their wallet. If they do not, show them the notifi onboarding flow.
36
- const targetGroups = await client.getTargetGroups()
86
+ const targetGroups = await notifiClient.getTargetGroups()
37
87
  const emailTargets = targetGroups[0]?.emailTargets?.[0]
38
88
 
39
89
  if (emailTargets == null || emailTargets.emailAddress == null) {
@@ -44,28 +94,7 @@ export const useIsFirstTimeNotifiUser = (
44
94
  }
45
95
 
46
96
  checkIsFirstTimeNotifiUser()
47
- }, [account, chainId])
97
+ }, [notifiChainSupported, notifiClient])
48
98
 
49
99
  return { isFirstTimeNotifiUser }
50
100
  }
51
-
52
- export const useDoesChainSupportNotifi = (
53
- account: string | undefined,
54
- chainId: number | undefined,
55
- ) => {
56
- const [notifiChainSupported, setNotifiChainSupported] = useState(false)
57
-
58
- useEffect(() => {
59
- const checkNotifiChainSupported = async () => {
60
- if (account != null && chainId != null) {
61
- setNotifiChainSupported(
62
- doesChainSupportNotifi(chainId, checkIsDev(), account),
63
- )
64
- }
65
- }
66
-
67
- checkNotifiChainSupported()
68
- }, [account, chainId])
69
-
70
- return { notifiChainSupported }
71
- }