Skip to content

Commit

Permalink
Merge pull request #319 from oraichain/feat/check-balance-universal-swap
Browse files Browse the repository at this point in the history
  • Loading branch information
haunv3 authored Aug 31, 2023
2 parents 40985fe + b85d317 commit 976e902
Show file tree
Hide file tree
Showing 5 changed files with 464 additions and 168 deletions.
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sonar.projectKey=oraichain_oraiswap-frontend_AYoDOebvkauZkVxG9Y0p
sonar.projectKey=oraichain_oraiswap-frontend_AYpL50t8tGfUdSAJ_QO4
25 changes: 22 additions & 3 deletions src/pages/Balance/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { createWasmAminoConverters, ExecuteResult } from '@cosmjs/cosmwasm-stargate';
import { coin, Coin } from '@cosmjs/proto-signing';
import { AminoTypes, DeliverTxResponse, GasPrice, SigningStargateClient } from '@cosmjs/stargate';
import { AminoTypes, DeliverTxResponse, GasPrice, SigningStargateClient, StargateClient } from '@cosmjs/stargate';
import {
cosmosTokens,
flattenTokens,
gravityContracts,
kawaiiTokens,
oraichainTokens,
TokenItemType,
tokenMap,
UniversalSwapType
Expand All @@ -17,12 +18,16 @@ import { network } from 'config/networks';
import { calculateTimeoutTimestamp, getNetworkGasPrice } from 'helper';

import { CwIcs20LatestClient, TransferBackMsg } from '@oraichain/common-contracts-sdk';
import { OraiswapTokenClient } from '@oraichain/oraidex-contracts-sdk';
import {
OraiswapTokenClient,
OraiswapTokenQueryClient,
OraiswapTokenReadOnlyInterface
} from '@oraichain/oraidex-contracts-sdk';
import CosmJs, { getExecuteContractMsgs, HandleOptions, parseExecuteContractMultiple } from 'libs/cosmjs';
import KawaiiverseJs from 'libs/kawaiiversejs';
import { MsgTransfer } from 'libs/proto/ibc/applications/transfer/v1/tx';
import customRegistry, { customAminoTypes } from 'libs/registry';
import { buildMultipleMessages, generateError, toAmount } from 'libs/utils';
import { buildMultipleMessages, generateError, toAmount, toDisplay } from 'libs/utils';
import {
generateConvertCw20Erc20Message,
generateConvertMsgs,
Expand Down Expand Up @@ -241,6 +246,20 @@ export const convertTransferIBCErc20Kwt = async (
return result;
};

export const getBalanceIBCOraichain = async (
token: TokenItemType,
tokenQueryClient?: OraiswapTokenReadOnlyInterface
) => {
if (!token) return { balance: 0 };
if (token.contractAddress) {
const cw20Token = tokenQueryClient ?? new OraiswapTokenQueryClient(window.client, token.contractAddress);
const { balance } = await cw20Token.balance({ address: process.env.REACT_APP_IBC_WASM_CONTRACT });
return { balance: toDisplay(balance, token.decimals) };
}
const { amount } = await window.client.getBalance(process.env.REACT_APP_IBC_WASM_CONTRACT, token.denom);
return { balance: toDisplay(amount, token.decimals) };
};

export const transferEvmToIBC = async (
from: TokenItemType,
fromAmount: number,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Balance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import StuckOraib from './StuckOraib';
import useGetOraiBridgeBalances from './StuckOraib/useGetOraiBridgeBalances';
import TokenItem from './TokenItem';

interface BalanceProps {}
interface BalanceProps { }

const Balance: React.FC<BalanceProps> = () => {
const [searchParams] = useSearchParams();
Expand Down
Loading

0 comments on commit 976e902

Please sign in to comment.