Compare commits
No commits in common. "6c6af5ec210a0b5782c9d17ca3b2d4900dc270cc" and "7df77a134307823e058ca05541a004283189d0e1" have entirely different histories.
6c6af5ec21
...
7df77a1343
@ -91,7 +91,6 @@ func (ls *LocalHandlerService) GetHandler() (*ussd.Handlers, error) {
|
||||
ls.DbRs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
||||
ls.DbRs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
|
||||
ls.DbRs.AddLocalFunc("quit_with_help", ussdHandlers.QuitWithHelp)
|
||||
ls.DbRs.AddLocalFunc("set_default_voucher", ussdHandlers.SetDefaultVoucher)
|
||||
ls.DbRs.AddLocalFunc("check_vouchers", ussdHandlers.CheckVouchers)
|
||||
ls.DbRs.AddLocalFunc("get_vouchers", ussdHandlers.GetVoucherList)
|
||||
ls.DbRs.AddLocalFunc("view_voucher", ussdHandlers.ViewVoucher)
|
||||
|
@ -633,13 +633,41 @@ func (h *Handlers) CheckBalance(ctx context.Context, sym string, input []byte) (
|
||||
}
|
||||
|
||||
store := h.userdataStore
|
||||
|
||||
// get the active sym and active balance
|
||||
activeSym, err := store.ReadEntry(ctx, sessionId, utils.DATA_ACTIVE_SYM)
|
||||
publicKey, err := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
// check if the user has an active sym
|
||||
activeSym, err := store.ReadEntry(ctx, sessionId, utils.DATA_ACTIVE_SYM)
|
||||
if err != nil {
|
||||
if db.IsNotFound(err) {
|
||||
logg.Printf(logging.LVL_INFO, "Using the default sym to fetch balance")
|
||||
balance, err := h.accountService.CheckBalance(string(publicKey))
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
res.Content = balance
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
if len(activeSym) == 0 {
|
||||
logg.Printf(logging.LVL_INFO, "Using the default sym to fetch balance")
|
||||
balance, err := h.accountService.CheckBalance(string(publicKey))
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
res.Content = balance
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
activeBal, err := store.ReadEntry(ctx, sessionId, utils.DATA_ACTIVE_BAL)
|
||||
if err != nil {
|
||||
return res, err
|
||||
@ -976,69 +1004,6 @@ func (h *Handlers) GetProfileInfo(ctx context.Context, sym string, input []byte)
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// SetDefaultVoucher retrieves the current vouchers
|
||||
// and sets the first as the default voucher, if no active voucher is set
|
||||
func (h *Handlers) SetDefaultVoucher(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
var res resource.Result
|
||||
var err error
|
||||
store := h.userdataStore
|
||||
|
||||
sessionId, ok := ctx.Value("SessionId").(string)
|
||||
if !ok {
|
||||
return res, fmt.Errorf("missing session")
|
||||
}
|
||||
|
||||
fmt.Println("Running SetDefaultVoucher")
|
||||
|
||||
// check if the user has an active sym
|
||||
_, err = store.ReadEntry(ctx, sessionId, utils.DATA_ACTIVE_SYM)
|
||||
|
||||
if err != nil {
|
||||
if db.IsNotFound(err) {
|
||||
publicKey, err := store.ReadEntry(ctx, sessionId, utils.DATA_PUBLIC_KEY)
|
||||
|
||||
if err != nil {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Fetch vouchers from the API using the public key
|
||||
vouchersResp, err := h.accountService.FetchVouchers(string(publicKey))
|
||||
if err != nil {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// Ensure there is at least one voucher
|
||||
if len(vouchersResp.Result.Holdings) == 0 {
|
||||
return res, err
|
||||
}
|
||||
|
||||
// Use only the first voucher
|
||||
firstVoucher := vouchersResp.Result.Holdings[0]
|
||||
defaultSym := firstVoucher.TokenSymbol
|
||||
defaultBal := firstVoucher.Balance
|
||||
|
||||
// set the active symbol
|
||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_ACTIVE_SYM, []byte(defaultSym))
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
// set the active balance
|
||||
err = store.WriteEntry(ctx, sessionId, utils.DATA_ACTIVE_BAL, []byte(defaultBal))
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
fmt.Println("Nothing will happen as the error in not 404")
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// CheckVouchers retrieves the token holdings from the API using the "PublicKey" and stores
|
||||
// them to gdbm
|
||||
func (h *Handlers) CheckVouchers(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||
|
@ -171,7 +171,7 @@ func TestSaveFamilyname(t *testing.T) {
|
||||
mockStore.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestSaveTemporaryPin(t *testing.T) {
|
||||
func TestSaveTemporaryPIn(t *testing.T) {
|
||||
fm, err := NewFlagManager(flagsPath)
|
||||
mockStore := new(mocks.MockUserDataStore)
|
||||
if err != nil {
|
||||
|
@ -1,5 +1,3 @@
|
||||
LOAD set_default_voucher 8
|
||||
RELOAD set_default_voucher
|
||||
LOAD check_balance 64
|
||||
RELOAD check_balance
|
||||
LOAD check_vouchers 10
|
||||
|
Loading…
Reference in New Issue
Block a user