Skip to content

Commit

Permalink
fix: load token
Browse files Browse the repository at this point in the history
  • Loading branch information
quangdz1704 committed Sep 5, 2024
1 parent 0c44e2b commit bfff7aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
2 changes: 1 addition & 1 deletion components/page/bridge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const Bridge = () => {
const tonAddress = useAuthTonAddress();
const [tonConnectUI] = useTonConnectUI();
const [txtSearch, setTxtSearch] = useState<string>();
const tonNetwork = Environment.Staging;
const tonNetwork = process.env.NEXT_PUBLIC_ENV as Environment;

const { loadToken } = useLoadToken();
const { loadAllBalanceTonToken } = useLoadTonBalance({
Expand Down
1 change: 1 addition & 0 deletions contexts/app-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export const AppProvider = (props: React.PropsWithChildren<{}>) => {
useEffect(() => {
if (oraiAddress) {
const cosmosAddress = getAddressCosmos(oraiAddress);
console.log("first", cosmosAddress);
loadToken({
oraiAddress,
cosmosAddress,
Expand Down
41 changes: 14 additions & 27 deletions hooks/useLoadToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { chainInfos } from "@/constants/chainInfo";
import { Environment } from "@/constants/ton";
import { TON_ZERO_ADDRESS, TonTokensContract } from "@/constants/contract";
import { getNetworkConfig } from "@/constants/networks";
import { OsmosisTokenList, TonTokenList } from "@/constants/tokens";
import {
OsmosisTokenDenom,
OsmosisTokenList,
TonTokenList,
} from "@/constants/tokens";
import { genAddressCosmos, handleCheckWallet } from "@/helper";
import { useAmountsCache, useTokenActions } from "@/stores/token/selector";
import { fromBinary, toBinary } from "@cosmjs/cosmwasm-stargate";
Expand Down Expand Up @@ -44,7 +48,13 @@ async function loadNativeBalance(
});

const tokensAmount = amountAll
.filter((coin) => tokenMap[coin.denom])
.filter(
(coin) =>
tokenMap[coin.denom] ||
[...Object.values(OsmosisTokenDenom[Environment.Staging])].includes(
coin.denom
)
)
.map((coin) => [coin.denom, coin.amount]);
Object.assign(amountDetails, Object.fromEntries(tokensAmount));

Expand All @@ -55,31 +65,6 @@ async function loadNativeBalance(
}
}

async function loadTokensCosmos(
dispatch: (amount: AmountDetails) => void,
kwtAddress: string,
oraiAddress: string
) {
if (!kwtAddress && !oraiAddress) return;
await handleCheckWallet();
const cosmosInfos = chainInfos.filter(
(chainInfo) =>
(chainInfo.networkType === "cosmos" ||
chainInfo.bip44.coinType === 118) &&
// TODO: ignore oraibtc
chainInfo.chainId !== ("oraibtc-mainnet-1" as string)
);
for (const chainInfo of cosmosInfos) {
const { cosmosAddress } = genAddressCosmos(
chainInfo,
kwtAddress,
oraiAddress
);
if (!cosmosAddress) continue;
loadNativeBalance(dispatch, cosmosAddress, chainInfo);
}
}

async function loadCw20Balance(
dispatch: (amount: AmountDetails) => void,
address: string
Expand Down Expand Up @@ -358,6 +343,8 @@ export const useLoadToken = () => {
);

for (const chainInfo of cosmosInfos) {
console.log("chainInfo", chainInfo);

loadNativeBalance(
(amounts) => handleSetAmountsCache(amounts),
cosmosAddress,
Expand Down

0 comments on commit bfff7aa

Please sign in to comment.