read the data entries directly from the store
Some checks failed
release / docker (push) Has been cancelled
Some checks failed
release / docker (push) Has been cancelled
This commit is contained in:
parent
465b3b5604
commit
09954d967f
@ -161,7 +161,7 @@ func (h *MenuHandlers) ConfirmDebtRemoval(ctx context.Context, sym string, input
|
|||||||
userStore := h.userdataStore
|
userStore := h.userdataStore
|
||||||
|
|
||||||
// Fetch session data
|
// Fetch session data
|
||||||
_, _, activeSym, activeAddress, publicKey, _, err := h.getSessionData(ctx, sessionId)
|
_, _, activeSym, activeAddress, publicKey, activeDecimal, err := h.getSessionData(ctx, sessionId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
@ -172,12 +172,19 @@ func (h *MenuHandlers) ConfirmDebtRemoval(ctx context.Context, sym string, input
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
swapData, err := store.ReadSwapPreviewData(ctx, userStore, sessionId)
|
// Resolve active pool
|
||||||
|
activePoolAddress, _, err := h.resolveActivePoolDetails(ctx, sessionId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
maxValue, err := strconv.ParseFloat(swapData.ActiveSwapMaxAmount, 64)
|
swapMaxAmount, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SWAP_MAX_AMOUNT)
|
||||||
|
if err != nil {
|
||||||
|
logg.ErrorCtxf(ctx, "failed to read swapMaxAmount entry with", "key", storedb.DATA_ACTIVE_SWAP_MAX_AMOUNT, "error", err)
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
maxValue, err := strconv.ParseFloat(string(swapMaxAmount), 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(ctx, "Failed to convert the swapMaxAmount to a float", "error", err)
|
logg.ErrorCtxf(ctx, "Failed to convert the swapMaxAmount to a float", "error", err)
|
||||||
return res, err
|
return res, err
|
||||||
@ -191,7 +198,7 @@ func (h *MenuHandlers) ConfirmDebtRemoval(ctx context.Context, sym string, input
|
|||||||
}
|
}
|
||||||
|
|
||||||
var finalAmountStr string
|
var finalAmountStr string
|
||||||
if inputStr == swapData.ActiveSwapMaxAmount {
|
if inputStr == string(swapMaxAmount) {
|
||||||
finalAmountStr = string(payDebtVoucher.Balance)
|
finalAmountStr = string(payDebtVoucher.Balance)
|
||||||
} else {
|
} else {
|
||||||
finalAmountStr, err = store.ParseAndScaleAmount(inputStr, payDebtVoucher.TokenDecimals)
|
finalAmountStr, err = store.ParseAndScaleAmount(inputStr, payDebtVoucher.TokenDecimals)
|
||||||
@ -207,7 +214,7 @@ func (h *MenuHandlers) ConfirmDebtRemoval(ctx context.Context, sym string, input
|
|||||||
}
|
}
|
||||||
|
|
||||||
// call the API to get the quote
|
// call the API to get the quote
|
||||||
r, err := h.accountService.GetPoolSwapQuote(ctx, finalAmountStr, string(publicKey), payDebtVoucher.TokenAddress, swapData.ActivePoolAddress, string(activeAddress))
|
r, err := h.accountService.GetPoolSwapQuote(ctx, finalAmountStr, string(publicKey), payDebtVoucher.TokenAddress, string(activePoolAddress), string(activeAddress))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||||
res.FlagSet = append(res.FlagSet, flag_api_call_error)
|
res.FlagSet = append(res.FlagSet, flag_api_call_error)
|
||||||
@ -216,8 +223,8 @@ func (h *MenuHandlers) ConfirmDebtRemoval(ctx context.Context, sym string, input
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale down the quoted amount
|
// Scale down the quoted amount (for the AT)
|
||||||
quoteAmountStr := store.ScaleDownBalance(r.OutValue, swapData.ActiveSwapFromDecimal)
|
quoteAmountStr := store.ScaleDownBalance(r.OutValue, string(activeDecimal))
|
||||||
|
|
||||||
// Format to 2 decimal places
|
// Format to 2 decimal places
|
||||||
qouteStr, _ := store.TruncateDecimalString(string(quoteAmountStr), 2)
|
qouteStr, _ := store.TruncateDecimalString(string(quoteAmountStr), 2)
|
||||||
@ -272,17 +279,18 @@ func (h *MenuHandlers) InitiatePayDebt(ctx context.Context, sym string, input []
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
swapData, err := store.ReadSwapPreviewData(ctx, userStore, sessionId)
|
|
||||||
if err != nil {
|
|
||||||
return res, err
|
|
||||||
}
|
|
||||||
|
|
||||||
swapAmount, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SWAP_AMOUNT)
|
swapAmount, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_ACTIVE_SWAP_AMOUNT)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(ctx, "failed to read swapAmount entry with", "key", storedb.DATA_ACTIVE_SWAP_AMOUNT, "error", err)
|
logg.ErrorCtxf(ctx, "failed to read swapAmount entry with", "key", storedb.DATA_ACTIVE_SWAP_AMOUNT, "error", err)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debtQuotedAmount, err := userStore.ReadEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE)
|
||||||
|
if err != nil {
|
||||||
|
logg.ErrorCtxf(ctx, "failed to read debtQuotedAmount entry with", "key", storedb.DATA_TEMPORARY_VALUE, "error", err)
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
swapAmountStr := string(swapAmount)
|
swapAmountStr := string(swapAmount)
|
||||||
|
|
||||||
// Call the poolSwap API
|
// Call the poolSwap API
|
||||||
@ -300,7 +308,7 @@ func (h *MenuHandlers) InitiatePayDebt(ctx context.Context, sym string, input []
|
|||||||
|
|
||||||
res.Content = l.Get(
|
res.Content = l.Get(
|
||||||
"Your request has been sent. You will receive an SMS when your debt of %s %s has been removed from %s.",
|
"Your request has been sent. You will receive an SMS when your debt of %s %s has been removed from %s.",
|
||||||
swapData.TemporaryValue,
|
string(debtQuotedAmount),
|
||||||
string(activeSym),
|
string(activeSym),
|
||||||
activePoolName,
|
activePoolName,
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user