menu-voucherlist #101

Merged
lash merged 63 commits from menu-voucherlist into master 2024-10-25 15:59:47 +02:00
6 changed files with 22 additions and 7 deletions
Showing only changes of commit 25bc7006a4 - Show all commits

View File

@ -624,7 +624,7 @@ func (h *Handlers) ResetIncorrectYob(ctx context.Context, sym string, input []by
return res, nil
}
// CheckBalance retrieves the balance from the API using the "PublicKey" and sets
// CheckBalance retrieves the balance of the active voucher and sets
// the balance as the result content
func (h *Handlers) CheckBalance(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result
@ -640,12 +640,13 @@ func (h *Handlers) CheckBalance(ctx context.Context, sym string, input []byte) (
// get the active sym and active balance
activeSym, err := store.ReadEntry(ctx, sessionId, utils.DATA_ACTIVE_SYM)
if err != nil {
Alfred-mk marked this conversation as resolved Outdated
Outdated
Review

If no active sym then the user has no vouchers yet, and then no balance should be displayed, I think?

If no active sym then the user has no vouchers yet, and then no balance should be displayed, I think?

For this, I've added a function that sets the default voucher, (expecting it to be SRF) if no active voucher is set for the user.

This will be loaded on the main.vis, ensuring that one has the default sym if they haven't set their own

For this, I've added a function that sets the default voucher, (expecting it to be SRF) if no active voucher is set for the user. This will be loaded on the main.vis, ensuring that one has the default sym if they haven't set their own
return res, err
res.Content = "0.00"
lash marked this conversation as resolved Outdated
Outdated
Review

Why should it be 0.00 when error?

Why should it be 0.00 when error?

The 0.00 is a placeholder. I set it like this without a symbol since the error indicates no symbol exists.

I have updated this to check the specific db error

The 0.00 is a placeholder. I set it like this without a symbol since the error indicates no symbol exists. I have updated this to check the specific db error
return res, nil
}
activeBal, err := store.ReadEntry(ctx, sessionId, utils.DATA_ACTIVE_BAL)
if err != nil {
return res, err
return res, nil
}
res.Content = fmt.Sprintf("%s %s", activeBal, activeSym)
@ -991,6 +992,8 @@ func (h *Handlers) SetDefaultVoucher(ctx context.Context, sym string, input []by
return res, fmt.Errorf("missing session")
}
flag_no_active_voucher, _ := h.flagManager.GetFlag("flag_no_active_voucher")
// check if the user has an active sym
_, err = store.ReadEntry(ctx, sessionId, utils.DATA_ACTIVE_SYM)
@ -1008,9 +1011,10 @@ func (h *Handlers) SetDefaultVoucher(ctx context.Context, sym string, input []by
return res, nil
}
// Ensure there is at least one voucher
// Return if there is no voucher
if len(vouchersResp.Result.Holdings) == 0 {
return res, err
res.FlagSet = append(res.FlagSet, flag_no_active_voucher)
return res, nil
}
// Use only the first voucher
@ -1035,6 +1039,8 @@ func (h *Handlers) SetDefaultVoucher(ctx context.Context, sym string, input []by
return res, err
}
res.FlagReset = append(res.FlagReset, flag_no_active_voucher)
return res, nil
}

View File

@ -0,0 +1 @@
You need a voucher to send

View File

@ -0,0 +1,5 @@
MOUT back 0
MOUT quit 9
HALT
INCMP ^ 0
INCMP quit 9

View File

@ -0,0 +1 @@
Unahitaji sarafu kutuma

View File

@ -16,3 +16,4 @@ flag,flag_single_edit,22,this is set to allow a user to edit a single profile it
flag,flag_incorrect_date_format,23,this is set when the given year of birth is invalid
flag,flag_incorrect_voucher,24,this is set when the selected voucher is invalid
flag,flag_api_call_error,25,this is set when communication to an external service fails
flag,flag_no_active_voucher,26,this is set when a user does not have an active voucher

1 flag flag_language_set 8 checks whether the user has set their prefered language
16 flag flag_incorrect_date_format 23 this is set when the given year of birth is invalid
17 flag flag_api_call_error flag_incorrect_voucher 25 24 this is set when communication to an external service fails this is set when the selected voucher is invalid
18 flag flag_api_call_error 25 this is set when communication to an external service fails
19 flag flag_no_active_voucher 26 this is set when a user does not have an active voucher

View File

@ -1,4 +1,5 @@
LOAD transaction_reset 0
CATCH no_voucher flag_no_active_voucher 1
MOUT back 0
HALT
LOAD validate_recipient 20