Skip to content

Commit

Permalink
Merge pull request #1073 from oraidex/hotfix/check-balance
Browse files Browse the repository at this point in the history
hotfix check balance max
  • Loading branch information
haunv3 authored Dec 6, 2024
2 parents 89d5d29 + 3c5e291 commit fba0d84
Showing 1 changed file with 31 additions and 22 deletions.
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

0 comments on commit fba0d84

Please sign in to comment.