Skip to content

Commit

Permalink
chore(earn): Beefy terms and conditions changes (#6127)
Browse files Browse the repository at this point in the history
### Description

Allow for showing provider docs and valora T&Cs if provider T&Cs don't
exist

### Test plan

<img
src="https://github.com/user-attachments/assets/78e09a87-1153-4287-bfc5-8471f64a3da0"
width="250" />



https://github.com/user-attachments/assets/a3ea05b2-a4f7-49c7-b753-745f62290c27



### Related issues

- Fixes ACT-1399

### Backwards compatibility

Yes

### Network scalability

If a new NetworkId and/or Network are added in the future, the changes
in this PR will:

- [X] Continue to work without code changes, OR trigger a compilation
error (guaranteeing we find it when a new network is added)
  • Loading branch information
finnian0826 authored Oct 2, 2024
1 parent c0a9178 commit 24b234c
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 7 deletions.
1 change: 1 addition & 0 deletions locales/base/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -2610,6 +2610,7 @@
"network": "Network",
"footer": "By depositing crypto into an Aave pool, you accept the risks associated with using Aave. <0>Terms & Conditions</0>",
"footerV1_93": "By depositing crypto into an {{providerName}} pool, you accept the risks associated with using {{providerName}}. <0>Terms & Conditions</0>",
"noTermsUrlFooter": "You are responsible for your actions in {{appName}}. {{appName}} disclaims all responsibility for your assets or interactions with {{providerName}}. You can review {{providerName}}'s documents <0>here</0> and our Terms & Conditions <1>here</1>.",
"primaryCta": "Complete",
"secondaryCta": "Cancel",
"yieldRate": "Yield Rate (est.)",
Expand Down
4 changes: 3 additions & 1 deletion src/analytics/Properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,9 @@ interface EarnEventsProperties {
} & TokenProperties &
EarnCommonProperties
[EarnEvents.earn_deposit_provider_info_press]: EarnDepositProperties
[EarnEvents.earn_deposit_terms_and_conditions_press]: EarnDepositProperties
[EarnEvents.earn_deposit_terms_and_conditions_press]: {
type: 'providerTermsAndConditions' | 'providerDocuments' | 'appTermsAndConditions'
} & EarnDepositProperties
[EarnEvents.earn_deposit_complete]: EarnDepositProperties
[EarnEvents.earn_deposit_cancel]: EarnDepositProperties
[EarnEvents.earn_deposit_submit_start]: EarnDepositProperties
Expand Down
52 changes: 51 additions & 1 deletion src/earn/EarnDepositBottomSheet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,61 @@ describe('EarnDepositBottomSheet', () => {
fireEvent.press(getByTestId('EarnDeposit/TermsAndConditions'))
expect(AppAnalytics.track).toHaveBeenCalledWith(
EarnEvents.earn_deposit_terms_and_conditions_press,
expectedAnalyticsProperties
{ type: 'providerTermsAndConditions', ...expectedAnalyticsProperties }
)
expect(store.getActions()).toEqual([openUrl('termsUrl', true)])
})

it('pressing provider docs opens the providers doc URL (when provider does not have terms and conditions)', () => {
const store = createMockStore({ tokens: { tokenBalances: mockTokenBalances } })
const { getByTestId } = render(
<Provider store={store}>
<EarnDepositBottomSheet
{...{
...props,
pool: {
...props.pool,
appId: 'beefy',
dataProps: { ...props.pool.dataProps, termsUrl: undefined },
},
}}
/>
</Provider>
)

fireEvent.press(getByTestId('EarnDeposit/ProviderDocuments'))
expect(AppAnalytics.track).toHaveBeenCalledWith(
EarnEvents.earn_deposit_terms_and_conditions_press,
{ type: 'providerDocuments', ...expectedAnalyticsProperties, providerId: 'beefy' }
)
expect(store.getActions()).toEqual([openUrl('https://docs.beefy.finance/', true)])
})

it('pressing app terms and conditions opens the app T&C URL (when provider does not have terms and conditions)', () => {
const store = createMockStore({ tokens: { tokenBalances: mockTokenBalances } })
const { getByTestId } = render(
<Provider store={store}>
<EarnDepositBottomSheet
{...{
...props,
pool: {
...props.pool,
appId: 'beefy',
dataProps: { ...props.pool.dataProps, termsUrl: undefined },
},
}}
/>
</Provider>
)

fireEvent.press(getByTestId('EarnDeposit/AppTermsAndConditions'))
expect(AppAnalytics.track).toHaveBeenCalledWith(
EarnEvents.earn_deposit_terms_and_conditions_press,
{ type: 'appTermsAndConditions', ...expectedAnalyticsProperties, providerId: 'beefy' }
)
expect(store.getActions()).toEqual([openUrl('https://valora.xyz/terms', true)])
})

it('shows loading state and buttons are disabled when deposit is submitted', () => {
const store = createMockStore({
tokens: { tokenBalances: mockTokenBalances },
Expand Down
52 changes: 47 additions & 5 deletions src/earn/EarnDepositBottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ import {
} from 'src/viem/prepareTransactions'
import { getSerializablePreparedTransactions } from 'src/viem/preparedTransactionSerialization'

const APP_ID_TO_PROVIDER_DOCUMENTS_URL: Record<string, string | undefined> = {
beefy: 'https://docs.beefy.finance/',
}
const APP_TERMS_AND_CONDITIONS_URL = 'https://valora.xyz/terms'

export default function EarnDepositBottomSheet({
forwardedRef,
preparedTransaction,
Expand Down Expand Up @@ -85,13 +90,30 @@ export default function EarnDepositBottomSheet({
}

const onPressTermsAndConditions = () => {
AppAnalytics.track(
EarnEvents.earn_deposit_terms_and_conditions_press,
commonAnalyticsProperties
)
AppAnalytics.track(EarnEvents.earn_deposit_terms_and_conditions_press, {
type: 'providerTermsAndConditions',
...commonAnalyticsProperties,
})
termsUrl && dispatch(openUrl(termsUrl, true))
}

const onPressProviderDocuments = () => {
AppAnalytics.track(EarnEvents.earn_deposit_terms_and_conditions_press, {
type: 'providerDocuments',
...commonAnalyticsProperties,
})
const providerDocumentsUrl = APP_ID_TO_PROVIDER_DOCUMENTS_URL[pool.appId]
providerDocumentsUrl && dispatch(openUrl(providerDocumentsUrl, true))
}

const onPressAppTermsAndConditions = () => {
AppAnalytics.track(EarnEvents.earn_deposit_terms_and_conditions_press, {
type: 'appTermsAndConditions',
...commonAnalyticsProperties,
})
dispatch(openUrl(APP_TERMS_AND_CONDITIONS_URL, true))
}

const onPressComplete = () => {
dispatch(
depositStart({
Expand Down Expand Up @@ -211,7 +233,7 @@ export default function EarnDepositBottomSheet({
{NETWORK_NAMES[preparedTransaction.feeCurrency.networkId]}
</Text>
</LabelledItem>
{!!termsUrl && (
{termsUrl ? (
<Text style={styles.footer}>
<Trans
i18nKey="earnFlow.depositBottomSheet.footerV1_93"
Expand All @@ -224,6 +246,26 @@ export default function EarnDepositBottomSheet({
/>
</Trans>
</Text>
) : (
APP_ID_TO_PROVIDER_DOCUMENTS_URL[pool.appId] && (
<Text style={styles.footer}>
<Trans
i18nKey="earnFlow.depositBottomSheet.noTermsUrlFooter"
tOptions={{ providerName: pool.appName }}
>
<Text
testID="EarnDeposit/ProviderDocuments"
style={styles.termsLink}
onPress={onPressProviderDocuments}
/>
<Text
testID="EarnDeposit/AppTermsAndConditions"
style={styles.termsLink}
onPress={onPressAppTermsAndConditions}
/>
</Trans>
</Text>
)
)}
<View style={styles.ctaContainer}>
<Button
Expand Down

0 comments on commit 24b234c

Please sign in to comment.