Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(earn): Add Claiming Reward line item on enter amount screen #6169

Open
wants to merge 68 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
6f1d0ee
chore: replace EarnDepositMode with EarnEnterMode
MuckT Oct 2, 2024
06ce84e
feat(earn): support partial withdrawals
MuckT Oct 2, 2024
d7769d2
Merge branch 'main' into tomm/act-1386
MuckT Oct 3, 2024
f5a612b
Merge branch 'main' into tomm/act-1386
MuckT Oct 4, 2024
3feb5f8
feat(earn): support partial withdrawals for earn pools
MuckT Oct 8, 2024
5821ff8
Merge branch 'main' into tomm/act-1386
MuckT Oct 8, 2024
dc155d2
fix(earn): rename EarnDepositMode to EarnEnterMode
MuckT Oct 8, 2024
a33d30c
fix(earn): rename EarnDepositMode to EarnEnterMode
MuckT Oct 8, 2024
4d01e46
fix: remove unused export
MuckT Oct 8, 2024
73c5067
fix(earn): amount TransactionWithdrawDetails display
MuckT Oct 9, 2024
364f551
test(earn): earn partial withdrawal flow
MuckT Oct 9, 2024
292d739
chore: add feature gate for partial withdrawals
MuckT Oct 9, 2024
87990f0
test(earn): partial withdrawal feature gate and navigation
MuckT Oct 9, 2024
6363e9f
docs: remove stray todo
MuckT Oct 9, 2024
71b13b9
Merge branch 'main' into tomm/act-1386
MuckT Oct 9, 2024
a58d40f
Merge branch 'main' into tomm/act-1386
MuckT Oct 9, 2024
345b535
Update test/values.ts
MuckT Oct 9, 2024
5fb98c5
refactor(earn): combine deposit and withdrawal hooks
MuckT Oct 9, 2024
96caa2e
fix(earn): use correct token amounts
MuckT Oct 11, 2024
9e8dcbf
Merge branch 'main' into tomm/act-1386
MuckT Oct 11, 2024
584acfb
fix(earn): disable continue when transaction is not possible
MuckT Oct 11, 2024
4196505
style(earn): use transactionToken instead of isWithdrawal ternaries
MuckT Oct 11, 2024
ebe3a2a
chore: PR feedback
MuckT Oct 11, 2024
1dbf295
style: naming
MuckT Oct 11, 2024
ad16ffa
fix(earn): use withdraw token and adjust display
MuckT Oct 12, 2024
7420841
Merge branch 'main' into tomm/act-1386
MuckT Oct 14, 2024
f5fecc5
fix: show correct withdrawal amounts
MuckT Oct 14, 2024
3879b52
fix: use correct fiat value display
MuckT Oct 14, 2024
9b29dfb
test(earn): show correct local amount
MuckT Oct 14, 2024
9ed4dfc
fix(earn): deposits should use input token
MuckT Oct 15, 2024
7b20e2d
fix(earn): use deposit token amounts in token input
MuckT Oct 15, 2024
6ed3c09
style(earn): use transaction token balance instead of pool balance
MuckT Oct 15, 2024
ca51c7d
test(earn): clean-up mock pool params
MuckT Oct 15, 2024
3150c45
Merge branch 'main' into tomm/act-1386
MuckT Oct 15, 2024
4bd8d62
Apply suggestions from code review
MuckT Oct 15, 2024
1f1db1e
style(earn): rename inputToken to depositToken in useTokens
MuckT Oct 15, 2024
819e297
fix(earn): set transaction token on token select for deposits
MuckT Oct 15, 2024
9c6a05d
fix(earn): display withdrawal text on fee bottom sheet
MuckT Oct 15, 2024
1da7fac
chore: pr feedback
MuckT Oct 15, 2024
686a01c
style: create reusable const balanceInTransactionToken
MuckT Oct 16, 2024
2681ce6
style: use input token directly
MuckT Oct 16, 2024
24c47be
fix(earn): use converted token amount in withdrawals
MuckT Oct 16, 2024
d6a1616
fix(earn): convert withdrawal amount correctly usd for analytics
MuckT Oct 16, 2024
6cef451
Merge branch 'main' into tomm/act-1386
MuckT Oct 16, 2024
da91f3d
fix(earn): remove duplicate condition
MuckT Oct 16, 2024
f85bed4
fix(earn): naming
MuckT Oct 16, 2024
c662e3b
docs: remove unnecessary comment
MuckT Oct 16, 2024
38853d8
style(earn): simplify dropdownEnabled
MuckT Oct 16, 2024
b989f05
fix(earn): use decimals from input token
MuckT Oct 16, 2024
2fe5293
style(earn): return single withdrawal and deposit token from useToken…
MuckT Oct 16, 2024
4af772d
style(earn): PR pair feedback
MuckT Oct 16, 2024
775a925
fix(earn): display correct amounts on input amount token toggle
MuckT Oct 16, 2024
176cb9d
Revert "fix(earn): display correct amounts on input amount token toggle"
MuckT Oct 16, 2024
2d87478
fix(earn): add inputToken to dependency array
MuckT Oct 17, 2024
8ccfbfc
chore(earn): update analytics for withdrawals
MuckT Oct 17, 2024
6924060
fix: analytics build errors
MuckT Oct 17, 2024
30c6ea9
test(earn): withdrawals from pools with high price per share
MuckT Oct 17, 2024
ea9f94e
Merge branch 'main' into tomm/act-1386
MuckT Oct 17, 2024
ddb06e3
feat(earn): Show Withdrawing and Claiming card when withdrawalInclude…
finnian0826 Oct 17, 2024
fb586fc
feat(earn): Add Claiming Reward line item on enter amount screen
finnian0826 Oct 17, 2024
e6b66b1
add unit test
finnian0826 Oct 18, 2024
735e6f8
add crypto and test
finnian0826 Oct 18, 2024
2c9ef5d
cleanup
finnian0826 Oct 18, 2024
98a3fd8
Merge branch 'main' into finnian0826/act-1411-2
finnian0826 Oct 18, 2024
b1759af
prettier
finnian0826 Oct 18, 2024
1c4ba05
fix
finnian0826 Oct 18, 2024
9c382f1
fix wrapping
finnian0826 Oct 18, 2024
acbdd0f
use useMemo
finnian0826 Oct 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions locales/base/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -2559,6 +2559,7 @@
"fees": "Fees",
"available": "Available",
"swap": "Swap",
"claimingReward": "Claiming Reward",
"earnUpToLabel": "You could earn up to:",
"rateLabel": "Rate (est.)",
"earnUpTo": "~{{fiatSymbol}}{{amount}} / yr",
Expand Down
33 changes: 32 additions & 1 deletion src/earn/EarnEnterAmount.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { usePrepareTransactions } from 'src/earn/prepareTransactions'
import { CICOFlow } from 'src/fiatExchanges/utils'
import { navigate } from 'src/navigator/NavigationService'
import { Screens } from 'src/navigator/Screens'
import { getFeatureGate } from 'src/statsig'
import { StatsigFeatureGates } from 'src/statsig/types'
import { SwapTransaction } from 'src/swap/types'
import { TokenBalance } from 'src/tokens/slice'
import { NetworkId } from 'src/transactions/types'
Expand All @@ -27,13 +29,18 @@ import {
mockArbEthTokenId,
mockArbUsdcTokenId,
mockEarnPositions,
mockPositions,
mockRewardsPositions,
mockTokenBalances,
mockUSDCAddress,
} from 'test/values'

