rename the func to match updated functionality
This commit is contained in:
parent
4660527e66
commit
f6c613abd6
@ -51,8 +51,8 @@ func (h *MenuHandlers) GetMpesaMaxLimit(ctx context.Context, sym string, input [
|
||||
}
|
||||
|
||||
// Store the active transaction voucher data (from token)
|
||||
if err := store.StoreTemporaryVoucher(ctx, h.userdataStore, sessionId, metadata); err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on StoreTemporaryVoucher", "error", err)
|
||||
if err := store.StoreTransactionVoucher(ctx, h.userdataStore, sessionId, metadata); err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on StoreTransactionVoucher", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@ -265,9 +265,9 @@ func (h *MenuHandlers) GetMpesaPreview(ctx context.Context, sym string, input []
|
||||
}
|
||||
|
||||
// get the selected voucher
|
||||
mpesaWithdrawalVoucher, err := store.GetTemporaryVoucherData(ctx, h.userdataStore, sessionId)
|
||||
mpesaWithdrawalVoucher, err := store.GetTransactionVoucherData(ctx, h.userdataStore, sessionId)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on GetTemporaryVoucherData", "error", err)
|
||||
logg.ErrorCtxf(ctx, "failed on GetTransactionVoucherData", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@ -406,9 +406,9 @@ func (h *MenuHandlers) InitiateGetMpesa(ctx context.Context, sym string, input [
|
||||
}
|
||||
|
||||
// get the selected voucher
|
||||
mpesaWithdrawalVoucher, err := store.GetTemporaryVoucherData(ctx, h.userdataStore, sessionId)
|
||||
mpesaWithdrawalVoucher, err := store.GetTransactionVoucherData(ctx, h.userdataStore, sessionId)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on GetTemporaryVoucherData", "error", err)
|
||||
logg.ErrorCtxf(ctx, "failed on GetTransactionVoucherData", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
@ -83,8 +83,8 @@ func (h *MenuHandlers) PoolDepositMaxAmount(ctx context.Context, sym string, inp
|
||||
}
|
||||
|
||||
// Store the pool deposit voucher data
|
||||
if err := store.StoreTemporaryVoucher(ctx, h.userdataStore, sessionId, metadata); err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on StoreTemporaryVoucher", "error", err)
|
||||
if err := store.StoreTransactionVoucher(ctx, h.userdataStore, sessionId, metadata); err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on StoreTransactionVoucher", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@ -119,9 +119,9 @@ func (h *MenuHandlers) ConfirmPoolDeposit(ctx context.Context, sym string, input
|
||||
|
||||
userStore := h.userdataStore
|
||||
|
||||
poolDepositVoucher, err := store.GetTemporaryVoucherData(ctx, h.userdataStore, sessionId)
|
||||
poolDepositVoucher, err := store.GetTransactionVoucherData(ctx, h.userdataStore, sessionId)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on GetTemporaryVoucherData", "error", err)
|
||||
logg.ErrorCtxf(ctx, "failed on GetTransactionVoucherData", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@ -179,9 +179,9 @@ func (h *MenuHandlers) InitiatePoolDeposit(ctx context.Context, sym string, inpu
|
||||
return res, err
|
||||
}
|
||||
|
||||
poolDepositVoucher, err := store.GetTemporaryVoucherData(ctx, h.userdataStore, sessionId)
|
||||
poolDepositVoucher, err := store.GetTransactionVoucherData(ctx, h.userdataStore, sessionId)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on GetTemporaryVoucherData", "error", err)
|
||||
logg.ErrorCtxf(ctx, "failed on GetTransactionVoucherData", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
@ -357,9 +357,9 @@ func (h *MenuHandlers) MaxAmount(ctx context.Context, sym string, input []byte)
|
||||
customVoucherValue, _ := strconv.ParseUint(string(customVoucherSelection), 0, 64)
|
||||
if customVoucherValue == 1 {
|
||||
// use the custom voucher
|
||||
customTransactionVoucher, err := store.GetTemporaryVoucherData(ctx, h.userdataStore, sessionId)
|
||||
customTransactionVoucher, err := store.GetTransactionVoucherData(ctx, h.userdataStore, sessionId)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on GetTemporaryVoucherData", "error", err)
|
||||
logg.ErrorCtxf(ctx, "failed on GetTransactionVoucherData", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@ -625,15 +625,15 @@ func (h *MenuHandlers) ValidateAmount(ctx context.Context, sym string, input []b
|
||||
logg.ErrorCtxf(ctx, "failed to read activeBal entry with", "key", storedb.DATA_ACTIVE_BAL, "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
customVoucherSelection, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_TRANSACTION_CUSTOM_VOUCHER_STATE)
|
||||
if err == nil {
|
||||
customVoucherValue, _ := strconv.ParseUint(string(customVoucherSelection), 0, 64)
|
||||
if customVoucherValue == 1 {
|
||||
// use the custom voucher
|
||||
customTransactionVoucher, err := store.GetTemporaryVoucherData(ctx, h.userdataStore, sessionId)
|
||||
customTransactionVoucher, err := store.GetTransactionVoucherData(ctx, h.userdataStore, sessionId)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on GetTemporaryVoucherData", "error", err)
|
||||
logg.ErrorCtxf(ctx, "failed on GetTransactionVoucherData", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@ -760,9 +760,9 @@ func (h *MenuHandlers) NormalTransactionPreview(ctx context.Context, sym string,
|
||||
customVoucherValue, _ := strconv.ParseUint(string(customVoucherSelection), 0, 64)
|
||||
if customVoucherValue == 1 {
|
||||
// use the custom voucher
|
||||
customTransactionVoucher, err := store.GetTemporaryVoucherData(ctx, h.userdataStore, sessionId)
|
||||
customTransactionVoucher, err := store.GetTransactionVoucherData(ctx, h.userdataStore, sessionId)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on GetTemporaryVoucherData", "error", err)
|
||||
logg.ErrorCtxf(ctx, "failed on GetTransactionVoucherData", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@ -811,9 +811,9 @@ func (h *MenuHandlers) InitiateNormalTransaction(ctx context.Context, sym string
|
||||
customVoucherValue, _ := strconv.ParseUint(string(customVoucherSelection), 0, 64)
|
||||
if customVoucherValue == 1 {
|
||||
// use the custom voucher
|
||||
customTransactionVoucher, err := store.GetTemporaryVoucherData(ctx, h.userdataStore, sessionId)
|
||||
customTransactionVoucher, err := store.GetTransactionVoucherData(ctx, h.userdataStore, sessionId)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on GetTemporaryVoucherData", "error", err)
|
||||
logg.ErrorCtxf(ctx, "failed on GetTransactionVoucherData", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
@ -333,8 +333,8 @@ func (h *MenuHandlers) ViewVoucher(ctx context.Context, sym string, input []byte
|
||||
return res, nil
|
||||
}
|
||||
|
||||
if err := store.StoreTemporaryVoucher(ctx, h.userdataStore, sessionId, metadata); err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on StoreTemporaryVoucher", "error", err)
|
||||
if err := store.StoreTransactionVoucher(ctx, h.userdataStore, sessionId, metadata); err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on StoreTransactionVoucher", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@ -362,9 +362,9 @@ func (h *MenuHandlers) SetVoucher(ctx context.Context, sym string, input []byte)
|
||||
}
|
||||
|
||||
// Get temporary data
|
||||
tempData, err := store.GetTemporaryVoucherData(ctx, h.userdataStore, sessionId)
|
||||
tempData, err := store.GetTransactionVoucherData(ctx, h.userdataStore, sessionId)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on GetTemporaryVoucherData", "error", err)
|
||||
logg.ErrorCtxf(ctx, "failed on GetTransactionVoucherData", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
@ -445,8 +445,8 @@ func (h *MenuHandlers) ValidateCreditVoucher(ctx context.Context, sym string, in
|
||||
}
|
||||
|
||||
// Store the transaction voucher data
|
||||
if err := store.StoreTemporaryVoucher(ctx, h.userdataStore, sessionId, metadata); err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on StoreTemporaryVoucher", "error", err)
|
||||
if err := store.StoreTransactionVoucher(ctx, h.userdataStore, sessionId, metadata); err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed on StoreTransactionVoucher", "error", err)
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
||||
@ -185,8 +185,8 @@ func MatchVoucher(input, symbols, balances, decimals, addresses string) (symbol,
|
||||
return
|
||||
}
|
||||
|
||||
// StoreTemporaryVoucher saves voucher metadata as temporary entries in the DataStore.
|
||||
func StoreTemporaryVoucher(ctx context.Context, store DataStore, sessionId string, data *dataserviceapi.TokenHoldings) error {
|
||||
// StoreTransactionVoucher saves voucher metadata in the DataStore.
|
||||
func StoreTransactionVoucher(ctx context.Context, store DataStore, sessionId string, data *dataserviceapi.TokenHoldings) error {
|
||||
tempData := fmt.Sprintf("%s,%s,%s,%s", data.TokenSymbol, data.Balance, data.TokenDecimals, data.TokenAddress)
|
||||
|
||||
if err := store.WriteEntry(ctx, sessionId, storedb.DATA_TRANSACTION_CUSTOM_VOUCHER, []byte(tempData)); err != nil {
|
||||
@ -196,8 +196,8 @@ func StoreTemporaryVoucher(ctx context.Context, store DataStore, sessionId strin
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTemporaryVoucherData retrieves temporary voucher metadata from the DataStore.
|
||||
func GetTemporaryVoucherData(ctx context.Context, store DataStore, sessionId string) (*dataserviceapi.TokenHoldings, error) {
|
||||
// GetTransactionVoucherData retrieves the transaction voucher metadata from the DataStore.
|
||||
func GetTransactionVoucherData(ctx context.Context, store DataStore, sessionId string) (*dataserviceapi.TokenHoldings, error) {
|
||||
temp_data, err := store.ReadEntry(ctx, sessionId, storedb.DATA_TRANSACTION_CUSTOM_VOUCHER)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -118,7 +118,7 @@ func TestStoreTemporaryVoucher(t *testing.T) {
|
||||
}
|
||||
|
||||
// Execute the function being tested
|
||||
err := StoreTemporaryVoucher(ctx, store, sessionId, voucherData)
|
||||
err := StoreTransactionVoucher(ctx, store, sessionId, voucherData)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Verify stored data
|
||||
@ -142,11 +142,11 @@ func TestGetTemporaryVoucherData(t *testing.T) {
|
||||
}
|
||||
|
||||
// Store the data
|
||||
err := StoreTemporaryVoucher(ctx, store, sessionId, tempData)
|
||||
err := StoreTransactionVoucher(ctx, store, sessionId, tempData)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Execute the function being tested
|
||||
data, err := GetTemporaryVoucherData(ctx, store, sessionId)
|
||||
data, err := GetTransactionVoucherData(ctx, store, sessionId)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tempData, data)
|
||||
}
|
||||
@ -170,7 +170,7 @@ func TestUpdateVoucherData(t *testing.T) {
|
||||
TokenDecimals: "8",
|
||||
TokenAddress: "0xold",
|
||||
}
|
||||
require.NoError(t, StoreTemporaryVoucher(ctx, store, sessionId, tempData))
|
||||
require.NoError(t, StoreTransactionVoucher(ctx, store, sessionId, tempData))
|
||||
|
||||
// Execute update
|
||||
err := UpdateVoucherData(ctx, store, sessionId, newData)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user