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

refactor(earn): connect pool details to deposit screen #5858

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions src/earn/EarnPoolInfoScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Provider } from 'react-redux'
import AppAnalytics from 'src/analytics/AppAnalytics'
import { EarnEvents } from 'src/analytics/Events'
import EarnPoolInfoScreen from 'src/earn/EarnPoolInfoScreen'
import { navigate } from 'src/navigator/NavigationService'
import { Screens } from 'src/navigator/Screens'
import { navigateToURI } from 'src/utils/linking'
import MockedNavigator from 'test/MockedNavigator'
Expand All @@ -13,6 +14,10 @@ import { mockEarnPositions } from 'test/values'
const defaultStore = createMockStore({})

describe('EarnPoolInfoScreen', () => {
beforeEach(() => {
jest.clearAllMocks()
})

it('renders correctly', () => {
const { getByTestId, getByText } = render(
<Provider store={defaultStore}>
Expand Down Expand Up @@ -80,4 +85,26 @@ describe('EarnPoolInfoScreen', () => {
positionId: 'arbitrum-sepolia:0x460b97bd498e1157530aeb3086301d5225b91216',
})
})

it('navigate to EarnEnterAmount when Deposit button is tapped', () => {
const { getByText } = render(
<Provider store={defaultStore}>
<MockedNavigator
component={() => {
return (
<EarnPoolInfoScreen
{...getMockStackScreenProps(Screens.EarnPoolInfoScreen, {
pool: mockEarnPositions[0],
})}
/>
)
}}
/>
</Provider>
)
fireEvent.press(getByText('earnFlow.poolInfoScreen.deposit'))
expect(navigate).toHaveBeenCalledWith(Screens.EarnEnterAmount, {
pool: mockEarnPositions[0],
})
})
})
6 changes: 3 additions & 3 deletions src/earn/EarnPoolInfoScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import InfoIcon from 'src/icons/InfoIcon'
import OpenLinkIcon from 'src/icons/OpenLinkIcon'
import { useDollarsToLocalAmount } from 'src/localCurrency/hooks'
import { getLocalCurrencySymbol } from 'src/localCurrency/selectors'
import { navigate } from 'src/navigator/NavigationService'
import { Screens } from 'src/navigator/Screens'
import useScrollAwareHeader from 'src/navigator/ScrollAwareHeader'
import { StackParamList } from 'src/navigator/types'
Expand Down Expand Up @@ -293,9 +294,8 @@ function ActionButtons({ earnPosition }: { earnPosition: EarnPosition }) {
<Button
text={t('earnFlow.poolInfoScreen.deposit')}
onPress={() => {
// TODO hook up after ACT-1342 is merged and remove Logger.debug
// navigate(Screens.EarnEnterAmount, { pool: earnPosition })
Logger.debug('Deposit Button Pressed!')
// TODO(ACT-1351): add analytics event
navigate(Screens.EarnEnterAmount, { pool: earnPosition })
}}
size={BtnSizes.FULL}
style={styles.flex}
Expand Down
4 changes: 2 additions & 2 deletions src/earn/prepareTransactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('prepareTransactions', () => {
baseTransactions: expectedTransactions,
feeCurrencies: [mockFeeCurrency],
spendToken: mockToken,
spendTokenAmount: new BigNumber(5),
spendTokenAmount: new BigNumber(5000000),
isGasSubsidized: false,
origin: 'earn-deposit',
})
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('prepareTransactions', () => {
baseTransactions: expectedTransactions,
feeCurrencies: [mockFeeCurrency],
spendToken: mockToken,
spendTokenAmount: new BigNumber(5),
spendTokenAmount: new BigNumber(5000000),
isGasSubsidized: true,
origin: 'earn-deposit',
})
Expand Down
2 changes: 1 addition & 1 deletion src/earn/prepareTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export async function prepareSupplyTransactions({
feeCurrencies,
baseTransactions,
spendToken: token,
spendTokenAmount: new BigNumber(amount),
spendTokenAmount: new BigNumber(amount).shiftedBy(token.decimals),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only an issue if the spendToken is also the gas currency. For aave, this can never be the case so there was no user impact

isGasSubsidized,
origin: 'earn-deposit',
})
Expand Down
2 changes: 1 addition & 1 deletion src/viem/prepareTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export async function tryEstimateTransactions(
*
* @param feeCurrencies
* @param spendToken
* @param spendTokenAmount
* @param spendTokenAmount BigNumber in smallest unit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exactly does smallest unit mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the smallest unit of the token (e.g., 1ETH => 1e18, 1 usdc => 1e6). I believe we use this term in a few places in the wallet

* @param decreasedAmountGasFeeMultiplier
* @param baseTransactions
* @param throwOnSpendTokenAmountExceedsBalance
Expand Down