Skip to content

Commit

Permalink
Merge pull request #1041 from oraidex/fix/inj
Browse files Browse the repository at this point in the history
fix inj
  • Loading branch information
haunv3 authored Nov 15, 2024
2 parents 3d7ab8e + 689b387 commit 874c090
Showing 1 changed file with 76 additions and 73 deletions.
149 changes: 76 additions & 73 deletions src/pages/Balance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ import { TokenItemBtc } from './TokenItem/TokenItemBtc';
import DepositBtcModalV2 from './DepositBtcModalV2';
import { CwBitcoinContext } from 'context/cw-bitcoin-context';
import { AppBitcoinClient } from '@oraichain/bitcoin-bridge-contracts-sdk';

import { MsgTransfer } from 'cosmjs-types/ibc/applications/transfer/v1/tx';
import { MsgTransfer as MsgTransferInjective } from '@injectivelabs/sdk-ts/node_modules/cosmjs-types/ibc/applications/transfer/v1/tx';
import { collectWallet, connectWithSigner, getCosmWasmClient } from 'libs/cosmjs';

interface BalanceProps { }
interface BalanceProps {}

export const isMaintainBridge = false;

Expand Down Expand Up @@ -599,15 +599,19 @@ const Balance: React.FC<BalanceProps> = () => {
);

const receiver = await handleCheckAddress(to.chainId);
const msgTransfer = MsgTransfer.fromPartial({
const msgTransferObj = {
sourcePort: ibcInfo.source,
receiver,
sourceChannel: ibcInfo.channel,
token: coin(toAmount(fromAmount, from.decimals).toString(), from.denom),
sender: cosmosAddress,
memo: '',
timeoutTimestamp: BigInt(calculateTimeoutTimestamp(ibcInfo.timeout))
});
timeoutTimestamp: calculateTimeoutTimestamp(ibcInfo.timeout)
};
let msgTransfer: any = MsgTransfer.fromPartial(msgTransferObj as any);
if (from.chainId === 'injective-1') {
msgTransfer = MsgTransferInjective.fromPartial(msgTransferObj);
}

const msgTransferEncodeObj = {
typeUrl: '/ibc.applications.transfer.v1.MsgTransfer',
Expand Down Expand Up @@ -749,75 +753,74 @@ const Balance: React.FC<BalanceProps> = () => {
<LoadingBox loading={loadingRefresh}>
<div className={styles.tokens}>
<div className={styles.tokens_form} ref={ref}>
{getFilterTokens(filterNetworkUI)
.map((t: TokenItemType) => {
// check balance cw20
let amount = BigInt(amounts[t.denom] ?? 0);
let usd = getUsd(amount, t, prices);
let subAmounts: AmountDetails;
if (t.contractAddress && t.evmDenoms) {
subAmounts = getSubAmountDetails(amounts, t);
const subAmount = toAmount(toSumDisplay(subAmounts), t.decimals);
amount += subAmount;
usd += getUsd(subAmount, t, prices);
}
// TODO: hardcode check bitcoinTestnet need update later
const isOwallet =
walletByNetworks.cosmos &&
walletByNetworks.cosmos === 'owallet' &&
//@ts-ignore
window?.owallet?.isOwallet;

const isBtcToken = t.chainId === bitcoinChainId && t?.coinGeckoId === 'bitcoin';
const isV2 = false;
const TokenItemELement: React.FC<TokenItemProps> = isBtcToken && isV2 ? TokenItemBtc : TokenItem;
return (
<div key={t.denom}>
{!isOwallet && !isMobile() && isBtcToken && (
<div className={styles.info}>
<div>
<TooltipIcon width={20} height={20} />
</div>
<span>Feature only supported on Owallet. Please connect Cosmos with Owallet</span>
{getFilterTokens(filterNetworkUI).map((t: TokenItemType) => {
// check balance cw20
let amount = BigInt(amounts[t.denom] ?? 0);
let usd = getUsd(amount, t, prices);
let subAmounts: AmountDetails;
if (t.contractAddress && t.evmDenoms) {
subAmounts = getSubAmountDetails(amounts, t);
const subAmount = toAmount(toSumDisplay(subAmounts), t.decimals);
amount += subAmount;
usd += getUsd(subAmount, t, prices);
}
// TODO: hardcode check bitcoinTestnet need update later
const isOwallet =
walletByNetworks.cosmos &&
walletByNetworks.cosmos === 'owallet' &&
//@ts-ignore
window?.owallet?.isOwallet;

const isBtcToken = t.chainId === bitcoinChainId && t?.coinGeckoId === 'bitcoin';
const isV2 = false;
const TokenItemELement: React.FC<TokenItemProps> = isBtcToken && isV2 ? TokenItemBtc : TokenItem;
return (
<div key={t.denom}>
{!isOwallet && !isMobile() && isBtcToken && (
<div className={styles.info}>
<div>
<TooltipIcon width={20} height={20} />
</div>
)}
<TokenItemELement
onDepositBtc={async () => {
setIsDepositBtcModal(true);
}}
isBtcOfOwallet={isOwallet || isMobile()}
isBtcToken={isBtcToken}
className={classNames(styles.tokens_element, styles[theme])}
key={t.denom}
amountDetail={{ amount: amount.toString(), usd }}
subAmounts={subAmounts}
active={from?.denom === t.denom}
token={t}
theme={theme}
onClick={() => {
if (t.denom !== from?.denom) {
onClickToken(t);
}
}}
onClickTransfer={async (fromAmount: number, filterNetwork?: NetworkChainId) => {
await onClickTransfer(fromAmount, from, to, filterNetwork);
}}
convertKwt={async (transferAmount: number, fromToken: TokenItemType) => {
try {
const result = await convertKwt(transferAmount, fromToken);
processTxResult(from.rpc, result, getTransactionUrl(from.chainId, result.transactionHash));
} catch (ex) {
displayToast(TToastType.TX_FAILED, {
message: ex.message
});
}
}}
isFastMode={isFastMode}
setIsFastMode={setIsFastMode}
/>
</div>
);
})}
<span>Feature only supported on Owallet. Please connect Cosmos with Owallet</span>
</div>
)}
<TokenItemELement
onDepositBtc={async () => {
setIsDepositBtcModal(true);
}}
isBtcOfOwallet={isOwallet || isMobile()}
isBtcToken={isBtcToken}
className={classNames(styles.tokens_element, styles[theme])}
key={t.denom}
amountDetail={{ amount: amount.toString(), usd }}
subAmounts={subAmounts}
active={from?.denom === t.denom}
token={t}
theme={theme}
onClick={() => {
if (t.denom !== from?.denom) {
onClickToken(t);
}
}}
onClickTransfer={async (fromAmount: number, filterNetwork?: NetworkChainId) => {
await onClickTransfer(fromAmount, from, to, filterNetwork);
}}
convertKwt={async (transferAmount: number, fromToken: TokenItemType) => {
try {
const result = await convertKwt(transferAmount, fromToken);
processTxResult(from.rpc, result, getTransactionUrl(from.chainId, result.transactionHash));
} catch (ex) {
displayToast(TToastType.TX_FAILED, {
message: ex.message
});
}
}}
isFastMode={isFastMode}
setIsFastMode={setIsFastMode}
/>
</div>
);
})}
</div>
</div>
</LoadingBox>
Expand Down

0 comments on commit 874c090

Please sign in to comment.