Skip to content

Commit

Permalink
fix(pins): Remove unnecessary "error" tag in "invalidPin" state; tran…
Browse files Browse the repository at this point in the history
…sfer machine.

- Renames 'ward' to 'other' for easier communication on menus.

Closes #68
  • Loading branch information
mango-habanero committed May 25, 2023
1 parent 38d71f1 commit cf8e0ad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/i18n/eng/pins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const eng_pins: NamespacePinsTranslation = {
pinChangeSuccess:
'CON Your PIN change request has been successful.\n0. Back\n9. Exit',
pinManagementMenu:
'CON PIN Management:\n1. Change PIN\n2. Reset ward\'s PIN\n3. Guard my PIN\n0. Back',
'CON PIN Management:\n1. Change PIN\n2. Reset other\'s PIN\n3. Guard my PIN\n0. Back',
socialRecoveryMenu:
'CON PIN guarding:\n1. Add guardian\n2. Remove guardian\n3. View guardians\n0. Back',
wardResetError:
Expand Down
9 changes: 5 additions & 4 deletions src/machines/pins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function saveValidatedWard(context: PinManagementContext, event: any) {
context.data = {
...(context.data || {}),
validatedWardEntry: {
language: event.data.language,
language: event.data.ward.language,
phoneNumber: event.data.ward.phoneNumber,
tag: event.data.ward.tag
}
Expand Down Expand Up @@ -330,8 +330,8 @@ async function initiateWardPinReset(context: PinManagementContext, event: any) {
const message = tSMS('pinReset', validatedWardEntry.language, { initiator: tag ? tag : phone_number })
await sendSMS(message, notifier, [validatedWardEntry.phoneNumber])
return { success: true }
} catch (error) {
throw new MachineError(PinsError.WARD_RESET_ERROR, "Failed to reset ward's PIN.")
} catch (error: any) {
throw new MachineError(PinsError.WARD_RESET_ERROR, error.message)
}
}

Expand All @@ -348,12 +348,13 @@ async function validateWardToReset(context: PinManagementContext, event: any) {
if (!guardian && !isSystemGuardian) {
throw new MachineError(PinsError.UNAUTHORIZED_GUARDIAN, "You are not a guardian of this account")
}
return { success: true, ward: { phoneNumber: wardPhoneNumber, tag: ward.tag } }
return { success: true, ward: { language: ward.account.language, phoneNumber: wardPhoneNumber, tag: ward.tag } }
}

export async function pinsTranslations(context: PinManagementContext, state: string, translator: any) {
const { data: { validatedWardEntry, wardEntry } } = context;
switch (state) {
case 'enteringPinWR':
case 'wardResetSuccess':
return await translate(state, translator, { ward: validatedWardEntry.tag });
case 'wardResetError':
Expand Down
4 changes: 1 addition & 3 deletions src/machines/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
MachineEvent,
MachineId, NotifierContext,
updateErrorMessages,
UserContext,
validateTargetUser
} from '@machines/utils';
import { isBlocked, isValidPin, validatePin } from '@machines/auth';
Expand Down Expand Up @@ -52,7 +51,7 @@ export const stateMachine = createMachine<TransferContext, MachineEvent>({
onError: [
{ target: 'accountBlocked', cond: 'isBlocked' },
{ target: 'transferError', cond: 'isTransferError', actions: 'updateErrorMessages' },
{ target: 'invalidPin' },
{ target: 'invalidPin', actions: 'updateErrorMessages' },
]
},
tags: 'invoked'
Expand Down Expand Up @@ -159,7 +158,6 @@ export const stateMachine = createMachine<TransferContext, MachineEvent>({
on: {
RETRY: 'enteringPin'
},
tags: 'error'
},
validatingRecipient: {
description: 'Invoked service that validates the recipient.',
Expand Down

0 comments on commit cf8e0ad

Please sign in to comment.