Skip to content

Commit

Permalink
check tonAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
tubackkhoa committed Jul 16, 2024
1 parent fba9079 commit 1f2a7dd
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions hooks/useLoadToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export const useLoadTonBalance = ({
}
};

const loadAllBalanceTonToken = async () => {
const loadAllBalanceTonToken = async (address: Address) => {
// if (!address) return;
const allTokens = Object.values(TonTokensContract[tonNetwork]);

Expand All @@ -232,7 +232,7 @@ export const useLoadTonBalance = ({
});

if (!item) {
const balance = await client.getBalance(Address.parse(tonAddress));
const balance = await client.getBalance(address);

return {
balance: balance,
Expand All @@ -242,7 +242,7 @@ export const useLoadTonBalance = ({
}
const jettonMinter = JettonMinter.createFromAddress(Address.parse(item));
const jettonMinterContract = client.open(jettonMinter);
const jettonWalletAddress = await jettonMinterContract.getWalletAddress(Address.parse(tonAddress));
const jettonWalletAddress = await jettonMinterContract.getWalletAddress(address);
const jettonWallet = JettonWallet.createFromAddress(jettonWalletAddress);
const jettonWalletContract = client.open(jettonWallet);
const balance = await jettonWalletContract.getBalance();
Expand Down Expand Up @@ -274,7 +274,13 @@ export const useLoadTonBalance = ({

// @dev: this function will changed based on token minter address (which is USDT, USDC, bla bla bla)
useEffect(() => {
if (tonAddress) loadAllBalanceTonToken();
if (!tonAddress) return;
try {
const address = Address.parse(tonAddress);
loadAllBalanceTonToken(address);
} catch (ex) {
console.log(ex);
}
}, [tonAddress, tonNetwork]);

return {
Expand Down

0 comments on commit 1f2a7dd

Please sign in to comment.