Skip to content

Commit

Permalink
feat(cash-in): have the user input fiat amount for CELO cash-ins (#3954)
Browse files Browse the repository at this point in the history
### Description

have the user input fiat amount for CELO cash-ins just like all the
other cryptos. Now there is consistent behavior between the different
cryptos when cashing in.

| CELO cash in | cUSD cash in | 
| :---:        |     :---:      |
| ![Simulator Screen Shot - iPhone 13 - 2023-07-12 at 13 17
17](https://github.com/valora-inc/wallet/assets/8432644/bf49884a-78b2-4a02-a28c-d32bf3c0ef65)
| ![Simulator Screen Shot - iPhone 13 - 2023-07-12 at 13 17
00](https://github.com/valora-inc/wallet/assets/8432644/2aaeca95-3749-4dbf-bce6-1f8853b76e1f)
|
| ![Simulator Screen Shot - iPhone 13 - 2023-07-12 at 13 20
32](https://github.com/valora-inc/wallet/assets/8432644/891ff73a-488b-4358-b234-69ac50349cac)
| ![Simulator Screen Shot - iPhone 13 - 2023-07-12 at 13 21
23](https://github.com/valora-inc/wallet/assets/8432644/e64d6491-9f6f-4eab-a625-a081bcb2fcf2)
|


### Test plan

updated unit tests

### Related issues


https://linear.app/valora/issue/ACT-851/refactor-cash-in-with-celo-flow-to-use-fiat-amount-not-crypto-amount
### Backwards compatibility

<!-- Brief explanation of why these changes are/are not backwards
compatible. -->
  • Loading branch information
jh2oman authored Jul 12, 2023
1 parent f7b3a2c commit da51471
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 deletions.
19 changes: 4 additions & 15 deletions src/fiatExchanges/FiatExchangeAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import colors from 'src/styles/colors'
import fontStyles from 'src/styles/fonts'
import variables from 'src/styles/variables'
import {
useConvertBetweenTokens,
useLocalToTokenAmount,
useTokenInfoBySymbol,
useTokenToLocalAmount,
Expand Down Expand Up @@ -92,7 +91,7 @@ function FiatExchangeAmount({ route }: Props) {

const localCurrencySymbol = LocalCurrencySymbol[localCurrencyCode]

const inputIsCrypto = isUserInputCrypto(flow, currency)
const inputIsCrypto = isUserInputCrypto(flow)

const inputCryptoAmount = inputIsCrypto ? parsedInputAmount : inputConvertedToCrypto
const inputLocalCurrencyAmount = inputIsCrypto ? inputConvertedToLocalCurrency : parsedInputAmount
Expand All @@ -108,19 +107,9 @@ function FiatExchangeAmount({ route }: Props) {
useTokenToLocalAmount(new BigNumber(DOLLAR_ADD_FUNDS_MAX_AMOUNT), cUSDToken.address) ||
new BigNumber(0)

const currencyMaxAmount =
useConvertBetweenTokens(
new BigNumber(DOLLAR_ADD_FUNDS_MAX_AMOUNT),
cUSDToken.address,
address
) || new BigNumber(0)

let overLocalLimitDisplayString = ''
if (localCurrencyCode !== LocalCurrencyCode.USD) {
overLocalLimitDisplayString =
currency === CiCoCurrency.CELO
? ` (${roundUp(currencyMaxAmount, 3)} CELO)`
: ` (${localCurrencySymbol}${roundUp(localCurrencyMaxAmount)})`
overLocalLimitDisplayString = ` (${localCurrencySymbol}${roundUp(localCurrencyMaxAmount)})`
}

const showExchangeRate = !getFeatureGate(
Expand Down Expand Up @@ -278,7 +267,7 @@ function FiatExchangeAmount({ route }: Props) {
/>
)}
</KeyboardAwareScrollView>
{currency !== CiCoCurrency.CELO && showExchangeRate && (
{showExchangeRate && (
<Text style={styles.disclaimerFiat}>
{t('disclaimerFiat', { currency: t(displayCurrencyKey) })}
</Text>
Expand All @@ -305,7 +294,7 @@ FiatExchangeAmount.navOptions = ({
route: RouteProp<StackParamList, Screens.FiatExchangeAmount>
}) => {
const { currency, flow } = route.params
const inputIsCrypto = isUserInputCrypto(flow, currency)
const inputIsCrypto = isUserInputCrypto(flow)
return {
...emptyHeader,
headerLeft: () => <BackButton eventName={FiatExchangeEvents.cico_amount_back} />,
Expand Down
3 changes: 1 addition & 2 deletions src/fiatExchanges/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,7 @@ export const filterProvidersByPaymentMethod = (
return externalProviders?.find((quote) => quote.paymentMethods.includes(paymentMethod))
}

export const isUserInputCrypto = (flow: CICOFlow, currency: Currency | CiCoCurrency): boolean =>
flow === CICOFlow.CashOut || currency === Currency.Celo || currency === CiCoCurrency.CELO
export const isUserInputCrypto = (flow: CICOFlow): boolean => flow === CICOFlow.CashOut

export function resolveCloudFunctionDigitalAsset(
currency: CiCoCurrency
Expand Down
12 changes: 6 additions & 6 deletions src/fiatconnect/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { FetchMock } from 'jest-fetch-mock'
import { CICOFlow } from 'src/fiatExchanges/utils'
import { LocalCurrencyCode } from 'src/localCurrency/consts'
import { getPassword } from 'src/pincode/authentication'
import { CiCoCurrency } from 'src/utils/currencies'
import Logger from 'src/utils/Logger'
import { CiCoCurrency } from 'src/utils/currencies'
import ValoraCeloWallet from 'src/web3/ValoraCeloWallet'
import KeychainAccountManager from 'src/web3/KeychainAccountManager'
import networkConfig from 'src/web3/networkConfig'
Expand All @@ -16,15 +16,15 @@ import {
mockGetFiatConnectQuotesResponse,
} from 'test/values'
import {
fetchQuotes,
FetchQuotesInput,
FiatConnectProviderInfo,
QuotesInput,
fetchQuotes,
getFiatConnectProviders,
getFiatConnectQuotes,
getObfuscatedAccountNumber,
getObfuscatedEmail,
loginWithFiatConnectProvider,
QuotesInput,
} from './index'

jest.mock('src/pincode/authentication', () => ({
Expand Down Expand Up @@ -182,13 +182,13 @@ describe('FiatConnect helpers', () => {
expect(mockFetch).toHaveBeenCalledWith(expect.stringContaining('fiatAmount=100'))
expect(mockFetch).toHaveBeenCalledWith(expect.not.stringContaining('cryptoAmount=100'))
})
it('calls with cryptoAmount for cash in when crypto is CELO', async () => {
it('calls with fiatAmount for cash in when crypto is CELO', async () => {
mockFetch.mockResponseOnce(JSON.stringify({ quotes: mockGetFiatConnectQuotesResponse }), {
status: 200,
})
await getFiatConnectQuotes({ ...getQuotesInput, digitalAsset: CiCoCurrency.CELO })
expect(mockFetch).toHaveBeenCalledWith(expect.stringContaining('cryptoAmount=100'))
expect(mockFetch).toHaveBeenCalledWith(expect.not.stringContaining('fiatAmount=100'))
expect(mockFetch).toHaveBeenCalledWith(expect.not.stringContaining('cryptoAmount=100'))
expect(mockFetch).toHaveBeenCalledWith(expect.stringContaining('fiatAmount=100'))
})
})
describe('loginWithFiatConnectProvider', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/fiatconnect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export async function getFiatConnectQuotes(
const quoteParams: CreateQuoteParams = {
fiatType,
cryptoType,
...(isUserInputCrypto(flow, digitalAsset)
...(isUserInputCrypto(flow)
? { cryptoAmount: cryptoAmount.toString() }
: { fiatAmount: fiatAmount.toString() }),
country,
Expand Down

0 comments on commit da51471

Please sign in to comment.