Skip to content

Commit

Permalink
Merge branch 'main' into cajubelt/transfer-with-comments-fee-previews
Browse files Browse the repository at this point in the history
  • Loading branch information
cajubelt authored Nov 6, 2023
2 parents 6a4ec4a + c24cb9d commit c9a4d69
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/fiatExchanges/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import Logger from 'src/utils/Logger'
import { Currency } from 'src/utils/currencies'
import {
mockAccount,
mockCusdAddress,
mockCusdTokenId,
mockCeurAddress,
mockCeurTokenId,
mockCusdAddress,
mockCusdTokenId,
} from 'test/values'

const now = Date.now()
Expand Down Expand Up @@ -105,7 +105,7 @@ describe(watchBidaliPaymentRequests, () => {
}
)
)
.dispatch(sendPaymentSuccess(amount))
.dispatch(sendPaymentSuccess({ amount, tokenId: expectedTokenId }))
.run()

expect(navigate).toHaveBeenCalledWith(Screens.SendConfirmationModal, {
Expand Down
10 changes: 9 additions & 1 deletion src/send/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface SendPaymentAction {
export interface SendPaymentSuccessAction {
type: Actions.SEND_PAYMENT_SUCCESS
amount: BigNumber
tokenId: string
}

export interface SendPaymentFailureAction {
Expand Down Expand Up @@ -113,9 +114,16 @@ export const sendPayment = (
feeInfo,
})

export const sendPaymentSuccess = (amount: BigNumber): SendPaymentSuccessAction => ({
export const sendPaymentSuccess = ({
amount,
tokenId,
}: {
amount: BigNumber
tokenId: string
}): SendPaymentSuccessAction => ({
type: Actions.SEND_PAYMENT_SUCCESS,
amount,
tokenId,
})

export const sendPaymentFailure = (): SendPaymentFailureAction => ({
Expand Down
3 changes: 1 addition & 2 deletions src/send/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ export const sendReducer = (
...state,
isSending: false,
recentPayments: [...paymentsLast24Hours, latestPayment],
// TODO(satish): set lastUsedToken once this is available in the send flow (after
// #4306 is merged)
lastUsedTokenId: action.tokenId,
}
case Actions.SEND_PAYMENT_FAILURE:
return {
Expand Down
4 changes: 2 additions & 2 deletions src/send/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import { StatsigFeatureGates } from 'src/statsig/types'
import {
getERC20TokenContract,
getStableTokenContract,
getTokenInfo,
getTokenInfoByAddress,
tokenAmountInSmallestUnit,
getTokenInfo,
} from 'src/tokens/saga'
import { TokenBalance } from 'src/tokens/slice'
import { getTokenId } from 'src/tokens/utils'
Expand Down Expand Up @@ -298,7 +298,7 @@ export function* sendPaymentSaga({
navigateHome()
}

yield* put(sendPaymentSuccess(amount))
yield* put(sendPaymentSuccess({ amount, tokenId }))
SentryTransactionHub.finishTransaction(SentryTransaction.send_payment)
} catch (e) {
yield* put(showErrorOrFallback(e, ErrorMessages.SEND_PAYMENT_FAILED))
Expand Down
46 changes: 42 additions & 4 deletions src/tokens/TokenDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@ import { CICOFlow } from 'src/fiatExchanges/utils'
import { navigate } from 'src/navigator/NavigationService'
import { Screens } from 'src/navigator/Screens'
import TokenDetailsScreen from 'src/tokens/TokenDetails'
import { Network } from 'src/transactions/types'
import { Network, NetworkId } from 'src/transactions/types'
import { CiCoCurrency } from 'src/utils/currencies'
import { ONE_DAY_IN_MILLIS } from 'src/utils/time'
import MockedNavigator from 'test/MockedNavigator'
import { createMockStore } from 'test/utils'
import {
exchangePriceHistory,
mockCeloTokenId,
mockEthTokenId,
mockPoofTokenId,
mockTokenBalances,
} from 'test/values'

jest.mock('src/statsig', () => ({
getDynamicConfigParams: jest.fn(() => {
return {
showCico: ['celo-alfajores'],
showSend: ['celo-alfajores'],
showSwap: ['celo-alfajores'],
showCico: ['celo-alfajores', 'ethereum-sepolia'],
showSend: ['celo-alfajores', 'ethereum-sepolia'],
showSwap: ['celo-alfajores', 'ethereum-sepolia'],
}
}),
}))
Expand Down Expand Up @@ -372,4 +373,41 @@ describe('TokenDetails', () => {
expect(navigate).toHaveBeenCalledWith(Screens.WithdrawSpend)
expect(ValoraAnalytics.track).toHaveBeenCalledTimes(5) // 4 actions + 1 more action
})

// TODO(ACT-954): remove once we switch to passing just token ids, above test
// should be sufficient
it('add action sends appropriate network', async () => {
const store = createMockStore({
tokens: {
tokenBalances: {
[mockEthTokenId]: {
symbol: 'ETH',
balance: '0',
showZeroBalance: true,
isCashInEligible: true,
tokenId: mockEthTokenId,
networkId: NetworkId['ethereum-sepolia'],
},
},
},
app: {
showSwapMenuInDrawerMenu: true,
},
})

const { getByTestId } = render(
<Provider store={store}>
<MockedNavigator component={TokenDetailsScreen} params={{ tokenId: mockEthTokenId }} />
</Provider>
)

fireEvent.press(getByTestId('TokenDetails/Action/Add'))
expect(navigate).toHaveBeenCalledWith(Screens.FiatExchangeAmount, {
currency: CiCoCurrency.ETH,
tokenId: mockEthTokenId,
flow: CICOFlow.CashIn,
network: Network.Ethereum,
})
expect(ValoraAnalytics.track).toHaveBeenCalledTimes(1)
})
})
5 changes: 3 additions & 2 deletions src/tokens/TokenDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import {
import { TokenBalance } from 'src/tokens/slice'
import { TokenDetailsAction, TokenDetailsActionName } from 'src/tokens/types'
import { getTokenAnalyticsProps, isCicoToken, isHistoricalPriceUpdated } from 'src/tokens/utils'
import { Network } from 'src/transactions/types'
import { networkIdToNetwork } from 'src/web3/networkConfig'

type Props = NativeStackScreenProps<StackParamList, Screens.TokenDetails>

Expand Down Expand Up @@ -194,10 +194,11 @@ export const useActions = (token: TokenBalance) => {
// token is CiCoCurrency, but adding it here to ensure type safety
if (isCicoToken(tokenSymbol)) {
navigate(Screens.FiatExchangeAmount, {
// TODO(ACT-954): only pass token id
currency: tokenSymbol,
tokenId: token.tokenId,
flow: CICOFlow.CashIn,
network: Network.Celo, // TODO (ACT-954): use networkId from token
network: networkIdToNetwork[token.networkId],
})
}
},
Expand Down

0 comments on commit c9a4d69

Please sign in to comment.