credit-send-pool-selection-hotfix #117
@ -3,6 +3,7 @@ package application
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.defalsify.org/vise.git/db"
|
"git.defalsify.org/vise.git/db"
|
||||||
"git.defalsify.org/vise.git/resource"
|
"git.defalsify.org/vise.git/resource"
|
||||||
@ -104,6 +105,7 @@ func (h *MenuHandlers) GetDefaultPool(ctx context.Context, sym string, input []b
|
|||||||
|
|
||||||
// ViewPool retrieves the pool details from the user store
|
// ViewPool retrieves the pool details from the user store
|
||||||
// and displays it to the user for them to select it.
|
// and displays it to the user for them to select it.
|
||||||
|
// if the data does not exist, it calls the API to get the pool details
|
||||||
func (h *MenuHandlers) ViewPool(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
func (h *MenuHandlers) ViewPool(ctx context.Context, sym string, input []byte) (resource.Result, error) {
|
||||||
var res resource.Result
|
var res resource.Result
|
||||||
sessionId, ok := ctx.Value("SessionId").(string)
|
sessionId, ok := ctx.Value("SessionId").(string)
|
||||||
@ -131,8 +133,11 @@ func (h *MenuHandlers) ViewPool(ctx context.Context, sym string, input []byte) (
|
|||||||
if poolData == nil {
|
if poolData == nil {
|
||||||
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
flag_api_call_error, _ := h.flagManager.GetFlag("flag_api_call_error")
|
||||||
|
|
||||||
|
// convert to uppercase before the call
|
||||||
|
poolSymbol := strings.ToUpper(inputStr)
|
||||||
|
|
||||||
// no match found. Call the API using the inputStr as the symbol
|
// no match found. Call the API using the inputStr as the symbol
|
||||||
poolResp, err := h.accountService.RetrievePoolDetails(ctx, inputStr)
|
poolResp, err := h.accountService.RetrievePoolDetails(ctx, poolSymbol)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.FlagSet = append(res.FlagSet, flag_api_call_error)
|
res.FlagSet = append(res.FlagSet, flag_api_call_error)
|
||||||
return res, nil
|
return res, nil
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/big"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -757,8 +758,19 @@ func (h *MenuHandlers) TransactionSwapPreview(ctx context.Context, sym string, i
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// multiply by 1.015 (i.e. * 1015 / 1000)
|
||||||
|
amountInt, ok := new(big.Int).SetString(finalAmountStr, 10)
|
||||||
|
if !ok {
|
||||||
|
return res, fmt.Errorf("invalid amount: %s", finalAmountStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
amountInt.Mul(amountInt, big.NewInt(1015))
|
||||||
|
amountInt.Div(amountInt, big.NewInt(1000))
|
||||||
|
|
||||||
|
scaledFinalAmountStr := amountInt.String()
|
||||||
|
|
||||||
// call the credit send API to get the reverse quote
|
// call the credit send API to get the reverse quote
|
||||||
r, err := h.accountService.GetCreditSendReverseQuote(ctx, swapData.ActivePoolAddress, swapData.ActiveSwapFromAddress, swapData.ActiveSwapToAddress, finalAmountStr)
|
r, err := h.accountService.GetCreditSendReverseQuote(ctx, swapData.ActivePoolAddress, swapData.ActiveSwapFromAddress, swapData.ActiveSwapToAddress, scaledFinalAmountStr)
|
||||||
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)
|
||||||
@ -770,23 +782,23 @@ func (h *MenuHandlers) TransactionSwapPreview(ctx context.Context, sym string, i
|
|||||||
sendInputAmount := r.InputAmount // amount of SAT that should be swapped
|
sendInputAmount := r.InputAmount // amount of SAT that should be swapped
|
||||||
sendOutputAmount := r.OutputAmount // amount of RAT that will be received
|
sendOutputAmount := r.OutputAmount // amount of RAT that will be received
|
||||||
|
|
||||||
// store the sendOutputAmount as the final amount (that will be sent)
|
// store the finalAmountStr as the final amount (that will be sent after the swap)
|
||||||
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_AMOUNT, []byte(sendOutputAmount))
|
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_AMOUNT, []byte(finalAmountStr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(ctx, "failed to write output amount value entry with", "key", storedb.DATA_AMOUNT, "value", sendOutputAmount, "error", err)
|
logg.ErrorCtxf(ctx, "failed to write output amount value entry with", "key", storedb.DATA_AMOUNT, "value", sendOutputAmount, "error", err)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale down the quoted output amount
|
// Scale down the quoted output amount
|
||||||
quoteAmountStr := store.ScaleDownBalance(sendOutputAmount, swapData.ActiveSwapToDecimal)
|
// quoteAmountStr := store.ScaleDownBalance(sendOutputAmount, swapData.ActiveSwapToDecimal)
|
||||||
|
|
||||||
// Format the qouteAmount amount to 2 decimal places
|
// Format the qouteAmount amount to 2 decimal places
|
||||||
qouteAmount, _ := store.TruncateDecimalString(quoteAmountStr, 2)
|
// qouteAmount, _ := store.TruncateDecimalString(quoteAmountStr, 2)
|
||||||
|
|
||||||
// store the qouteAmount in the temporary value
|
// store the qouteAmount in the temporary value
|
||||||
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(qouteAmount))
|
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(inputStr))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logg.ErrorCtxf(ctx, "failed to write temporary qouteAmount entry with", "key", storedb.DATA_TEMPORARY_VALUE, "value", qouteAmount, "error", err)
|
logg.ErrorCtxf(ctx, "failed to write temporary inputStr entry with", "key", storedb.DATA_TEMPORARY_VALUE, "value", inputStr, "error", err)
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -799,7 +811,7 @@ func (h *MenuHandlers) TransactionSwapPreview(ctx context.Context, sym string, i
|
|||||||
|
|
||||||
res.Content = l.Get(
|
res.Content = l.Get(
|
||||||
"%s will receive %s %s",
|
"%s will receive %s %s",
|
||||||
string(recipientPhoneNumber), qouteAmount, swapData.ActiveSwapToSym,
|
string(recipientPhoneNumber), inputStr, swapData.ActiveSwapToSym,
|
||||||
)
|
)
|
||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user