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

chore: Update fiat exchange flow to use token IDs #4450

Merged
merged 52 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
240a141
initial work on removing cicocurrency enum
finnian0826 Nov 7, 2023
7f46333
continue token id update
finnian0826 Nov 8, 2023
2a30eae
more clean up
finnian0826 Nov 9, 2023
e3e8bc3
Merge branch 'main' into finnian0826/use-token-ids-in-fiat-exchange-flow
finnian0826 Nov 9, 2023
f098bd9
even more
finnian0826 Nov 9, 2023
3a5fd94
Merge branch 'main' into finnian0826/use-token-ids-in-fiat-exchange-flow
finnian0826 Nov 10, 2023
8033f95
update quotes
finnian0826 Nov 10, 2023
c366b31
fix type errors
finnian0826 Nov 10, 2023
4d164a9
fix tests
finnian0826 Nov 10, 2023
5c90df3
fix some hook issues
finnian0826 Nov 10, 2023
efa21f5
fix tests
finnian0826 Nov 10, 2023
1e8afbd
Merge branch 'main' into finnian0826/use-token-ids-in-fiat-exchange-flow
finnian0826 Nov 13, 2023
e9dba4b
fix saga hooks (hopefully)
finnian0826 Nov 13, 2023
c2fc19b
fix FiatExchangeAmount hook call
finnian0826 Nov 13, 2023
f08b467
fix tests
finnian0826 Nov 13, 2023
f69e32d
clean up
finnian0826 Nov 13, 2023
0166cba
fix add flow header
finnian0826 Nov 13, 2023
6b2426b
feedback
finnian0826 Nov 14, 2023
3905489
fix tests
finnian0826 Nov 14, 2023
f8b8592
fix hardcoded token symbols
finnian0826 Nov 15, 2023
278c14d
Merge branch 'main' into finnian0826/use-token-ids-in-fiat-exchange-flow
finnian0826 Nov 15, 2023
b365381
clean up
finnian0826 Nov 15, 2023
2083582
self review
finnian0826 Nov 15, 2023
6ff0101
remove eth check
finnian0826 Nov 15, 2023
97d3afe
Merge branch 'main' into finnian0826/use-token-ids-in-fiat-exchange-flow
finnian0826 Nov 16, 2023
72d40ea
feedback
finnian0826 Nov 17, 2023
332f23c
Merge branch 'main' into finnian0826/use-token-ids-in-fiat-exchange-flow
finnian0826 Nov 17, 2023
0614266
fix merge
finnian0826 Nov 17, 2023
2da137b
clean up
finnian0826 Nov 20, 2023
d7a9429
Merge branch 'main' into finnian0826/use-token-ids-in-fiat-exchange-flow
finnian0826 Nov 20, 2023
9dd6bbb
refactor
finnian0826 Nov 21, 2023
5e22cf2
clean up
finnian0826 Nov 21, 2023
b7ac5fa
Merge branch 'main' into finnian0826/use-token-ids-in-fiat-exchange-flow
finnian0826 Nov 27, 2023
b8ee42b
fix merge
finnian0826 Nov 27, 2023
32bee1a
Merge branch 'main' into finnian0826/use-token-ids-in-fiat-exchange-flow
finnian0826 Nov 27, 2023
2e2d1f6
Merge branch 'main' into finnian0826/use-token-ids-in-fiat-exchange-flow
finnian0826 Nov 27, 2023
dc89201
fix merge imports
finnian0826 Nov 27, 2023
23cd8e3
feedback
finnian0826 Nov 29, 2023
cd0d41b
fix test
finnian0826 Nov 29, 2023
90d504c
more clean up
finnian0826 Nov 29, 2023
f28024e
update stuff
finnian0826 Nov 29, 2023
ef48fe4
feedback
finnian0826 Nov 30, 2023
9e1bced
Merge branch 'main' into finnian0826/use-token-ids-in-fiat-exchange-flow
finnian0826 Nov 30, 2023
2e4a10b
fix navigation for new bottom sheet
finnian0826 Nov 30, 2023
bc5ffaf
feedback
finnian0826 Nov 30, 2023
41b3567
fix cico logic and fix tests
finnian0826 Dec 1, 2023
83938d3
fix test
finnian0826 Dec 1, 2023
b1c2f26
add regression testing
finnian0826 Dec 1, 2023
39818cd
Merge branch 'main' into finnian0826/use-token-ids-in-fiat-exchange-flow
cajubelt Dec 1, 2023
73727cf
Merge branch 'main' into finnian0826/use-token-ids-in-fiat-exchange-flow
cajubelt Dec 1, 2023
bd88cb4
Merge branch 'main' into finnian0826/use-token-ids-in-fiat-exchange-flow
cajubelt Dec 2, 2023
75c5c5d
Merge branch 'main' into finnian0826/use-token-ids-in-fiat-exchange-flow
finnian0826 Dec 2, 2023
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
12 changes: 6 additions & 6 deletions src/analytics/Properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ import { RecipientType } from 'src/recipients/recipient'
import { Field } from 'src/swap/types'
import { TokenDetailsActionName } from 'src/tokens/types'
import { NetworkId, TokenTransactionTypeV2, TransactionStatus } from 'src/transactions/types'
import { AnalyticsCurrency, CiCoCurrency, Currency } from 'src/utils/currencies'
import { Currency } from 'src/utils/currencies'

