add temp and active balance
This commit is contained in:
parent
9ad7d5a522
commit
7c08a0f0af
@ -1123,6 +1123,10 @@ func (h *Handlers) ViewVoucher(ctx context.Context, sym string, input []byte) (r
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_BAL, []byte(matchedBalance))
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
res.Content = fmt.Sprintf("%s\n%s", matchedSymbol, matchedBalance)
|
res.Content = fmt.Sprintf("%s\n%s", matchedSymbol, matchedBalance)
|
||||||
res.FlagReset = append(res.FlagReset, flag_incorrect_voucher)
|
res.FlagReset = append(res.FlagReset, flag_incorrect_voucher)
|
||||||
} else {
|
} else {
|
||||||
@ -1149,18 +1153,33 @@ func (h *Handlers) SetVoucher(ctx context.Context, sym string, input []byte) (re
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
// get the current temporary balance
|
||||||
|
temporaryBal, err := store.ReadEntry(ctx, sessionId, utils.DATA_TEMPORARY_BAL)
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
// set the active symbol
|
// set the active symbol
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_ACTIVE_SYM, []byte(temporarySym))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_ACTIVE_SYM, []byte(temporarySym))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
// set the active balance
|
||||||
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_ACTIVE_BAL, []byte(temporaryBal))
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
// reset the temporary symbol
|
// reset the temporary symbol
|
||||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_SYM, []byte(""))
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_SYM, []byte(""))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
// reset the temporary balance
|
||||||
|
err = store.WriteEntry(ctx, sessionId, utils.DATA_TEMPORARY_BAL, []byte(""))
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
res.Content = string(temporarySym)
|
res.Content = string(temporarySym)
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@ const (
|
|||||||
DATA_VOUCHER_LIST
|
DATA_VOUCHER_LIST
|
||||||
DATA_TEMPORARY_SYM
|
DATA_TEMPORARY_SYM
|
||||||
DATA_ACTIVE_SYM
|
DATA_ACTIVE_SYM
|
||||||
|
DATA_TEMPORARY_BAL
|
||||||
|
DATA_ACTIVE_BAL
|
||||||
)
|
)
|
||||||
|
|
||||||
func typToBytes(typ DataTyp) []byte {
|
func typToBytes(typ DataTyp) []byte {
|
||||||
|
Loading…
Reference in New Issue
Block a user