Skip to content

Commit a96f8c1

Browse files
authored
ToS update (#4000)
* Revert "Revert tos changes (#3998)" This reverts commit bf7f55f. * preflight handler * lint fix * Add preflight to risk * update daily rays * remove expressjwt * update dates * remove unused method
1 parent 573a144 commit a96f8c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+674
-1159
lines changed

components/portfolio/helpers/getRaysDailyChallenge.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ export const getDailyRaysBaseData = ({
2525

2626
export const updateDailyRaysData = ({
2727
wallet,
28-
token,
2928
callback,
3029
}: {
3130
wallet: Wallet
32-
token: string
3331
callback: (data: RaysDailyChallengeResponse) => void
3432
}) =>
3533
wallet?.address &&
@@ -38,7 +36,6 @@ export const updateDailyRaysData = ({
3836
method: 'POST',
3937
headers: {
4038
'Content-Type': 'application/json',
41-
authorization: 'Bearer ' + token,
4239
},
4340
body: JSON.stringify({
4441
address: wallet?.address,
@@ -47,4 +44,4 @@ export const updateDailyRaysData = ({
4744
})
4845
.then((res) => res.json())
4946
.then(callback)
50-
.catch(() => callback({ loaded: true, isJwtValid: false }))
47+
.catch(() => callback({ loaded: true }))

components/portfolio/positions/PortfolioDailyRays.tsx

+59-45
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ import {
88
updateDailyRaysData,
99
} from 'components/portfolio/helpers/getRaysDailyChallenge'
1010
import { SkeletonLine } from 'components/Skeleton'
11-
import { jwtAuthGetToken } from 'features/shared/jwt'
11+
import { currentContent } from 'features/content'
12+
import { checkAcceptanceFromApi$ } from 'features/termsOfService/termsAcceptanceApi'
1213
import { TermsOfService } from 'features/termsOfService/TermsOfService'
1314
import { useWalletManagement } from 'features/web3OnBoard/useConnection'
1415
import { bonusRaysAmount, dailyRaysAmount, explodeRays } from 'helpers/dailyRays'
1516
import { getGradientColor, summerBrandGradient } from 'helpers/getGradientColor'
17+
import { useObservable } from 'helpers/observableHook'
1618
import { staticFilesRuntimeUrl } from 'helpers/staticPaths'
17-
import React, { useEffect, useState } from 'react'
19+
import React, { useEffect, useMemo, useState } from 'react'
20+
import { EMPTY } from 'rxjs'
1821
import { rays } from 'theme/icons'
1922
import { Box, Button, Divider, Flex, Grid, Image, Text } from 'theme-ui'
2023

@@ -34,16 +37,21 @@ const flashButton = ({
3437
}, 400)
3538
})
3639

37-
const SignTosComponent = ({ wallet }: { wallet?: string }) => {
40+
const SignTosComponent = ({ isAuthorized }: { isAuthorized?: boolean }) => {
3841
const [signTosEnabled, setSignTosEnabled] = useState(false)
39-
const jwtToken = wallet ? jwtAuthGetToken(wallet) : ''
40-
if (!jwtToken && !signTosEnabled) {
42+
43+
if (isAuthorized || isAuthorized === undefined) {
44+
return null
45+
}
46+
47+
if (!isAuthorized && !signTosEnabled) {
4148
return (
4249
<Button variant="outlineSmall" onClick={() => setSignTosEnabled(true)} sx={{ mt: 3 }}>
4350
Sign Terms of service
4451
</Button>
4552
)
4653
}
54+
4755
return <TermsOfService refreshAfterSign />
4856
}
4957

@@ -70,7 +78,13 @@ export const PortfolioDailyRays = ({
7078
loaded: false,
7179
})
7280
const [loadingBaseRaysChallengeData, setloadingBaseRaysChallengeData] = useState(false)
73-
const jwtToken = wallet?.address ? jwtAuthGetToken(wallet.address) : ''
81+
const _checkAcceptanceFromApi$ = useMemo(
82+
() => (wallet ? checkAcceptanceFromApi$(currentContent.tos.version, wallet.address) : EMPTY),
83+
[wallet?.address],
84+
)
85+
const [checkAcceptanceFromApiData] = useObservable(_checkAcceptanceFromApi$)
86+
87+
const isAuthorized = checkAcceptanceFromApiData?.authorized
7488

7589
useEffect(() => {
7690
if (!loadingBaseRaysChallengeData && !baseRaysChallengeData.loaded && wallet?.address) {
@@ -84,14 +98,13 @@ export const PortfolioDailyRays = ({
8498
}
8599
}, [baseRaysChallengeData, wallet?.address, loadingBaseRaysChallengeData])
86100

87-
const requiredItems = wallet?.address && wallet?.chainId && baseRaysChallengeData && jwtToken
101+
const requiredItems = wallet?.address && wallet?.chainId && baseRaysChallengeData && isAuthorized
88102

89103
const updateDailyRays = () => {
90104
setIsAddingPoints(true)
91105
requiredItems &&
92106
void updateDailyRaysData({
93107
wallet,
94-
token: jwtToken,
95108
callback: (res) => {
96109
setIsAddingPoints(false)
97110
if (res.isJwtValid) {
@@ -117,7 +130,7 @@ export const PortfolioDailyRays = ({
117130
setUserError(false)
118131
void flashButton({ setIsExploding, small: true }).then(() => {
119132
if (requiredItems && baseRaysChallengeData.loaded) {
120-
if (!jwtToken) {
133+
if (!isAuthorized) {
121134
setUserError(true)
122135
return
123136
}
@@ -175,45 +188,46 @@ export const PortfolioDailyRays = ({
175188
borderRadius: 'round',
176189
}}
177190
>
178-
{jwtToken ? (
179-
<Button
180-
variant="outlineSmall"
181-
disabled={!requiredItems || baseRaysChallengeData?.alreadyClaimed || isAddingPoints}
182-
sx={{
183-
display: 'flex',
184-
alignItems: 'center',
185-
mt: 3,
186-
transition: 'box-shadow 0.5s cubic-bezier(0,1.81,.41,1.37)',
187-
userSelect: 'none',
188-
boxShadow: isExploding
189-
? '-10px -6px 14px -8px #007da3,14px -8px 15px -8px #e7a77f,-11px 14px 15px -14px #e97047'
190-
: '0px',
191-
animation: 'animateGradient 10s infinite linear alternate',
192-
...getGradientColor(summerBrandGradient),
193-
backgroundSize: '400px',
194-
'@keyframes animateGradient': {
195-
'0%': {
196-
backgroundPositionX: '50px',
197-
},
198-
'100%': {
199-
backgroundPositionX: '-160px',
191+
<>
192+
{isAuthorized && (
193+
<Button
194+
variant="outlineSmall"
195+
disabled={!requiredItems || baseRaysChallengeData?.alreadyClaimed || isAddingPoints}
196+
sx={{
197+
display: 'flex',
198+
alignItems: 'center',
199+
mt: 3,
200+
transition: 'box-shadow 0.5s cubic-bezier(0,1.81,.41,1.37)',
201+
userSelect: 'none',
202+
boxShadow: isExploding
203+
? '-10px -6px 14px -8px #007da3,14px -8px 15px -8px #e7a77f,-11px 14px 15px -14px #e97047'
204+
: '0px',
205+
animation: 'animateGradient 10s infinite linear alternate',
206+
...getGradientColor(summerBrandGradient),
207+
backgroundSize: '400px',
208+
'@keyframes animateGradient': {
209+
'0%': {
210+
backgroundPositionX: '50px',
211+
},
212+
'100%': {
213+
backgroundPositionX: '-160px',
214+
},
200215
},
201-
},
202-
}}
203-
onClick={
204-
requiredItems && !baseRaysChallengeData?.alreadyClaimed
205-
? explodeRaysHandler
206-
: () => null
207-
}
208-
>
209-
<Icon icon={rays} color="primary60" sx={{ mr: 3 }} />
210-
Claim {dailyRaysAmount} Rays now
211-
</Button>
212-
) : (
216+
}}
217+
onClick={
218+
requiredItems && !baseRaysChallengeData?.alreadyClaimed
219+
? explodeRaysHandler
220+
: () => null
221+
}
222+
>
223+
<Icon icon={rays} color="primary60" sx={{ mr: 3 }} />
224+
Claim {dailyRaysAmount} Rays now
225+
</Button>
226+
)}
213227
<FunctionalContextHandler>
214-
<SignTosComponent wallet={wallet?.address} />
228+
<SignTosComponent isAuthorized={isAuthorized} />
215229
</FunctionalContextHandler>
216-
)}
230+
</>
217231
</Box>
218232
{userError && (
219233
<Text as="p" variant="paragraph3" color="warning100" sx={{ mt: 3 }}>

components/vault/DefaultVaultHeadline.tsx

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { FollowButtonControlProps } from 'features/follow/controllers/FollowButtonControl'
21
import type { PriceInfo } from 'features/shared/priceInfo.types'
32
import { formatAmount, formatPercent } from 'helpers/formatters/format'
43
import { moreMinutes } from 'helpers/time'
@@ -15,14 +14,12 @@ export function DefaultVaultHeadline({
1514
token,
1615
priceInfo,
1716
colRatio,
18-
followButton,
1917
shareButton,
2018
}: {
2119
header: VaultHeadlineProps['header']
2220
token: VaultHeadlineProps['tokens']
2321
priceInfo: PriceInfo
2422
colRatio?: string
25-
followButton?: FollowButtonControlProps
2623
shareButton?: boolean
2724
}) {
2825
const { t } = useTranslation()
@@ -72,12 +69,6 @@ export function DefaultVaultHeadline({
7269
}
7370

7471
return (
75-
<VaultHeadline
76-
header={header}
77-
tokens={token}
78-
details={detailsList}
79-
followButton={followButton}
80-
shareButton={shareButton}
81-
/>
72+
<VaultHeadline header={header} tokens={token} details={detailsList} shareButton={shareButton} />
8273
)
8374
}

components/vault/EarnVaultHeadline.tsx

+2-14
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,8 @@ import React from 'react'
33
import type { VaultHeadlineProps } from './VaultHeadline'
44
import { VaultHeadline } from './VaultHeadline'
55

6-
export function EarnVaultHeadline({
7-
header,
8-
tokens,
9-
details,
10-
followButton,
11-
shareButton,
12-
}: VaultHeadlineProps) {
6+
export function EarnVaultHeadline({ header, tokens, details, shareButton }: VaultHeadlineProps) {
137
return (
14-
<VaultHeadline
15-
header={header}
16-
tokens={tokens}
17-
details={details}
18-
followButton={followButton}
19-
shareButton={shareButton}
20-
/>
8+
<VaultHeadline header={header} tokens={tokens} details={details} shareButton={shareButton} />
219
)
2210
}

components/vault/GeneralManageControl.tsx

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { BigNumber } from 'bignumber.js'
2-
import { useMainContext } from 'components/context/MainContextProvider'
32
import { useProductContext } from 'components/context/ProductContextProvider'
43
import { MakerAutomationContext } from 'features/automation/contexts/MakerAutomationContext'
54
import { RefinanceGeneralContextProvider } from 'features/refinance/contexts'
@@ -18,16 +17,12 @@ interface GeneralManageControlProps {
1817
}
1918

2019
export function GeneralManageControl({ id }: GeneralManageControlProps) {
21-
const { context$ } = useMainContext()
2220
const { generalManageVault$ } = useProductContext()
2321
const generalManageVaultWithId$ = generalManageVault$(id)
2422
const [generalManageVaultData, generalManageVaultError] = useObservable(generalManageVaultWithId$)
25-
const [context] = useObservable(context$)
2623
const { chainId } = useWalletManagement()
2724
const { MakerTenderly } = useAppConfig('features')
2825

29-
const account = context?.status === 'connected' ? context.account : ''
30-
3126
useEffect(() => {
3227
return () => {
3328
generalManageVaultData?.state.clear()
@@ -51,16 +46,7 @@ export function GeneralManageControl({ id }: GeneralManageControlProps) {
5146
We need to refactor it so it accepts reactNode as modal content
5247
*/}
5348
<ModalProvider>
54-
<GeneralManageLayout
55-
generalManageVault={generalManageVault}
56-
followButton={{
57-
followerAddress: account,
58-
vaultId: id,
59-
chainId: chainId,
60-
protocol: 'maker',
61-
}}
62-
chainId={chainId}
63-
/>
49+
<GeneralManageLayout generalManageVault={generalManageVault} chainId={chainId} />
6450
</ModalProvider>
6551
</RefinanceGeneralContextProvider>
6652
</MakerAutomationContext>

components/vault/GeneralManageLayout.tsx

+2-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { NetworkIds } from 'blockchain/networks'
33
import { isSupportedAutomationIlk } from 'blockchain/tokensMetadata'
44
import { guniFaq } from 'features/content/faqs/guni'
55
import { GuniVaultHeader } from 'features/earn/guni/common/GuniVaultHeader'
6-
import type { FollowButtonControlProps } from 'features/follow/controllers/FollowButtonControl'
76
import type { GeneralManageVaultState } from 'features/generalManageVault/generalManageVault.types'
87
import { VaultType } from 'features/generalManageVault/vaultType.types'
98
import { VaultNoticesView } from 'features/notices/VaultsNoticesView'
@@ -18,15 +17,10 @@ import { GeneralManageTabBar } from './GeneralManageTabBar'
1817

1918
interface GeneralManageLayoutProps {
2019
generalManageVault: GeneralManageVaultState
21-
followButton?: FollowButtonControlProps
2220
chainId: NetworkIds
2321
}
2422

25-
export function GeneralManageLayout({
26-
generalManageVault,
27-
followButton,
28-
chainId,
29-
}: GeneralManageLayoutProps) {
23+
export function GeneralManageLayout({ generalManageVault, chainId }: GeneralManageLayoutProps) {
3024
const { t } = useTranslation()
3125
const { ilkData, vault, priceInfo, account } = generalManageVault.state
3226
const colRatioPercnentage = vault.collateralizationRatio.times(100).toFixed(2)
@@ -35,19 +29,13 @@ export function GeneralManageLayout({
3529

3630
const headlineElement =
3731
generalManageVault.type === VaultType.Earn ? (
38-
<GuniVaultHeader
39-
token={ilkData.token}
40-
ilk={ilkData.ilk}
41-
followButton={followButton}
42-
shareButton
43-
/>
32+
<GuniVaultHeader token={ilkData.token} ilk={ilkData.ilk} shareButton />
4433
) : (
4534
<DefaultVaultHeadline
4635
header={t('vault.header', { ilk: vault.ilk, id: vault.id })}
4736
token={[vault.token]}
4837
priceInfo={priceInfo}
4938
colRatio={colRatioPercnentage}
50-
followButton={followButton}
5139
shareButton
5240
/>
5341
)

components/vault/VaultHeadline.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
twitterSharePositionText,
99
twitterSharePositionVia,
1010
} from 'features/follow/common/ShareButton'
11-
import type { FollowButtonControlProps } from 'features/follow/controllers/FollowButtonControl'
1211
import type { ReactNode } from 'react'
1312
import React from 'react'
1413
import { Flex } from 'theme-ui'
@@ -18,7 +17,6 @@ import { VaultHeadlineDetails } from './VaultHeadlineDetails'
1817

1918
export type VaultHeadlineProps = {
2019
details: HeadlineDetailsProp[]
21-
followButton?: FollowButtonControlProps
2220
header?: ReactNode
2321
loading?: boolean
2422
shareButton?: boolean

features/aave/components/AavePositionHeader.tsx

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import type { IRiskRatio } from '@oasisdex/dma-library'
22
import { RiskRatio } from '@oasisdex/dma-library'
3-
import type { Protocol } from '@prisma/client'
43
import type BigNumber from 'bignumber.js'
54
import { getPriceChangeColor } from 'components/vault/VaultDetails'
65
import { VaultHeadline } from 'components/vault/VaultHeadline'
76
import { useAaveContext } from 'features/aave'
8-
import { createFollowButton } from 'features/aave/helpers/createFollowButton'
97
import { useAaveEarnYields } from 'features/aave/hooks'
108
import type { IStrategyConfig, ManageAaveHeaderProps } from 'features/aave/types'
11-
import type { FollowButtonControlProps } from 'features/follow/controllers/FollowButtonControl'
129
import { AppSpinner, WithLoadingIndicator } from 'helpers/AppSpinner'
1310
import { WithErrorHandler } from 'helpers/errorHandlers/WithErrorHandler'
1411
import { formatCryptoBalance, formatPercent } from 'helpers/formatters/format'
@@ -199,20 +196,15 @@ export function headerWithDetails(minimumRiskRatio: IRiskRatio) {
199196
}
200197
}
201198

202-
export function AavePositionHeaderNoDetails({ strategyConfig, positionId }: ManageAaveHeaderProps) {
199+
export function AavePositionHeaderNoDetails({ strategyConfig }: ManageAaveHeaderProps) {
203200
const { t } = useTranslation()
204201
const tokenData = tokenPairList[strategyConfig.protocol][strategyConfig.name]
205-
const { protocol } = strategyConfig
206-
const followButton: FollowButtonControlProps | undefined = createFollowButton(
207-
positionId,
208-
protocol.toLowerCase() as Protocol,
209-
)
202+
210203
return (
211204
<VaultHeadline
212205
header={t(tokenData.translationKey)}
213206
tokens={tokenData.tokenList}
214207
details={[]}
215-
followButton={followButton}
216208
shareButton
217209
/>
218210
)

0 commit comments

Comments
 (0)