type Web3LibraryProps = { web3Library: 'contract-kit' | 'viem' }

Expand Down Expand Up @@ -797,21 +797,21 @@ interface FiatExchangeEventsProperties {
[FiatExchangeEvents.cico_landing_how_to_fund]: undefined
[FiatExchangeEvents.cico_currency_chosen]: {
flow: FiatExchangeFlow
currency: AnalyticsCurrency
currency: string
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 being changed from AnalyticsCurrency to string to allow any token symbol to be passed here. In the future, this allows for adding new CICO currencies without wallet changes.

}
[FiatExchangeEvents.cico_currency_back]: { flow: FiatExchangeFlow }
[FiatExchangeEvents.cico_amount_chosen]: {
amount: number
currency: AnalyticsCurrency
currency: string
flow: CICOFlow
}
[FiatExchangeEvents.cico_amount_chosen_invalid]: {
amount: number
currency: AnalyticsCurrency
currency: string
flow: CICOFlow
}
[FiatExchangeEvents.cico_amount_back]: {
currency: AnalyticsCurrency
currency: string
flow: CICOFlow
}
[FiatExchangeEvents.cico_providers_section_impression]: {
Expand Down Expand Up @@ -926,7 +926,7 @@ interface FiatExchangeEventsProperties {
}
[FiatExchangeEvents.cico_simplex_open_webview]: {
amount: number
cryptoCurrency: CiCoCurrency
cryptoCurrency: string
feeInFiat: number
fiatCurrency: string
}
Expand Down
5 changes: 2 additions & 3 deletions src/fiatExchanges/ExternalExchanges.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import * as React from 'react'
import { Provider } from 'react-redux'
import ExternalExchanges from 'src/fiatExchanges/ExternalExchanges'
import { Screens } from 'src/navigator/Screens'
import { CiCoCurrency } from 'src/utils/currencies'
import { navigateToURI } from 'src/utils/linking'
import { createMockStore, getMockStackScreenProps } from 'test/utils'
import { mockAccount, mockExchanges } from 'test/values'
import { mockAccount, mockCusdTokenId, mockExchanges } from 'test/values'

const mockStore = createMockStore({
web3: {
Expand All @@ -29,7 +28,7 @@ describe('ExternalExchanges', () => {
// ExternalExchanges Screen will always have providers passed in via props
it('shows list of available exchanges', async () => {
const mockScreenProps = getMockStackScreenProps(Screens.ExternalExchanges, {
currency: CiCoCurrency.cUSD,
tokenId: mockCusdTokenId,
exchanges: mockExchanges,
})

Expand Down
6 changes: 4 additions & 2 deletions src/fiatExchanges/ExternalExchanges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Screens } from 'src/navigator/Screens'
import { StackParamList } from 'src/navigator/types'
import fontStyles from 'src/styles/fonts'
import variables from 'src/styles/variables'
import { useTokenInfo } from 'src/tokens/hooks'
import { Currency } from 'src/utils/currencies'
import { navigateToURI } from 'src/utils/linking'

Expand All @@ -39,6 +40,7 @@ type Props = NativeStackScreenProps<StackParamList, Screens.ExternalExchanges>
function ExternalExchanges({ route }: Props) {
const { t } = useTranslation()
const providers = route.params?.exchanges
const tokenInfo = useTokenInfo(route.params.tokenId)

const goToExchange = (provider: ExternalExchangeProvider) => {
const { name, link } = provider
Expand All @@ -56,7 +58,7 @@ function ExternalExchanges({ route }: Props) {
<SafeAreaView style={styles.container}>
<Text style={styles.pleaseSelectExchange}>
{t('youCanTransferOut', {
digitalAsset: route.params.currency,
digitalAsset: tokenInfo?.symbol,
})}
</Text>

Expand All @@ -73,7 +75,7 @@ function ExternalExchanges({ route }: Props) {
})}
</ScrollView>
{providers?.length ? (
<SendBar skipImport={true} selectedCurrency={route.params.currency} />
<SendBar skipImport={true} selectedTokenId={route.params.tokenId} />
) : (
<></>
)}
Expand Down
85 changes: 42 additions & 43 deletions src/fiatExchanges/FiatExchangeAmount.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LocalCurrencyCode } from 'src/localCurrency/consts'
import { navigate } from 'src/navigator/NavigationService'
import { Screens } from 'src/navigator/Screens'
import { getFeatureGate } from 'src/statsig'
import { Network } from 'src/transactions/types'
import { NetworkId } from 'src/transactions/types'
import { CiCoCurrency } from 'src/utils/currencies'
import { createMockStore, getElementText, getMockStackScreenProps } from 'test/utils'
import {
Expand All @@ -24,11 +24,11 @@ import {
mockMaxSendAmount,
} from 'test/values'
import { CICOFlow } from './utils'
import { NetworkId } from 'src/transactions/types'

const mockUseMaxSendAmount = jest.fn(() => mockMaxSendAmount)

jest.mock('src/fees/hooks', () => ({
useMaxSendAmountByAddress: () => mockUseMaxSendAmount(),
useMaxSendAmount: () => mockUseMaxSendAmount(),
}))
jest.mock('src/statsig', () => ({
getFeatureGate: jest.fn(),
Expand All @@ -42,7 +42,7 @@ jest.mock('src/web3/networkConfig', () => {
...originalModule.default,
networkToNetworkId: {
celo: 'celo-alfajores',
ethereum: 'ethereuim-sepolia',
ethereum: 'ethereum-sepolia',
},
defaultNetworkId: 'celo-alfajores',
},
Expand Down Expand Up @@ -85,6 +85,16 @@ const mockTokens = {
isCoreToken: true,
priceFetchedAt: Date.now(),
},
[mockEthTokenId]: {
address: undefined,
tokenId: mockEthTokenId,
networkId: NetworkId['ethereum-sepolia'],
symbol: 'ETH',
balance: '1',
priceUsd: '1000',
isCoreToken: true,
priceFetchedAt: Date.now(),
},
},
}

Expand Down Expand Up @@ -123,15 +133,14 @@ describe('FiatExchangeAmount cashIn', () => {
})

it.each([
{ currency: CiCoCurrency.cUSD, tokenId: mockCusdTokenId, network: Network.Celo },
{ currency: CiCoCurrency.cEUR, tokenId: mockCeurTokenId, network: Network.Celo },
{ currency: CiCoCurrency.ETH, tokenId: mockEthTokenId, network: Network.Ethereum },
])(`disables the next button if the $currency amount is 0`, ({ currency, network, tokenId }) => {
{ currency: 'cUSD', tokenId: mockCusdTokenId },
{ currency: 'cEUR', tokenId: mockCeurTokenId },
{ currency: 'ETH', tokenId: mockEthTokenId },
])(`disables the next button if the $currency amount is 0`, ({ tokenId, currency }) => {
const mockScreenProps = getMockStackScreenProps(Screens.FiatExchangeAmount, {
currency,
tokenId,
flow: CICOFlow.CashIn,
network,
tokenSymbol: currency,
})
const tree = render(
<Provider store={storeWithUSD}>
Expand All @@ -145,31 +154,27 @@ describe('FiatExchangeAmount cashIn', () => {

it.each([
{
currency: CiCoCurrency.cUSD,
currency: 'cUSD',
tokenId: mockCusdTokenId,
network: Network.Celo,
store: storeWithUSD,
},
{
currency: CiCoCurrency.cEUR,
currency: 'cEUR',
tokenId: mockCeurTokenId,
network: Network.Celo,
store: storeWithPHP,
},
{
currency: CiCoCurrency.ETH,
currency: 'ETH',
tokenId: mockEthTokenId,
network: Network.Ethereum,
store: storeWithUSD,
},
])(
`enables the next button if the $currency amount is greater than 0`,
({ currency, tokenId, network, store }) => {
({ tokenId, currency, store }) => {
const mockScreenProps = getMockStackScreenProps(Screens.FiatExchangeAmount, {
currency,
tokenId,
flow: CICOFlow.CashIn,
network,
tokenSymbol: currency,
})
const tree = render(
<Provider store={store}>
Expand All @@ -184,10 +189,9 @@ describe('FiatExchangeAmount cashIn', () => {

it('renders correctly with USD as app currency', () => {
const mockScreenProps = getMockStackScreenProps(Screens.FiatExchangeAmount, {
currency: CiCoCurrency.cUSD,
tokenId: mockCusdTokenId,
flow: CICOFlow.CashIn,
network: Network.Celo,
tokenSymbol: 'cUSD',
})
const tree = render(
<Provider store={storeWithUSD}>
Expand All @@ -199,10 +203,9 @@ describe('FiatExchangeAmount cashIn', () => {

it('renders correctly with EUR as app currency', () => {
const mockScreenProps = getMockStackScreenProps(Screens.FiatExchangeAmount, {
currency: CiCoCurrency.cUSD,
tokenId: mockCusdTokenId,
flow: CICOFlow.CashIn,
network: Network.Celo,
tokenSymbol: 'cUSD',
})
const tree = render(
<Provider store={storeWithEUR}>
Expand All @@ -215,24 +218,21 @@ describe('FiatExchangeAmount cashIn', () => {

describe('FiatExchangeAmount cashOut', () => {
const mockScreenProps = getMockStackScreenProps(Screens.FiatExchangeAmount, {
currency: CiCoCurrency.cUSD,
tokenId: mockCusdTokenId,
flow: CICOFlow.CashOut,
network: Network.Celo,
tokenSymbol: 'cUSD',
})

const mockScreenPropsEuro = getMockStackScreenProps(Screens.FiatExchangeAmount, {
currency: CiCoCurrency.cEUR,
tokenId: mockCeurTokenId,
flow: CICOFlow.CashOut,
network: Network.Celo,
tokenSymbol: 'cEUR',
})

const mockScreenPropsCelo = getMockStackScreenProps(Screens.FiatExchangeAmount, {
currency: CiCoCurrency.CELO,
tokenId: mockCeloTokenId,
flow: CICOFlow.CashOut,
network: Network.Celo,
tokenSymbol: 'CELO',
})

beforeEach(() => {
Expand All @@ -249,9 +249,9 @@ describe('FiatExchangeAmount cashOut', () => {
</Provider>
)
expect(getByText('amount (cUSD)')).toBeTruthy()
expect(getElementText(getByTestId('LineItemRowTitle/subtotal'))).toBe('celoDollar @ $1.00')
expect(getElementText(getByTestId('LineItemRowTitle/subtotal'))).toBe('cUSD @ $1.00')
expect(getElementText(getByTestId('LineItemRow/subtotal'))).toBe('$0.00')
expect(getByText('disclaimerFiat, {"currency":"celoDollar"}')).toBeTruthy()
expect(getByText('disclaimerFiat, {"currency":"cUSD"}')).toBeTruthy()
})

it('displays correctly for cEUR when local currency is USD', () => {
Expand All @@ -261,9 +261,9 @@ describe('FiatExchangeAmount cashOut', () => {
</Provider>
)
expect(getByText('amount (cEUR)')).toBeTruthy()
expect(getElementText(getByTestId('LineItemRowTitle/subtotal'))).toBe('celoEuro @ $1.20')
expect(getElementText(getByTestId('LineItemRowTitle/subtotal'))).toBe('cEUR @ $1.20')
expect(getElementText(getByTestId('LineItemRow/subtotal'))).toBe('$0.00')
expect(getByText('disclaimerFiat, {"currency":"celoEuro"}')).toBeTruthy()
expect(getByText('disclaimerFiat, {"currency":"cEUR"}')).toBeTruthy()
})

it('displays correctly for CELO when local currency is USD', () => {
Expand All @@ -273,7 +273,7 @@ describe('FiatExchangeAmount cashOut', () => {
</Provider>
)
expect(getByText('amount (CELO)')).toBeTruthy()
expect(getElementText(getByTestId('LineItemRowTitle/subtotal'))).toBe('subtotal @ $5.00')
expect(getElementText(getByTestId('LineItemRowTitle/subtotal'))).toBe('CELO @ $5.00')
expect(getElementText(getByTestId('LineItemRow/subtotal'))).toBe('$0.00')
})

Expand All @@ -287,7 +287,7 @@ describe('FiatExchangeAmount cashOut', () => {
expect(getByText('amount (cUSD)')).toBeTruthy()
expect(queryByTestId('LineItemRowTitle/subtotal')).toBeFalsy()
expect(queryByTestId('LineItemRow/subtotal')).toBeFalsy()
expect(queryByText('disclaimerFiat, {"currency":"celoDollar"}')).toBeFalsy()
expect(queryByText('disclaimerFiat, {"currency":"cUSD"}')).toBeFalsy()
})

it('disables the next button if the cUSD amount is 0', () => {
Expand Down Expand Up @@ -350,12 +350,11 @@ describe('FiatExchangeAmount cashOut', () => {
fireEvent.press(tree.getByTestId('FiatExchangeNextButton'))
expect(navigate).toHaveBeenCalledWith(Screens.SelectProvider, {
flow: CICOFlow.CashOut,
selectedCrypto: CiCoCurrency.cUSD,
amount: {
fiat: 750,
crypto: 750,
},
network: Network.Celo,
tokenId: mockCusdTokenId,
})
})
it('calls dispatch attemptReturnUserFlow when there is a previously linked fiatconnect account', () => {
Expand All @@ -382,9 +381,8 @@ describe('FiatExchangeAmount cashOut', () => {
store.dispatch = jest.fn()
const screenProps = getMockStackScreenProps(Screens.FiatExchangeAmount, {
tokenId: mockCusdTokenId,
currency: CiCoCurrency.cUSD,
flow: CICOFlow.CashOut,
network: Network.Celo,
tokenSymbol: 'cUSD',
})
const tree = render(
<Provider store={store}>
Expand All @@ -397,7 +395,7 @@ describe('FiatExchangeAmount cashOut', () => {
expect(store.dispatch).toHaveBeenLastCalledWith(
attemptReturnUserFlow({
flow: CICOFlow.CashOut,
selectedCrypto: CiCoCurrency.cUSD,
selectedCrypto: 'cUSD',
amount: {
crypto: 750,
fiat: 750,
Expand All @@ -406,6 +404,7 @@ describe('FiatExchangeAmount cashOut', () => {
fiatAccountId: '123',
fiatAccountType: FiatAccountType.BankAccount,
fiatAccountSchema: FiatAccountSchema.AccountNumber,
tokenId: mockCusdTokenId,
})
)
})
Expand All @@ -432,10 +431,9 @@ describe('FiatExchangeAmount cashOut', () => {
})
store.dispatch = jest.fn()
const screenProps = getMockStackScreenProps(Screens.FiatExchangeAmount, {
currency: CiCoCurrency.cUSD,
tokenId: mockCusdTokenId,
flow: CICOFlow.CashOut,
network: Network.Celo,
tokenSymbol: 'cUSD',
})
const tree = render(
<Provider store={store}>
Expand All @@ -448,7 +446,7 @@ describe('FiatExchangeAmount cashOut', () => {
expect(store.dispatch).toHaveBeenLastCalledWith(
attemptReturnUserFlow({
flow: CICOFlow.CashOut,
selectedCrypto: CiCoCurrency.cUSD,
selectedCrypto: 'cUSD',
amount: {
crypto: 750,
fiat: 750,
Expand All @@ -457,6 +455,7 @@ describe('FiatExchangeAmount cashOut', () => {
fiatAccountId: '123',
fiatAccountType: FiatAccountType.BankAccount,
fiatAccountSchema: FiatAccountSchema.AccountNumber,
tokenId: mockCusdTokenId,
})
)
})
Expand Down
Loading