jest.mock('src/earn/prepareTransactions')
jest.mock('react-native-localize')
jest.mock('src/statsig') // statsig isn't used directly but the hooksApiSelector uses it
jest
.mocked(getFeatureGate)
.mockImplementation((featureGateName) => featureGateName === StatsigFeatureGates.SHOW_POSITIONS)

const mockPreparedTransaction: PreparedTransactionsPossible = {
type: 'possible' as const,
Expand Down Expand Up @@ -132,6 +139,9 @@ const store = createMockStore({
},
},
},
positions: {
positions: [...mockPositions, ...mockRewardsPositions],
},
})

const params = {
Expand Down Expand Up @@ -523,7 +533,28 @@ describe('EarnEnterAmount', () => {
expect(getByTestId('EarnEnterAmount/Continue')).toBeDisabled()
})

it('should show the the Withdrawing and Claiming card if withdrawalIncludesClaim is true', async () => {
it('should show the Claiming Reward line item if withdrawalIncludesClaim is true and user has rewards', async () => {
const { getByTestId } = render(
<Provider store={store}>
<MockedNavigator
component={EarnEnterAmount}
params={{
pool: {
...mockEarnPositions[0],
dataProps: { ...mockEarnPositions[0].dataProps, withdrawalIncludesClaim: true },
},
mode: 'withdraw',
}}
/>
</Provider>
)

expect(getByTestId('LabelWithInfo/ClaimingReward-0')).toBeTruthy()
expect(getByTestId('EarnEnterAmount/Reward-0')).toHaveTextContent('₱0.016')
expect(getByTestId('EarnEnterAmount/Reward-0-crypto')).toHaveTextContent('0.01 ARB')
})

it('should show the Withdrawing and Claiming card if withdrawalIncludesClaim is true', async () => {
const { getByTestId } = render(
<Provider store={store}>
<MockedNavigator
Expand Down
46 changes: 43 additions & 3 deletions src/earn/EarnEnterAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import { getLocalCurrencySymbol } from 'src/localCurrency/selectors'
import { navigate } from 'src/navigator/NavigationService'
import { Screens } from 'src/navigator/Screens'
import { StackParamList } from 'src/navigator/types'
import { hooksApiUrlSelector } from 'src/positions/selectors'
import { EarnPosition } from 'src/positions/types'
import { hooksApiUrlSelector, positionsWithBalanceSelector } from 'src/positions/selectors'
import { EarnPosition, Position } from 'src/positions/types'
import { useSelector } from 'src/redux/hooks'
import { AmountInput } from 'src/send/EnterAmount'
import { AmountEnteredIn } from 'src/send/types'
Expand Down Expand Up @@ -286,6 +286,16 @@ function EarnEnterAmount({ route }: Props) {
prepareTransactionsResult.type === 'possible' &&
prepareTransactionsResult.transactions.length > 0

const allRewardsPositions = useSelector(positionsWithBalanceSelector)

const rewardsPositions = useMemo(
() =>
allRewardsPositions.filter((position) =>
pool.dataProps.rewardsPositionIds?.includes(position.positionId)
),
[allRewardsPositions, pool.dataProps.rewardsPositionIds]
)

const disabled =
// Should disable if the user enters 0, has enough balance but the transaction is not possible, or does not have enough balance
!!tokenAmount?.isZero() || !transactionIsPossible
Expand Down Expand Up @@ -450,6 +460,7 @@ function EarnEnterAmount({ route }: Props) {
prepareTransactionsResult={prepareTransactionsResult}
feeDetailsBottomSheetRef={feeDetailsBottomSheetRef}
balanceInInputToken={balanceInInputToken}
rewardsPositions={rewardsPositions}
/>
)}
</View>
Expand Down Expand Up @@ -507,7 +518,7 @@ function EarnEnterAmount({ route }: Props) {
testID="EarnEnterAmount/PrepareTransactionError"
/>
)}
{isWithdrawal && pool.dataProps.withdrawalIncludesClaim && (
{isWithdrawal && pool.dataProps.withdrawalIncludesClaim && rewardsPositions.length > 0 && (
<InLineNotification
variant={NotificationVariant.Info}
title={t('earnFlow.enterAmount.withdrawingAndClaimingCard.title')}
Expand Down Expand Up @@ -582,12 +593,14 @@ function TransactionWithdrawDetails({
prepareTransactionsResult,
feeDetailsBottomSheetRef,
balanceInInputToken,
rewardsPositions,
}: {
pool: EarnPosition
token: TokenBalance
prepareTransactionsResult?: PreparedTransactionsResult
feeDetailsBottomSheetRef: React.RefObject<BottomSheetModalRefType>
balanceInInputToken: BigNumber
rewardsPositions: Position[]
}) {
const { t } = useTranslation()
const { maxFeeAmount, feeCurrency } = getFeeCurrencyAndAmounts(prepareTransactionsResult)
Expand Down Expand Up @@ -619,6 +632,33 @@ function TransactionWithdrawDetails({
</Text>
</View>
</View>
{pool.dataProps.withdrawalIncludesClaim &&
rewardsPositions.map((position, index) => (
<View key={index} style={styles.txDetailsLineItem}>
<LabelWithInfo
label={t('earnFlow.enterAmount.claimingReward')}
testID={`LabelWithInfo/ClaimingReward-${index}`}
/>
<View style={{ ...styles.txDetailsValue, flex: 1 }}>
<TokenDisplay
testID={`EarnEnterAmount/Reward-${index}`}
tokenId={position.tokens[0].tokenId}
amount={position.tokens[0].balance.toString()}
style={styles.txDetailsValueText}
/>
<Text style={[styles.txDetailsValueText, styles.gray4]}>
{'('}
<TokenDisplay
testID={`EarnEnterAmount/Reward-${index}-crypto`}
tokenId={position.tokens[0].tokenId}
amount={position.tokens[0].balance.toString()}
showLocalAmount={false}
/>
{')'}
</Text>
</View>
</View>
))}
{feeCurrency && maxFeeAmount && (
<View style={styles.txDetailsLineItem}>
<LabelWithInfo
Expand Down
Loading