Skip to content

Commit

Permalink
Merge pull request #18 from oraichain/feat/usdc
Browse files Browse the repository at this point in the history
fix: update the way fetch ton clinet
  • Loading branch information
perfogic authored Sep 10, 2024
2 parents aa9733d + c8f8b6b commit de90fb7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion components/page/bridge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const Bridge = () => {
const handleCheckBalanceBridgeOfTonNetwork = async (token: TokenType) => {
try {
// get the decentralized RPC endpoint
const client = getTonClient();
const client = await getTonClient();
const bridgeAdapter = TonInteractionContract[tonNetwork].bridgeAdapter;

if (token.contractAddress === TON_ZERO_ADDRESS) {
Expand Down
22 changes: 15 additions & 7 deletions helper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -660,11 +660,19 @@ 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;
export const getTonClient = async () => {
try {
const endpoint = await getHttpEndpoint({
network: "mainnet",
});
const client = new TonClient({
endpoint,
});
return client;
} catch (err) {
return new TonClient({
endpoint:
"https://ton.access.orbs.network/55013c0ff5Bd3F8B62C092Ab4D238bEE463E5501/1/mainnet/toncenter-api-v2/jsonRPC",
});
}
};
4 changes: 2 additions & 2 deletions hooks/useLoadToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export const useLoadTonBalance = ({
const loadBalanceByToken = async (address?: string) => {
try {
// get the decentralized RPC endpoint
const client = getTonClient();
const client = await getTonClient();
if (address === TON_ZERO_ADDRESS) {
const balance = await client.getBalance(Address.parse(tonAddress));

Expand Down Expand Up @@ -228,7 +228,7 @@ export const useLoadTonBalance = ({
if (!tonAddress) return;

const allTokens = Object.values(TonTokensContract[tonNetwork]);
const client = getTonClient();
const client = await getTonClient();

const fullData = await Promise.all(
allTokens.map(async (item) => {
Expand Down
2 changes: 1 addition & 1 deletion hooks/useLoadWalletsTon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const useLoadWalletsTon = ({
}

await retryOrbs(async () => {
const client = getTonClient();
const client = await getTonClient();

const jettonMinter = JettonMinter.createFromAddress(
Address.parse(tokenOnTon.contractAddress)
Expand Down

0 comments on commit de90fb7

Please sign in to comment.