();
+
const [deductNativeAmount, setDeductNativeAmount] = useState(0n);
const { data: prices } = useCoinGeckoPrices();
@@ -121,6 +123,8 @@ const Bridge = () => {
if (toNetwork.id === NetworkList["osmosis-1"].id)
destinationAddress = getAddressCosmos(oraiAddress);
+ const network = getNetworkConfig(tonNetwork);
+
const { bridgeFee, tokenFee } = useGetFee({
token,
});
@@ -130,6 +134,40 @@ const Bridge = () => {
setToNetwork,
});
+ useEffect(() => {
+ try {
+ (async () => {
+ const values = TonTokenList(tonNetwork).values();
+ const endpoint = await getHttpEndpoint();
+ const client = new TonClient({
+ endpoint,
+ });
+ const bridgeAdapter = TonInteractionContract[tonNetwork].bridgeAdapter;
+ const jettonWallet = await Promise.all(
+ [...values].map((value) => {
+ if (value.contractAddress === TON_ZERO_ADDRESS)
+ return Address.parse(TON_ZERO_ADDRESS);
+ const jettonMinter = client.open(
+ JettonMinter.createFromAddress(
+ Address.parse(value.contractAddress)
+ )
+ );
+ return jettonMinter.getWalletAddress(Address.parse(bridgeAdapter));
+ })
+ );
+ const allJettonWallet = jettonWallet.reduce((acc, cur, idx) => {
+ acc.push(cur.toString());
+ return acc;
+ }, [] as string[]);
+ console.log({ allJettonWallet });
+ console.log({ bridgeAdapter });
+ setBridgeJettonWallets(allJettonWallet);
+ })();
+ } catch (error) {
+ console.log("error :>>", error);
+ }
+ }, []);
+
useEffect(() => {
if (
toNetwork.id == NetworkList.oraichain.id &&
@@ -163,11 +201,16 @@ const Bridge = () => {
const jettonMinter = JettonMinter.createFromAddress(
Address.parse(token.contractAddress)
);
- const jettonMinterContract = client.open(jettonMinter);
- const jettonWalletAddress = await jettonMinterContract.getWalletAddress(
- Address.parse(tonAddress)
- );
+ const jettonMinterContract = client.open(jettonMinter);
+ const [jettonWalletAddress, bridgeJettonWalletAddress] =
+ await Promise.all([
+ jettonMinterContract.getWalletAddress(Address.parse(tonAddress)),
+ jettonMinterContract.getWalletAddress(
+ Address.parse(TonInteractionContract[tonNetwork].bridgeAdapter)
+ ),
+ ]);
+ console.log({ bridgeJettonWalletAddress });
setTokenInfo({
jettonWalletAddress,
});
@@ -185,8 +228,7 @@ const Bridge = () => {
const client = new TonClient({
endpoint,
});
- const bridgeAdapter =
- TonInteractionContract[TonNetwork.Mainnet].bridgeAdapter;
+ const bridgeAdapter = TonInteractionContract[tonNetwork].bridgeAdapter;
if (token.contractAddress === TON_ZERO_ADDRESS) {
const balance = await client.getBalance(Address.parse(bridgeAdapter));
@@ -206,7 +248,7 @@ const Bridge = () => {
const jettonWallet = JettonWallet.createFromAddress(jettonWalletAddress);
const jettonWalletContract = client.open(jettonWallet);
const balance = await jettonWalletContract.getBalance();
-
+ console.log({ bridgeAdapter, jettonMinter, jettonWallet, balance });
return {
balance: balance.amount,
};
@@ -313,7 +355,9 @@ const Bridge = () => {
if (!token || !amount) throw "Not valid!";
- validatePrice(token, amount);
+ if (tonNetwork == "mainnet") {
+ validatePrice(token, amount);
+ }
setLoading(true);
@@ -469,19 +513,6 @@ const Bridge = () => {
if (!token || !amount) throw "Not valid!";
- // get the decentralized RPC endpoint
- // const endpoint = await getHttpEndpoint();
- // const client = new TonClient({
- // endpoint,
- // });
-
- // const isActiveDestinationAddress = await client.isContractDeployed(
- // Address.parse(destinationAddress)
- // );
- // if (!isActiveDestinationAddress) {
- // throw "Destination address has to be an active address!";
- // }
-
setLoading(true);
const isFromOsmosisToOraichain =
fromNetwork.id === NetworkList["osmosis-1"].id &&
@@ -524,7 +555,7 @@ const Bridge = () => {
undefined,
undefined,
{
- contractAddress: CW_TON_BRIDGE,
+ contractAddress: network.CW_TON_BRIDGE,
msg: toBinary({
bridge_to_ton: {
to: tonAddress,
@@ -607,22 +638,23 @@ const Bridge = () => {
}
return;
}
+ if (tonNetwork == "mainnet") {
+ validatePrice(token, amount);
+ }
- validatePrice(token, amount);
-
- const tokenInTon = TonTokenList(TonNetwork.Mainnet).find(
+ const tokenInTon = TonTokenList(tonNetwork).find(
+ (tk) => tk.coingeckoId === token.coingeckoId
+ );
+ const index = TonTokenList(tonNetwork).findIndex(
(tk) => tk.coingeckoId === token.coingeckoId
);
+ const bridgeJettonWallet = bridgeJettonWallets[index];
+
const balanceMax = (sentBalance || []).find(
- (b) => b.native.denom === tokenInTon.contractAddress
+ (b) => b.native.denom === bridgeJettonWallet
)?.native.amount;
- // const balanceMax = await checkBalanceBridgeByNetwork(
- // NetworkList.oraichain.id,
- // tokenInTon
- // );
-
const displayBalance = toDisplay(
balanceMax,
tokenInTon?.decimal || CW20_DECIMALS
@@ -642,11 +674,10 @@ const Bridge = () => {
let tx;
const timeout = Math.floor(new Date().getTime() / 1000) + 3600;
+
const msg = {
// crcSrc: ARG_BRIDGE_TO_TON.CRC_SRC,
- denom: TonTokenList(tonNetwork).find(
- (tk) => tk.coingeckoId === token.coingeckoId
- ).contractAddress,
+ denom: bridgeJettonWallet,
timeout,
to: tonAddress,
};
@@ -734,7 +765,7 @@ const Bridge = () => {
}
// const isMaintained = fromNetwork.id === NetworkList.oraichain.id;
- const isMaintained = true;
+ const isMaintained = false;
return (
diff --git a/constants/chainInfo.ts b/constants/chainInfo.ts
index 0a6306c..680fdb0 100644
--- a/constants/chainInfo.ts
+++ b/constants/chainInfo.ts
@@ -154,6 +154,16 @@ export const oraichainNetwork: CustomChainInfo = {
coinDecimals: 6,
Icon: UsdtIcon,
},
+ {
+ coinDenom: "jUSDT",
+ coinGeckoId: "bridged-tether-ton-bridge",
+ coinMinimalDenom: "jusdt",
+ type: "cw20",
+ contractAddress: USDT_CONTRACT,
+ bridgeTo: ["0x38", "0x2b6653dc", "0x01"],
+ coinDecimals: 6,
+ Icon: UsdtIcon,
+ },
{
coinDenom: "USDC",
coinGeckoId: "usd-coin",
diff --git a/constants/contract.ts b/constants/contract.ts
index 65776ac..cef3b9e 100644
--- a/constants/contract.ts
+++ b/constants/contract.ts
@@ -1,32 +1,59 @@
-import { TonNetwork } from "./ton";
+import { Environment } from "./ton";
+
+export const TON_ZERO_ADDRESS =
+ "EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c";
export const TonInteractionContract = {
- [TonNetwork.Mainnet]: {
+ [Environment.Mainnet]: {
lightClient: "EQDzy_POlimFDyzrHd3OQsb9sZCngyG3O7Za4GRFzM-rrO93",
whitelist: "EQATDM6mfPZjPDMD9TVa6D9dlbmAKY5w6xOJiTXJ9Nqj_dsu",
bridgeAdapter: "EQC-aFP0rJXwTgKZQJPbPfTSpBFc8wxOgKHWD9cPvOl_DnaY",
},
- [TonNetwork.Testnet]: {
+ [Environment.Staging]: {
+ lightClient: "EQDzy_POlimFDyzrHd3OQsb9sZCngyG3O7Za4GRFzM-rrO93",
+ whitelist: "EQAbJI3NZKGcVu-ec_z_LcmXca9ZOtzkgCW5H9glnWBDpaFg",
+ bridgeAdapter: "EQA3ISho4fpW3wmCkKEwsyXulIw7vLf-2jxso40ul3QQJ_O7",
+ },
+ [Environment.Testnet]: {
lightClient: "",
whitelist: "EQD2xPIqdeggqtP3q852Y-7yD-RRHi12Zy7M4iUx4-7q0E1",
bridgeAdapter: "EQDZfQX89gMo3HAiW1tSK9visb2gouUvDCt6PODo3qkXKeox",
},
};
-export const TON_ZERO_ADDRESS =
- "EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c";
-
export const TonTokensContract = {
- [TonNetwork.Mainnet]: {
+ [Environment.Mainnet]: {
usdt: "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs",
+ // jUSDT: "EQBynBO23ywHy_CgarY9NK9FTz0yDsG82PtcbSTQgGoXwiuA",
ton: TON_ZERO_ADDRESS,
},
- [TonNetwork.Testnet]: {
+ [Environment.Staging]: {
+ usdt: "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs",
+ jUSDT: "EQBynBO23ywHy_CgarY9NK9FTz0yDsG82PtcbSTQgGoXwiuA",
+ ton: TON_ZERO_ADDRESS,
+ },
+ [Environment.Testnet]: {
usdt: "EQA5FnPP13uZPJQq7aj6UHLEukJJZSZW053cU1Wu6R6BpYYB",
+ jUSDT: "EQA5FnPP13uZPJQq7aj6UHLEukJJZSZW053cU1Wu6R6BpYYB",
ton: TON_ZERO_ADDRESS,
},
};
+export const CwInteractionContract = {
+ [Environment.Mainnet]: {
+ cosmwasmBridge:
+ "orai159l8l9c5ckhqpuwdfgs9p4v599nqt3cjlfahalmtrhfuncnec2ms5mz60e",
+ tokenFactory:
+ "orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6n5vtlngfzes3k0rq9",
+ },
+ [Environment.Staging]: {
+ cosmwasmBridge:
+ "orai16e976su89dygmapmepqerktwj3zvx5znahnj0zpgwj2scef2sjask4vm58",
+ tokenFactory:
+ "orai17hyr3eg92fv34fdnkend48scu32hn26gqxw3hnwkfy904lk9r09qqzty42",
+ },
+};
+
export const CW_TON_BRIDGE =
"orai159l8l9c5ckhqpuwdfgs9p4v599nqt3cjlfahalmtrhfuncnec2ms5mz60e";
export const TOKEN_FACTORY =
diff --git a/constants/networks.ts b/constants/networks.ts
index 36e2e32..fabbb18 100644
--- a/constants/networks.ts
+++ b/constants/networks.ts
@@ -4,18 +4,21 @@ import {
ROUTER_V2_CONTRACT,
} from "@oraichain/oraidex-common";
import { oraichainNetwork } from "./chainInfo";
-import { CW_TON_BRIDGE, TOKEN_FACTORY } from "./contract";
+import { CwInteractionContract } from "./contract";
+import { Environment } from "./ton";
-export const network = {
- ...oraichainNetwork,
- prefix: oraichainNetwork.bech32Config.bech32PrefixAccAddr,
- denom: "orai",
- coinType: oraichainNetwork.bip44.coinType,
- fee: { gasPrice: "0.00506", amount: "1518", gas: "2000000" }, // 0.000500 ORAI
- explorer: "https://scan.orai.io",
- router: ROUTER_V2_CONTRACT,
- oracle: ORACLE_CONTRACT,
- multicall: MULTICALL_CONTRACT,
- CW_TON_BRIDGE: CW_TON_BRIDGE,
- TOKEN_FACTORY: TOKEN_FACTORY,
+export const getNetworkConfig = (env: Environment) => {
+ return {
+ ...oraichainNetwork,
+ prefix: oraichainNetwork.bech32Config.bech32PrefixAccAddr,
+ denom: "orai",
+ coinType: oraichainNetwork.bip44.coinType,
+ fee: { gasPrice: "0.00506", amount: "1518", gas: "2000000" }, // 0.000500 ORAI
+ explorer: "https://scan.orai.io",
+ router: ROUTER_V2_CONTRACT,
+ oracle: ORACLE_CONTRACT,
+ multicall: MULTICALL_CONTRACT,
+ CW_TON_BRIDGE: CwInteractionContract[env].cosmwasmBridge,
+ TOKEN_FACTORY: CwInteractionContract[env].tokenFactory,
+ };
};
diff --git a/constants/tokens.ts b/constants/tokens.ts
index 5ec819e..81c0c59 100644
--- a/constants/tokens.ts
+++ b/constants/tokens.ts
@@ -1,10 +1,11 @@
-import { TonNetwork } from "./ton";
+import { Environment } from "./ton";
import { TonTokensContract } from "./contract";
import { UsdtIcon, TetherIcon } from "@/assets/icons/token";
import { USDT_CONTRACT } from "@oraichain/oraidex-common";
import { TonNetworkICon } from "@/assets/icons/network";
export type TokenType = {
+ chainId?: string;
name: string;
symbol: string;
Icon: () => JSX.Element;
@@ -18,6 +19,7 @@ export const TON_DENOM = `factory/orai1wuvhex9xqs3r539mvc6mtm7n20fcj3qr2m0y9khx6
export const OraichainTokenList: TokenType[] = [
{
+ chainId: "Oraichain",
name: "Tether",
symbol: "USDT",
Icon: UsdtIcon,
@@ -26,7 +28,18 @@ export const OraichainTokenList: TokenType[] = [
coingeckoId: "tether",
decimal: 6,
},
+ // {
+ // chainId: "Oraichain",
+ // name: "Tether",
+ // symbol: "jUSDT",
+ // Icon: UsdtIcon,
+ // contractAddress: USDT_CONTRACT,
+ // denom: "jusdt",
+ // coingeckoId: "bridged-tether-ton-bridge",
+ // decimal: 6,
+ // },
{
+ chainId: "Oraichain",
name: "Ton",
symbol: "TON",
Icon: TonNetworkICon,
@@ -37,20 +50,29 @@ export const OraichainTokenList: TokenType[] = [
},
];
-export const OsmosisTokenList: TokenType[] = [
+export const OsmosisTokenDenom = {
+ [Environment.Mainnet]: {
+ ton: "ibc/905889A7F0B94F1CE1506D9BADF13AE9141E4CBDBCD565E1DFC7AE418B3E3E98",
+ },
+ [Environment.Staging]: {
+ ton: "ibc/64BF62F8C7C0B1AADBCFBCB45E778DA144E86804420AC5AD4F29D141A14A031B",
+ },
+};
+
+export const OsmosisTokenList = (network: Environment): TokenType[] => [
{
+ chainId: "osmosis-1",
name: "Ton",
symbol: "TON",
Icon: TonNetworkICon,
contractAddress: null,
- denom:
- "ibc/905889A7F0B94F1CE1506D9BADF13AE9141E4CBDBCD565E1DFC7AE418B3E3E98",
+ denom: OsmosisTokenDenom[network].ton,
coingeckoId: "the-open-network",
decimal: 9,
},
];
-export const TonTokenList = (network: TonNetwork): TokenType[] => [
+export const TonTokenList = (network: Environment): TokenType[] => [
{
name: "Tether",
symbol: "USDT",
@@ -60,6 +82,15 @@ export const TonTokenList = (network: TonNetwork): TokenType[] => [
coingeckoId: "tether",
decimal: 6,
},
+ // {
+ // name: "Jetton USDT",
+ // symbol: "jUSDT",
+ // Icon: TetherIcon,
+ // contractAddress: TonTokensContract[network].jUSDT,
+ // denom: "ton20_usdt",
+ // coingeckoId: "bridged-tether-ton-bridge",
+ // decimal: 6,
+ // },
{
name: "Ton",
symbol: "TON",
diff --git a/constants/ton.ts b/constants/ton.ts
index a4fa5b7..286f037 100644
--- a/constants/ton.ts
+++ b/constants/ton.ts
@@ -1,4 +1,5 @@
-export enum TonNetwork {
+export enum Environment {
Mainnet = "mainnet",
Testnet = "testnet",
+ Staging = "staging",
}
diff --git a/contexts/app-provider.tsx b/contexts/app-provider.tsx
index bddd867..f9e072a 100644
--- a/contexts/app-provider.tsx
+++ b/contexts/app-provider.tsx
@@ -1,7 +1,7 @@
"use client";
-import { TonNetwork } from "@/constants/ton";
-import { network } from "@/constants/networks";
+import { Environment } from "@/constants/ton";
+import { getNetworkConfig } from "@/constants/networks";
import { useLoadToken, useLoadTonBalance } from "@/hooks/useLoadToken";
import { getCosmWasmClient } from "@/libs/cosmjs";
import Keplr from "@/libs/keplr";
@@ -25,6 +25,8 @@ import React, { useEffect } from "react";
import { TToastType, displayToast } from "./toasts/Toast";
import { getAddressCosmos } from "@/components/page/bridge/helper";
+const env = process.env.NEXT_PUBLIC_ENV as Environment;
+const network = getNetworkConfig(env);
if (typeof window !== "undefined") {
polyfill();
@@ -53,7 +55,7 @@ export const AppProvider = (props: React.PropsWithChildren<{}>) => {
const { loadToken } = useLoadToken();
const { loadAllBalanceTonToken } = useLoadTonBalance({
tonAddress,
- tonNetwork: TonNetwork.Mainnet,
+ tonNetwork: Environment.Mainnet,
});
const keplrHandler = async () => {
@@ -69,7 +71,7 @@ export const AppProvider = (props: React.PropsWithChildren<{}>) => {
}
if (oraiWallet || mobileMode) {
- oraiAddress = await window.Keplr.getKeplrAddr();
+ oraiAddress = await window.Keplr.getKeplrAddr("Oraichain");
if (oraiAddress) {
handleSetOraiAddress({ oraiAddress });
@@ -100,6 +102,7 @@ export const AppProvider = (props: React.PropsWithChildren<{}>) => {
useEffect(() => {
if (oraiAddress) {
const cosmosAddress = getAddressCosmos(oraiAddress);
+ console.log("first", cosmosAddress);
loadToken({
oraiAddress,
cosmosAddress,
@@ -111,6 +114,7 @@ export const AppProvider = (props: React.PropsWithChildren<{}>) => {
(async () => {
if (walletType && typeof window !== "undefined") {
const cosmWasmClient = await getCosmWasmClient({
+ env: process.env.NEXT_PUBLIC_ENV as Environment,
chainId: network.chainId,
});
if (cosmWasmClient && cosmWasmClient.client) {
diff --git a/contexts/ton-provider.tsx b/contexts/ton-provider.tsx
index 205f398..b4f7526 100644
--- a/contexts/ton-provider.tsx
+++ b/contexts/ton-provider.tsx
@@ -1,6 +1,6 @@
"use client";
-import { TonNetwork } from "@/constants/ton";
+import { Environment } from "@/constants/ton";
import { MANIFEST_URL } from "@/constants/config";
import { useLoadTonBalance } from "@/hooks/useLoadToken";
import { useAuthTonAddress } from "@/stores/authentication/selector";
@@ -12,7 +12,7 @@ export const TonProvider = (props: React.PropsWithChildren<{}>) => {
const { loadAllBalanceTonToken } = useLoadTonBalance({
tonAddress,
- tonNetwork: TonNetwork.Mainnet,
+ tonNetwork: Environment.Mainnet,
});
const [isMounted, setIsMounted] = useState(false);
diff --git a/firebase.json b/firebase.json
index a7c59b8..b1e80b4 100644
--- a/firebase.json
+++ b/firebase.json
@@ -43,6 +43,50 @@
"destination": "/index.html"
}
]
+ },
+ {
+ "target": "ton-bridge-staging",
+ "public": "out",
+ "ignore": [
+ "firebase.json",
+ "**/.*",
+ "**/node_modules/**"
+ ],
+ "headers": [
+ {
+ "source": "**/*.@(jpg|jpeg|gif|png|svg|webp)",
+ "headers": [
+ {
+ "key": "Cache-Control",
+ "value": "max-age=604800" // Cache images for 7 days
+ }
+ ]
+ },
+ {
+ "source": "**/*.@(css|js)",
+ "headers": [
+ {
+ "key": "Cache-Control",
+ "value": "max-age=604800" // Cache CSS and JS files for 7 days
+ }
+ ]
+ },
+ {
+ "source": "/index.html",
+ "headers": [
+ {
+ "key": "Cache-Control",
+ "value": "no-cache, no-store, must-revalidate" // Do not cache the main HTML file
+ }
+ ]
+ }
+ ],
+ "rewrites": [
+ {
+ "source": "**",
+ "destination": "/index.html"
+ }
+ ]
}
]
}
\ No newline at end of file
diff --git a/helper/index.tsx b/helper/index.tsx
index 517f219..298a077 100644
--- a/helper/index.tsx
+++ b/helper/index.tsx
@@ -1,4 +1,4 @@
-import { network } from "@/constants/networks";
+import { getNetworkConfig } from "@/constants/networks";
import {
BSC_SCAN,
BigDecimal,
@@ -34,6 +34,7 @@ import {
OraiWallet,
TonWallet,
} from "@/stores/authentication/useAuthenticationStore";
+import { Environment } from "@/constants/ton";
export interface Tokens {
denom?: string;
@@ -132,14 +133,19 @@ export const getTransactionUrl = (
case "kawaii_6886-1":
return `${KWT_SCAN}/tx/${transactionHash}`;
case "Oraichain":
- return `${network.explorer}/txs/${transactionHash}`;
+ return `${
+ getNetworkConfig(process.env.NEXT_PUBLIC_ENV as Environment)
+ .explorer
+ }/txs/${transactionHash}`;
}
return null;
}
};
export const getAccountUrl = (account: string) => {
- return `${network.explorer}/account/${account}`;
+ return `${
+ getNetworkConfig(process.env.NEXT_PUBLIC_ENV as Environment).explorer
+ }/account/${account}`;
};
export const getNetworkGasPrice = async (chainId): Promise => {
diff --git a/hooks/useLoadToken.ts b/hooks/useLoadToken.ts
index 9dc93e2..1be0a5c 100644
--- a/hooks/useLoadToken.ts
+++ b/hooks/useLoadToken.ts
@@ -6,10 +6,14 @@ import {
tokenMap,
} from "@/constants/bridgeTokens";
import { chainInfos } from "@/constants/chainInfo";
-import { TonNetwork } from "@/constants/ton";
+import { Environment } from "@/constants/ton";
import { TON_ZERO_ADDRESS, TonTokensContract } from "@/constants/contract";
-import { network } from "@/constants/networks";
-import { TonTokenList } from "@/constants/tokens";
+import { getNetworkConfig } from "@/constants/networks";
+import {
+ OsmosisTokenDenom,
+ OsmosisTokenList,
+ TonTokenList,
+} from "@/constants/tokens";
import { genAddressCosmos, handleCheckWallet } from "@/helper";
import { useAmountsCache, useTokenActions } from "@/stores/token/selector";
import { fromBinary, toBinary } from "@cosmjs/cosmwasm-stargate";
@@ -17,13 +21,13 @@ import { StargateClient } from "@cosmjs/stargate";
import { MulticallQueryClient } from "@oraichain/common-contracts-sdk";
import { OraiswapTokenTypes } from "@oraichain/oraidex-contracts-sdk";
import { useEffect } from "react";
-
-import { CW20_DECIMALS, toDisplay } from "@oraichain/oraidex-common";
+import { toDisplay } from "@oraichain/oraidex-common";
import { JettonMinter, JettonWallet } from "@oraichain/ton-bridge-contracts";
import { getHttpEndpoint } from "@orbs-network/ton-access";
import { Address } from "@ton/core";
import { TonClient } from "@ton/ton";
+const env = process.env.NEXT_PUBLIC_ENV as Environment;
async function loadNativeBalance(
dispatch: (amount: AmountDetails) => void,
address: string,
@@ -37,51 +41,30 @@ async function loadNativeBalance(
let amountDetails: AmountDetails = {};
// reset native balances
- [...cosmosTokens]
+ [...cosmosTokens, ...OsmosisTokenList(env)]
.filter((t) => t.chainId === tokenInfo.chainId && !t.contractAddress)
.forEach((t) => {
amountDetails[t.denom] = "0";
});
const tokensAmount = amountAll
- .filter((coin) => tokenMap[coin.denom])
+ .filter(
+ (coin) =>
+ tokenMap[coin.denom] ||
+ [...Object.values(OsmosisTokenDenom[Environment.Staging])].includes(
+ coin.denom
+ )
+ )
.map((coin) => [coin.denom, coin.amount]);
Object.assign(amountDetails, Object.fromEntries(tokensAmount));
dispatch(amountDetails);
} catch (ex) {
- console.trace("errror");
+ console.trace("error");
console.log(ex);
}
}
-const timer = {};
-
-async function loadTokensCosmos(
- dispatch: (amount: AmountDetails) => void,
- kwtAddress: string,
- oraiAddress: string
-) {
- if (!kwtAddress && !oraiAddress) return;
- await handleCheckWallet();
- const cosmosInfos = chainInfos.filter(
- (chainInfo) =>
- (chainInfo.networkType === "cosmos" ||
- chainInfo.bip44.coinType === 118) &&
- // TODO: ignore oraibtc
- chainInfo.chainId !== ("oraibtc-mainnet-1" as string)
- );
- for (const chainInfo of cosmosInfos) {
- const { cosmosAddress } = genAddressCosmos(
- chainInfo,
- kwtAddress,
- oraiAddress
- );
- if (!cosmosAddress) continue;
- loadNativeBalance(dispatch, cosmosAddress, chainInfo);
- }
-}
-
async function loadCw20Balance(
dispatch: (amount: AmountDetails) => void,
address: string
@@ -95,7 +78,10 @@ async function loadCw20Balance(
balance: { address },
});
- const multicall = new MulticallQueryClient(window.client, network.multicall);
+ const multicall = new MulticallQueryClient(
+ window.client,
+ getNetworkConfig(env).multicall
+ );
const res = await multicall.aggregate({
queries: cw20Tokens.map((t) => ({
@@ -150,7 +136,10 @@ async function loadCw20BalanceWithSpecificTokens(
balance: { address },
});
- const multicall = new MulticallQueryClient(window.client, network.multicall);
+ const multicall = new MulticallQueryClient(
+ window.client,
+ getNetworkConfig(env).multicall
+ );
const res = await multicall.aggregate({
queries: cw20Tokens.map((t) => ({
@@ -177,25 +166,12 @@ async function loadCw20BalanceWithSpecificTokens(
return amountDetails;
}
-// async function loadNativeBtcBalance(address: string, chain: CustomChainInfo) {
-// const data = await getUtxos(address, chain.rest);
-// const total = reduce(
-// data,
-// function (sum, n) {
-// return sum + n.value;
-// },
-// 0
-// );
-
-// return total;
-// }
-
export const useLoadTonBalance = ({
tonAddress,
- tonNetwork = TonNetwork.Mainnet,
+ tonNetwork = Environment.Mainnet,
}: {
tonAddress: string;
- tonNetwork?: TonNetwork;
+ tonNetwork?: Environment;
// address: string
}) => {
const { handleSetTonAmountsCache } = useTokenActions();
@@ -332,7 +308,7 @@ export const useLoadTonBalance = ({
const loadTonBalance = (
dispatch: (amount: AmountDetails) => void,
address: string,
- tonNetwork: TonNetwork = TonNetwork.Mainnet
+ tonNetwork: Environment = Environment.Mainnet
) => {
return {};
};
@@ -340,8 +316,6 @@ const loadTonBalance = (
export const useLoadToken = () => {
const amounts = useAmountsCache();
const { handleSetAmountsCache, handleSetTonAmountsCache } = useTokenActions();
- // const oraiAddress = useAuthOraiAddress();
- // const tonAddress = useAuthTonAddress();
const loadToken = ({
oraiAddress,
@@ -355,7 +329,10 @@ export const useLoadToken = () => {
loadNativeBalance(
(amounts) => handleSetAmountsCache(amounts),
oraiAddress,
- { chainId: network.chainId, rpc: network.rpc }
+ {
+ chainId: getNetworkConfig(env).chainId,
+ rpc: getNetworkConfig(env).rpc,
+ }
);
loadCw20Balance((amounts) => handleSetAmountsCache(amounts), oraiAddress);
}
@@ -366,6 +343,8 @@ export const useLoadToken = () => {
);
for (const chainInfo of cosmosInfos) {
+ console.log("chainInfo", chainInfo);
+
loadNativeBalance(
(amounts) => handleSetAmountsCache(amounts),
cosmosAddress,
@@ -373,13 +352,6 @@ export const useLoadToken = () => {
);
}
}
-
- // if (tonAddress) {
- // loadTonBalance(
- // (amounts) => handleSetTonAmountsCache(amounts),
- // oraiAddress
- // );
- // }
};
return {
diff --git a/libs/bitcoin.ts b/libs/bitcoin.ts
index 9110177..f5c832c 100644
--- a/libs/bitcoin.ts
+++ b/libs/bitcoin.ts
@@ -1,6 +1,6 @@
import { Key } from "@keplr-wallet/types";
-import { network } from "@/constants/networks";
+import { getNetworkConfig } from "@/constants/networks";
import { bitcoinChainId } from "@/helper/constants";
export type BitcoinMode = "core" | "extension" | "mobile-web" | "walletconnect";
// import { CosmosChainId, BitcoinWallet } from '@oraichain/oraidex-common';
@@ -25,9 +25,9 @@ export interface IBitcoin {
export default class Bitcoin {
constructor() {}
disconnect() {}
- async getBitcoinKey(chainId?: string): Promise {
+ async getBitcoinKey(chainId: string = "Oraichain"): Promise {
try {
- chainId = chainId ?? network.chainId;
+ chainId = chainId;
if (!chainId) return undefined;
if (!window.owallet) {
diff --git a/libs/cosmjs.ts b/libs/cosmjs.ts
index d650c7d..45b969b 100644
--- a/libs/cosmjs.ts
+++ b/libs/cosmjs.ts
@@ -4,31 +4,41 @@ import { OfflineSigner } from "@cosmjs/proto-signing";
import { Coin, GasPrice } from "@cosmjs/stargate";
import { Tendermint37Client } from "@cosmjs/tendermint-rpc";
import { Stargate } from "@injectivelabs/sdk-ts";
-import { network } from "@/constants/networks";
+import { getNetworkConfig } from "@/constants/networks";
import { MetamaskOfflineSigner } from "./eip191";
import { getWalletByNetworkCosmosFromStorage } from "@/helper";
+import { Environment } from "@/constants/ton";
export type clientType = "cosmwasm" | "injective";
const collectWallet = async (chainId: string) => {
const keplr = await window.Keplr.getKeplr();
if (keplr) return await keplr.getOfflineSignerAuto(chainId);
if (window.ethereum)
- return await MetamaskOfflineSigner.connect(window.ethereum, network.denom);
+ return await MetamaskOfflineSigner.connect(window.ethereum, "orai");
throw new Error(
"You have to install Cosmos wallet first if you do not use a mnemonic to sign transactions"
);
};
const getCosmWasmClient = async (
- config: { signer?: OfflineSigner; chainId?: string; rpc?: string },
+ config: {
+ signer?: OfflineSigner;
+ chainId?: string;
+ rpc?: string;
+ env?: Environment;
+ },
options?: cosmwasm.SigningCosmWasmClientOptions
) => {
try {
- const { chainId, rpc, signer } = config;
+ const { chainId, rpc, signer, env } = config;
+ if (!rpc && !env) {
+ throw new Error("Rpc or env must be provided");
+ }
const wallet = signer ?? (await collectWallet(chainId));
const defaultAddress = (await wallet.getAccounts())[0];
+
const tmClient = await Tendermint37Client.connect(
- rpc ?? (network.rpc as string)
+ rpc ?? getNetworkConfig(env).rpc
);
const client = await cosmwasm.SigningCosmWasmClient.createWithSigner(
tmClient,
@@ -36,7 +46,9 @@ const getCosmWasmClient = async (
options
? { ...options, broadcastPollIntervalMs: 600 }
: {
- gasPrice: GasPrice.fromString(network.fee.gasPrice + network.denom),
+ gasPrice: GasPrice.fromString(
+ getNetworkConfig(env).fee.gasPrice + getNetworkConfig(env).denom
+ ),
broadcastPollIntervalMs: 600,
}
);
@@ -84,7 +96,7 @@ class CosmJs {
const walletType = this.getWalletByFromStorage();
const keplr = await window.Keplr.getKeplr();
if (keplr || (walletType && walletType === "eip191")) {
- await window.Keplr.suggestChain(network.chainId);
+ await window.Keplr.suggestChain("Oraichain");
const result = await window.client.execute(
data.walletAddr,
data.address,
@@ -115,7 +127,7 @@ class CosmJs {
const walletType = this.getWalletByFromStorage();
const keplr = await window.Keplr.getKeplr();
if (keplr || (walletType && walletType === "eip191")) {
- await window.Keplr.suggestChain(network.chainId);
+ await window.Keplr.suggestChain("Oraichain");
const result = await window.client.executeMultiple(
data.walletAddr,
data.msgs,
diff --git a/libs/eip191.ts b/libs/eip191.ts
index 9669e65..d90161e 100644
--- a/libs/eip191.ts
+++ b/libs/eip191.ts
@@ -79,20 +79,15 @@ export class MetamaskOfflineSigner implements OfflineAminoSigner {
try {
const result = localStorage.getItem(EIP_EIP_STORAGE_KEY_ACC);
const parsedResult = JSON.parse(result);
- return (
- {
- ...parsedResult,
- accounts: [
- {
- ...parsedResult.accounts[0],
- pubkey: this.stringToUint8Array(parsedResult.accounts[0].pubkey),
- },
- ],
- } ?? {
- accounts: [],
- cosmosToEvm: {},
- }
- );
+ return {
+ ...parsedResult,
+ accounts: [
+ {
+ ...parsedResult.accounts[0],
+ pubkey: this.stringToUint8Array(parsedResult.accounts[0].pubkey),
+ },
+ ],
+ };
} catch (error) {
console.log("error getAccountFromStorage: ", error);
return { accounts: [], cosmosToEvm: {} };
diff --git a/libs/keplr.ts b/libs/keplr.ts
index 7f4252c..592567c 100644
--- a/libs/keplr.ts
+++ b/libs/keplr.ts
@@ -15,7 +15,7 @@ import {
import { isMobile } from "@walletconnect/browser-utils";
// import { displayToast, TToastType } from 'components/Toasts/Toast';
import { chainInfos, OraiBTCBridgeNetwork } from "@/constants/chainInfo";
-import { network } from "@/constants/networks";
+import { getNetworkConfig } from "@/constants/networks";
import { getAddress, getAddressByEIP191 } from "@/helper";
import { EIP_EIP_STORAGE_KEY_ACC, MetamaskOfflineSigner } from "./eip191";
import { displayToast, TToastType } from "@/contexts/toasts/Toast";
@@ -25,10 +25,7 @@ export default class Keplr extends CosmosWallet {
const keplr = await this.getKeplr();
if (keplr) return await keplr.getOfflineSignerAuto(chainId);
if (window.ethereum)
- return await MetamaskOfflineSigner.connect(
- window.ethereum,
- network.denom
- );
+ return await MetamaskOfflineSigner.connect(window.ethereum, "orai");
throw new Error(
"You have to install Cosmos wallet first if you do not use a mnemonic to sign transactions"
);
@@ -142,9 +139,9 @@ export default class Keplr extends CosmosWallet {
});
}
- async getKeplrKey(chainId?: string): Promise {
+ async getKeplrKey(chainId: string): Promise {
try {
- chainId = chainId ?? network.chainId;
+ chainId = chainId;
if (!chainId) return undefined;
const keplr = await this.getKeplr();
@@ -159,9 +156,11 @@ export default class Keplr extends CosmosWallet {
}
}
- async getKeplrAddr(chainId?: NetworkChainId): Promise {
+ async getKeplrAddr(
+ chainId: NetworkChainId = "Oraichain"
+ ): Promise {
// not support network.chainId (Oraichain)
- chainId = chainId ?? network.chainId;
+ chainId = chainId;
try {
if (this.typeWallet === ("eip191" as any)) {
// TODO: cache if type wallet is eip191 ( metamask cosmos )
diff --git a/libs/nomic/models/nomic-client/nomic-client.ts b/libs/nomic/models/nomic-client/nomic-client.ts
index c3b272d..89f300f 100644
--- a/libs/nomic/models/nomic-client/nomic-client.ts
+++ b/libs/nomic/models/nomic-client/nomic-client.ts
@@ -68,7 +68,7 @@ export class NomicClient implements NomicClientInterface {
// @ts-ignore-check
await window.Keplr.suggestChain(Config.chainId);
const sender = await window.Keplr.getKeplrAddr(Config.chainId as any);
- const receiver = await window.Keplr.getKeplrAddr();
+ const receiver = await window.Keplr.getKeplrAddr("Oraichain");
if (!sender || !receiver) {
return;
}
diff --git a/libs/utils.ts b/libs/utils.ts
index 1d9c651..26a524c 100644
--- a/libs/utils.ts
+++ b/libs/utils.ts
@@ -1,10 +1,10 @@
import { cosmosTokens, tokenMap } from "@/constants/bridgeTokens";
import { chainInfos } from "@/constants/chainInfo";
-import { network } from "@/constants/networks";
+import { getNetworkConfig } from "@/constants/networks";
+import { Environment } from "@/constants/ton";
import { CoinGeckoPrices } from "@/hooks/useCoingecko";
import { getCosmWasmClient } from "@/libs/cosmjs";
import {
- COSMOS_CHAIN_ID_COMMON,
NetworkChainId,
TokenItemType,
getSubAmountDetails,
@@ -254,14 +254,18 @@ export const initEthereum = async () => {
}
};
-export const initClient = async () => {
+export const initClient = async (env: Environment = Environment.Mainnet) => {
try {
- // suggest our chain
- const arrChainIds = [network.chainId] as NetworkChainId[];
+ const chainId = getNetworkConfig(env).chainId;
+ console.log({ chainId });
+ const arrChainIds = [chainId] as NetworkChainId[];
for (const chainId of arrChainIds) {
await window.Keplr.suggestChain(chainId);
}
- const { client } = await getCosmWasmClient({ chainId: network.chainId });
+ const { client } = await getCosmWasmClient({
+ chainId: chainId,
+ env,
+ });
window.client = client;
} catch (ex) {
console.log({ errorInitClient: ex });