Skip to content

Commit

Permalink
feat(earn): Add exchanges to Add Crypto bottom sheet (#5413)
Browse files Browse the repository at this point in the history
### Description

Add in exchanges to the Transfer option of the Add Crypto bottom sheet

### Test plan

Manual test:


https://github.com/valora-inc/wallet/assets/140328381/de7ec117-4b44-4013-a7f1-e2c107064aa9



### Related issues

- Fixes #ACT-1177

### 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
finnian0826 committed May 14, 2024
1 parent 258f77a commit 69e1e64
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/earn/EarnAddCryptoBottomSheet.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import BigNumber from 'bignumber.js'
import React, { RefObject } from 'react'
import { useAsync } from 'react-async-hook'
import { useTranslation } from 'react-i18next'
import { StyleSheet, Text, View } from 'react-native'
import { useSelector } from 'react-redux'
import { EarnEvents } from 'src/analytics/Events'
import ValoraAnalytics from 'src/analytics/ValoraAnalytics'
import BottomSheet, { BottomSheetRefType } from 'src/components/BottomSheet'
import Touchable from 'src/components/Touchable'
import { CICOFlow } from 'src/fiatExchanges/utils'
import { CICOFlow, fetchExchanges } from 'src/fiatExchanges/utils'
import QuickActionsAdd from 'src/icons/quick-actions/Add'
import QuickActionsSend from 'src/icons/quick-actions/Send'
import QuickActionsSwap from 'src/icons/quick-actions/Swap'
import { navigate } from 'src/navigator/NavigationService'
import { Screens } from 'src/navigator/Screens'
import { isAppSwapsEnabledSelector } from 'src/navigator/selectors'
import { userLocationDataSelector } from 'src/networkInfo/selectors'
import { NETWORK_NAMES } from 'src/shared/conts'
import { Colors } from 'src/styles/colors'
import { typeScale } from 'src/styles/fonts'
Expand All @@ -36,6 +38,7 @@ export default function EarnAddCryptoBottomSheet({
const { swappableFromTokens } = useSwappableTokens()
const cashInTokens = useCashInTokens()
const isSwapEnabled = useSelector(isAppSwapsEnabledSelector)
const userLocation = useSelector(userLocationDataSelector)

const showAdd = !!cashInTokens.find((tokenInfo) => tokenInfo.tokenId === token.tokenId)
const showSwap =
Expand All @@ -50,6 +53,17 @@ export default function EarnAddCryptoBottomSheet({
),
}

const asyncExchanges = useAsync(async () => {
try {
const availableExchanges = await fetchExchanges(userLocation.countryCodeAlpha2, token.tokenId)

return availableExchanges
} catch (error) {
return []
}
}, [])
const exchanges = asyncExchanges.result ?? []

const actions = [
{
name: TokenActionName.Add,
Expand Down Expand Up @@ -77,7 +91,7 @@ export default function EarnAddCryptoBottomSheet({
}),
iconComponent: QuickActionsSend,
onPress: () => {
navigate(Screens.ExchangeQR, { flow: CICOFlow.CashIn, exchanges: [] })
navigate(Screens.ExchangeQR, { flow: CICOFlow.CashIn, exchanges })
},
visible: true,
},
Expand Down

0 comments on commit 69e1e64

Please sign in to comment.