diff --git a/handlers/application/menuhandler.go b/handlers/application/menuhandler.go index 3077ef2..26cf13a 100644 --- a/handlers/application/menuhandler.go +++ b/handlers/application/menuhandler.go @@ -186,10 +186,16 @@ func (h *MenuHandlers) SetLanguage(ctx context.Context, sym string, input []byte // handles the account creation when no existing account is present for the session and stores associated data in the user data store. func (h *MenuHandlers) createAccountNoExist(ctx context.Context, sessionId string, res *resource.Result) error { flag_account_created, _ := h.flagManager.GetFlag("flag_account_created") + flag_account_creation_failed, _ := h.flagManager.GetFlag("flag_account_creation_failed") + r, err := h.accountService.CreateAccount(ctx) if err != nil { - return err + res.FlagSet = append(res.FlagSet, flag_account_creation_failed) + logg.ErrorCtxf(ctx, "failed to create an account", "error", err) + return nil } + res.FlagReset = append(res.FlagReset, flag_account_creation_failed) + trackingId := r.TrackingId publicKey := r.PublicKey @@ -487,6 +493,14 @@ func (h *MenuHandlers) ResetInvalidPIN(ctx context.Context, sym string, input [] return res, nil } +// ResetApiCallFailure resets the api call failure flag +func (h *MenuHandlers) ResetApiCallFailure(ctx context.Context, sym string, input []byte) (resource.Result, error) { + var res resource.Result + flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error") + res.FlagReset = append(res.FlagReset, flag_api_error) + return res, nil +} + // ConfirmPinChange validates user's new PIN. If input matches the temporary PIN, saves it as the new account PIN. func (h *MenuHandlers) ConfirmPinChange(ctx context.Context, sym string, input []byte) (resource.Result, error) { var res resource.Result @@ -1403,7 +1417,7 @@ func (h *MenuHandlers) CheckAccountStatus(ctx context.Context, sym string, input if err != nil { res.FlagSet = append(res.FlagSet, flag_api_error) logg.ErrorCtxf(ctx, "failed on TrackAccountStatus", "error", err) - return res, err + return res, nil } res.FlagReset = append(res.FlagReset, flag_api_error) @@ -1569,6 +1583,7 @@ func (h *MenuHandlers) ValidateRecipient(ctx context.Context, sym string, input } flag_invalid_recipient, _ := h.flagManager.GetFlag("flag_invalid_recipient") flag_invalid_recipient_with_invite, _ := h.flagManager.GetFlag("flag_invalid_recipient_with_invite") + flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error") recipient := string(input) @@ -1642,10 +1657,13 @@ func (h *MenuHandlers) ValidateRecipient(ctx context.Context, sym string, input logg.InfoCtxf(ctx, "Resolving with fqdn alias", "alias", fqdn) AliasAddress, err = h.accountService.CheckAliasAddress(ctx, fqdn) if err == nil { + res.FlagReset = append(res.FlagReset, flag_api_error) AliasAddressResult = AliasAddress.Address continue } else { + res.FlagSet = append(res.FlagSet, flag_api_error) logg.ErrorCtxf(ctx, "failed to resolve alias", "alias", recipient, "error_alias_check", err) + return res, nil } } } @@ -1960,6 +1978,7 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b } flag_no_active_voucher, _ := h.flagManager.GetFlag("flag_no_active_voucher") + flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error") publicKey, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY) if err != nil { @@ -1970,9 +1989,10 @@ func (h *MenuHandlers) ManageVouchers(ctx context.Context, sym string, input []b // Fetch vouchers from API vouchersResp, err := h.accountService.FetchVouchers(ctx, string(publicKey)) if err != nil { - res.FlagSet = append(res.FlagSet, flag_no_active_voucher) + res.FlagSet = append(res.FlagSet, flag_api_error) return res, nil } + res.FlagReset = append(res.FlagReset, flag_api_error) if len(vouchersResp) == 0 { res.FlagSet = append(res.FlagSet, flag_no_active_voucher) @@ -2183,6 +2203,7 @@ func (h *MenuHandlers) GetVoucherDetails(ctx context.Context, sym string, input res.FlagSet = append(res.FlagSet, flag_api_error) return res, nil } + res.FlagReset = append(res.FlagReset, flag_api_error) res.Content = fmt.Sprintf( "Name: %s\nSymbol: %s\nCommodity: %s\nLocation: %s", voucherData.TokenName, voucherData.TokenSymbol, voucherData.TokenCommodity, voucherData.TokenLocation, @@ -2216,6 +2237,7 @@ func (h *MenuHandlers) CheckTransactions(ctx context.Context, sym string, input logg.ErrorCtxf(ctx, "failed on FetchTransactions", "error", err) return res, err } + res.FlagReset = append(res.FlagReset, flag_api_error) // Return if there are no transactions if len(transactionsResp) == 0 { @@ -2453,6 +2475,8 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input return res, nil } + flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error") + store := h.userdataStore aliasHint, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE) if err != nil { @@ -2476,9 +2500,12 @@ func (h *MenuHandlers) RequestCustomAlias(ctx context.Context, sym string, input sanitizedInput := sanitizeAliasHint(string(input)) aliasResult, err := h.accountService.RequestAlias(ctx, string(pubKey), sanitizedInput) if err != nil { + res.FlagSet = append(res.FlagSet, flag_api_error) logg.ErrorCtxf(ctx, "failed to retrieve alias", "alias", string(aliasHint), "error_alias_request", err) - return res, fmt.Errorf("Failed to retrieve alias: %s", err.Error()) + return res, nil } + res.FlagReset = append(res.FlagReset, flag_api_error) + alias := aliasResult.Alias logg.InfoCtxf(ctx, "Suggested alias ", "alias", alias) diff --git a/handlers/application/menuhandler_test.go b/handlers/application/menuhandler_test.go index 1a3789b..e3fd124 100644 --- a/handlers/application/menuhandler_test.go +++ b/handlers/application/menuhandler_test.go @@ -201,6 +201,8 @@ func TestCreateAccount(t *testing.T) { } flag_account_created, err := fm.GetFlag("flag_account_created") + flag_account_creation_failed, _ := fm.GetFlag("flag_account_creation_failed") + if err != nil { t.Logf(err.Error()) } @@ -217,7 +219,8 @@ func TestCreateAccount(t *testing.T) { PublicKey: "0xD3adB33f", }, expectedResult: resource.Result{ - FlagSet: []uint32{flag_account_created}, + FlagSet: []uint32{flag_account_created}, + FlagReset: []uint32{flag_account_creation_failed}, }, }, } @@ -2002,6 +2005,11 @@ func TestManageVouchers(t *testing.T) { t.Fatal(err) } flag_no_active_voucher, err := fm.GetFlag("flag_no_active_voucher") + if err != nil { + t.Fatal(err) + } + flag_api_error, err := fm.GetFlag("flag_api_call_error") + if err != nil { t.Fatal(err) } @@ -2025,7 +2033,8 @@ func TestManageVouchers(t *testing.T) { expectedVoucherSymbols: []byte(""), expectedUpdatedAddress: []byte(""), expectedResult: resource.Result{ - FlagSet: []uint32{flag_no_active_voucher}, + FlagSet: []uint32{flag_no_active_voucher}, + FlagReset: []uint32{flag_api_error}, }, }, { @@ -2041,7 +2050,7 @@ func TestManageVouchers(t *testing.T) { expectedVoucherSymbols: []byte("1:TOKEN1"), expectedUpdatedAddress: []byte("0x123"), expectedResult: resource.Result{ - FlagReset: []uint32{flag_no_active_voucher}, + FlagReset: []uint32{flag_api_error, flag_no_active_voucher}, }, }, { @@ -2054,7 +2063,7 @@ func TestManageVouchers(t *testing.T) { expectedVoucherSymbols: []byte("1:SRF\n2:MILO"), expectedUpdatedAddress: []byte("0xd4c288865Ce"), expectedResult: resource.Result{ - FlagReset: []uint32{flag_no_active_voucher}, + FlagReset: []uint32{flag_api_error, flag_no_active_voucher}, }, }, } @@ -2205,6 +2214,8 @@ func TestGetVoucherDetails(t *testing.T) { if err != nil { t.Logf(err.Error()) } + + flag_api_error, _ := fm.GetFlag("flag_api_call_error") mockAccountService := new(mocks.MockAccountService) sessionId := "session123" @@ -2232,8 +2243,8 @@ func TestGetVoucherDetails(t *testing.T) { "Name: %s\nSymbol: %s\nCommodity: %s\nLocation: %s", tokenDetails.TokenName, tokenDetails.TokenSymbol, tokenDetails.TokenCommodity, tokenDetails.TokenLocation, ) mockAccountService.On("VoucherData", string(tokA_AAddress)).Return(tokenDetails, nil) - res, err := h.GetVoucherDetails(ctx, "SessionId", []byte("")) + expectedResult.FlagReset = append(expectedResult.FlagReset, flag_api_error) assert.NoError(t, err) assert.Equal(t, expectedResult, res) } diff --git a/handlers/local.go b/handlers/local.go index 3116b66..2d65d21 100644 --- a/handlers/local.go +++ b/handlers/local.go @@ -128,6 +128,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService) ls.DbRs.AddLocalFunc("get_suggested_alias", appHandlers.GetSuggestedAlias) ls.DbRs.AddLocalFunc("confirm_new_alias", appHandlers.ConfirmNewAlias) ls.DbRs.AddLocalFunc("check_account_created", appHandlers.CheckAccountCreated) + ls.DbRs.AddLocalFunc("reset_api_call_failure", appHandlers.ResetApiCallFailure) ls.first = appHandlers.Init diff --git a/menutraversal_test/group_test.json b/menutraversal_test/group_test.json index b3177a9..99958dd 100644 --- a/menutraversal_test/group_test.json +++ b/menutraversal_test/group_test.json @@ -612,7 +612,7 @@ }, { "input": "1234", - "expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 80\nLocation: Kilifi\nYou provide: Bananas\nYour alias: \n\n0:Back\n9:Quit" + "expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 80\nLocation: Kilifi\nYou provide: Bananas\nYour alias: Not Provided\n\n0:Back\n9:Quit" }, { "input": "0", diff --git a/services/registration/amount.vis b/services/registration/amount.vis index 10d4430..ac3abd1 100644 --- a/services/registration/amount.vis +++ b/services/registration/amount.vis @@ -6,7 +6,6 @@ MOUT back 0 HALT LOAD validate_amount 64 RELOAD validate_amount -CATCH api_failure flag_api_call_error 1 CATCH invalid_amount flag_invalid_amount 1 INCMP _ 0 LOAD get_recipient 0 diff --git a/services/registration/api_failure b/services/registration/api_failure index 06d2d9e..915b7fc 100644 --- a/services/registration/api_failure +++ b/services/registration/api_failure @@ -1 +1 @@ -Failed to connect to the custodial service.Please try again. \ No newline at end of file +Failed to connect to the custodial service .Please try again. \ No newline at end of file diff --git a/services/registration/api_failure.vis b/services/registration/api_failure.vis index 37b3deb..469b5db 100644 --- a/services/registration/api_failure.vis +++ b/services/registration/api_failure.vis @@ -1,5 +1,7 @@ +LOAD reset_api_call_failure 6 +RELOAD reset_api_call_failure MOUT retry 1 MOUT quit 9 HALT -INCMP _ 1 +INCMP ^ 1 INCMP quit 9 diff --git a/services/registration/api_failure_swa b/services/registration/api_failure_swa new file mode 100644 index 0000000..fb24f2c --- /dev/null +++ b/services/registration/api_failure_swa @@ -0,0 +1 @@ +Imeshindwa kuunganisha kwenye huduma ya uangalizi. Tafadhali jaribu tena. \ No newline at end of file diff --git a/services/registration/check_statement.vis b/services/registration/check_statement.vis index d79b5ca..c393a0a 100644 --- a/services/registration/check_statement.vis +++ b/services/registration/check_statement.vis @@ -1,5 +1,6 @@ LOAD check_transactions 0 RELOAD check_transactions +CATCH api_failure flag_api_call_error 1 CATCH no_transfers flag_no_transfers 1 LOAD authorize_account 6 MOUT back 0 diff --git a/services/registration/main.vis b/services/registration/main.vis index cda6844..efa8b2a 100644 --- a/services/registration/main.vis +++ b/services/registration/main.vis @@ -2,6 +2,7 @@ LOAD clear_temporary_value 2 RELOAD clear_temporary_value LOAD manage_vouchers 160 RELOAD manage_vouchers +CATCH api_failure flag_api_call_error 1 LOAD check_balance 128 RELOAD check_balance CATCH api_failure flag_api_call_error 1 diff --git a/services/registration/my_account_alias.vis b/services/registration/my_account_alias.vis index 506f432..1a6894f 100644 --- a/services/registration/my_account_alias.vis +++ b/services/registration/my_account_alias.vis @@ -5,4 +5,5 @@ HALT INCMP _ 0 LOAD request_custom_alias 0 RELOAD request_custom_alias +CATCH api_failure flag_api_call_error 1 INCMP confirm_new_alias * diff --git a/services/registration/send.vis b/services/registration/send.vis index 369bb67..dfdcd70 100644 --- a/services/registration/send.vis +++ b/services/registration/send.vis @@ -5,6 +5,7 @@ MOUT back 0 HALT LOAD validate_recipient 50 RELOAD validate_recipient +CATCH api_failure flag_api_call_error 1 CATCH invalid_recipient flag_invalid_recipient 1 CATCH invite_recipient flag_invalid_recipient_with_invite 1 INCMP _ 0 diff --git a/services/registration/voucher_details.vis b/services/registration/voucher_details.vis index 1b009f1..628e034 100644 --- a/services/registration/voucher_details.vis +++ b/services/registration/voucher_details.vis @@ -1,5 +1,7 @@ CATCH no_voucher flag_no_active_voucher 1 LOAD get_voucher_details 0 +RELOAD get_voucher_details +CATCH api_failure flag_api_call_error 1 MAP get_voucher_details MOUT back 0 HALT