Skip to content

Commit

Permalink
fix(send): avoid showing invite modal for contacts that have an addre…
Browse files Browse the repository at this point in the history
…ss (#4462)

### Description

When a contact is selected and a CPV lookup is done for an address with
that contact's phone number, the recipient object given to the
SendAmount screen as a prop is not filled in with an address, even if an
address is found for them. Instead, their verification status is just
[updated](https://github.com/valora-inc/wallet/blob/9393d6a4bfd2e5425394e60710e275b0ce30f149/src/send/useFetchRecipientVerificationStatus.ts#L34)
to "VERIFIED" and the user is ushered along in the flow, and it is
expected that redux state is used later on to fill in the recipient
address. This breaks an assumption I made in #4415 that verified
recipients will always have addresses.

Note: contact address lookups for the "new" send flow are still broken,
but that is behind a feature flag and incomplete anyway. Since this bug
is on the release branch, we need to get a stopgap out sooner, and we
can follow up to fix the new flow later.

### Test plan

- jest
- tested manually to verify that invite modal does not erroneously
appear when an address exists for that PN

### Related issues

na

### Backwards compatibility

na
  • Loading branch information
cajubelt authored and jeanregisser committed Nov 13, 2023
1 parent 4d3fbe6 commit 1921fc1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
29 changes: 29 additions & 0 deletions src/send/Send.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import Send from 'src/send/Send'
import { getFeatureGate } from 'src/statsig'
import { createMockStore, getMockStackScreenProps } from 'test/utils'
import {
mockAccount,
mockAccount2,
mockCeloTokenId,
mockCusdTokenId,
mockE164Number,
Expand Down Expand Up @@ -200,6 +202,33 @@ describe('Send', () => {
expect(navigate).not.toHaveBeenCalled()
})

it('looks up a new phone number and navigates to send amount if it has two addresses', async () => {
const store = createMockStore({
...defaultStore,
identity: {
e164NumberToAddress: { [mockRecipient4.e164PhoneNumber]: [mockAccount, mockAccount2] },
},
})
const { getAllByTestId } = render(
<Provider store={store}>
<Send
{...mockScreenProps({
defaultTokenIdOverride: mockCeloTokenId,
})}
/>
</Provider>
)
fireEvent.press(getAllByTestId('RecipientItem')[2])

await waitFor(() => expect(navigate).toHaveBeenCalledTimes(1))
expect(navigate).toHaveBeenCalledWith(Screens.SendAmount, {
recipient: expect.objectContaining(mockRecipient4),
origin: SendOrigin.AppSendFlow,
defaultTokenIdOverride: mockCeloTokenId,
isFromScan: false,
})
})

it('uses old send flow by default', () => {
const store = createMockStore(defaultStore)

Expand Down
29 changes: 18 additions & 11 deletions src/send/Send.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ import { TokenBalance } from 'src/tokens/slice'
import { sortFirstStableThenCeloThenOthersByUsdBalance } from 'src/tokens/utils'
import { navigateToPhoneSettings } from 'src/utils/linking'
import { requestContactsPermission } from 'src/utils/permissions'
import Logger from 'src/utils/Logger'

const SEARCH_THROTTLE_TIME = 100
const TAG = 'send/Send'

type Props = NativeStackScreenProps<StackParamList, Screens.Send>

Expand Down Expand Up @@ -126,22 +128,27 @@ function Send({ route }: Props) {
// interfere with the invite modal or bottom sheet.
Keyboard.dismiss()

if (
recipientVerificationStatus === RecipientVerificationStatus.UNVERIFIED ||
!hasAddressField(recipient) // should already be caught by UNVERIFIED and UNKNOWN checks, but doing this to be safe and to satisfy the TS compiler
) {
if (recipientVerificationStatus === RecipientVerificationStatus.UNVERIFIED) {
setShowInviteModal(true)
return
}

if (getFeatureGate(StatsigFeatureGates.USE_NEW_SEND_FLOW)) {
navigate(Screens.SendEnterAmount, {
isFromScan: false,
defaultTokenIdOverride,
forceTokenId,
recipient,
origin: SendOrigin.AppSendFlow,
})
if (hasAddressField(recipient)) {
navigate(Screens.SendEnterAmount, {
isFromScan: false,
defaultTokenIdOverride,
forceTokenId,
recipient,
origin: SendOrigin.AppSendFlow,
})
} else {
// TODO(cajubelt): get the recipient address before navigating to SendEnterAmount
Logger.error(
TAG,
'Recipient does not have address field. Cannot continue with new send flow'
)
}
} else if (defaultTokenIdOverride) {
navigate(Screens.SendAmount, {
isFromScan: false,
Expand Down

0 comments on commit 1921fc1

Please sign in to comment.