Skip to content

Commit

Permalink
[Wallet] fix attestation codes being wrongly set as completed (#4557)
Browse files Browse the repository at this point in the history
### Description

Fix a bug, described in details here - #4477 (comment)

### Other changes

* Remove error toast, when verification fails, cause we show Modal instead.
* Fix a bug, when user presses `Enter Codes` on the error modal but nothing happens until timer has elapsed.

### Tested

iOS simulator

### Related issues

- Fixes #4477

### Backwards compatibility

Yes
  • Loading branch information
i1skn authored Jul 29, 2020
1 parent c4e0ede commit 84ae9fb
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/mobile/locales/en-US/nuxVerification2.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"body2InsufficientBalance": "Please try again when you have added funds to your wallet.",
"body1SaltQuotaExceeded": "Your phone number lookup quota is used up",
"body2SaltQuotaExceeded": "Please try again when you have purchased more lookups",
"enterCodesBody": " If you already received three codes via SMS, you can still enter them.",
"enterCodesBody": "If you already received three codes via SMS, you can still enter them.",
"enterCodesButton": "Enter Codes"
},
"retryWithFornoModal": {
Expand Down
2 changes: 1 addition & 1 deletion packages/mobile/locales/es-419/nuxVerification2.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"body2InsufficientBalance": "Intente nuevamente cuando haya agregado fondos a su billetera.",
"body1SaltQuotaExceeded": "Su cuota de búsqueda de número de teléfono está agotada",
"body2SaltQuotaExceeded": "Intente nuevamente cuando haya comprado más búsquedas",
"enterCodesBody": " Si ya recibió tres códigos por SMS, aún puede ingresarlos.",
"enterCodesBody": "Si ya recibió tres códigos por SMS, aún puede ingresarlos.",
"enterCodesButton": "Ingresar códigos"
},
"retryWithFornoModal": {
Expand Down
20 changes: 15 additions & 5 deletions packages/mobile/src/identity/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export enum Actions {
RESET_VERIFICATION = 'IDENTITY/RESET_VERIFICATION',
SET_VERIFICATION_STATUS = 'IDENTITY/SET_VERIFICATION_STATUS',
SET_SEEN_VERIFICATION_NUX = 'IDENTITY/SET_SEEN_VERIFICATION_NUX',
SET_COMPLETED_CODES = 'IDENTITY/SET_COMPLETED_CODES',
REVOKE_VERIFICATION = 'IDENTITY/REVOKE_VERIFICATION',
RECEIVE_ATTESTATION_MESSAGE = 'IDENTITY/RECEIVE_ATTESTATION_MESSAGE',
INPUT_ATTESTATION_CODE = 'IDENTITY/INPUT_ATTESTATION_CODE',
Expand Down Expand Up @@ -69,14 +70,19 @@ export interface ReceiveAttestationMessageAction {
inputType: CodeInputType
}

export interface SetCompletedCodesAction {
type: Actions.SET_COMPLETED_CODES
numComplete: number
}

export interface InputAttestationCodeAction {
type: Actions.INPUT_ATTESTATION_CODE
code: AttestationCode
}

export interface CompleteAttestationCodeAction {
type: Actions.COMPLETE_ATTESTATION_CODE
numComplete: number
code: AttestationCode
}

export interface UpdateE164PhoneNumberAddressesAction {
Expand Down Expand Up @@ -173,6 +179,7 @@ export type ActionTypes =
| ResetVerificationAction
| SetVerificationStatusAction
| SetHasSeenVerificationNux
| SetCompletedCodesAction
| ReceiveAttestationMessageAction
| InputAttestationCodeAction
| CompleteAttestationCodeAction
Expand Down Expand Up @@ -227,16 +234,19 @@ export const receiveAttestationMessage = (
inputType,
})

export const setCompletedCodes = (numComplete: number): SetCompletedCodesAction => ({
type: Actions.SET_COMPLETED_CODES,
numComplete,
})

export const inputAttestationCode = (code: AttestationCode): InputAttestationCodeAction => ({
type: Actions.INPUT_ATTESTATION_CODE,
code,
})

export const completeAttestationCode = (
numComplete: number = 1
): CompleteAttestationCodeAction => ({
export const completeAttestationCode = (code: AttestationCode): CompleteAttestationCodeAction => ({
type: Actions.COMPLETE_ATTESTATION_CODE,
numComplete,
code,
})

export const fetchAddressesAndValidate = (
Expand Down
14 changes: 8 additions & 6 deletions packages/mobile/src/identity/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,26 +119,28 @@ export const reducer = (
return {
...state,
verificationStatus: action.status,
// Reset accepted codes on fail otherwise there's no way for user
// to try again with same codes
acceptedAttestationCodes:
action.status === VerificationStatus.Failed ? [] : state.acceptedAttestationCodes,
}
case Actions.SET_SEEN_VERIFICATION_NUX:
return {
...state,
hasSeenVerificationNux: action.status,
}
case Actions.SET_COMPLETED_CODES:
return {
...state,
...completeCodeReducer(state, action.numComplete),
}

case Actions.INPUT_ATTESTATION_CODE:
return {
...state,
attestationCodes: [...state.attestationCodes, action.code],
acceptedAttestationCodes: [...state.acceptedAttestationCodes, action.code],
}
case Actions.COMPLETE_ATTESTATION_CODE:
return {
...state,
...completeCodeReducer(state, state.numCompleteAttestations + action.numComplete),
...completeCodeReducer(state, state.numCompleteAttestations + 1),
acceptedAttestationCodes: [...state.acceptedAttestationCodes, action.code],
}
case Actions.UPDATE_E164_PHONE_NUMBER_ADDRESSES:
return {
Expand Down
12 changes: 7 additions & 5 deletions packages/mobile/src/identity/verification.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ErrorMessages } from 'src/app/ErrorMessages'
import {
cancelVerification,
completeAttestationCode,
setCompletedCodes,
setVerificationStatus,
} from 'src/identity/actions'
import { fetchPhoneHashPrivate } from 'src/identity/privateHashing'
Expand Down Expand Up @@ -225,11 +226,12 @@ describe('Do Verification Saga', () => {
])
.put(setVerificationStatus(VerificationStatus.Prepping))
.put(setVerificationStatus(VerificationStatus.GettingStatus))
.put(setCompletedCodes(0))
.put(setVerificationStatus(VerificationStatus.RequestingAttestations))
.put(setVerificationStatus(VerificationStatus.RevealingNumber))
.put(completeAttestationCode())
.put(completeAttestationCode())
.put(completeAttestationCode())
.put(completeAttestationCode(attestationCode0))
.put(completeAttestationCode(attestationCode1))
.put(completeAttestationCode(attestationCode2))
.put(setVerificationStatus(VerificationStatus.Done))
.put(setNumberVerified(true))
.returns(true)
Expand All @@ -255,7 +257,8 @@ describe('Do Verification Saga', () => {
[call(balanceSufficientForAttestations, mockAttestationsRemainingForPartialVerified), true],
[select(attestationCodesSelector), attestationCodes],
])
.put(completeAttestationCode())
.put(setCompletedCodes(2))
.put(completeAttestationCode(attestationCode0))
.put(setVerificationStatus(VerificationStatus.Done))
.put(setNumberVerified(true))
.returns(true)
Expand Down Expand Up @@ -355,7 +358,6 @@ describe('Do Verification Saga', () => {
[call(balanceSufficientForAttestations, mockAttestationsRemainingForPartialVerified), true],
[select(attestationCodesSelector), attestationCodes],
])
.put(showError(ErrorMessages.REVEAL_ATTESTATION_FAILURE))
.put(setVerificationStatus(VerificationStatus.RevealAttemptFailed))
.run()
})
Expand Down
8 changes: 3 additions & 5 deletions packages/mobile/src/identity/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
InputAttestationCodeAction,
ReceiveAttestationMessageAction,
resetVerification,
setCompletedCodes,
setVerificationStatus,
} from 'src/identity/actions'
import { fetchPhoneHashPrivate, PhoneNumberHashDetails } from 'src/identity/privateHashing'
Expand Down Expand Up @@ -154,9 +155,7 @@ export function* doVerificationFlow() {
}

// Mark codes completed in previous attempts
yield put(
completeAttestationCode(NUM_ATTESTATIONS_REQUIRED - status.numAttestationsRemaining)
)
yield put(setCompletedCodes(NUM_ATTESTATIONS_REQUIRED - status.numAttestationsRemaining))

yield put(setVerificationStatus(VerificationStatus.RequestingAttestations))

Expand Down Expand Up @@ -516,7 +515,7 @@ function* revealAndCompleteAttestation(

ValoraAnalytics.track(VerificationEvents.verification_reveal_attestation_complete, { issuer })

yield put(completeAttestationCode())
yield put(completeAttestationCode(code))
Logger.debug(TAG + '@revealAttestation', `Attestation for issuer ${issuer} completed`)
}

Expand Down Expand Up @@ -609,7 +608,6 @@ function* tryRevealPhoneNumber(
issuer,
error: error.message,
})
yield put(showError(ErrorMessages.REVEAL_ATTESTATION_FAILURE))
yield put(setVerificationStatus(VerificationStatus.RevealAttemptFailed))
}
}
Expand Down
11 changes: 11 additions & 0 deletions packages/mobile/src/redux/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,15 @@ describe('Redux persist migrations', () => {
const migratedSchema = migrations[3](v2Stub)
expect(migratedSchema.send.recentPayments.length).toEqual(0)
})
it('works for v3 to v4', () => {
const v3Stub = {
...v2Schema,
identity: {
...v2Schema.identity,
acceptedAttestationCodes: [{ code: 'code', issuer: 'issuer' }],
},
}
const migratedSchema = migrations[4](v3Stub)
expect(migratedSchema.identity.acceptedAttestationCodes.length).toEqual(0)
})
})
9 changes: 9 additions & 0 deletions packages/mobile/src/redux/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,13 @@ export const migrations = {
},
}
},
4: (state: any) => {
return {
...state,
identity: {
...state.identity,
acceptedAttestationCodes: [],
},
}
},
}
2 changes: 1 addition & 1 deletion packages/mobile/src/redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { rootSaga } from 'src/redux/sagas'

const persistConfig: any = {
key: 'root',
version: 3, // default is -1, increment as we make migrations
version: 4, // default is -1, increment as we make migrations
storage: AsyncStorage,
blacklist: ['home', 'geth', 'networkInfo', 'alert', 'fees', 'recipients', 'imports'],
stateReconciler: autoMergeLevel2,
Expand Down
1 change: 1 addition & 0 deletions packages/mobile/src/verify/VerificationFailedModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export function VerificationFailedModal({ verificationStatus, retryWithForno, fo

const onDismiss = () => {
setIsDismissed(true)
navigate(Screens.VerificationInputScreen)
}

const onSkip = () => {
Expand Down

0 comments on commit 84ae9fb

Please sign in to comment.