Compare commits

..

4 Commits

8 changed files with 49 additions and 4 deletions

View File

@ -109,6 +109,7 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountServiceIn
ls.DbRs.AddLocalFunc("get_vouchers", ussdHandlers.GetVoucherList) ls.DbRs.AddLocalFunc("get_vouchers", ussdHandlers.GetVoucherList)
ls.DbRs.AddLocalFunc("view_voucher", ussdHandlers.ViewVoucher) ls.DbRs.AddLocalFunc("view_voucher", ussdHandlers.ViewVoucher)
ls.DbRs.AddLocalFunc("set_voucher", ussdHandlers.SetVoucher) ls.DbRs.AddLocalFunc("set_voucher", ussdHandlers.SetVoucher)
ls.DbRs.AddLocalFunc("get_voucher_details", ussdHandlers.GetVoucherDetails)
ls.DbRs.AddLocalFunc("reset_valid_pin", ussdHandlers.ResetValidPin) ls.DbRs.AddLocalFunc("reset_valid_pin", ussdHandlers.ResetValidPin)
ls.DbRs.AddLocalFunc("check_pin_mismatch", ussdHandlers.CheckPinMisMatch) ls.DbRs.AddLocalFunc("check_pin_mismatch", ussdHandlers.CheckPinMisMatch)
ls.DbRs.AddLocalFunc("validate_blocked_number", ussdHandlers.ValidateBlockedNumber) ls.DbRs.AddLocalFunc("validate_blocked_number", ussdHandlers.ValidateBlockedNumber)

View File

@ -1624,3 +1624,36 @@ func (h *Handlers) SetVoucher(ctx context.Context, sym string, input []byte) (re
res.Content = tempData.TokenSymbol res.Content = tempData.TokenSymbol
return res, nil return res, nil
} }
// GetVoucherDetails retrieves the voucher details
func (h *Handlers) GetVoucherDetails(ctx context.Context, sym string, input []byte) (resource.Result, error) {
var res resource.Result
store := h.userdataStore
sessionId, ok := ctx.Value("SessionId").(string)
if !ok {
return res, fmt.Errorf("missing session")
}
flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error")
// get the active address
activeAddress, err := store.ReadEntry(ctx, sessionId, common.DATA_ACTIVE_ADDRESS)
if err != nil {
logg.ErrorCtxf(ctx, "failed to read activeAddress entry with", "key", common.DATA_ACTIVE_ADDRESS, "error", err)
return res, err
}
// use the voucher contract address to get the data from the API
voucherData, err := h.accountService.VoucherData(ctx, string(activeAddress))
if err != nil {
res.FlagSet = append(res.FlagSet, flag_api_error)
return res, nil
}
tokenSymbol := voucherData.TokenSymbol
tokenName := voucherData.TokenName
res.Content = fmt.Sprintf("%s %s", tokenSymbol, tokenName)
return res, nil
}

View File

@ -3,6 +3,6 @@ package models
type VoucherDataResult struct { type VoucherDataResult struct {
TokenName string `json:"tokenName"` TokenName string `json:"tokenName"`
TokenSymbol string `json:"tokenSymbol"` TokenSymbol string `json:"tokenSymbol"`
TokenDecimals string `json:"tokenDecimals"` TokenDecimals int `json:"tokenDecimals"`
SinkAddress string `json:"sinkAddress"` SinkAddress string `json:"sinkAddress"`
} }

View File

@ -156,7 +156,9 @@ func (as *AccountService) FetchTransactions(ctx context.Context, publicKey strin
// Parameters: // Parameters:
// - address: The voucher address. // - address: The voucher address.
func (as *AccountService) VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error) { func (as *AccountService) VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error) {
var voucherDataResult models.VoucherDataResult var r struct {
TokenDetails models.VoucherDataResult `json:"tokenDetails"`
}
ep, err := url.JoinPath(config.VoucherDataURL, address) ep, err := url.JoinPath(config.VoucherDataURL, address)
if err != nil { if err != nil {
@ -168,8 +170,8 @@ func (as *AccountService) VoucherData(ctx context.Context, address string) (*mod
return nil, err return nil, err
} }
_, err = doRequest(ctx, req, &voucherDataResult) _, err = doRequest(ctx, req, &r)
return &voucherDataResult, err return &r.TokenDetails, err
} }
// TokenTransfer creates a new token transfer in the custodial system. // TokenTransfer creates a new token transfer in the custodial system.

View File

@ -6,3 +6,4 @@ MOUT back 0
HALT HALT
INCMP _ 0 INCMP _ 0
INCMP select_voucher 1 INCMP select_voucher 1
INCMP voucher_details 2

View File

@ -0,0 +1 @@
{{.get_voucher_details}}

View File

@ -0,0 +1,6 @@
CATCH no_voucher flag_no_active_voucher 1
LOAD get_voucher_details 0
MAP get_voucher_details
MOUT back 0
HALT
INCMP _ 0

View File

@ -0,0 +1 @@
{{.get_voucher_details}}