-
Notifications
You must be signed in to change notification settings - Fork 97
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 Crypto bottom sheet #5376
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3d51fe5
initial changes for earn add crypto bottom sheet
finnian0826 5af8fa3
add translations
finnian0826 3d4e39c
update QR screen
finnian0826 8d5c045
add unit tests
finnian0826 fa72cdb
update unit tests
finnian0826 7803b50
feedback pt. 1
finnian0826 4765c22
Merge branch 'main' into finnian0826/act-1177
finnian0826 c8691b5
update styles
finnian0826 0968b7f
uncomment selector
finnian0826 f3720a2
fix translation
finnian0826 ded18ff
move hook out of fn
finnian0826 07035ab
clean up
finnian0826 7b24cf3
fix hook issue
finnian0826 bd6dbd3
fix unit test
finnian0826 de4a527
Merge branch 'main' into finnian0826/act-1177
finnian0826 17316ef
fix translation
finnian0826 13d40d4
feedback
finnian0826 d92c733
Merge branch 'main' into finnian0826/act-1177
finnian0826 5866b76
feedback
finnian0826 418d8c2
Merge branch 'main' into finnian0826/act-1177
finnian0826 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
import { fireEvent, render } from '@testing-library/react-native' | ||
import BigNumber from 'bignumber.js' | ||
import React from 'react' | ||
import { Provider } from 'react-redux' | ||
import { EarnEvents } from 'src/analytics/Events' | ||
import ValoraAnalytics from 'src/analytics/ValoraAnalytics' | ||
import EarnAddCryptoBottomSheet from 'src/earn/EarnAddCryptoBottomSheet' | ||
import { navigate } from 'src/navigator/NavigationService' | ||
import { Screens } from 'src/navigator/Screens' | ||
import { getDynamicConfigParams } from 'src/statsig' | ||
import { StoredTokenBalance, TokenBalance } from 'src/tokens/slice' | ||
import { TokenActionName } from 'src/tokens/types' | ||
import { NetworkId } from 'src/transactions/types' | ||
import { createMockStore } from 'test/utils' | ||
|
||
jest.mock('src/statsig', () => ({ | ||
getDynamicConfigParams: jest.fn(), | ||
getFeatureGate: jest.fn().mockReturnValue(false), | ||
})) | ||
|
||
const mockStoredArbitrumUsdcTokenBalance: StoredTokenBalance = { | ||
tokenId: 'arbitrum-sepolia:0x123', | ||
priceUsd: '1.16', | ||
address: '0x123', | ||
isNative: false, | ||
symbol: 'USDC', | ||
imageUrl: | ||
'https://raw.githubusercontent.com/ubeswap/default-token-list/master/assets/asset_CELO.png', | ||
name: 'USDC', | ||
decimals: 6, | ||
balance: '5', | ||
isFeeCurrency: true, | ||
canTransferWithComment: false, | ||
priceFetchedAt: Date.now(), | ||
networkId: NetworkId['arbitrum-sepolia'], | ||
isSwappable: true, | ||
isCashInEligible: true, | ||
isCashOutEligible: true, | ||
} | ||
|
||
const mockArbitrumUsdcBalance: TokenBalance = { | ||
...mockStoredArbitrumUsdcTokenBalance, | ||
balance: new BigNumber(mockStoredArbitrumUsdcTokenBalance.balance!), | ||
lastKnownPriceUsd: new BigNumber(mockStoredArbitrumUsdcTokenBalance.priceUsd!), | ||
priceUsd: new BigNumber(mockStoredArbitrumUsdcTokenBalance.priceUsd!), | ||
} | ||
|
||
const store = createMockStore({ | ||
tokens: { | ||
tokenBalances: { | ||
['arbitrum-sepolia:0x123']: { | ||
...mockStoredArbitrumUsdcTokenBalance, | ||
balance: `${mockStoredArbitrumUsdcTokenBalance.balance!}`, | ||
}, | ||
['arbitrum-sepolia:0x456']: { | ||
...mockStoredArbitrumUsdcTokenBalance, | ||
address: '0x456', | ||
tokenId: 'arbitrum-sepolia:0x456', | ||
balance: `${mockStoredArbitrumUsdcTokenBalance.balance!}`, | ||
}, | ||
}, | ||
}, | ||
app: { | ||
showSwapMenuInDrawerMenu: true, | ||
}, | ||
}) | ||
|
||
describe('EarnAddCryptoBottomSheet', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
jest.mocked(getDynamicConfigParams).mockReturnValue({ | ||
showCico: ['arbitrum-sepolia'], | ||
showSwap: ['arbitrum-sepolia'], | ||
}) | ||
}) | ||
it('Renders all actions', () => { | ||
const { getByText } = render( | ||
<Provider store={store}> | ||
<EarnAddCryptoBottomSheet | ||
forwardedRef={{ current: null }} | ||
token={mockArbitrumUsdcBalance} | ||
tokenAmount={new BigNumber(100)} | ||
/> | ||
</Provider> | ||
) | ||
|
||
expect(getByText('earnFlow.addCryptoBottomSheet.actions.transfer')).toBeTruthy() | ||
expect(getByText('earnFlow.addCryptoBottomSheet.actions.swap')).toBeTruthy() | ||
expect(getByText('earnFlow.addCryptoBottomSheet.actions.add')).toBeTruthy() | ||
}) | ||
|
||
it('Does not render swap action when no tokens available to swap', () => { | ||
const mockStore = createMockStore({ | ||
tokens: { | ||
tokenBalances: { | ||
['arbitrum-sepolia:0x123']: { | ||
...mockStoredArbitrumUsdcTokenBalance, | ||
balance: `${mockStoredArbitrumUsdcTokenBalance.balance!}`, | ||
}, | ||
}, | ||
}, | ||
app: { | ||
showSwapMenuInDrawerMenu: true, | ||
}, | ||
}) | ||
const { getByText, queryByText } = render( | ||
<Provider store={mockStore}> | ||
<EarnAddCryptoBottomSheet | ||
forwardedRef={{ current: null }} | ||
token={mockArbitrumUsdcBalance} | ||
tokenAmount={new BigNumber(100)} | ||
/> | ||
</Provider> | ||
) | ||
|
||
expect(getByText('earnFlow.addCryptoBottomSheet.actions.transfer')).toBeTruthy() | ||
expect(queryByText('earnFlow.addCryptoBottomSheet.actions.swap')).toBeFalsy() | ||
expect(getByText('earnFlow.addCryptoBottomSheet.actions.add')).toBeTruthy() | ||
}) | ||
|
||
it('Does not render swap or add when network is not in dynamic config', () => { | ||
jest.mocked(getDynamicConfigParams).mockReturnValue({ | ||
showCico: ['ethereum-sepolia'], | ||
showSwap: ['ethereum-sepolia'], | ||
}) | ||
const { getByText, queryByText } = render( | ||
<Provider store={store}> | ||
<EarnAddCryptoBottomSheet | ||
forwardedRef={{ current: null }} | ||
token={mockArbitrumUsdcBalance} | ||
tokenAmount={new BigNumber(100)} | ||
/> | ||
</Provider> | ||
) | ||
|
||
expect(getByText('earnFlow.addCryptoBottomSheet.actions.transfer')).toBeTruthy() | ||
expect(queryByText('earnFlow.addCryptoBottomSheet.actions.swap')).toBeFalsy() | ||
expect(queryByText('earnFlow.addCryptoBottomSheet.actions.add')).toBeFalsy() | ||
}) | ||
|
||
it.each([ | ||
{ | ||
actionName: TokenActionName.Add, | ||
actionTitle: 'earnFlow.addCryptoBottomSheet.actions.add', | ||
navigateScreen: Screens.SelectProvider, | ||
navigateProps: { | ||
amount: { crypto: 100, fiat: 154 }, | ||
flow: 'CashIn', | ||
tokenId: 'arbitrum-sepolia:0x123', | ||
}, | ||
}, | ||
{ | ||
actionName: TokenActionName.Transfer, | ||
actionTitle: 'earnFlow.addCryptoBottomSheet.actions.transfer', | ||
navigateScreen: Screens.ExchangeQR, | ||
navigateProps: { exchanges: [], flow: 'CashIn' }, | ||
}, | ||
{ | ||
actionName: TokenActionName.Swap, | ||
actionTitle: 'earnFlow.addCryptoBottomSheet.actions.swap', | ||
navigateScreen: Screens.SwapScreenWithBack, | ||
navigateProps: { toTokenId: 'arbitrum-sepolia:0x123' }, | ||
}, | ||
])( | ||
'triggers the correct analytics and navigation for $actionName', | ||
async ({ actionName, actionTitle, navigateScreen, navigateProps }) => { | ||
const { getByText } = render( | ||
<Provider store={store}> | ||
<EarnAddCryptoBottomSheet | ||
forwardedRef={{ current: null }} | ||
token={mockArbitrumUsdcBalance} | ||
tokenAmount={new BigNumber(100)} | ||
/> | ||
</Provider> | ||
) | ||
|
||
fireEvent.press(getByText(actionTitle)) | ||
expect(ValoraAnalytics.track).toHaveBeenCalledWith(EarnEvents.earn_add_crypto_action_press, { | ||
action: actionName, | ||
address: '0x123', | ||
balanceUsd: 5.8, | ||
networkId: mockArbitrumUsdcBalance.networkId, | ||
symbol: mockArbitrumUsdcBalance.symbol, | ||
tokenId: 'arbitrum-sepolia:0x123', | ||
}) | ||
|
||
expect(navigate).toHaveBeenCalledWith(navigateScreen, navigateProps) | ||
} | ||
) | ||
}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this (and a few other files) conflicts with main. I used
earnStablecoin
as the key, but I likeearnFlow
and updated it here https://github.com/valora-inc/wallet/pull/5394/files#diff-d3d67f4b3f8dbec345426f534268e40d9b087dfa5d83750165d63caf136cb24cR2329