Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sentry error and max decimals #357

Merged
merged 4 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.dev
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VITE_NETWORK_NAME=
VITE_SENTRY_DSN=
ENABLE_EXPERIMENTAL_MAX_TOKENS_SWAP=true
VITE_ENABLE_EXPERIMENTAL_MAX_TOKENS_SWAP=true
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VITE_NETWORK_NAME=
VITE_SENTRY_DSN=
ENABLE_EXPERIMENTAL_MAX_TOKENS_SWAP=false
VITE_ENABLE_EXPERIMENTAL_MAX_TOKENS_SWAP=false
2 changes: 1 addition & 1 deletion src/app/util/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const formatInputTokenValue = (base: Decimal.Value, decimals: string) =>
};

export const formatDecimalsFromToken = (base: Decimal.Value, decimals: string) => {
return new Decimal(base || 0).dividedBy(Math.pow(10, parseFloat(decimals))).toFixed();
return new Decimal(base || 0).dividedBy(Math.pow(10, parseFloat(decimals || "0"))).toFixed();
};

export const checkIfPoolAlreadyExists = (id: string, poolArray: AnyJson[]) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/molecule/TokenAmountInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ const TokenAmountInput = ({
: tokenBalance || 0}
{tokenText &&
onMaxClick &&
process.env.ENABLE_EXPERIMENTAL_MAX_TOKENS_SWAP &&
process.env.ENABLE_EXPERIMENTAL_MAX_TOKENS_SWAP == "true" && (
process.env.VITE_ENABLE_EXPERIMENTAL_MAX_TOKENS_SWAP &&
process.env.VITE_ENABLE_EXPERIMENTAL_MAX_TOKENS_SWAP == "true" && (
<button
className="inline-flex h-5 w-11 flex-col items-start justify-start gap-2 px-1.5 text-pink"
onClick={onMaxClick}
Expand Down
13 changes: 7 additions & 6 deletions src/components/organism/CreatePool/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import WarningMessage from "../../atom/WarningMessage";
import TokenAmountInput from "../../molecule/TokenAmountInput";
import AddPoolLiquidity from "../AddPoolLiquidity";
import PoolSelectTokenModal from "../PoolSelectTokenModal";
import SwapAndPoolSuccessModal from "../SwapAndPoolSuccessModal";
import ReviewTransactionModal from "../ReviewTransactionModal";
import SwapAndPoolSuccessModal from "../SwapAndPoolSuccessModal";

type AssetTokenProps = {
tokenSymbol: string;
Expand Down Expand Up @@ -133,8 +133,8 @@ const CreatePool = ({ tokenBSelected }: CreatePoolProps) => {
selectedAccount,
nativeTokenValue,
assetTokenValue,
nativeTokenWithSlippage.tokenValue.toString(),
assetTokenWithSlippage.tokenValue.toString(),
nativeTokenWithSlippage.tokenValue,
assetTokenWithSlippage.tokenValue,
selectedTokenA.nativeTokenDecimals,
selectedTokenB.decimals,
dispatch
Expand Down Expand Up @@ -232,13 +232,14 @@ const CreatePool = ({ tokenBSelected }: CreatePoolProps) => {
if (selectedTokenAssetValue && api && selectedTokenB.assetTokenId) {
const assetTokenInfo: any = await api.query.assets.asset(selectedTokenB.assetTokenId);
const assetTokenMinBalance = assetTokenInfo.toHuman()?.minBalance;
const formattedMinTokenAmount = assetTokenMinBalance?.replace(/[, ]/g, "");
if (!assetTokenMinBalance) return;
const formattedMinTokenAmount = assetTokenMinBalance.replace(/[, ]/g, "");
const assetTokenMinBalanceFormatted = formatDecimalsFromToken(formattedMinTokenAmount, selectedTokenB.decimals);

if (new Decimal(selectedTokenAssetValue.tokenValue).gte(assetTokenMinBalanceFormatted)) {
if (new Decimal(selectedTokenAssetValue.tokenValue || 0).gte(assetTokenMinBalanceFormatted || 0)) {
setAssetTokenMinValueExceeded(false);
} else {
setAssetTokenMinValue(assetTokenMinBalanceFormatted.toString());
setAssetTokenMinValue(assetTokenMinBalanceFormatted);
setAssetTokenMinValueExceeded(true);
}
}
Expand Down
19 changes: 15 additions & 4 deletions src/components/organism/SwapTokens/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { t } from "i18next";
import { useEffect, useMemo, useState } from "react";
import { NumericFormat } from "react-number-format";
import useGetNetwork from "../../../app/hooks/useGetNetwork";
import { InputEditedProps, PoolCardProps, TokenDecimalsErrorProps, TokenProps } from "../../../app/types";
import {
ActionType,
ButtonVariants,
Expand All @@ -12,7 +13,6 @@ import {
TokenSelection,
TransactionTypes,
} from "../../../app/types/enum";
import { InputEditedProps, PoolCardProps, TokenDecimalsErrorProps, TokenProps } from "../../../app/types";
import {
calculateSlippageAdd,
calculateSlippageReduce,
Expand Down Expand Up @@ -776,13 +776,25 @@ const SwapTokens = () => {
if (selectedTokens.tokenB.tokenSymbol === nativeTokenSymbol) {
if (poolsCards) {
const poolNative = poolsCards.find((pool) => pool.assetTokenId === selectedTokens.tokenA.tokenId);
if (poolNative) setNativeTokensInPool(poolNative?.totalTokensLocked.nativeToken.formattedValue);
if (poolNative)
setNativeTokensInPool(
formatDecimalsFromToken(
poolNative.totalTokensLocked.nativeToken.value,
poolNative.totalTokensLocked.nativeToken.decimals
)
);
}
}
if (selectedTokens.tokenB.tokenSymbol !== nativeTokenSymbol) {
if (poolsCards) {
const poolAsset = poolsCards.find((pool) => pool.assetTokenId === selectedTokens.tokenB.tokenId);
if (poolAsset) setAssetTokensInPool(poolAsset?.totalTokensLocked.assetToken.formattedValue);
if (poolAsset)
setAssetTokensInPool(
formatDecimalsFromToken(
poolAsset.totalTokensLocked.assetToken.value,
poolAsset.totalTokensLocked.assetToken.decimals
)
);
}
}
}
Expand Down Expand Up @@ -861,7 +873,6 @@ const SwapTokens = () => {
}): TransactionValues => {
const priceCalcType = PriceCalcType.NativeFromAsset;

// ovde oduzeti
const valueA = new Decimal(selectedTokens.tokenA.tokenBalance.replace(/[, ]/g, ""))
.minus(assetTokenMinBalance) // TODO: substract this later if it is required, eg after calculation
.toFixed();
Expand Down