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(TokenEnterAmount): add new flow to EnterAmount.tsx #6245

Merged
merged 77 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
e5ab0a5
add new TokenEnterAmount component
sviderock Nov 18, 2024
2fbc1b2
fix exports
sviderock Nov 18, 2024
b12d50f
Merge branch 'main' into slava/add-new-enter-amount-component
sviderock Nov 18, 2024
8af7b8d
Add reusable useEnterAmount hook
sviderock Nov 18, 2024
44c0aab
remove unused code
sviderock Nov 18, 2024
1aa17d6
change flow on send
sviderock Nov 19, 2024
4ed89fc
fix tests
sviderock Nov 19, 2024
d0c7099
fix jumpstart
sviderock Nov 19, 2024
b7e5107
remove unnecessary changes
sviderock Nov 19, 2024
6ca6f92
Merge branch 'main' into slava/add-new-enter-amount-component
sviderock Nov 19, 2024
f2185bc
Merge branch 'slava/add-new-enter-amount-component' into slava/add-en…
sviderock Nov 19, 2024
8762401
Merge branch 'slava/add-enter-amount-hook' into slava/change-send-flow
sviderock Nov 19, 2024
98938bc
fix knip
sviderock Nov 19, 2024
5a3f776
uncomment some tests
sviderock Nov 19, 2024
9360626
fixes
sviderock Nov 19, 2024
b3f3c67
add tests
sviderock Nov 20, 2024
8ce68a4
clear up console logs
sviderock Nov 20, 2024
c2773fa
Merge branch 'slava/add-new-enter-amount-component' into slava/add-en…
sviderock Nov 20, 2024
37455cb
WIP: tests for the hook
sviderock Nov 20, 2024
8357b18
reformat groupNumber, finish number formatting tests
sviderock Nov 21, 2024
f5db952
add useEnterAmount initial tests
sviderock Nov 21, 2024
130b620
finish tests
sviderock Nov 21, 2024
10fb5bd
revert unnecessary change
sviderock Nov 21, 2024
112e5f9
Merge branch 'main' into slava/add-new-enter-amount-component
sviderock Nov 21, 2024
bce9c2b
Merge branch 'slava/add-new-enter-amount-component' into slava/add-en…
sviderock Nov 21, 2024
7048f8e
Merge branch 'slava/add-enter-amount-hook' into slava/change-send-flow
sviderock Nov 21, 2024
a08f3a9
format input values
sviderock Nov 22, 2024
22f4a44
fix tests
sviderock Nov 22, 2024
78218f6
fix zero values for readable amounts
sviderock Nov 22, 2024
cea53aa
add comments
sviderock Nov 22, 2024
060a81a
Merge branch 'slava/add-enter-amount-hook' into slava/change-send-flow
sviderock Nov 22, 2024
8d80b3d
add comment
sviderock Nov 22, 2024
f9b5e31
unskip test that checks logic when fiat prices unavailable
sviderock Nov 22, 2024
0d64a5b
fix as per the review
sviderock Nov 22, 2024
2031bbc
fix as per the review comments
sviderock Nov 25, 2024
d7b5f0a
Merge branch 'main' into slava/add-new-enter-amount-component
sviderock Nov 25, 2024
6d738e4
Merge branch 'slava/add-new-enter-amount-component' into slava/add-en…
sviderock Nov 25, 2024
4c9ed39
remove refs and their handlers outside of the component
sviderock Nov 25, 2024
e1dbbec
refactor tests related to amount formatting
sviderock Nov 25, 2024
e9fc844
rename readabale to display
sviderock Nov 25, 2024
ec1f0a8
change variables names
sviderock Nov 25, 2024
96bc9b3
Merge branch 'slava/add-enter-amount-hook' into slava/change-send-flow
sviderock Nov 25, 2024
2c6f88b
fix tests after changes to hook
sviderock Nov 26, 2024
1a0c2bc
Merge branch 'main' into slava/add-new-enter-amount-component
sviderock Nov 26, 2024
6921dc5
Merge branch 'slava/add-new-enter-amount-component' into slava/add-en…
sviderock Nov 26, 2024
bcb4c6f
Merge branch 'slava/add-enter-amount-hook' into slava/change-send-flow
sviderock Nov 26, 2024
5d85bbd
remove unused callback
sviderock Nov 26, 2024
da1652b
change derived to processedAmounts
sviderock Nov 26, 2024
f57fac6
rename readable to displayAmount
sviderock Nov 26, 2024
39c6766
remove unnecessary hooks and mocks
sviderock Nov 26, 2024
cdd8396
fix tests as per review
sviderock Nov 26, 2024
6bb7c89
fix tests
sviderock Nov 26, 2024
1f40e7c
fix test
sviderock Nov 26, 2024
5cec1fb
Merge branch 'slava/add-enter-amount-hook' into slava/change-send-flow
sviderock Nov 26, 2024
b9f21de
fix as per the comments, adjust to "max" button
sviderock Nov 26, 2024
3858035
Merge branch 'main' into slava/change-send-flow
sviderock Nov 26, 2024
4eb45ba
unskip "max" tests
sviderock Nov 26, 2024
639e612
replace props.children check with .toHaveTextContent() in tests
sviderock Nov 26, 2024
080de6d
fix lint
sviderock Nov 27, 2024
e0de08b
add spacing for title
sviderock Nov 27, 2024
8001e05
fix percentages
sviderock Nov 28, 2024
ae82212
rename handler for better clarity
sviderock Nov 28, 2024
7714b4d
clear percentage on token select
sviderock Nov 28, 2024
b91f09d
change as per the review
sviderock Nov 29, 2024
fbcd741
Merge branch 'main' into slava/change-send-flow
sviderock Nov 29, 2024
757a759
revert some changes
sviderock Nov 29, 2024
8aed766
remove unused ref
sviderock Nov 29, 2024
ac325bd
fix 2e2
sviderock Nov 29, 2024
c5bc604
fix assets e2e
sviderock Nov 29, 2024
c0b5ab2
try to fix assets again
sviderock Nov 29, 2024
81991b5
ignore currency symbols for unformat function, cover new functions wi…
sviderock Nov 29, 2024
7c746d6
revert changes with removing symbols
sviderock Nov 29, 2024
12b4e47
fix: fee amount formatting on android
kathaypacific Dec 2, 2024
6d6ae26
fix: avoid showing fees when no amount
kathaypacific Dec 2, 2024
e54e741
fix: more than max amount set when max amount selected
kathaypacific Dec 2, 2024
1aa565d
fix: ensure token symbol displayed in secondary amount
kathaypacific Dec 2, 2024
5e2dbee
chore: increase switch icon touch area
kathaypacific Dec 2, 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
2 changes: 1 addition & 1 deletion e2e/src/usecases/Assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function validateSendFlow(tokenSymbol) {
await element(by.text(recipientAddressDisplay)).atIndex(0).tap()
await waitForElementByIdAndTap('SendOrInviteButton')
await expect(
element(by.text(tokenSymbol).withAncestor(by.id('SendEnterAmount/TokenSelect')))
element(by.text(`${tokenSymbol} on Celo`).withAncestor(by.id('SendEnterAmount/TokenSelect')))
).toBeVisible()
await element(by.id('BackChevron')).tap()
await element(by.id('BackChevron')).tap()
Expand Down
2 changes: 1 addition & 1 deletion e2e/src/usecases/HandleDeepLinkSend.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default HandleDeepLinkSend = () => {
url: `celo://wallet/pay?address=${E2E_TEST_FAUCET}&currencyCode=USD&token=cUSD&displayName=TestFaucet`,
})
await waitForElementId('SendEnterAmount/TokenSelect', 10_000)
await expect(element(by.text('cUSD')).atIndex(0)).toBeVisible()
await expect(element(by.text('cUSD on Celo')).atIndex(0)).toBeVisible()
await element(by.id('SendEnterAmount/TokenAmountInput')).replaceText('0.01')
await element(by.id('SendEnterAmount/TokenAmountInput')).tapReturnKey()
await waitForElementByIdAndTap('SendEnterAmount/ReviewButton', 30_000)
Expand Down
10 changes: 5 additions & 5 deletions e2e/src/usecases/Send.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export default Send = () => {
it('Then should be able to change token', async () => {
await element(by.id('SendEnterAmount/TokenSelect')).tap()
await element(by.id('CELOSymbol')).tap()
await expect(element(by.text('CELO')).atIndex(0)).toBeVisible()
await expect(element(by.text('CELO on Celo')).atIndex(0)).toBeVisible()
await element(by.id('SendEnterAmount/TokenSelect')).tap()
await element(by.id('cUSDSymbol')).tap()
await expect(element(by.text('cUSD')).atIndex(0)).toBeVisible()
await expect(element(by.text('cUSD on Celo')).atIndex(0)).toBeVisible()
await element(by.id('SendEnterAmount/TokenSelect')).tap()
await element(by.id('cEURSymbol')).tap()
await expect(element(by.text('cEUR')).atIndex(0)).toBeVisible()
await expect(element(by.text('cEUR on Celo')).atIndex(0)).toBeVisible()
})

it('Then should be able to enter amount and navigate to review screen', async () => {
Expand Down Expand Up @@ -111,7 +111,7 @@ export default Send = () => {
it('Then should be able to choose token', async () => {
await element(by.id('SendEnterAmount/TokenSelect')).tap()
await element(by.id('cEURSymbol')).tap()
await expect(element(by.text('cEUR')).atIndex(0)).toBeVisible()
await expect(element(by.text('cEUR on Celo')).atIndex(0)).toBeVisible()
})

it('Then should be able to enter amount and navigate to review screen', async () => {
Expand Down Expand Up @@ -167,7 +167,7 @@ export default Send = () => {
it('Then should be able to select token', async () => {
await element(by.id('SendEnterAmount/TokenSelect')).tap()
await element(by.id('cUSDSymbol')).tap()
await expect(element(by.text('cUSD')).atIndex(0)).toBeVisible()
await expect(element(by.text('cUSD on Celo')).atIndex(0)).toBeVisible()
})

it('Then should be able to enter amount and navigate to review screen', async () => {
Expand Down
1 change: 1 addition & 0 deletions locales/base/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -2208,6 +2208,7 @@
"title": "Enter Amount",
"selectToken": "Select a Token",
"networkFee": "{{networkName}} Network Fee",
"networkFeeV1_97": "Network Fee",
"lowerAmount": "Enter a lower amount",
"maxAmountWarning": {
"title": "Sending the maximum amount",
Expand Down
3 changes: 2 additions & 1 deletion src/components/TokenDisplay.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as React from 'react'
import 'react-native'
import { Provider } from 'react-redux'
import TokenDisplay, { formatValueToDisplay } from 'src/components/TokenDisplay'
import { APPROX_SYMBOL } from 'src/components/TokenEnterAmount'
import { LocalCurrencyCode } from 'src/localCurrency/consts'
import { RootState } from 'src/redux/reducers'
import { NetworkId } from 'src/transactions/types'
Expand Down Expand Up @@ -253,7 +254,7 @@ describe('TokenDisplay', () => {
/>
</Provider>
)
expect(getElementText(getByTestId('test'))).toEqual(`~10.00 cUSD`)
expect(getElementText(getByTestId('test'))).toEqual(`${APPROX_SYMBOL} 10.00 cUSD`)
})
})
})
Expand Down
3 changes: 2 additions & 1 deletion src/components/TokenDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import BigNumber from 'bignumber.js'
import * as React from 'react'
import { StyleProp, Text, TextStyle } from 'react-native'
import { APPROX_SYMBOL } from 'src/components/TokenEnterAmount'
import { LocalCurrencyCode, LocalCurrencySymbol } from 'src/localCurrency/consts'
import { getLocalCurrencySymbol, usdToLocalCurrencyRateSelector } from 'src/localCurrency/selectors'
import { useSelector } from 'src/redux/hooks'
Expand Down Expand Up @@ -81,7 +82,7 @@ function TokenDisplay({
errorFallback
) : (
<>
{showApprox && '~'}
{showApprox && `${APPROX_SYMBOL} `}
{sign}
{showLocalAmount && fiatSymbol}
{amountToShow.isNaN()
Expand Down
30 changes: 22 additions & 8 deletions src/components/TokenEnterAmount.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import TokenEnterAmount, {
formatNumber,
getDisplayLocalAmount,
getDisplayTokenAmount,
roundFiatValue,
unformatNumberForProcessing,
useEnterAmount,
} from './TokenEnterAmount'

Expand Down Expand Up @@ -65,6 +67,15 @@ describe('TokenEnterAmount', () => {
.mocked(getNumberFormatSettings)
.mockReturnValue({ decimalSeparator: '.', groupingSeparator: ',' })

expect(unformatNumberForProcessing('')).toBe('')
expect(unformatNumberForProcessing('0.25')).toBe('0.25')
expect(unformatNumberForProcessing('1,234.34567')).toBe('1234.34567')

expect(roundFiatValue(null)).toBe('')
expect(roundFiatValue(new BigNumber('0.01'))).toBe('0.01')
expect(roundFiatValue(new BigNumber('0.000001'))).toBe('0.000001')
expect(roundFiatValue(new BigNumber('1234.34567'))).toBe('1234.35')

expect(formatNumber('')).toBe('')
expect(formatNumber('123')).toBe('123')
expect(formatNumber('1234')).toBe('1,234')
Expand All @@ -73,8 +84,6 @@ describe('TokenEnterAmount', () => {
expect(formatNumber('123456789012345')).toBe('123,456,789,012,345')
expect(formatNumber('12.34567')).toBe('12.34567')
expect(formatNumber('-1234567.89')).toBe('-1,234,567.89')
expect(formatNumber('1234abc')).toBe('1,234abc')
expect(formatNumber('1234.56abc')).toBe('1,234.56abc')

const { token } = defaultProps
expect(getDisplayTokenAmount(null, token)).toBe('')
Expand Down Expand Up @@ -107,6 +116,15 @@ describe('TokenEnterAmount', () => {
.mocked(getNumberFormatSettings)
.mockReturnValue({ decimalSeparator: ',', groupingSeparator: '.' })

expect(unformatNumberForProcessing('')).toBe('')
expect(unformatNumberForProcessing('0,25')).toBe('0.25')
expect(unformatNumberForProcessing('1.234,34567')).toBe('1234.34567')

expect(roundFiatValue(null)).toBe('')
expect(roundFiatValue(new BigNumber('0.01'))).toBe('0.01')
expect(roundFiatValue(new BigNumber('0.000001'))).toBe('0.000001')
expect(roundFiatValue(new BigNumber('1234.34567'))).toBe('1234.35')

expect(formatNumber('')).toBe('')
expect(formatNumber('123')).toBe('123')
expect(formatNumber('1234')).toBe('1.234')
Expand All @@ -115,8 +133,6 @@ describe('TokenEnterAmount', () => {
expect(formatNumber('123456789012345')).toBe('123.456.789.012.345')
expect(formatNumber('12.34567')).toBe('12,34567')
expect(formatNumber('-1234567.89')).toBe('-1.234.567,89')
expect(formatNumber('1234abc')).toBe('1.234abc')
expect(formatNumber('1234.56abc')).toBe('1.234,56abc')

const { token } = defaultProps
expect(getDisplayTokenAmount(null, token)).toBe('')
Expand Down Expand Up @@ -163,6 +179,7 @@ describe('TokenEnterAmount', () => {
decimals: 6,
tokenId: mockUSDCTokenId,
priceUsd: new BigNumber(1.001),
balance: new BigNumber(1500.76),
} as TokenBalance,
})

Expand All @@ -173,12 +190,10 @@ describe('TokenEnterAmount', () => {
expect(result.current.amount).toBe('1234.678')
expect(result.current.processedAmounts).toStrictEqual({
token: {
amount: '1234.678',
bignum: new BigNumber('1234.678'),
displayAmount: '1,234.678 USDC',
},
local: {
amount: '1235.91',
bignum: new BigNumber('1235.912678'),
displayAmount: '$1,235.91',
},
Expand All @@ -193,6 +208,7 @@ describe('TokenEnterAmount', () => {
decimals: 6,
tokenId: mockUSDCTokenId,
priceUsd: new BigNumber(1.001),
balance: new BigNumber(1500.76),
} as TokenBalance,
})

Expand All @@ -203,12 +219,10 @@ describe('TokenEnterAmount', () => {
expect(result.current.amount).toBe('1234.67')
expect(result.current.processedAmounts).toStrictEqual({
local: {
amount: '1234.67',
bignum: new BigNumber('1234.67'),
displayAmount: '$1,234.67',
},
token: {
amount: '1233.436563',
bignum: new BigNumber('1233.436563'),
displayAmount: '1,233.436563 USDC',
},
Expand Down
Loading
Loading