Skip to content

Commit

Permalink
use provider instead of wallet provider
Browse files Browse the repository at this point in the history
  • Loading branch information
notV4l committed Aug 29, 2024
1 parent 9e23c83 commit 386db41
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/keychain/src/components/Funding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,14 @@ function useTokens() {
const checkFunds = useCallback(async () => {
setIsFetching(true);

const checked = await updateBalance(tokens, controller.account as Account);
const checked = await updateBalance(tokens, controller.account.rpc, controller.address );
setTokens(checked);

setIsFetching(false);
if (!isChecked) {
setIsChecked(true);
}
}, [tokens, controller.account, isChecked]);
}, [tokens, controller, isChecked]);

useInterval(checkFunds, 3000);

Expand Down
7 changes: 4 additions & 3 deletions packages/keychain/src/components/connect/SignupArgent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import {
useAccount,
useConnect,
useInjectedConnectors,
useProvider,
voyager,
} from "@starknet-react/core";
import {
Account,
CallData,
RpcProvider,
cairo,
Expand Down Expand Up @@ -365,6 +365,7 @@ function ExternalWalletProvider({ children }: PropsWithChildren) {

function useTokens() {
const { account: extAccount } = useAccount();
const { provider } = useProvider();
const { controller, prefunds } = useConnection();
const [tokens, setTokens] = useState<TokenInfo[]>([]);
const [isChecked, setIsChecked] = useState(false);
Expand All @@ -379,14 +380,14 @@ function useTokens() {
const checkFunds = useCallback(async () => {
setIsFetching(true);

const checked = await updateBalance(tokens, extAccount as Account);
const checked = await updateBalance(tokens, provider, extAccount?.address);
setTokens(checked);

setIsFetching(false);
if (!isChecked) {
setIsChecked(true);
}
}, [tokens, controller, isChecked, extAccount]);
}, [tokens, controller, isChecked, extAccount?.address]);

useInterval(checkFunds, 3000);

Expand Down
11 changes: 6 additions & 5 deletions packages/keychain/src/utils/token.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EthereumIcon } from "@cartridge/ui";
import { Image } from "@chakra-ui/react";
import { formatEther } from "viem";
import { formatAddress } from "./contracts";
import { Account, uint256 } from "starknet";
import { ProviderInterface, uint256 } from "starknet";

export const ETH_CONTRACT_ADDRESS =
"0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
Expand Down Expand Up @@ -65,16 +65,17 @@ export async function fetchTokenInfo(prefunds: Prefund[]) {
return tokens;
}

export async function updateBalance(tokens: TokenInfo[], account: Account) {
if (!account) return tokens;
export async function updateBalance(tokens: TokenInfo[], provider: ProviderInterface, address: string) {
if (!provider) return tokens;

const res = await Promise.allSettled(
tokens.map(async (t) => {
try {
let balance = await account.callContract({

let balance = await provider.callContract({
contractAddress: t.address,
entrypoint: "balanceOf",
calldata: [account.address],
calldata: [address],
});

/* @ts-ignore */
Expand Down

0 comments on commit 386db41

Please sign in to comment.