Skip to content

Commit

Permalink
Merge pull request #17 from oraichain/feat/usdc
Browse files Browse the repository at this point in the history
fix: update rpc for ton
  • Loading branch information
perfogic authored Sep 10, 2024
2 parents b19eb02 + 41b3eab commit aa9733d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
12 changes: 6 additions & 6 deletions components/page/bridge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions helper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
18 changes: 8 additions & 10 deletions hooks/useLoadToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";

Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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) => {
Expand Down
9 changes: 3 additions & 6 deletions hooks/useLoadWalletsTon.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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)
);
Expand Down

0 comments on commit aa9733d

Please sign in to comment.