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

hotfix check balance max #1073

Merged
merged 1 commit into from
Dec 6, 2024
Merged
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
53 changes: 31 additions & 22 deletions src/pages/Balance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {
getCosmosGasPrice,
solChainId,
SOLANA_RPC,
toDisplay
toDisplay,
MAX_ORAICHAIN_DENOM,
MAX_SOL_CONTRACT_ADDRESS
} from '@oraichain/oraidex-common';
import { UniversalSwapHandler, UniversalSwapHelper } from '@oraichain/oraidex-universal-swap';
import { isMobile } from '@walletconnect/browser-utils';
Expand Down Expand Up @@ -459,16 +461,19 @@ const Balance: React.FC<BalanceProps> = () => {

const web3Solana = new Web3SolanaProgramInteraction();
console.log('from token address: ', fromToken.contractAddress);
const bridgeBalance =
fromToken.contractAddress === NATIVE_MINT.toBase58()
? await web3Solana.getSolanaBalance(new PublicKey(SOL_RELAYER_ADDRESS))
: await web3Solana.getTokenBalance(SOL_RELAYER_ADDRESS, fromToken.contractAddress);
console.log('token balance to oraichain: ', bridgeBalance, fromToken.contractAddress);
if (bridgeBalance < transferAmount) {
throw new Error(
`Transfer ${fromToken.denom} to Oraichain failed. The bridge balance only has ${bridgeBalance}${fromToken.denom}, wanted ${transferAmount}${fromToken.denom}`
);
if (fromToken.contractAddress !== MAX_SOL_CONTRACT_ADDRESS) {
const bridgeBalance =
fromToken.contractAddress === NATIVE_MINT.toBase58()
? await web3Solana.getSolanaBalance(new PublicKey(SOL_RELAYER_ADDRESS))
: await web3Solana.getTokenBalance(SOL_RELAYER_ADDRESS, fromToken.contractAddress);
console.log('token balance to oraichain: ', bridgeBalance, fromToken.contractAddress);
if (bridgeBalance < transferAmount) {
throw new Error(
`Transfer ${fromToken.denom} to Oraichain failed. The bridge balance only has ${bridgeBalance}${fromToken.denom}, wanted ${transferAmount}${fromToken.denom}`
);
}
}

const response = await web3Solana.bridgeSolToOrai(wallet, fromToken, transferAmount, oraiAddress);
const transaction = response?.transaction;
if (transaction) {
Expand All @@ -490,20 +495,24 @@ const Balance: React.FC<BalanceProps> = () => {
}

const receiverAddress = ORAICHAIN_RELAYER_ADDRESS;
const currentBridgeBalance = await window.client.getBalance(receiverAddress, fromToken.denom);
console.log(
'Current bridge balance transfer to sol: ',
toDisplay(currentBridgeBalance.amount, fromToken.decimals),
fromToken.denom
);
if (toDisplay(currentBridgeBalance.amount, fromToken.decimals) < transferAmount) {
throw new Error(
`Transfer ${fromToken.denom} to Solana failed. The bridge balance only has ${toDisplay(
currentBridgeBalance.amount,
fromToken.decimals
)}${currentBridgeBalance.denom.toUpperCase()}, wanted ${transferAmount}${currentBridgeBalance.denom.toUpperCase()}`

if (fromToken.denom !== MAX_ORAICHAIN_DENOM) {
const currentBridgeBalance = await window.client.getBalance(receiverAddress, fromToken.denom);
console.log(
'Current bridge balance transfer to sol: ',
toDisplay(currentBridgeBalance.amount, fromToken.decimals),
fromToken.denom
);
if (toDisplay(currentBridgeBalance.amount, fromToken.decimals) < transferAmount) {
throw new Error(
`Transfer ${fromToken.denom} to Solana failed. The bridge balance only has ${toDisplay(
currentBridgeBalance.amount,
fromToken.decimals
)}${currentBridgeBalance.denom.toUpperCase()}, wanted ${transferAmount}${currentBridgeBalance.denom.toUpperCase()}`
);
}
}

const result = await window.client.sendTokens(
oraiAddress,
receiverAddress,
Expand Down
Loading