Skip to content

Commit

Permalink
Merge pull request #23 from oraichain/fix/disable-btn
Browse files Browse the repository at this point in the history
fix disable button
  • Loading branch information
quangdz1704 authored Oct 3, 2024
2 parents 266e6b0 + 7b7249b commit d2fc058
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
26 changes: 23 additions & 3 deletions components/page/bridge/hooks/useGetFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@ import { TonbridgeBridgeClient } from "@oraichain/tonbridge-contracts-sdk";
import { useEffect, useState } from "react";
import { useWalletsTonCache } from "@/stores/token/selector";

const useGetFee = ({ token }: { token: TokenType }) => {
const useGetFee = ({
token,
fromNetwork,
toNetwork,
}: {
token: TokenType;
fromNetwork: {
id: string;
};
toNetwork: {
id: string;
};
}) => {
const oraiAddress = useAuthOraiAddress();
const [bridgeFee, setBridgeFee] = useState(0);
const [tokenFee, setTokenFee] = useState(0);
Expand All @@ -17,6 +29,10 @@ const useGetFee = ({ token }: { token: TokenType }) => {
useEffect(() => {
(async () => {
try {
if (![fromNetwork.id, toNetwork.id].includes("Ton")) {
return setTokenFee(0);
}

if (token) {
const tokenInTon = TonTokenList(
process.env.NEXT_PUBLIC_ENV as Environment
Expand Down Expand Up @@ -59,10 +75,14 @@ const useGetFee = ({ token }: { token: TokenType }) => {
}
}
})();
}, [token, oraiAddress, walletsTon]);
}, [token, oraiAddress, walletsTon, fromNetwork.id, toNetwork.id]);

useEffect(() => {
(async () => {
if (![fromNetwork.id, toNetwork.id].includes("Ton")) {
return setBridgeFee(0);
}

if (token) {
const tokenInTon = TonTokenList(
process.env.NEXT_PUBLIC_ENV as Environment
Expand Down Expand Up @@ -92,7 +112,7 @@ const useGetFee = ({ token }: { token: TokenType }) => {
);
}
})();
}, [token, oraiAddress, walletsTon]);
}, [token, oraiAddress, walletsTon, fromNetwork.id, toNetwork.id]);

return {
bridgeFee,
Expand Down
28 changes: 18 additions & 10 deletions components/page/bridge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ const Bridge = () => {

const { bridgeFee, tokenFee } = useGetFee({
token,
fromNetwork,
toNetwork,
});

const { handleUpdateQueryURL } = useFillNetwork({
Expand Down Expand Up @@ -920,7 +922,9 @@ const Bridge = () => {
denom: token?.symbol,
};

let newIsInsufficientBalance = false;
// FIXME: default when isTonSource is false and isTonDestination is false
// osmosis <-> oraichain
let newIsInsufficientBalance = true;

if (isTonSource) {
newIsInsufficientBalance =
Expand All @@ -930,7 +934,9 @@ const Bridge = () => {
newValidateAmount.status = numAmount > bridgeFee + 1;
newValidateAmount.minAmount = bridgeFee + 1;
}
} else if (isTonDestination) {
}

if (isTonDestination) {
newIsInsufficientBalance =
numAmount >
toDisplay(amountsTon[token?.denom] || "0", token?.decimal);
Expand Down Expand Up @@ -1231,14 +1237,16 @@ const Bridge = () => {
{token?.symbol}
</span>
</div>
{token && !!!validateAmount.status && (
<div className={styles.itemEst}>
<span className={styles.value}>
More than {validateAmount.minAmount} {validateAmount.denom} is
required to execute this transaction.
</span>
</div>
)}
{token &&
!!!validateAmount.status &&
[toNetwork.id, fromNetwork.id].includes("Ton") && (
<div className={styles.itemEst}>
<span className={styles.value}>
More than {validateAmount.minAmount} {validateAmount.denom}{" "}
is required to execute this transaction.
</span>
</div>
)}
</div>

<div className={styles.button}>
Expand Down

0 comments on commit d2fc058

Please sign in to comment.