Skip to content

Commit

Permalink
fix: wrong usage of async function in inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
bojan07 committed Oct 21, 2023
1 parent 9ca03d6 commit ff34256
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions packages/dapp/components/layout/inventory.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Tippy from "@tippyjs/react";
import { BaseContract, BigNumber, ethers } from "ethers";
import { useEffect } from "react";
import { useState } from "react";
import useEffectAsync from "../lib/hooks/use-effect-async";

import useWeb3 from "@/lib/hooks/use-web-3";
import icons from "@/ui/icons";
Expand All @@ -17,8 +18,12 @@ const Inventory = () => {
const [balances, refreshBalances] = useBalances();
const protocolContracts = useProtocolContracts();
const namedContracts = useNamedContracts();
const [contracts, setContracts] = useState<ProtocolContracts>();

useEffectAsync(async () => {
const contract = await protocolContracts;
setContracts(contract);

useEffect(() => {
if (walletAddress) {
refreshBalances();
}
Expand Down Expand Up @@ -65,17 +70,14 @@ const Inventory = () => {
}

const balance = balances[key];
(async function () {
const contracts = await protocolContracts;
if (Number(balance) && contracts) {
let selectedContract = contracts[id as keyof ProtocolContracts] as BaseContract;
if (!selectedContract && namedContracts) {
selectedContract = namedContracts[key as keyof typeof namedContracts];
}

return <Token token={name} balance={balance} accountAddr={walletAddress as string} tokenAddr={selectedContract.address} decimals={usdcFix()} />;
if (Number(balance) && contracts) {
let selectedContract = contracts[id as keyof ProtocolContracts] as BaseContract;
if (!selectedContract && namedContracts) {
selectedContract = namedContracts[key as keyof typeof namedContracts];
}
})();

return <Token token={name} balance={balance} accountAddr={walletAddress as string} tokenAddr={selectedContract.address} decimals={usdcFix()} />;
}
}
};

Expand Down

0 comments on commit ff34256

Please sign in to comment.