From 41b3eab9b81444e436c374246cea004e36413c6b Mon Sep 17 00:00:00 2001 From: perfogic Date: Tue, 10 Sep 2024 17:17:28 +0700 Subject: [PATCH] fix: update rpc for ton --- components/page/bridge/index.tsx | 12 ++++++------ helper/index.tsx | 11 +++++++++++ hooks/useLoadToken.ts | 18 ++++++++---------- hooks/useLoadWalletsTon.ts | 9 +++------ 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/components/page/bridge/index.tsx b/components/page/bridge/index.tsx index 7076fba..7d15c26 100644 --- a/components/page/bridge/index.tsx +++ b/components/page/bridge/index.tsx @@ -19,7 +19,11 @@ import { TonTokenList, } from "@/constants/tokens"; import { TToastType, displayToast } from "@/contexts/toasts/Toast"; -import { getTransactionUrl, handleErrorTransaction } from "@/helper"; +import { + getTonClient, + getTransactionUrl, + handleErrorTransaction, +} from "@/helper"; import { useLoadToken, useLoadTonBalance } from "@/hooks/useLoadToken"; import { useAuthOraiAddress, @@ -44,7 +48,6 @@ import { JettonWallet, } from "@oraichain/ton-bridge-contracts"; import { TonbridgeBridgeClient } from "@oraichain/tonbridge-contracts-sdk"; -import { getHttpEndpoint } from "@orbs-network/ton-access"; import { Address, Cell, beginCell, toNano } from "@ton/core"; import { TonClient } from "@ton/ton"; import { Base64 } from "@tonconnect/protocol"; @@ -176,10 +179,7 @@ const Bridge = () => { const handleCheckBalanceBridgeOfTonNetwork = async (token: TokenType) => { try { // get the decentralized RPC endpoint - const endpoint = await getHttpEndpoint(); - const client = new TonClient({ - endpoint, - }); + const client = getTonClient(); const bridgeAdapter = TonInteractionContract[tonNetwork].bridgeAdapter; if (token.contractAddress === TON_ZERO_ADDRESS) { diff --git a/helper/index.tsx b/helper/index.tsx index b00e49f..a0f52b9 100644 --- a/helper/index.tsx +++ b/helper/index.tsx @@ -36,6 +36,8 @@ import { } from "@/stores/authentication/useAuthenticationStore"; import { Environment } from "@/constants/ton"; import { Jersey_10 } from "next/font/google"; +import { TonClient } from "@ton/ton"; +import { getHttpEndpoint, getHttpEndpoints } from "@orbs-network/ton-access"; export interface Tokens { denom?: string; @@ -657,3 +659,12 @@ export const retryOrbs = async (fn, retryTimes = 30, delay = 2000) => { } } }; + +export const getTonClient = () => { + const endpoint = + "https://ton.access.orbs.network/55013c0ff5Bd3F8B62C092Ab4D238bEE463E5501/1/mainnet/toncenter-api-v2/jsonRPC"; + const client = new TonClient({ + endpoint, + }); + return client; +}; diff --git a/hooks/useLoadToken.ts b/hooks/useLoadToken.ts index 44cf34e..f170561 100644 --- a/hooks/useLoadToken.ts +++ b/hooks/useLoadToken.ts @@ -14,7 +14,12 @@ import { OsmosisTokenList, TonTokenList, } from "@/constants/tokens"; -import { genAddressCosmos, handleCheckWallet, retryOrbs } from "@/helper"; +import { + genAddressCosmos, + getTonClient, + handleCheckWallet, + retryOrbs, +} from "@/helper"; import { useAmountsCache, useTokenActions } from "@/stores/token/selector"; import { fromBinary, toBinary } from "@cosmjs/cosmwasm-stargate"; import { StargateClient } from "@cosmjs/stargate"; @@ -23,7 +28,6 @@ import { OraiswapTokenTypes } from "@oraichain/oraidex-contracts-sdk"; import { useEffect } from "react"; 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"; @@ -179,10 +183,7 @@ export const useLoadTonBalance = ({ const loadBalanceByToken = async (address?: string) => { try { // get the decentralized RPC endpoint - const endpoint = await getHttpEndpoint(); - const client = new TonClient({ - endpoint, - }); + const client = getTonClient(); if (address === TON_ZERO_ADDRESS) { const balance = await client.getBalance(Address.parse(tonAddress)); @@ -227,10 +228,7 @@ export const useLoadTonBalance = ({ if (!tonAddress) return; const allTokens = Object.values(TonTokensContract[tonNetwork]); - const endpoint = await getHttpEndpoint(); - const client = new TonClient({ - endpoint, - }); + const client = getTonClient(); const fullData = await Promise.all( allTokens.map(async (item) => { diff --git a/hooks/useLoadWalletsTon.ts b/hooks/useLoadWalletsTon.ts index acdf30a..7406ff7 100644 --- a/hooks/useLoadWalletsTon.ts +++ b/hooks/useLoadWalletsTon.ts @@ -1,10 +1,9 @@ import { TON_ZERO_ADDRESS, TonInteractionContract } from "@/constants/contract"; import { TonTokenList } from "@/constants/tokens"; import { Environment } from "@/constants/ton"; -import { retryOrbs } from "@/helper"; +import { getTonClient, retryOrbs } from "@/helper"; import { useTokenActions } from "@/stores/token/selector"; import { JettonMinter } from "@oraichain/ton-bridge-contracts"; -import { getHttpEndpoint } from "@orbs-network/ton-access"; import { Address, TonClient } from "@ton/ton"; import { useEffect } from "react"; @@ -30,10 +29,8 @@ export const useLoadWalletsTon = ({ } await retryOrbs(async () => { - const endpoint = await getHttpEndpoint(); - const client = new TonClient({ - endpoint, - }); + const client = getTonClient(); + const jettonMinter = JettonMinter.createFromAddress( Address.parse(tokenOnTon.contractAddress) );