alfred/pool-swap #33
@ -2635,13 +2635,18 @@ func (h *MenuHandlers) SwapMaxLimit(ctx context.Context, sym string, input []byt
 | 
				
			|||||||
		return res, fmt.Errorf("missing session")
 | 
							return res, fmt.Errorf("missing session")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						flag_incorrect_voucher, _ := h.flagManager.GetFlag("flag_incorrect_voucher")
 | 
				
			||||||
 | 
						flag_api_error, _ := h.flagManager.GetFlag("flag_api_error")
 | 
				
			||||||
 | 
						flag_low_swap_amount, _ := h.flagManager.GetFlag("flag_low_swap_amount")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						res.FlagReset = append(res.FlagReset, flag_incorrect_voucher)
 | 
				
			||||||
 | 
						res.FlagReset = append(res.FlagSet, flag_low_swap_amount)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	inputStr := string(input)
 | 
						inputStr := string(input)
 | 
				
			||||||
	if inputStr == "0" {
 | 
						if inputStr == "0" {
 | 
				
			||||||
		return res, nil
 | 
							return res, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	flag_incorrect_voucher, _ := h.flagManager.GetFlag("flag_incorrect_voucher")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	metadata, err := store.GetSwapToVoucherData(ctx, h.prefixDb, inputStr)
 | 
						metadata, err := store.GetSwapToVoucherData(ctx, h.prefixDb, inputStr)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return res, fmt.Errorf("failed to retrieve swap to voucher data: %v", err)
 | 
							return res, fmt.Errorf("failed to retrieve swap to voucher data: %v", err)
 | 
				
			||||||
@ -2659,35 +2664,41 @@ func (h *MenuHandlers) SwapMaxLimit(ctx context.Context, sym string, input []byt
 | 
				
			|||||||
		return res, err
 | 
							return res, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	res.FlagReset = append(res.FlagReset, flag_incorrect_voucher)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	swapData, err := store.ReadSwapData(ctx, userStore, sessionId)
 | 
						swapData, err := store.ReadSwapData(ctx, userStore, sessionId)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return res, err
 | 
							return res, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// call the API
 | 
						// call the api using the ActivePoolAddress, ActiveSwapFromAddress, ActiveSwapToAddress and PublicKey to get the swap max limit
 | 
				
			||||||
	// /pool/:pool/limit/:from/:to/:address
 | 
						r, err := h.accountService.GetSwapFromTokenMaxLimit(ctx, swapData.ActivePoolAddress, swapData.ActiveSwapFromAddress, swapData.ActiveSwapToAddress, swapData.PublicKey)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							res.FlagSet = append(res.FlagSet, flag_api_error)
 | 
				
			||||||
 | 
							logg.ErrorCtxf(ctx, "failed on FetchTransactions", "error", err)
 | 
				
			||||||
 | 
							return res, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Scale down the amount
 | 
						// Scale down the amount
 | 
				
			||||||
	maxAmountStr := store.ScaleDownBalance("1339482", swapData.ActiveSwapFromDecimal)
 | 
						maxAmountStr := store.ScaleDownBalance(r.Max, swapData.ActiveSwapFromDecimal)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return res, err
 | 
							return res, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	maxAmount, err := strconv.ParseFloat(maxAmountStr, 64)
 | 
						maxAmountFloat, err := strconv.ParseFloat(maxAmountStr, 64)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logg.ErrorCtxf(ctx, "failed to parse maxAmountStr as float", "value", maxAmountStr, "error", err)
 | 
							logg.ErrorCtxf(ctx, "failed to parse maxAmountStr as float", "value", maxAmountStr, "error", err)
 | 
				
			||||||
		return res, err
 | 
							return res, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if maxAmount < 0.1 {
 | 
						// Format to 2 decimal places
 | 
				
			||||||
 | 
						maxStr := fmt.Sprintf("%.2f", maxAmountFloat)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if maxAmountFloat < 0.1 {
 | 
				
			||||||
		// return with low amount flag
 | 
							// return with low amount flag
 | 
				
			||||||
 | 
							res.Content = maxStr
 | 
				
			||||||
 | 
							res.FlagSet = append(res.FlagSet, flag_low_swap_amount)
 | 
				
			||||||
		return res, nil
 | 
							return res, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Format to 2 decimal places
 | 
					 | 
				
			||||||
	maxStr := fmt.Sprintf("%.2f", maxAmount)
 | 
					 | 
				
			||||||
	err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_ACTIVE_SWAP_MAX_AMOUNT, []byte(maxStr))
 | 
						err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_ACTIVE_SWAP_MAX_AMOUNT, []byte(maxStr))
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		logg.ErrorCtxf(ctx, "failed to write swap max amount entry with", "key", storedb.DATA_ACTIVE_SWAP_MAX_AMOUNT, "value", maxStr, "error", err)
 | 
							logg.ErrorCtxf(ctx, "failed to write swap max amount entry with", "key", storedb.DATA_ACTIVE_SWAP_MAX_AMOUNT, "value", maxStr, "error", err)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user