Skip to content

Commit

Permalink
Merge pull request #16 from oraichain/feat/usdc
Browse files Browse the repository at this point in the history
Feat/usdc
  • Loading branch information
perfogic authored Sep 9, 2024
2 parents a298c73 + 823b6a0 commit b19eb02
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
9 changes: 4 additions & 5 deletions helper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,13 @@ export const retryOrbs = async (fn, retryTimes = 30, delay = 2000) => {
} catch (error) {
let response = error?.response;
let message = response?.data?.error;
if (retryTimes <= 0) {
return;
}
if (message?.includes("No working liteservers")) {
await sleep(delay * 2);
return await retryOrbs(fn, retryTimes, delay);
}
await sleep(delay * 5);
return await retryOrbs(fn, retryTimes - 1, delay);
if (retryTimes > 0) {
await sleep(delay * 5);
return await retryOrbs(fn, retryTimes - 1, delay);
}
}
};
44 changes: 22 additions & 22 deletions hooks/useLoadToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ export const useLoadTonBalance = ({
const loadAllBalanceTonToken = async () => {
if (!tonAddress) return;

await retryOrbs(async () => {
const allTokens = Object.values(TonTokensContract[tonNetwork]);
const endpoint = await getHttpEndpoint();
const client = new TonClient({
endpoint,
});
const allTokens = Object.values(TonTokensContract[tonNetwork]);
const endpoint = await getHttpEndpoint();
const client = new TonClient({
endpoint,
});

const fullData = await Promise.all(
allTokens.map(async (item) => {
const fullData = await Promise.all(
allTokens.map(async (item) => {
return retryOrbs(async () => {
if (item === TON_ZERO_ADDRESS) {
// native token: TON
const balance = await client.getBalance(Address.parse(tonAddress));
Expand Down Expand Up @@ -267,23 +267,23 @@ export const useLoadTonBalance = ({
jettonWalletAddress,
token: item,
};
})
);

let amountDetail: AmountDetails = {};
fullData?.map((data) => {
const token = TonTokenList(tonNetwork).find(
(e) => e.contractAddress === data.token
);
});
})
);

amountDetail = {
...amountDetail,
[token?.denom]: (data.balance || "0").toString(),
};
});
let amountDetail: AmountDetails = {};
fullData?.map((data) => {
const token = TonTokenList(tonNetwork).find(
(e) => e.contractAddress === data.token
);

handleSetTonAmountsCache(amountDetail);
amountDetail = {
...amountDetail,
[token?.denom]: (data.balance || "0").toString(),
};
});

handleSetTonAmountsCache(amountDetail);
};

// @dev: this function will changed based on token minter address (which is USDT, USDC, bla bla bla)
Expand Down
28 changes: 14 additions & 14 deletions hooks/useLoadWalletsTon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ export const useLoadWalletsTon = ({
const { handleSetWalletsTonCache } = useTokenActions();

const loadWalletsTon = async () => {
await retryOrbs(async () => {
let tokenOnTons = TonTokenList(tonNetwork);
let tokenOnTons = TonTokenList(tonNetwork);

let walletsTon = {};
for (const tokenOnTon of tokenOnTons) {
if (tokenOnTon.contractAddress == TON_ZERO_ADDRESS) {
walletsTon = {
...walletsTon,
[tokenOnTon.denom]: TON_ZERO_ADDRESS,
};
continue;
}
let walletsTon = {};
for (const tokenOnTon of tokenOnTons) {
if (tokenOnTon.contractAddress == TON_ZERO_ADDRESS) {
walletsTon = {
...walletsTon,
[tokenOnTon.denom]: TON_ZERO_ADDRESS,
};
continue;
}

await retryOrbs(async () => {
const endpoint = await getHttpEndpoint();
const client = new TonClient({
endpoint,
Expand All @@ -45,9 +45,9 @@ export const useLoadWalletsTon = ({
...walletsTon,
[tokenOnTon.denom]: jettonWalletAddress.toString(),
};
}
handleSetWalletsTonCache(walletsTon);
});
});
}
handleSetWalletsTonCache(walletsTon);
};

useEffect(() => {
Expand Down

0 comments on commit b19eb02

Please sign in to comment.