-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: earn transaction feed items (#5414)
### Description Adds the `EarnFeedItem.tsx`, types and associated GraphQL queries to populate the transaction feed. #### Screenshots | iOS transaction Feed | iOS Details | | ----- | ----- | | ![](https://github.com/valora-inc/wallet/assets/26950305/52a3099b-5ff1-4c65-bafd-eccc1c44cabe "iOS Feed") | ![](https://github.com/valora-inc/wallet/assets/26950305/9a7d6598-c3e8-4ee5-9007-95b68afc318c "iOS Details") | ### Test plan - [x] Tested locally on iOS - [x] Tested locally on Android - [x] Unit tests added ### Related issues - Fixes ACT-1182 ### 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
Showing
13 changed files
with
775 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
import { fireEvent, render, within } from '@testing-library/react-native' | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { EarnEvents } from 'src/analytics/Events' | ||
import ValoraAnalytics from 'src/analytics/ValoraAnalytics' | ||
import { navigate } from 'src/navigator/NavigationService' | ||
import { Screens } from 'src/navigator/Screens' | ||
import EarnFeedItem from 'src/transactions/feed/EarnFeedItem' | ||
import { NetworkId, TransactionStatus } from 'src/transactions/types' | ||
import networkConfig from 'src/web3/networkConfig' | ||
import { createMockStore } from 'test/utils' | ||
import { mockAaveArbUsdcAddress, mockArbArbTokenId } from 'test/values' | ||
|
||
const store = createMockStore({ | ||
tokens: { | ||
tokenBalances: { | ||
[networkConfig.arbUsdcTokenId]: { | ||
tokenId: networkConfig.arbUsdcTokenId, | ||
symbol: 'USDC', | ||
priceUsd: '1', | ||
priceFetchedAt: Date.now(), | ||
networkId: NetworkId['arbitrum-sepolia'], | ||
}, | ||
[mockArbArbTokenId]: { | ||
tokenId: mockArbArbTokenId, | ||
symbol: 'ARB', | ||
priceUsd: '0.9898', | ||
priceFetchedAt: Date.now(), | ||
networkId: NetworkId['arbitrum-sepolia'], | ||
}, | ||
[networkConfig.aaveArbUsdcTokenId]: { | ||
networkId: NetworkId['arbitrum-sepolia'], | ||
address: mockAaveArbUsdcAddress, | ||
tokenId: networkConfig.aaveArbUsdcTokenId, | ||
symbol: 'aArbSepUSDC', | ||
priceUsd: '1', | ||
priceFetchedAt: Date.now(), | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
describe.each([ | ||
{ | ||
type: 'EarnWithdraw', | ||
transaction: { | ||
__typename: 'EarnWithdraw', | ||
inAmount: { | ||
localAmount: null, | ||
tokenAddress: '0xdef', | ||
tokenId: networkConfig.arbUsdcTokenId, | ||
value: '1', | ||
}, | ||
outAmount: { | ||
localAmount: null, | ||
tokenAddress: mockAaveArbUsdcAddress, | ||
tokenId: networkConfig.aaveArbUsdcTokenId, | ||
value: '0.996614', | ||
}, | ||
block: '211276583', | ||
fees: [ | ||
{ | ||
amount: { | ||
localAmount: null, | ||
tokenAddress: null, | ||
tokenId: mockArbArbTokenId, | ||
value: '0.00000229122', | ||
}, | ||
type: 'SECURITY_FEE', | ||
}, | ||
], | ||
networkId: NetworkId['arbitrum-sepolia'], | ||
providerId: 'aave-v3', | ||
timestamp: Date.now(), | ||
transactionHash: '0xHASH0', | ||
type: 'EARN_WITHDRAW', | ||
status: TransactionStatus.Complete, | ||
}, | ||
expectedTitle: 'earnFlow.transactionFeed.earnWithdrawTitle', | ||
expectedSubTitle: 'earnFlow.transactionFeed.earnWithdrawSubtitle, {"providerName":"Aave"}', | ||
expectedTotal: '+1.00 USDC', | ||
expectedTotalLocal: '₱1.33', | ||
}, | ||
{ | ||
type: 'EarnDeposit', | ||
transaction: { | ||
__typename: 'EarnDeposit', | ||
inAmount: { | ||
localAmount: null, | ||
tokenAddress: mockAaveArbUsdcAddress, | ||
tokenId: networkConfig.aaveArbUsdcTokenId, | ||
value: '10', | ||
}, | ||
outAmount: { | ||
localAmount: null, | ||
tokenAddress: '0xdef', | ||
tokenId: networkConfig.arbUsdcTokenId, | ||
value: '10', | ||
}, | ||
block: '210927567', | ||
fees: [ | ||
{ | ||
amount: { | ||
localAmount: null, | ||
tokenAddress: null, | ||
tokenId: mockArbArbTokenId, | ||
value: '0.00000284243', | ||
}, | ||
type: 'SECURITY_FEE', | ||
}, | ||
], | ||
networkId: NetworkId['arbitrum-sepolia'], | ||
providerId: 'aave-v3', | ||
timestamp: Date.now(), | ||
transactionHash: '0xHASH1', | ||
type: 'EARN_DEPOSIT', | ||
status: TransactionStatus.Complete, | ||
}, | ||
expectedTitle: 'earnFlow.transactionFeed.earnDepositTitle', | ||
expectedSubTitle: 'earnFlow.transactionFeed.earnDepositSubtitle, {"providerName":"Aave"}', | ||
expectedTotal: '-10.00 USDC', | ||
expectedTotalLocal: '₱13.30', | ||
}, | ||
{ | ||
type: 'EarnClaimReward', | ||
transaction: { | ||
__typename: 'EarnClaimReward', | ||
amount: { | ||
localAmount: null, | ||
tokenAddress: '0xhij', | ||
tokenId: mockArbArbTokenId, | ||
value: '1.5', | ||
}, | ||
block: '211278852', | ||
fees: [ | ||
{ | ||
amount: { | ||
localAmount: null, | ||
tokenAddress: null, | ||
tokenId: mockArbArbTokenId, | ||
value: '0.00000146037', | ||
}, | ||
type: 'SECURITY_FEE', | ||
}, | ||
], | ||
networkId: NetworkId['arbitrum-sepolia'], | ||
providerId: 'aave-v3', | ||
timestamp: Date.now(), | ||
transactionHash: '0xHASH2', | ||
type: 'EARN_CLAIM_REWARD', | ||
status: TransactionStatus.Complete, | ||
} as any, | ||
expectedTitle: 'earnFlow.transactionFeed.earnClaimTitle', | ||
expectedSubTitle: 'earnFlow.transactionFeed.earnClaimSubtitle, {"providerName":"Aave"}', | ||
expectedTotal: '+1.50 ARB', | ||
expectedTotalLocal: '₱1.97', | ||
}, | ||
])( | ||
`$type`, | ||
({ type, transaction, expectedTitle, expectedSubTitle, expectedTotal, expectedTotalLocal }) => { | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
it('Should render correctly', () => { | ||
const { getByText, getByTestId } = render( | ||
<Provider store={store}> | ||
<EarnFeedItem transaction={transaction} /> | ||
</Provider> | ||
) | ||
|
||
expect(getByText(expectedTitle)).toBeTruthy() | ||
expect(getByText(expectedSubTitle)).toBeTruthy() | ||
expect( | ||
within(getByTestId(`EarnFeedItem/${type}-amount-crypto`)).getByText(expectedTotal) | ||
).toBeTruthy() | ||
expect( | ||
within(getByTestId(`EarnFeedItem/${type}-amount-local`)).getByText(expectedTotalLocal) | ||
).toBeTruthy() | ||
}) | ||
|
||
it('Should navigate correctly on tap', () => { | ||
const { getByTestId } = render( | ||
<Provider store={store}> | ||
<EarnFeedItem transaction={transaction} /> | ||
</Provider> | ||
) | ||
|
||
fireEvent.press(getByTestId(`EarnFeedItem/${transaction.transactionHash}`)) | ||
expect(navigate).toHaveBeenCalledWith(Screens.TransactionDetailsScreen, { transaction }) | ||
}) | ||
|
||
it('Should fire analytic event on tap', () => { | ||
const { getByTestId } = render( | ||
<Provider store={store}> | ||
<EarnFeedItem transaction={transaction} /> | ||
</Provider> | ||
) | ||
|
||
fireEvent.press(getByTestId(`EarnFeedItem/${transaction.transactionHash}`)) | ||
expect(ValoraAnalytics.track).toHaveBeenCalledWith(EarnEvents.earn_feed_item_select, { | ||
origin: type, | ||
}) | ||
}) | ||
} | ||
) |
Oops, something went wrong.